FFmpeg Zoompan: Set Zoom Factor and Pan Speed
This guide explains how to control the zoom factor and panning speed
using FFmpeg's zoompan complex video filter. By
manipulating the z (zoom), x (horizontal pan),
and y (vertical pan) expressions alongside duration
parameters, you can create smooth, customized Ken Burns effects, slow
cinematic pushes, or rapid camera sweeps on images and videos.
Understanding the Key Parameters
The zoompan filter generates dynamic pan-and-zoom
sequences using several core parameters:
z: The zoom factor expression. Evaluated per output frame.x: The horizontal position of the top-left corner of the viewing frame.y: The vertical position of the top-left corner of the viewing frame.d: Duration of the effect per input image in output frames (e.g.,d=125at 25 fps equals 5 seconds).s: Target output resolution, formatted asWIDTHxHEIGHT(e.g.,1920x1080).fps: Output frame rate (defaults to 25).
Important built-in variables you can use inside your expressions:
zoom: The current zoom factor.pzoom: The previous frame's zoom factor.on: The current output frame number (starts at 0).in: The current input frame number.iw/ih: Input image width and height.
Configuring the Zoom Factor and Zoom Speed
The zoom factor is set with z='...'. The speed of the
zoom is determined by the increment applied per frame.
1. Slow, Smooth Zoom In
To zoom in slowly from 1.0x to 1.5x, increment the current zoom value
by a small decimal per frame and cap it with min():
ffmpeg -loop 1 -i input.jpg -vf "zoompan=z='min(zoom+0.0015,1.5)':d=125:s=1920x1080" -c:v libx264 -t 5 -pix_fmt yuv420p output.mp4- Zoom Speed: Increasing
0.0015to0.003doubles the zoom speed; decreasing it to0.0005creates an ultra-slow push. - Zoom Cap:
1.5prevents the image from zooming past 150%.
2. Zoom Out
To start zoomed in and pull back, use if() logic or
decrement from a higher starting value:
ffmpeg -loop 1 -i input.jpg -vf "zoompan=z='if(eq(on,0),1.5,max(1.0,zoom-0.002))':d=125:s=1920x1080" -c:v libx264 -t 5 -pix_fmt yuv420p output.mp4Configuring Panning Speed
Panning speed is governed by how many pixels the viewing window
shifts along the x (horizontal) or y
(vertical) axes each frame.
1. Fixed Pixel Speed (Linear Pan)
To move the camera across an image without changing zoom:
ffmpeg -loop 1 -i wide_input.jpg -vf "zoompan=z=1.0:x='x+2':y=0:d=150:s=1920x1080" -c:v libx264 -t 6 -pix_fmt yuv420p output.mp4x='x+2': Shifts the view 2 pixels to the right every frame.- Increasing
2to5will more than double the panning speed.
2. Panning Across the Full Image Width
To pan across the available space uniformly over the entire duration,
calculate the step size based on on (current frame) and
d (total frames):
ffmpeg -loop 1 -i wide_input.jpg -vf "zoompan=z=1.0:x='on*(iw-iw/zoom)/150':y=0:d=150:s=1920x1080" -c:v libx264 -t 6 -pix_fmt yuv420p output.mp4Combining Zoom and Pan: Centered Push-In
When zooming into the center of an image, the x and
y coordinates must adjust relative to the changing zoom
level so the focal point stays centered:
ffmpeg -loop 1 -i input.jpg -vf "zoompan=z='min(zoom+0.002,1.4)':x='(iw-iw/zoom)/2':y='(ih-ih/zoom)/2':d=200:s=1920x1080" -c:v libx264 -t 8 -pix_fmt yuv420p output.mp4z='min(zoom+0.002,1.4)': Controls the zoom speed (+0.002 per frame) up to 1.4x magnification.x='(iw-iw/zoom)/2': Keeps the horizontal view centered automatically.y='(ih-ih/zoom)/2': Keeps the vertical view centered automatically.
Panning Towards a Specific Target
To zoom and pan toward an offset focal point (e.g., upper-right corner), shift the pan formula toward that target:
ffmpeg -loop 1 -i input.jpg -vf "zoompan=z='min(zoom+0.002,1.5)':x='(iw-iw/zoom)*0.8':y='(ih-ih/zoom)*0.2':d=150:s=1920x1080" -c:v libx264 -t 6 -pix_fmt yuv420p output.mp4x='(iw-iw/zoom)*0.8': Pans towards 80% to the right.y='(ih-ih/zoom)*0.2': Pans towards 20% down from the top.- Adjusting the multiplier controls the target destination while the zoom increment controls the movement rate.