How to Swap Color Planes in FFmpeg with shuffleplanes

This guide explains how to use FFmpeg's shuffleplanes filter to reorder color planes in digital video. By manipulating color components directly, you can easily swap the chrominance planes—specifically U and V in YUV video—to correct channel mapping errors or produce unique stylized visual effects. Below, you will find the parameter syntax, plane indexing conventions, and practical FFmpeg command examples.

Understanding the shuffleplanes Filter

The shuffleplanes filter reorders color planes according to four mapping arguments:

shuffleplanes=map0:map1:map2:map3

Each argument specifies which input plane should be mapped to the corresponding output plane:

  • map0: Destination for the 1st plane (Y in YUV, or the first color channel).
  • map1: Destination for the 2nd plane (U / Cb in YUV).
  • map2: Destination for the 3rd plane (V / Cr in YUV).
  • map3: Destination for the 4th plane (Alpha channel, if present).

In a standard YUV format:

  • 0 represents the Y (Luma) plane.
  • 1 represents the U (Chroma Blue) plane.
  • 2 represents the V (Chroma Red) plane.
  • 3 represents the Alpha plane.

Swapping U and V Planes

To swap the U and V planes while leaving the luma (Y) untouched, map plane 0 to 0, plane 2 to 1, and plane 1 to 2:

ffmpeg -i input.mp4 -vf "shuffleplanes=0:2:1" -c:a copy output.mp4

Explanation of the Parameters

  • 0: The output Y plane receives input plane 0 (Y).
  • 2: The output U plane receives input plane 2 (V).
  • 1: The output V plane receives input plane 1 (U).
  • Any omitted trailing plane indices keep their original mappings by default.

Preserving the Alpha Channel

If your source video includes an alpha (transparency) channel (such as yuva420p), include the fourth plane explicitly to prevent the alpha channel from being dropped:

ffmpeg -i input.mov -vf "shuffleplanes=0:2:1:3" -c:v prores_ks -pix_fmt yuva444p10le output.mov

Additional Use Cases

Inverting RGB Color Channels

For RGB pixel formats (such as gbrp or planar RGB layouts), the indices correspond to the order of planes in that specific format. To swap Red and Blue in a planar RGB format:

ffmpeg -i input.mp4 -vf "format=gbrp,shuffleplanes=2:1:0,format=yuv420p" -c:a copy output.mp4

Duplicating a Plane

You can copy a single plane to another channel. For example, replacing the V plane with the U plane:

ffmpeg -i input.mp4 -vf "shuffleplanes=0:1:1" -c:a copy output.mp4