[FFmpeg-trac] #7787(documentation:new): Examples don't flush the decoder causing missing frames

FFmpeg trac at avcodec.org
Tue Mar 12 16:49:23 EET 2019

#7787: Examples don't flush the decoder causing missing frames
             Reporter:               |                     Type:  defect
  MichelRouzic                       |
               Status:  new          |                 Priority:  normal
            Component:               |                  Version:  git-
  documentation                      |  master
             Keywords:  examples     |               Blocked By:
  docs decoding                      |
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
 Summary of the bug: The examples in doc/examples don't use
 av_read_frame()'s return properly which can cause them to fail to decode
 the last few frames. In the case of transcoding.c breaking out of the loop
 when av_read_frame() returns negative thus stopping further decoding is at
     while (1) {
         if ((ret = av_read_frame(ifmt_ctx, &packet)) < 0)

 The decoder should be flushed which isn't being done here. It seems that
 all the examples are affected which is a serious problem for anyone (like
 me) trying to learn from them as it doesn't show us how to decode a stream

 How to reproduce:
 After building the examples, using this video with numbered frames
 https://photosounder.com/misc/drop_loop_300_frames_360p.mp4 as test input
 and running this:
 ./transcoding.exe drop_loop_300_frames_360p.mp4 transcoded.mp4
 we can see that there are two frames missing at the end of the output
 video. Using the output video as input creates another video with two more
 frames missing. I tried other input files like a 1080p YouTube MP4 and
 ffprobe reported one frame missing in transcoding.c's transcoded video, so
 this seems to be a pretty universal problem.

Ticket URL: <https://trac.ffmpeg.org/ticket/7787>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker

More information about the FFmpeg-trac mailing list