Adjust FFmpeg Lenscorrection Center and Focal Coordinates
This article provides a quick guide on how to configure the optical
center point and correction parameters in FFmpeg’s
lenscorrection filter. You will learn how to use the
coordinate parameters (cx and cy) to define
the distortion center, and how the correction coefficients
(k1 and k2) adjust the focal correction to
eliminate barrel and pincushion lens distortion.
The lenscorrection filter in FFmpeg uses a mathematical
model to correct radial lens distortion. To adjust the optical center
(the point from which the radial correction propagates) and the
distortion coefficients, you must configure the four primary parameters
of the filter: cx, cy, k1, and
k2.
The Correction Syntax
The basic syntax for applying the filter in your FFmpeg command is:
ffmpeg -i input.mp4 -vf "lenscorrection=cx=0.5:cy=0.5:k1=0.0:k2=0.0" output.mp4Adjusting the Center Point
(cx and cy)
The parameters cx and cy define the
horizontal and vertical coordinates of the optical center (focal center)
of the image.
- Value Range: Both parameters accept fractional
values between
0.0and1.0. - Default Coordinates: The default is
cx=0.5andcy=0.5, which represents the exact geometric center of the frame. - Shifting the Center: If your camera lens was offset
or the image was cropped unevenly, you must shift these values. For
example, setting
cx=0.6shifts the center of the correction slightly to the right, whilecy=0.4shifts it upward.
Adjusting Focal Correction
(k1 and k2)
The k1 and k2 parameters are the correction
coefficients that determine the strength and direction of the correction
relative to the center coordinates.
- k1 (Main Quadratic Term): This corrects the primary distortion closest to the center.
- k2 (Double Quadratic Term): This corrects the distortion further out, near the edges of the frame.
- Barrel Distortion (fisheye effect): Use negative
values for
k1andk2to flatten the outward bulging. - Pincushion Distortion (inward bending): Use positive values to correct lines that curve inward.
Practical Examples
Standard Center-Aligned Correction: To correct moderate barrel distortion from a centered camera lens:
ffmpeg -i input.mp4 -vf "lenscorrection=cx=0.5:cy=0.5:k1=-0.1:k2=-0.05" output.mp4Off-Center Focal Correction: If the lens axis is slightly misaligned to the top-left of the physical sensor, adjust the optical center accordingly:
ffmpeg -i input.mp4 -vf "lenscorrection=cx=0.45:cy=0.42:k1=-0.15:k2=-0.08" output.mp4