Using FFmpeg chromaberrap for Chromatic Aberration

Simulating chromatic aberration in video post-production introduces a stylized optical defect where color channels separate and fringe toward the edges of the frame. This guide details how to apply chromatic aberration using the chromaberrap filter in FFmpeg, explaining command syntax, parameter adjustments, and practical examples to produce both subtle lens dispersion and heavy glitch effects.

Understanding the chromaberrap Filter

The chromaberrap filter simulates optical chromatic aberration by shifting or scaling individual color channels (typically red and blue) relative to the green channel. This mimics real-world lens imperfections where different wavelengths of light bend at slightly different angles when passing through a lens element.

Syntax and Parameters

The basic syntax for calling the filter within a video filtergraph (-vf) is:

ffmpeg -i input.mp4 -vf "chromaberrap=parameter1=value1:parameter2=value2" -c:a copy output.mp4

Depending on the custom or experimental build of FFmpeg providing chromaberrap, the filter generally accepts the following configuration parameters:

  • strength: Controls the overall magnitude of the chromatic separation across the image. Values typically range from 0.0 to 1.0.
  • rx / ry: The horizontal and vertical offset applied specifically to the red channel. Positive values move the plane right/down, while negative values move it left/up.
  • bx / by: The horizontal and vertical offset applied to the blue channel.
  • radial: A boolean or integer (0 or 1) toggle. When enabled, separation increases exponentially toward the edges of the frame, preserving a sharp, aligned image at the center.

Practical Usage Examples

1. Subtle Radial Lens Aberration

To emulate standard vintage lens fringing that keeps the center clear and displaces the perimeter:

ffmpeg -i input.mp4 -vf "chromaberrap=radial=1:strength=0.015" -c:v libx264 -crf 18 -c:a copy output.mp4

2. Manual Color Offsets (Glitch Effect)

For an aggressive RGB split effect common in retro or VHS aesthetics, define explicit horizontal and vertical shifts for the red and blue channels:

ffmpeg -i input.mp4 -vf "chromaberrap=rx=5:ry=0:bx=-5:by=0" -c:v libx264 -crf 18 -c:a copy output.mp4

In this command, the red channel shifts five pixels to the right, the blue channel shifts five pixels to the left, and the green channel remains stationary at the center.

Built-In FFmpeg Fallback: rgbashift

If your standard FFmpeg build does not include the custom chromaberrap module, you can produce an identical chromatic aberration effect natively using the built-in rgbashift filter:

ffmpeg -i input.mp4 -vf "format=rgba,rgbashift=rh=4:rv=0:bh=-4:bv=0,format=yuv420p" -c:v libx264 -crf 18 -c:a copy output.mp4
  • format=rgba: Converts the pixel format to RGBA to allow channel shifts.
  • rh / rv: Horizontal and vertical shift for red.
  • bh / bv: Horizontal and vertical shift for blue.
  • format=yuv420p: Re-encodes the stream back to standard YUV color space for universal player compatibility.