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.mp4

Parameter Breakdown

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.mp4

How It Works

  1. 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].
  2. Red Channel Shift ([r]crop...pad...):
    • crop=iw-10:ih:0:0 crops 10 pixels off the right side of the red frame.
    • pad=iw:ih:10:0 adds 10 pixels of padding back to the left side. This effectively shifts the red channel 10 pixels to the right.
  3. Blue Channel Shift ([b]crop...pad...):
    • crop=iw-10:ih:10:0 crops 10 pixels off the left side of the blue frame.
    • pad=iw:ih:0:0 adds 10 pixels of padding to the right side. This shifts the blue channel 10 pixels to the left.
  4. Green Channel ([g]): Left unmodified to serve as the stable anchor.
  5. mergeplanes=0x000102:rgb: Recombines the shifted red channel, the untouched green channel, and the shifted blue channel back into a single RGB video stream.