FFmpeg Chromatic Aberration Channel Displacement Guide
This guide explains how to configure the displacement of red, green,
and blue channels in FFmpeg to create a chromatic aberration effect. You
will learn how to use the built-in chromashift filter for
quick adjustments in YUV color space, as well as how to perform precise
pixel shifts in RGB space by splitting, transforming, and merging
individual color channels.
Method 1: Using the Built-In Chromashift Filter (YUV Space)
The fastest way to introduce chromatic aberration is using the
chromashift filter. Because most digital video is processed
in YUV format, this filter shifts the chroma planes—Chroma Blue (Cb) and
Chroma Red (Cr)—relative to the luminance (Y) plane, which holds most of
the green channel data and overall brightness.
The Command
ffmpeg -i input.mp4 -vf "chromashift=cbh=5:cbv=2:crh=-5:crv=-2" -c:a copy output.mp4Parameter Breakdown
cbh(Chroma Blue Horizontal): Displaces the blue channel horizontally. Positive values shift it to the right; negative values shift it to the left.cbv(Chroma Blue Vertical): Displaces the blue channel vertically. Positive values shift it down; negative values shift it up.crh(Chroma Red Horizontal): Displaces the red channel horizontally.crv(Chroma Red Vertical): Displaces the red channel vertically.
In the example above, the blue channel is shifted 5 pixels right and 2 pixels down, while the red channel is shifted 5 pixels left and 2 pixels up, creating a balanced chromatic aberration effect.
Method 2: Precision RGB Channel Displacement (RGB Space)
For projects requiring precise pixel-level displacement of the actual
Red, Green, and Blue channels, you must convert the video to RGB, split
the channels, shift them using the crop and
pad filters, and then merge them back together.
The Command
ffmpeg -i input.mp4 -filter_complex \
"[0:v]format=rgb24,split=3[r][g][b]; \
[r]crop=iw-10:ih:0:0,pad=iw:ih:10:0[r_shifted]; \
[b]crop=iw-10:ih:10:0,pad=iw:ih:0:0[b_shifted]; \
[r_shifted][g][b_shifted]mergeplanes=0x000102:rgb[out]" \
-map "[out]" -c:a copy output.mp4How It Works
format=rgb24,split=3: Converts the input video to the RGB24 color space and duplicates it into three identical streams labeled[r],[g], and[b].- Red Channel Shift (
[r]crop...pad...):crop=iw-10:ih:0:0crops 10 pixels off the right side of the red frame.pad=iw:ih:10:0adds 10 pixels of padding back to the left side. This effectively shifts the red channel 10 pixels to the right.
- Blue Channel Shift (
[b]crop...pad...):crop=iw-10:ih:10:0crops 10 pixels off the left side of the blue frame.pad=iw:ih:0:0adds 10 pixels of padding to the right side. This shifts the blue channel 10 pixels to the left.
- Green Channel (
[g]): Left unmodified to serve as the stable anchor. mergeplanes=0x000102:rgb: Recombines the shifted red channel, the untouched green channel, and the shifted blue channel back into a single RGB video stream.