4

I am using ffmpeg to turn a sequence of images (img001.png, img002.png, and so on) into a video (output.mp4) using the following command:

ffmpeg -r 1/5 -i img%03d.png  -r 25 -qscale:v 2 -shortest -codec:a copy output.mp4

The result is a video that displays every input image for five (5) seconds.

  1. Is it possible to have ffmpeg parse the filename paths and timings from a file? I tried the slideshow tutorial on the official ffmpeg website but the output displayed only the last image, briefly, at the end of the video.
  2. Is it possible to bundle audio files with those settings?

For example:

file 'image001.png'
file 'sound001.wav'
duration 5
file 'image002.png'
file 'sound002.wav'
duration 2
file 'image003.png'
file 'sound003.wav'
duration 3

Image001 is displayed for five(5) seconds while sound001 is being played back and so on.

1 Answer 1

6

The concat demuxer method in the slideshow tutorial is the way to do this. Did you repeat the last image entry once, as mentioned?

Concat demuxer text files specify serial inputs, so can't be used to specify paired or parallel inputs. However, you can always use two text files.

Text file for images:

file 'image001.png'
duration 5
file 'image002.png'
duration 2
file 'image003.png'
duration 3
file 'image003.png'

Text file for sounds:

file 'sound001.wav'
outpoint 5
file 'sound002.wav'
outpoint 2
file 'sound003.wav'
outpoint 3

(For video or audio files, inpoint/outpoint have to be specified to use a trimmed portion of the file)

And with both those files,

ffmpeg -f concat -i images.txt -f concat -i sounds.txt -r 25 -pix_fmt yuv420p out.mp4
5
  • Thank you very much. This works fine and I integrated it in a Java application I am writing. The only hick-up is that I get a weird error ("Unsafe file name") if I use an absolute path to one of the images/sounds instead of a relative one but I can live with it. :)
    – melanie93
    May 7, 2018 at 8:51
  • 1
    Change -f concat to -f concat -safe 0 to avoid that issue.
    – Gyan
    May 7, 2018 at 8:53
  • Oh good. That solved everything. I was chasing my tail for a moment there. xoxo
    – melanie93
    May 7, 2018 at 9:11
  • Thanks for the output, any chance we can have a fade effect between the pictures? Jan 13, 2022 at 10:00
  • This creates a corrupt mp4
    – jjxtra
    Mar 7 at 2:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .