12

First, I have almost zero experience in making videos from images.

What I have is a set of BMP timestamped images from which I want to generate a video. Since the timestamps are not equally spaced, I cannot simply use software that create constant-frame-rate videos from images.

A possible solution would be to create artificial images at fixed time intervals, but I prefer to leave that as a last resort if I fail to make a VFR video.

Any suggestions on how to achieve what I want?

Beginner
  • 325
  • 5
  • 16
  • 1
    More recent answers to this question in [How do I render a video from a list of time-stamped images?](https://stackoverflow.com/q/25073292/1670156) and [Variable framerate with FFmpeg](https://superuser.com/q/1098282/416032). – Arnon Weinberg May 31 '22 at 04:35

3 Answers3

10

You can use a combination of two tools to do this: ffmpeg and mp4fpsmod

Step 1 is to generate a constant frame rate file using ffmpeg

ffmpeg -i images%d.bmp -pix_fmt yuv420p ffmpeg-cfr.mp4

Step 2 is to generate a timecode file like the one below, with each line containing the relative timestamp for a frame in milliseconds.

# timecode format v2

0
33
88
100
120
160
200
230
330
347

Step 3 is to use mp4fpsmod to generate the VFR file

mp4fpsmod -o vfr.mp4 -t timecodes.txt ffmpeg-cfr.mp4 

This file plays as expected with ffplay but may not with some players, in which case run

Step 4 Generate a CFR MP4 from the VFR using FFmpeg

ffmpeg -i vfr.mp4 final-cfr.mp4

This is a CFR file but the temporal relations are preserved as per the VFR, although there will be some PTS adjustments, if the timecode intervals are very irregular. That can be remedied by specifying a high framerate -r N

Gyan
  • 85,394
  • 9
  • 169
  • 201
0

Take a look at this link. http://avisynth.nl/index.php/VFR#encoding_to_vfr_.28mkv.29

It might be a little outdated now, as you now do the process of importing the timecode format file from mkvtoolnix (instead of mkvmerge), but it should let you do it.

Miguel
  • 64
  • 4
0

first make a input.txt file looking like

file '1.jpg'
duration 0.1
file '2.jpg'
duration 0.12
file '3.jpg'
duration 0.115

where duration is number of seconds each image should be displayed, in this example 1.jpg is displayed for 100 milliseconds (0.1 seconds), 2.jpg is displayed for 120 milliseconds (0.12 second) and 3.jpg is supposed to be displayed for 115 milliseconds (0.115 seconds)

then do

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

this works on all frames except the last frame, which will just be displayed for a fraction of a second regardless of duration specification. (i have no idea why ffmpeg fails on the last frame, perhaps it is a bug?)

Edit: seems like on Chrome it works correctly on all frames except the last frame. On VLC it works correctly on all frames except the last 2 frames? Well that is confusing.

hanshenrik
  • 19,904
  • 4
  • 43
  • 89
  • 1
    This is the slideshow method. Repeat the last entry to enact the final duration. See https://trac.ffmpeg.org/wiki/Slideshow#Concatdemuxer – Gyan Aug 28 '23 at 08:05