I'm trying to create a barrel distortion effect using FFmpeg. The
lenscorrection filter can do this, but depending on the source material the results can be pretty bad, with moire patterns / bad interpolation.
Result with FFmpeg
I get better results from both ImageMagick and Photoshop here's a Photoshop example for comparison.
For single images that works fine, but I need a way to do this with FFmpeg for video.
Is there a better way? Any tips?
Edit, following the comments: there are at least two ways to improve the FFmpeg results, but they don't really work for real-world usage since they have roughly the same (big) drawback:
Upscale the image by a large factor before feeding it to lenscorrection, and downscale it afterwards. This effectively eliminates moire, and looks even better if I add a little gaussian blur as a lowpass filter. For example:
ffmpeg -i in.png -vf "scale=iw*8:ih*8:flags=neighbor, lenscorrection=k1=.1:k2=.1, gblur=9:1:15:2, scale=iw/8:ih/8:flags=lanczos" out.png
Drawback: the larger the scaling factor, the better the result; it starts looking acceptable at 8x, but for large videos these scale factors are hardly practical, due to extreme CPU/memory overhead.
Use the v360 filter, which does support better interpolation methods (default is bilinear). For instance:
ffmpeg -i 1s.png -vf v360=flat:fisheye:ih_fov=60:v_fov=45:h_fov=60:v_fov=45:w=360:h=240 out.png-
Drawback: I can't find an intuitive way to control the amount of distortion. It can be reduced by padding the frame, so that the image occupies a smaller proportion of its area (=equivalent to moving the 'lens' further away). But then, for smaller distortions, the frame sizes quickly become unmanageable - same problem as method #1.
So I'm still looking for a better solution if it exists.