[FFmpeg-user] lenscorrection and vignette filters

Michael Koch astroelectronic at t-online.de
Tue Feb 23 18:51:55 CET 2016

Am 23.02.2016 um 10:00 schrieb Michael Koch:
>> I found a bug in the documentation of the lenscorrection filter:
>> https://www.ffmpeg.org/ffmpeg-all.html#lenscorrection
>> It's written there "0.5 means no correction" for the coefficients k1 
>> and k2.
>> This can't be right, or the formula is wrong. It's obvious that the 
>> formula makes no correction if k1=k2=0.
> The remarks "0.5 means no correction" in the documentation are wrong. 
> This can easily be tested:
> ffmpeg -i input.png -vf lenscorrection=k1=0.5:k2=0.5 output.png
> It's clearly visible that the output is not the same as the input.
> ffmpeg -i input.png -vf lenscorrection=k1=0:k2=0 output.png
> Now the output is the same as the input. It is clear that 0 means no 
> correction.
> But unfortunately this isn't the only error in the documentation. I 
> haven't yet found out which formula is actually used in the 
> lenscorrection filter, but one thing is absolutely sure: It's not the 
> formula from the documentation.

After spending many hours with this problem, finally I figured out 
what's going on.
This is the formula from the documentation:
r_src = r_tgt * (1 + k1 * (r_tgt / r_0)^2 + k2 * (r_tgt / r_0)^4)

The formula is correct, but it must be clarified that it describes the 
behaviour of the lens. It does not describe the behaviour of the 
lenscorrection filter.
r_src is the radial coordinate in object space.
r_tgt is the radial coordinate in the image, which was taken with a 
distorted lens.

The behaviour of the lenscorrection filter can be described by the 
inverse of the above function.
However the inverse function is difficult to derive. For the simplified 
case k2=0 I found a solution:
r_tgt = 2 * sqrt(1 / (3 * k1)) * sinh(arcsinh(r_src / (2 * k1 * sqrt(1 / 
(3 * k1)) ^ 3)) / 3)


More information about the ffmpeg-user mailing list