Slideshow with ffmpeg results in stuttery, unseekable, incorrect length file

0

I'm using ffmpeg to show images for different durations in a video:

(command taken from example on this page)

ffmpeg -f concat -i input.txt -vsync vfr -pix_fmt yuv420p output.mp4

Here what input.txt roughly looks like:

file '/path/to/im1.png'
duration 123
file '/path/to/im2.png'
duration 234
file '/path/to/im3.png'
duration 235
file '/path/to/im4.png'
duration 400
file '/path/to/im4.png'

The resulting file has trouble playing back in mpv, Movies and TV (windows), and VLC. On a hunch, I ran the file through ffmpeg again to see I could 'fix' the output file (command used: ffmpeg -i in.mp4 out.mp4). out.mp4 was much larger than in.mp4 (around an order of magnitude), but played smoothly, showed progress correctly, and was able to seek properly. What could be the reason for this?

Matt M.

Posted 2020-02-14T22:56:46.963

Reputation: 163

Answers

1

With the -vsync vfr flag, ffmpeg will insert the images at time 0, 123, 357..etc with no frames in between. A video player normally works with streams where adjacent frames are centiseconds apart, so its buffering/caching system are designed with that expectation. You could get away with the VFR mode if durations were in the single-digit seconds, but not here. I would recommend CFR mode with a low frame rate.

So,

ffmpeg -f concat -i input.txt -vsync cfr -r 2 -pix_fmt yuv420p output.mp4

Gyan

Posted 2020-02-14T22:56:46.963

Reputation: 21 016

Ahh, so if I'm understanding correctly it's kinda the players faults for not handling this valid, but weird video? – Matt M. – 2020-02-15T06:40:35.510

You could say that, but fault is a harsh term. Any software will be designed for vanilla and common edge cases. – Gyan – 2020-02-15T06:44:44.340

Strangely enough, running my original command and then passing it through ffmpeg again is faster then just using -vsync cfr (around 4x faster) – Matt M. – 2020-02-15T06:46:20.240

Vsync cfr is default for mp4 output. The difference will be due to the framerate. – Gyan – 2020-02-15T07:08:45.640