FFmpeg is an opensource, powerful audio and video converter. Using FFmpeg, we can encode, decode, transcode, mux, demux, record, resize, stream, filter, and play almost all type of media files. Not only that, we can also grab live audio/video stream as well. FFmpeg ships with a lots of filters to perform different tasks. One of the lesser known, yet useful filter is zoompan. Using zoompan filter, we can easily zoom in and zoom out videos in Linux. Let me show you how to do that using an example command.
Make sure you have installed FFmpeg on your Linux machine. We have documented the steps to install FFmpeg on popular Linux operating systems in the following link.
Once FFmpeg is installed, go to the location where you've saved the video and run the following command to zoom in and zoom out it every X seconds:
$ ffmpeg -i input.mp4 -vf "zoompan=z='if(lte(mod(time,10),3),2,1)':d=1:x=iw/2-(iw/zoom/2):y=ih/2-(ih/zoom/2):fps=30" output.mp4
The above command will zoom in toward the center of the video to 2x zoom for the first 3 seconds of every 10 second block of time. Replace
input.mp4 with your filename. Also adjust the values as per your requirement and set the FPS for the filter to match the input. The default value is 25.
You can find the FPS details among other details of a given video using the following command:
$ ffmpeg -i input.mp4
Here is the actual input video before conversion:
And, here is the converted (zoom-in-out) video:
Did you notice the difference? The video is zoomed in to 2X for the first 3 seconds and then it went back to normal (zoom out). At exactly 10th second, the video is again zoomed in for the first 3 seconds and the cycle continues till the video ends.
You can also try the following zoompan settings given in the FFmpeg zoompan filter help section.
Zoom in up to 1.5x and pan at same time to some spot near center of picture:
Zoom in up to 1.5x and pan always at center of picture:
Same as above but without pausing:
Zoom in 2x into center of picture only for the first second of the input video:
For more FFmpeg command examples, refer the following guide:
Hope this helps.
Thanks a lot
very nice and useful article