ffmpeg - how to create 5 second video zooming out effect with 1 image

You must first set the zoom factor, as by default it is set to 1.0. I was able to do so like this:

ffmpeg -loop 1 -i image_1.jpg -vf "zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125" -c:v libx264 -t 5 -s "800x450" zoomout.mp4

Which will start zoomed in at 1.5 and zoom out 0.0015 every iteration. Note the value 1.001 was used (any value larger than 1.0) to ensure it would not zoom out past 1.0 and reset to 1.5.

Another solution could have been to simply reverse the output of your original zoompan, but after a quick search into it, reversing video seems like a lot of effort in ffmpeg.


Calculate the z from the frame index (on) and the duration.

on/duration will get you a percent from 0-1 that grows each frame.

1.5-on/duration*0.5 Gives you a number from 1.5-1.

All together:

ffmpeg -loop 1 -i image1.jpg -vf "zoompan=z='1.5-on/duration*0.5':d=125" -c:v libx264 -t 5 -s "800x450" zoomin.mp4

Tags:

Ffmpeg

Video