Correcting fisheye lens distortion and chromatic aberration

So chromatic aberration - is there any way to correct this undesirable image artifact using Kdenlive?

I have found the Defish effect, and as much as it lets me get rid of the distortion, it keeps the dispersion intact.

I have a fisheye lens attachement which is rather low quality and as much as it is a great tool to have, I wish I could compensate for the chromatic aberration this lens introduces.

In software like Darktable, Natron or Blender I know how to do this, but in Kdenlive so far I have been unable to find the right filter.

Here’s my example footage after Defish:

And here’s Defish settings that are seen above:

One thing I really miss in the Defish effect as well is translation. because the pipeline is destructive (the image gets rasterized after every effect) - I loose a lot of information in the center of the image (that gets “squeezed”) and that information is not recoverable via a following Transform node. I know there’s the Scale parameter which allows recovering that detail, but using it I have no access to what is on the side of my frame - I can’t pan the image AND keep the resolution.

I understand that’s a limitation of how the MLT pipeline is built, but if the Defish effect had a translation parameter, then that would improve some of my results incredibly.

What if you put the Transform effect before the Defish effect?

There are two Lens Distortion filters available in Kdenlive: one from avfilter, the other one from frei0r. The former seems to be able to “detach” red from the image. But honestly, I never used it and am not entirely sure this is what you are looking for. Just a suggestion to give it a try.

Reminds me of the plastic lens in my old Holga camera. That had some really cool, funky distortion and colour issues.

I wonder if there is a workaround to export as images, import into Darktable and do batch editing. Then reimport into Kdenlive? This is what we used to do with video some near 20 years ago if we needed sharpening, colour control etc on basic applications.

A complete faff, obviously.

The colour fringing from cheap fisheye adapters is mostly lateral chromatic aberration: red and blue are imaged at slightly different sizes than green, so the fix is to scale those two channels by a fraction of a percent around the centre. I don’t think Kdenlive has a dedicated filter for that, but you can do it as a pre-pass with ffmpeg and then edit the result:

ffmpeg -i in.mp4 -filter_complex "[0]format=gbrp,extractplanes=g+b+r[g][b][r];[r]scale=1286:724,crop=1280:720,setsar=1[r2];[b]scale=1276:718,pad=1280:720:-1:-1,setsar=1[b2];[g][b2][r2]mergeplanes=0x001020:gbrp,format=yuv420p" -c:v libx264 -crf 16 -c:a copy out.mp4

That’s for 1280x720 (use your real resolution). It enlarges red about 0.5% and shrinks blue about 0.3%. If the fringes get worse, flip the direction (shrink red, enlarge blue); if they get smaller, nudge the numbers until edges near the corners look neutral. Test on a 5-second clip with -t 5 first. Do it before Defish, since the aberration is centred on the lens axis, and shrinking a channel leaves a thin border at the frame edge that Defish/crop will hide anyway.

If you’d rather stay inside Kdenlive, the same idea works by stacking the clip three times with a channel-isolating effect on each, scaling the red and blue copies slightly with Transform, and compositing them additively, but it’s fiddly and slow to preview, so the ffmpeg pre-pass is usually less painful.

Could you turn your ffmpeg wizardry into a frei0r filter?