Home Ffmpeg How To Zoom In And Zoom Out Videos Using FFmpeg

How To Zoom In And Zoom Out Videos Using FFmpeg

By sk
Published: Updated: 11.7K views

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
Find FPS value of a video using ffmpeg
Find FPS value of a video using ffmpeg

Here is the actual input video before conversion:

Input video

And, here is the converted (zoom-in-out) video:

Zoom In And Zoom Out Videos Using FFmpeg

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.

You May Also Like

1 comment

Jalal Hajigholamali August 29, 2021 - 11:11 am

Thanks a lot
very nice and useful article


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More