Configure Zoom Factor and Pan Speed in FFmpeg

This article provides a quick guide on how to configure the zoom factor and panning speed using the FFmpeg zoompan video filter. You will learn the core parameters, how to manipulate the zoom expression, and how to control the direction and velocity of the panning camera effect.

Understanding the Zoompan Filter Syntax

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

zoompan=z='zoom_expr':x='x_expr':y='y_expr':d='duration':s='size'

Configuring the Zoom Factor

The zoom factor is set using the z parameter. It accepts values starting from 1.0 (no zoom). To create a dynamic zoom effect, you must write an expression that changes the zoom level incrementally on every frame.


Configuring Panning Speed and Direction

Panning is controlled by the x (horizontal) and y (vertical) expressions, which calculate the offset of the zoomed crop area for each frame.

By default, the zoom anchor is the top-left corner (0,0). To pan across the frame, you change x and y relative to the current zoom level.

1. Zooming to the Center (No Pan)

To keep the zoom centered, you must dynamically shift the crop coordinates x and y as the zoom factor increases:

x='iw/2-(iw/zoom)/2':y='ih/2-(ih/zoom)/2'

2. Panning Left to Right

To pan the camera to the right while zooming, increase the x coordinate offset manually. The speed of the pan is determined by the value added to x per frame:

x='(zoom-1)*iw/zoom':y='ih/2-(ih/zoom)/2'

To adjust the speed of the pan independently of the zoom, you can add a static multiplier or increment:

x='x+2':y='ih/2-(ih/zoom)/2'

(Note: Ensure that x does not exceed iw - ow to avoid rendering errors).


Complete Command Example

The following command applies a slow, continuous zoom-in to the center of a video, lasting for 150 frames:

ffmpeg -i input.mp4 -vf "zoompan=z='zoom+0.0015':x='iw/2-(iw/zoom)/2':y='ih/2-(ih/zoom)/2':d=150" -c:a copy output.mp4

To speed up the zoom, change 0.0015 to a higher number like 0.003. To slow it down, decrease it to 0.0005.