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:
- First value: Output Plane 0 (typically Y / Luma)
- Second value: Output Plane 1 (typically U / Chroma Blue)
- Third value: Output Plane 2 (typically V / Chroma Red)
- 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.mp4Swapping 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.mp4Important Considerations
Planar Formats Only: The
shuffleplanesfilter only works on planar pixel formats (likeyuv420p,yuv444p, oryuva420p). If your input video is in a packed format (likenv12oruyvy422), FFmpeg will automatically insert a format conversion filter. To guarantee predictable results, you can force a planar format before filtering:ffmpeg -i input.mp4 -vf "format=yuv420p,shuffleplanes=0:2:1" output.mp4Visual Effect: Swapping the U and V channels inverted-color shifts the chrominance of the image (often turning blues into reds/yellows and vice versa) while preserving the original brightness (Luma) structure.