Correct Fisheye Lens Distortion in FFmpeg

This article provides a step-by-step guide on how to remove fisheye distortion from video footage using the FFmpeg lenscorrection filter. You will learn the syntax of the filter, understand how its key parameters work, and see practical command-line examples to help you flatten your video and achieve a natural, rectilinear perspective.

Understanding the lenscorrection Filter

The lenscorrection filter in FFmpeg corrects radial distortion—commonly known as barrel distortion (fisheye) or pincushion distortion—using a mathematical model based on the distance from the center of the image.

The basic syntax for the filter is:

lenscorrection=cx=cx_val:cy=cy_val:k1=k1_val:k2=k2_val

Parameter Breakdown

To correct barrel (fisheye) distortion, you must use negative values for k1 and k2.

Step-by-Step Command Examples

1. Basic Fisheye Correction

For standard action cameras (like GoPros or dashcams), the optical center is usually the exact center of the frame (cx=0.5 and cy=0.5). You only need to adjust k1 and k2.

Run the following command to apply a moderate correction:

ffmpeg -i input.mp4 -vf "lenscorrection=cx=0.5:cy=0.5:k1=-0.22:k2=-0.022" -c:a copy output.mp4

2. Strong Fisheye Correction

If your camera has an ultra-wide 170-degree lens, you will need stronger negative coefficients:

ffmpeg -i input.mp4 -vf "lenscorrection=cx=0.5:cy=0.5:k1=-0.35:k2=-0.05" -c:a copy output.mp4

3. Real-Time Preview and Tuning

Because every camera lens is different, finding the perfect k1 and k2 values requires some trial and error. You can use ffplay to preview the results in real-time without rendering a new file:

ffplay -i input.mp4 -vf "lenscorrection=k1=-0.25:k2=-0.03"

Adjust the k1 and k2 values in the command until straight lines in the real world (like walls, horizons, or pillars) appear straight in your video preview. Once you find the ideal values, apply them to the ffmpeg export command.