Zoom into Specific Coordinates Using FFmpeg Zoompan

This guide explains how to use the FFmpeg zoompan filter to zoom into a specific X and Y coordinate on a video. You will learn the mathematics behind centering the zoom on your target coordinates, how to structure the FFmpeg command, and how to apply smooth transitions.

Understanding the Zoompan Coordinate System

The zoompan filter works by cropping a portion of the input video and scaling it back up to the output resolution. By default, the filter calculates the zoom from the top-left corner (0,0) of the video frame.

To zoom into a specific coordinate \((X_{target}, Y_{target})\), you must offset the crop window’s top-left corner (\(x\) and \(y\)) so that your target coordinate remains in the center of the zoomed area.

The formulas to center the zoom window on your target coordinates are:

Where: * iw and ih are the input video’s width and height. * zoom is the current zoom factor (e.g., 1.5, 2, or a dynamic variable).

The Basic FFmpeg Command

To zoom into a static target coordinate—for example, \(X=500\) and \(Y=300\) on a 1920x1080 video with a zoom factor of 2—use the following command:

ffmpeg -i input.mp4 -vf "zoompan=z='2':x='500-(iw/(2*zoom))':y='300-(ih/(2*zoom))':d=125:s=1920x1080" -c:v libx264 output.mp4

Parameter Breakdown:

Creating a Dynamic Zoom-In Effect

To create a smooth, gradual zoom-in effect towards a specific coordinate over time, change the zoom parameter z to increase incrementally on every frame.

The following command zooms in smoothly toward coordinate \((1200, 800)\) up to a maximum zoom of 1.5x:

ffmpeg -i input.mp4 -vf "zoompan=z='min(zoom+0.003,1.5)':x='1200-(iw/(2*zoom))':y='800-(ih/(2*zoom))':d=150:s=1920x1080" -c:v libx264 output.mp4

How the Dynamics Work: