When writeffmpeg closes the output stream in end_ffmpeg, it doesn't write any delayed frames that may still be held by the encoder. As, for example, x264, outputs frames out of order:
alloc video stream 09D5EB90
Writing frame 1, render width=640, render height=480
Append frame 1 Time: 00:01.64
Writing frame 2, render width=640, render height=480
Append frame 2 Time: 00:01.64
Writing frame 3, render width=640, render height=480
Append frame 3 Time: 00:01.64
Writing frame 4, render width=640, render height=480
Append frame 4 Time: 00:01.64
Writing frame 5, render width=640, render height=480
Append frame 5 Time: 00:01.64
Writing frame 6, render width=640, render height=480
Video Frame PTS: 0 <---- Frame number output by ffmpeg
Append frame 6 Time: 00:01.64
Writing frame 7, render width=640, render height=480
Video Frame PTS: 3
Append frame 7 Time: 00:01.64
Writing frame 8, render width=640, render height=480
Video Frame PTS: 1
Append frame 8 Time: 00:01.64
Writing frame 9, render width=640, render height=480
Video Frame PTS: 2
Append frame 9 Time: 00:01.64
Writing frame 10, render width=640, render height=480
Video Frame PTS: 4
Append frame 10 Time: 00:01.64
Writing frame 11, render width=640, render height=480
Video Frame PTS: 7
Append frame 11 Time: 00:01.63
Writing frame 12, render width=640, render height=480
Video Frame PTS: 5
As can be seen, the frames output by ffmpeg are:
1. Delayed
2. Out of order
When end_ffmpeg closes the stream, the delayed frames never get written to the output stream, which results in the last 20 or so frames being dropped from the output.
The attached patch does two things:
1. Adds a flush_ffmpeg function that is called before the av_write_trailer function is called.
2. Fixes the ffmpeg x264 preset options. (see bug #20843)
Description
Description