[FFmpeg-user] Mpeg Encode returns zero for the first frame

Jorge Fonseca jcbfonseca at gmail.com
Wed Aug 15 15:00:45 CEST 2012


All,

Below the function related to write video frame..

Let me know if you have any suggestions...

------------

*static void write_video_frame() {*
    int out_size, ret;
    static struct SwsContext *img_convert_ctx;

    img_convert_ctx = sws_getContext(pCodec_ctx_output->width,
            pCodec_ctx_output->height, pCodecCtx_input->pix_fmt,
            pCodec_ctx_output->width, pCodec_ctx_output->height,
            pCodec_ctx_output->pix_fmt, sws_flags, NULL, NULL, NULL );

    if (img_convert_ctx == NULL ) {
        fprintf(stderr, "Cannot initialize the conversion context\n");
        exit(1);
    }

    sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize,
0,pCodec_ctx_output->height, tmp_picture->data, tmp_picture->linesize);

*    //All returns zero for the first frame*
    *out_size = avcodec_encode_video(pCodec_ctx_output, video_outbuf,
video_outbuf_size, tmp_picture);*

        if(*out_size >0*) {
            AVPacket pkt;
            av_init_packet(&pkt);

            if (pCodec_ctx_output->coded_frame->pts != AV_NOPTS_VALUE)
                pkt.pts = av_rescale_q(pCodec_ctx_output->coded_frame->pts,
pCodec_ctx_output->time_base, video_st->time_base);
            if (pCodec_ctx_output->coded_frame->key_frame)
                pkt.flags |= AV_PKT_FLAG_KEY;

            pkt.stream_index = video_st->index;
            pkt.data = video_outbuf;
            pkt.size = out_size;

            /* Write the compressed frame to the media file. */
            ret = av_interleaved_write_frame(ctx_video, &pkt);

*    }
*
------------

Jorge

2012/8/14 Jorge Fonseca <jcbfonseca at gmail.com>

> Hi All,
>
> I trying to create a mpeg video following FFmpeg examples.
> Every time* "avcodec_encode_video"* returns ZERO only for the FIRST
> frame/packet.
>
> Consequently, after insert more frames i got "*Encode Buffer underflow*"
> in Encode function.
>
> ------------------------------------
> Does anyone know how MPEG encode works for the first frame? E why zero is
> return?
>
> PS. in this case, the outbut buffer was not filled.
>
> ------------------------------------
>
> Regards,
> Jorge.
>


More information about the ffmpeg-user mailing list