0

I have 900 images:

  • 001.tif
  • 002.tif
  • 003.tif
  • ...
  • 900.tif

I use the following code to generate a video from these images:

ffmpeg -r 30 -start_number 1 -i %03d.tif -c:v libx264 -r 30 -pix_fmt yuv420p output.mp4

It works perfectly, but I also need to make another video that is slow (e.g. 5 fps) at the beginning and is gradually (e.g. 6, 7, 8, ... fps) speeding up to reach a very high speed (e.g. 90 fps). Each second of the video should have a different fps compared to the second before and the second after it, a totally gradual acceleration.

Can I do it with FFmpeg? If so, them how?

Siamak
  • 335
  • 1
  • 11
  • I’m voting to close this question because as the ffmpeg tag states: Only questions about programmatic use of the FFmpeg libraries, API, or tools are on topic. Questions about interactive use of the command line tool should be asked on https://superuser.com/ or https://video.stackexchange.com/. Please delete this. – Rob Aug 28 '23 at 22:20

1 Answers1

4

You can use the setpts filter to gradually change fps.

It's more helpful to think of this in terms of frame duration rather than fps, since that is what setpts can directly alter. A fps of 5 indicates a frame duration of 200 ms whereas a fps of 90 indicates a frame duration of 11 ms (after rounding). So, frame 0 starts at time 0 and has a duration of 200ms, so frame 1 shows at 200ms and has that timestamp. Frame 808 has a duration of 11ms. So for each frame, timestamp expr is 200ms-189ms*N/809 where N is frame index. Since we aren't reducing frame duration after 809, we have to clamp N to 809. 200ms-189ms*min(N,809)/809

Command then is

ffmpeg -start_number 1 -i %03d.tif -vf "settb=1/1000,setpts='if(eq(N,0),0,PREV_OUTPTS+200-189*(min(N,809)/809))'" -vsync vfr -enc_time_base 1/1000 -c:v libx264 -pix_fmt yuv420p output.mp4

The settb sets the timekeeping scale to 1 millisecond. As does enc_time_base for a different part of the processing pipeline.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • 1
    Thank you, @Gyan. It works. And your good explanation will allow me to change the code myself for my future jobs. – Siamak Apr 24 '20 at 21:43