How to Create Ken Burns Effect in FFmpeg with Zoompan
This guide demonstrates how to apply the Ken Burns effect to a static
image using FFmpeg's built-in zoompan video filter. You
will learn the core syntax of the filter, understand how to manipulate
zoom and pan coordinates over time, and see ready-to-use command
examples for zooming in, zooming out, and panning across an image
without jitter.
Understanding the
zoompan Filter Syntax
The zoompan filter works by cropping a moving window
over an input image and scaling it to an output resolution
frame-by-frame.
The most common parameters include:
z: The zoom factor expression for each frame. Default is1.x: The horizontal position of the crop window top-left corner.y: The vertical position of the crop window top-left corner.d: The duration of the effect expressed in frames.s: The output video resolution (e.g.,1920x1080).fps: The output frame rate (default is 25).
Useful internal variables used inside expressions:
in_woriw: Input image width.in_horih: Input image height.zoomorz: Current zoom level.on: Output frame number (starts at 0).
1. Zoom In to the Center
To zoom into the center of an image over 5 seconds at 25 frames per second (125 frames total):
ffmpeg -loop 1 -i input.jpg -vf "zoompan=z='min(zoom+0.0015,1.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=125:s=1920x1080:fps=25" -c:v libx264 -t 5 -pix_fmt yuv420p output_zoomin.mp4z='min(zoom+0.0015,1.5)': Increases zoom by0.0015each frame until it reaches a maximum scale of1.5x.x='iw/2-(iw/zoom/2)'andy='ih/2-(ih/zoom/2)': Centers the crop window horizontally and vertically as the zoom level changes.-t 5: Limits the output duration to 5 seconds to matchd=125atfps=25.
2. Zoom Out from the Center
To start zoomed in at 1.5x and smoothly zoom out to
normal scale:
ffmpeg -loop 1 -i input.jpg -vf "zoompan=z='if(lte(on,1),1.5,max(1.0,zoom-0.0015))':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=125:s=1920x1080:fps=25" -c:v libx264 -t 5 -pix_fmt yuv420p output_zoomout.mp4z='if(lte(on,1),1.5,...)': Sets the initial zoom on the first frame to1.5.max(1.0,zoom-0.0015): Decreases the zoom factor per frame until it returns to1.0.
3. Pan Across an Image (Left to Right)
To pan horizontally across an image while holding a steady zoom:
ffmpeg -loop 1 -i input.jpg -vf "zoompan=z=1.3:x='if(lte(on,1),0,x+((iw-iw/zoom)/125))':y='ih/2-(ih/zoom/2)':d=125:s=1920x1080:fps=25" -c:v libx264 -t 5 -pix_fmt yuv420p output_pan.mp4z=1.3: Keeps a constant zoom of1.3xto provide headroom for panning.x='if(lte(on,1),0,x+((iw-iw/zoom)/125))': Starts at coordinate0and moves the crop window rightward by an equal increment across 125 frames.
Avoiding Jitter and Choppiness
The zoompan filter internally calculates crop bounds
using integer pixels, which can cause micro-stuttering or jitter during
slow movements. To ensure completely smooth animation:
- Upscale before applying
zoompan: Scale the input image to a higher resolution (e.g., 4K or 8K) prior to zooming, then downscale to your target resolution.
ffmpeg -loop 1 -i input.jpg -vf "scale=8000:-1,zoompan=z='min(zoom+0.0015,1.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=125:s=1920x1080:fps=25" -c:v libx264 -t 5 -pix_fmt yuv420p smooth_output.mp4- Pixel Format: Always specify
-pix_fmt yuv420pat the end of the command to ensure the final MP4 file is compatible with web browsers and standard media players.