FFmpeg Perspective Filter: Skew and Tilt Video
This guide explains how to use the FFmpeg perspective
filter to skew, tilt, and distort video perspective. By adjusting the
coordinate points of a video’s four corners, you can create 3D angling
effects, correct camera keystoning, or tilt the horizon of your footage.
Below, you will find the syntax explanation, coordinate mapping logic,
and practical command-line examples to apply these transformations.
Understanding the Perspective Filter Syntax
The perspective filter works by mapping the original
four corners of a video to new coordinate destinations.
The basic syntax for the filter is:
perspective=x0:y0:x1:y1:x2:y2:x3:y3[:sense][:eval]The parameters x0 through y3 represent the
new coordinate pairs \((x, y)\) for the
four corners of the output video, ordered as follows:
- Top-Left Corner:
x0andy0 - Top-Right Corner:
x1andy1 - Bottom-Left Corner:
x2andy2 - Bottom-Right Corner:
x3andy3
To make formulas resolution-independent, FFmpeg allows you to use
variables representing the input frame’s dimensions: * W or
w: Width of the input video * H or
h: Height of the input video
Practical Examples
1. Tilting a Video Backward (Keystone Effect)
To tilt a video backward so that the top appears further away, you must pull the top-left and top-right corners inward toward the center, while leaving the bottom corners at their original boundaries.
ffmpeg -i input.mp4 -vf "perspective=0.15*W:0.15*H:0.85*W:0.15*H:0:H:W:H" -c:a copy output.mp4In this command: * The top-left corner is moved to 15% of the width
and height (0.15*W:0.15*H). * The top-right corner is moved
to 85% of the width and 15% of the height (0.85*W:0.15*H).
* The bottom corners remain at their default positions (0:H
and W:H).
2. Skewing a Video to the Left (Side Angle View)
To make the video look like it is being viewed from an angle on the right, you can compress the left side vertically and stretch/shift the perspective.
ffmpeg -i input.mp4 -vf "perspective=0:0.1*H:W:0:0:0.9*H:W:H" -c:a copy output.mp4In this command: * The left side is squeezed toward the vertical
center (y0 is shifted down to 0.1*H, and
y2 is shifted up to 0.9*H). * The right side
remains mapped to the absolute top and bottom edges of the frame
(y1 is 0, and y3 is
H).
3. Creating a Simple Horizon Tilt (Rotation)
If you want to tilt the entire frame slightly to fix an uneven horizon, you can offset the corners in a rotational pattern:
ffmpeg -i input.mp4 -vf "perspective=0:0.05*H:W:0:0:H:W:0.95*H" -c:a copy output.mp4This offsets the top-left and bottom-right corners down, creating a subtle clockwise tilt.
Fine-Tuning Parameters
- Sense (
sense): Set to0(default) for source-to-destination mapping, which tells FFmpeg where the original corners should move to in the output. Set to1for destination-to-source mapping, which defines what coordinates in the input frame should fill the output frame’s corners. - Interpolation (
eval): Useeval=initto calculate the coordinates once at the start of the video (highly recommended for performance), oreval=frameif you are using dynamic expressions to animate the perspective change over time.