[Libav-user] flushing internal buffers using custom I/O

Hung Nguyen Hung.Nguyen at ambientdigitalgroup.com
Fri Apr 10 13:03:25 CEST 2015

From transcoding.c example, there’s a flush_encoder(int stream_index) example. 
It works by simply provides the decoder null packet, which was initialised likes this:

    AVPacket packet = {.data = NULL, .size = 0};

Then you create a flush_decoder(stream_index) function:
static int flush_decoder(unsigned int stream_index) {
    int ret;
    int got_frame;
    AVFrame *frame = NULL;
    AVPacket packet = {.data = NULL, .size = 0};

       if (!(ofmt_ctx->streams[stream_index]->codec->codec->capabilities &
            return 0;

    while (1) {
        frame = av_frame_alloc();
        ret = avcodec_decode_video2(ifmt_ctx->streams[stream_index]->codec, frame,
                &got_frame, &packet);
        if (ret < 0)
        if (!got_frame)
            return 0;
        av_log(NULL, AV_LOG_INFO, "Flushing stream #%u decoder\n", stream_index);
    return ret;
loop through the input AVFormatContext’s number streams, and flush all buffered frame. 

Hung Nguyen
hung.nguyen at ambientdigitalgroup.com

> On Apr 10, 2015, at 5:49 PM, Selmeci, Tamás <tselmeci at open-st.eu> wrote:
> On Fri, 2015-04-10 at 10:00 +0000, Hung Nguyen wrote:
>> How do you know they’re ‘incomplete-frame’? 
>> From my experience with ffmpeg, these frame can be buffered frame because of thread model of ffmpeg. If it’s is, what you should do is:
> I know all the frames in the new MPEG-TS, and the 'incomplete' frame
> doesn't look like any of them. It exactly looks like a frame from the
> old MPEG-TS, since it has a correct DTS, but the size is shrinked.
> Furthermore, after reading the incomplete frame(s), the correct frames
> from the new MPEG-TS appear. Therefore something remains in ffmpeg
> buffer I can't flush.
> -- 
> Selmeci Tamás
> http://www.open-st.eu/
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user

More information about the Libav-user mailing list