[FFmpeg-user] Revisit FFmpeg Frame Lost

Thilo Borgmann thilo.borgmann at googlemail.com
Sat Feb 16 09:34:22 CET 2013


> Sorry to bug all of you. This is actually a very old topic, but I still
> would like to mention it again.
> [...]
> As mentioned in *av_read_frame()* documentation,
> *For video, the packet contains * exactly one frame*
> [...]
> However,
> for .mpg, I got 267 images after decoding; (lack of 1 frame)
> for .mp4, I got 260 images after decoding (lack of 8 frames)

> It seems http://ffmpeg.org/doxygen/trunk/api-example_8c-source.html is able
> to handle the "frame lost" issue, but it uses* fread()* instead of *
> av_read_frame()*. If I insist on using *av_read_frame()*, how can I avoid
> this "frame lost" issue?

The difference is that the example calls avcodec_decode_video2() in a loop until
the frame is found which is also what I alway do:

    if (packet.stream_index == format_video_stream_idx) {
        got_frame = 0;

        while (!got_frame) {
            if ((ret = avcodec_decode_video2(codec_ctx, &frame, &got_frame,
&packet)) < 0) {
                return false;

Maybe you give it a try.


More information about the ffmpeg-user mailing list