[Libav-user] Misuse of av_read_frame()'s return in the examples

Michel Rouzic Michel0528 at yahoo.fr
Mon Mar 11 01:05:12 EET 2019


Most of the examples provided in doc/examples stop decoding when 
av_read_frame() returns a negative number, which can cause them to 
completely miss the last few frames of a video. I have verified that 
this is a problem with transcoding.c using this 300 frame video (with 
visually labelled frames for convenience) 
https://photosounder.com/misc/drop_loop_300_frames_360p.mp4 and by 
running `./transcoding.exe drop_loop_300_frames_360p.mp4 
transcoded.mp4`. In a properly-written video player the original video's 
last frame shows "299" as expected whereas the transcoding example 
claims that only 298 were transcoded and the transcoded video indeed 
shows the last frame as labelled "297". Transcoding the transcoded video 
outputs only 296 frames, doing that again outputs only 294 frames, and 
so on, so this is quite serious, and a quick `grep 'av_read_frame' *.c 
-C 3` in the examples folder seems to show that all the examples might 
be affected, so that would be great for everyone relying on the examples 
if this could be addressed.

I don't quite know how to fix this except that somehow some empty frames 
should be provided when av_read_frame() returns a negative value. FFplay 
does it properly (see line 3007 of fftools/ffplay.c) however its code 
lacks the genericness and clarity of the examples which makes it hard to 
learn how to change the examples or my own code from it.


More information about the Libav-user mailing list