Swap U and V Planes in FFmpeg Using shuffleplanes

This article explains how to use the FFmpeg shuffleplanes video filter to swap color planes, specifically focusing on swapping the U (chrominance blue) and V (chrominance red) channels. You will learn the underlying mechanics of plane mapping, the correct command syntax, and practical examples for manipulating YUV video streams.

Understanding shuffleplanes Mapping

The shuffleplanes filter redirects color planes from the input video to different planes in the output video. It accepts up to four colon-separated values, representing the output destination for each plane in this specific order:

  1. First value: Output Plane 0 (typically Y / Luma)
  2. Second value: Output Plane 1 (typically U / Chroma Blue)
  3. Third value: Output Plane 2 (typically V / Chroma Red)
  4. Fourth value: Output Plane 3 (typically A / Alpha)

The numbers you assign to these positions correspond to the index of the input planes: * 0 = Input Plane 0 (Y) * 1 = Input Plane 1 (U) * 2 = Input Plane 2 (V) * 3 = Input Plane 3 (Alpha)

How to Swap U and V

To swap the U and V planes while leaving the Luma (Y) and Alpha (A) channels untouched, you must map the output as follows: * Output Plane 0 gets Input Plane 0 (Y remains Y) * Output Plane 1 gets Input Plane 2 (U becomes V) * Output Plane 2 gets Input Plane 1 (V becomes U) * Output Plane 3 gets Input Plane 3 (Alpha remains Alpha)

This results in the filter argument: shuffleplanes=0:2:1:3.

FFmpeg Command Examples

Standard U and V Swap

For standard YUV video (with or without an alpha channel), run the following command:

ffmpeg -i input.mp4 -vf "shuffleplanes=0:2:1:3" output.mp4

Swapping U and V without Alpha

If your input video does not contain an alpha channel (such as standard yuv420p video), you can omit the fourth index:

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

Important Considerations