Configure FFmpeg Perspective Filter Coordinates

This article explains how to configure the eight coordinate points of the perspective filter in FFmpeg to perform perspective distortion or correction. You will learn the exact order of the input and output coordinate pairs, how to define the coordinates using absolute values or relative variables, and how to apply practical transformations such as keystone correction or angled video projections.

The Perspective Filter Syntax

The FFmpeg perspective filter requires two sets of four coordinate points (eight points total, consisting of sixteen individual coordinate values): four source points and four destination points.

The basic syntax is:

perspective=x0:y0:x1:y1:x2:y2:x3:y3:X0:Y0:X1:Y1:X2:Y2:X3:Y3
  • Lowercase (x0 to y3): The four source points on the original video.
  • Uppercase (X0 to Y3): The four destination points on the resulting output frame.

The Order of Corner Points

Both the source and destination points follow a strict corner ordering:

  1. Point 0 (x0, y0 / X0, Y0): Top-Left corner
  2. Point 1 (x1, y1 / X1, Y1): Top-Right corner
  3. Point 2 (x2, y2 / X2, Y2): Bottom-Left corner
  4. Point 3 (x3, y3 / X3, Y3): Bottom-Right corner

Coordinate Values and Variables

You can specify coordinates using raw pixel numbers or built-in variables:

  • W: Width of the input video
  • H: Height of the input video

Using expressions with W and H ensures the transformation adapts automatically if the input resolution changes.

Configuration Use Cases

1. Tilting a Flat Video into Perspective (Trapezoid Effect)

To make a standard rectangular video look like it recedes into the distance, keep the source points set to the standard four corners of the frame and move the top destination points inward:

ffmpeg -i input.mp4 -vf "perspective=0:0:W:0:0:H:W:H:W*0.2:H*0.1:W*0.8:H*0.1:0:H:W:H" output.mp4

In this command:

  • Source: (0, 0) is top-left, (W, 0) is top-right, (0, H) is bottom-left, (W, H) is bottom-right.
  • Destination: The top-left corner moves to (0.2*W, 0.1*H), the top-right corner moves to (0.8*W, 0.1*H), while bottom-left (0, H) and bottom-right (W, H) remain unchanged.

2. Keystone Correction (Straightening a Distorted Capture)

If you have a video recorded from an off-center angle where the content is distorted into a quadrilateral, map the four corners of that distorted area in the source video to the full bounds of the output frame:

ffmpeg -i input.mp4 -vf "perspective=150:80:1100:120:80:680:1180:640:0:0:W:0:0:H:W:H" output.mp4

In this command:

  • Source: Explicit pixel coordinates identify the four corners of the skewed object in the input frame:
    • Top-Left: (150, 80)
    • Top-Right: (1100, 120)
    • Bottom-Left: (80, 680)
    • Bottom-Right: (1180, 640)
  • Destination: The target corners are mapped to the standard output boundaries (0, 0), (W, 0), (0, H), and (W, H), effectively flattening and squaring the video.

Additional Parameters

You can append optional parameters after the coordinates using colons:

  • interpolation: Defines resampling quality. Options are linear (default) or cubic.
  • sense: Specifies the direction of the transformation. Set to 0 for source-to-destination mapping (default) or 1 for destination-to-source mapping.

Example using cubic interpolation:

ffmpeg -i input.mp4 -vf "perspective=0:0:W:0:0:H:W:H:50:50:W-50:50:0:H:W:H:interpolation=cubic" output.mp4