How to Zoom into Coordinates Using FFmpeg Zoompan

This guide explains how to use FFmpeg's zoompan video filter to smoothly zoom into a designated set of coordinates (X, Y) on a video. By configuring the filter's zoom factor alongside horizontal and vertical offset expressions, you can center the camera viewport on any specific point of interest while controlling the speed and duration of the zoom.

The Coordinate Formula

The zoompan filter defines the viewport by its top-left corner (x, y) and its zoom factor z. When you zoom into an image, the visible area becomes smaller:

  • Visible width: iw / zoom (where iw is the input width)
  • Visible height: ih / zoom (where ih is the input height)

To center your target coordinate (X_target, Y_target) inside the viewport, subtract half of the visible area from the target position:

  • x = X_target - (iw / zoom / 2)
  • y = Y_target - (ih / zoom / 2)

Complete Command Example

Suppose you have a 1920x1080 video and want to zoom into the point X = 1200, Y = 400 up to a maximum 2x zoom over 150 frames (5 seconds at 30 fps):

ffmpeg -i input.mp4 -vf "zoompan=z='min(zoom+0.007,2.0)':x='1200-(iw/zoom/2)':y='400-(ih/zoom/2)':d=150:s=1920x1080:fps=30" -c:v libx264 -c:a copy output.mp4

Parameter Breakdown

  • z='min(zoom+0.007,2.0)': Controls the zoom progression. It starts at 1.0 (normal scale), increments by 0.007 per frame, and caps at a maximum scale of 2.0.
  • x='1200-(iw/zoom/2)': Adjusts the top-left X position per frame so that the horizontal center remains focused on X = 1200.
  • y='400-(ih/zoom/2)': Adjusts the top-left Y position per frame so that the vertical center remains focused on Y = 400.
  • d=150: Sets the duration of the zoom sequence in frames.
  • s=1920x1080: Explicitly sets the output resolution to prevent downscaling.
  • fps=30: Matches the frame rate of the filter output with the source file.

Preventing Out-of-Bounds Errors

If your target coordinate is too close to an edge, the calculated top-left coordinate might drop below 0 or push the crop window beyond the input width/height. You can clamp the values using the clip() function:

ffmpeg -i input.mp4 -vf "zoompan=z='min(zoom+0.007,2.0)':x='clip(1200-(iw/zoom/2), 0, iw-(iw/zoom))':y='clip(400-(ih/zoom/2), 0, ih-(ih/zoom))':d=150:s=1920x1080:fps=30" -c:v libx264 -c:a copy output.mp4

This prevents the viewport from moving outside the video dimensions while executing the zoom.