FFmpeg Zoompan: Zoom to Specific Video Coordinates

This article explains how to use the FFmpeg zoompan filter to zoom into a specific X and Y coordinate on a video. You will learn the mathematical logic behind targeting precise coordinates, how to write the correct FFmpeg command for static zooms, and how to create a smooth, animated zoom effect targeting a specific point.

The Math Behind Zooming to a Coordinate

The zoompan filter works by cropping a portion of the input video and scaling it back up to the output resolution.

To zoom into a specific target coordinate \((T_x, T_y)\) on an input video, you cannot just set the filter’s x and y parameters to those exact coordinates. Instead, x and y define the top-left corner of the zoomed bounding box.

To center your zoom on target coordinates \((T_x, T_y)\), use the following formulas:

Where: * iw and ih are the input video width and height. * zoom is your desired zoom factor (e.g., 2 for 2x zoom).

Example 1: Static Zoom to a Specific Point

If you want to zoom in instantly by 2x and focus on the coordinates (500, 300) on a 1920x1080 video, use the following command:

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

Example 2: Smooth Animated Zoom to a Specific Point

To gradually zoom into the coordinates (500, 300) over a period of 150 frames, you must dynamically increase the zoom factor z using the frame counter variable on.

The following command gradually increases the zoom level from 1x to 2x, while dynamically adjusting the x and y parameters to keep the point (500, 300) perfectly centered:

ffmpeg -i input.mp4 -vf "zoompan=z='min(zoom+0.01,2)':x='500-(iw/(2*zoom))':y='300-(ih/(2*zoom))':d=150:s=1920x1080:fps=30" output.mp4

Key Parameter Breakdown