3

I'm going to make a video from series of screenshots (.png files). For each screenshot there is assosiated timestamp information about when it was taken. The time intervals between screenshots may vary and it's highly desired to preserve that difference in the video.

Is there a way to use single ffmpeg command/API providing to it sequence of image + time (or frame) offset and getting one video file as output? By now I have to generate short video files of custom length for each image, and then merge them manually:

ffmpeg -y -loop 1 -i image1.png -c:v libx264 -t 1.52 video1.avi
ffmpeg -y -loop 1 -i image2.png -c:v libx264 -t 2.28 video2.avi
...
ffmpeg -y -loop 1 -i imageN.png -c:v libx264 -t 1.04 videoN.avi


ffmpeg -i "concat:video1.avi|video2.avi|...videoN.avi" -c copy output.avi

This is quite ok, while intervals are large, but the whole approach seems to me a bit fragile.

2 Answers2

1

Use the concat demuxer.

enter image description here
Example using 2, 4, and 0.25 seconds.

  1. Make a text file indicating the desired duration per file:

    file 'image1.png'
    duration 1.52
    file 'image2.png'
    duration 2.28
    file 'image3.png'
    duration 1.04
    

    You may have to repeat the last file and duration lines to get it to display the last frame.

  2. Run the ffmpeg command:

    ffmpeg -f concat -i input.txt -c:v libx264 -pix_fmt yuv420p -movflags +faststart output.mp4
    
llogan
  • 121,796
  • 28
  • 232
  • 243
  • 1
    May you please explain the reason why last line should be repeated? Suppose I have one png file at all. I have to repeat it or otherwise the whole movie is black except for the first frame. This is really strange bahavior. – Maxim Kornienko Jun 02 '15 at 20:23
  • @MaximKornienko Can you show your command and complete console output? A link to a pastebin will be good. – llogan Jun 02 '15 at 21:25
  • I know I'm late to the party, but the reason for why the last frame has to be repeated is explained in the [docs](https://trac.ffmpeg.org/wiki/Slideshow): It's just a quirk of ffmpeg. – vatbub Jul 29 '22 at 07:18
-1

If you can sequence the images based on the timestamp value, and if the images are of the same size, then you can the below command to get the video:

ffmpeg -framerate X -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

Refer to the below url which gives you various command option to generate the video:

FFmpeg Wiki: Create a video slideshow from images

llogan
  • 121,796
  • 28
  • 232
  • 243
shri
  • 856
  • 1
  • 10
  • 26
  • 1
    Wouldn't that lead to all images having the same interval in the video? – Maxim Kornienko May 26 '15 at 11:32
  • yes since the frame rate will be based on the x value. but there is also another option provided. "ffmpeg also supports bash-style globbing (* represents any number of any characters). This is useful if your images are sequential but not necessarily in a numerically sequential order as in the previous examples." in that case may be you can try to give your input with out changing the sequence and try it. – shri May 26 '15 at 12:03