Configure FFmpeg Zoompan Zoom, Pan, and Frames

This article provides a practical guide on how to configure the zoom expression, frame count, and coordinate panning using the FFmpeg zoompan filter. You will learn the core syntax, how to control zoom speed, how to calculate coordinates for smooth panning, and how to set the exact duration of the effect using frame counts.

The Zoompan Filter Syntax

The zoompan filter works by cropping a portion of the input frame and scaling it back to the output resolution. The basic syntax is:

zoompan=z='zoom_expression':x='x_expression':y='y_expression':d=frame_count:s=output_resolution

1. Configuring the Zoom Expression (z)

The zoom expression z is evaluated for every frame. To create a gradual zoom, you must reference the current zoom state using the variable zoom.


2. Configuring Coordinate Panning (x and y)

Panning is controlled by defining the top-left x and y coordinates of the zoom box. The maximum range for these coordinates depends on the input width (iw), input height (ih), output width (ow), and output height (oh).


3. Configuring the Frame Count (d)

The d parameter defines the duration of the effect in frames.


Practical Example

To apply a smooth 5-second zoom-in to the center of a static image at 30 fps (150 frames total) and output at 1920x1080, use the following FFmpeg command:

ffmpeg -i input.jpg -vf "zoompan=z='zoom+0.0015':x='(iw-ow)/2':y='(ih-oh)/2':d=150:s=1920x1080" -c:v libx264 -pix_fmt yuv420p output.mp4