Configure FFmpeg Chromatic Aberration Filter
Configuring chromatic aberration in FFmpeg allows you to create
stylized vintage effects, glitch aesthetics, or simulate optical lens
fringing by offsetting color channels. This guide explains how to
achieve this effect using FFmpeg's native rgbashift filter
to independently displace the red, green, and blue planes horizontally
and vertically, along with proper edge handling techniques.
The rgbashift Filter
Syntax
The primary filter for displacing color planes in FFmpeg is
rgbashift. It operates on RGB pixel formats and provides
independent pixel offset controls for each channel:
rh/rv: Horizontal and vertical shift for the red channel.gh/gv: Horizontal and vertical shift for the green channel.bh/bv: Horizontal and vertical shift for the blue channel.edge: Dictates how pixels at the frame boundaries are filled (smear,wrap, orblank).
Positive values displace a channel rightward or downward, while negative values shift it leftward or upward.
Basic Implementation
To apply a standard chromatic aberration where the red channel is displaced to the left and the blue channel is displaced to the right, use the following filter chain:
ffmpeg -i input.mp4 -vf "format=rgb24,rgbashift=rh=-6:rv=0:bh=6:bv=0:edge=smear,format=yuv420p" -c:a copy output.mp4In this command:
format=rgb24ensures the video is converted to an uncompressed RGB space compatible with the filter.rh=-6:rv=0moves the red plane 6 pixels to the left.bh=6:bv=0moves the blue plane 6 pixels to the right.- The green plane remains stationary at
0by default. format=yuv420pconverts the video back to standard YUV color for widespread player compatibility.
Multi-Directional Displacement
You can offset all three channels simultaneously in both dimensions to create diagonal or asymmetric separation:
ffmpeg -i input.mp4 -vf "format=rgb24,rgbashift=rh=-4:rv=-3:gh=2:gv=1:bh=5:bv=-2:edge=blank,format=yuv420p" -c:a copy output.mp4Configuring Edge Handling
Displacing channels leaves exposed margins where shifted planes no
longer cover the frame. The edge parameter controls how
these areas are treated:
edge=smear: Stretches the border pixels to the edge of the frame, avoiding harsh black borders. This is typically the most natural option for optical aberration.edge=wrap: Wraps pixels from the opposite side of the screen, commonly used in digital glitch effects.edge=blank: Fills the missing boundary space with black pixels.