Opened 6 years ago
#7787 new defect
Examples don't flush the decoder causing missing frames
Reported by: | Michel Rouzic | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | documentation |
Version: | git-master | Keywords: | examples docs decoding |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
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 fault:
while (1) { if ((ret = av_read_frame(ifmt_ctx, &packet)) < 0) break;
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 properly.
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.