Jump to content

How To Zoom In And Zoom Out Videos Using FFmpeg


aum

Recommended Posts

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.

 

How To Install FFmpeg In Linux


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.p

Find FPS value of a video using ffmpeg

 

Here is the actual input video before conversion:

 

https://ostechnix.com/wp-content/uploads/2021/08/input.mp4

 

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

 

https://ostechnix.com/wp-content/uploads/2021/08/output.mp4

 

Output 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:

 

zoompan=z='min(zoom+0.0015,1.5)':d=700:x='if(gte(zoom,1.5),x,x+1/a)':y='if(gte(zoom,1.5),y,y+1)':s=640x360

 

Zoom in up to 1.5x and pan always at center of picture:

 

zoompan=z='min(zoom+0.0015,1.5)':d=700:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'

 

Same as above but without pausing:

 

zoompan=z='min(max(zoom,pzoom)+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'

 

Zoom in 2x into center of picture only for the first second of the input video:

 

zoompan=z='if(between(in_time,0,1),2,1)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'

 

 

For more FFmpeg command examples, refer the following guide:

 


Hope this helps.

 

Source

 

Link to comment
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...