FFmpeg Zoompan Filter Ken Burns Effect Tutorial
This guide explains how to use the FFmpeg zoompan filter
to apply a dynamic Ken Burns effect—slowly zooming and panning—to a
static image. You will learn the basic syntax, the mathematical formulas
behind the filter’s variables, and how to execute a complete command to
generate a high-quality video from a single photo.
The Basic Ken Burns Command
To create a smooth zoom towards the center of an image, use the following FFmpeg command:
ffmpeg -loop 1 -i input.jpg -vf "zoompan=z='zoom+0.0015':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=125:s=1920x1080" -c:v libx264 -t 5 -pix_fmt yuv420p output.mp4Command Breakdown
-loop 1 -i input.jpg: Loops the single input image to act as a continuous video stream.zoompan: The filter used to apply the motion.z='zoom+0.0015': Increments the zoom factor by 0.0015 on every frame. The default zoom starts at 1.0.x='iw/2-(iw/zoom/2)': Calculates the X coordinate of the zoom window to keep the horizontal focus centered.iwis the Input Width.y='ih/2-(ih/zoom/2)': Calculates the Y coordinate to keep the vertical focus centered.ihis the Input Height.d=125: Sets the duration of the filter effect to 125 frames. At the default output framerate of 25 fps, this equals 5 seconds.s=1920x1080: Defines the output resolution (Full HD).
-c:v libx264: Encodes the video using the H.264 codec.-t 5: Limits the output video length to 5 seconds.-pix_fmt yuv420p: Ensures pixel format compatibility for standard media players.
Adjusting the Movement and Direction
You can customize the Ken Burns effect by changing the x
and y equations to control where the camera pans.
Zooming into the Top-Left Corner
To zoom into the top-left corner, set both the X and Y coordinates to zero:
zoompan=z='zoom+0.0015':x=0:y=0:d=125:s=1920x1080Zooming into the Bottom-Right Corner
To zoom into the bottom-right corner, offset the focus point using the maximum boundaries of the zoomed frame:
zoompan=z='zoom+0.0015':x='iw-(iw/zoom)':y='ih-(ih/zoom)':d=125:s=1920x1080Pan Left-to-Right (No Zoom)
To pan across an image without changing the scale, set a constant
zoom level greater than 1 (e.g., 1.5) and transition the X
coordinate based on the current frame (on):
zoompan=z=1.5:x='(iw-iw/zoom)*(on/d)':y='ih/2-(ih/zoom/2)':d=125:s=1920x1080Preventing Jitter and Shaking
The zoompan filter performs coordinate calculations
using integers, which can cause the camera motion to appear shaky or
jittery. To achieve a perfectly smooth Ken Burns effect, pre-scale your
input image to a higher resolution before applying the
zoompan filter.
Add a scale filter directly before the zoompan filter in
your filtergraph:
ffmpeg -loop 1 -i input.jpg -vf "scale=3840:-1,zoompan=z='zoom+0.001':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=125:s=1920x1080" -c:v libx264 -t 5 -pix_fmt yuv420p output.mp4In this optimized command, scale=3840:-1 upscale-sizes
the image width to 3840 pixels (maintaining aspect ratio) before the
zoom is calculated, which provides more pixel data for smoother
fractional coordinate transitions.