FFmpeg Extract Luma Plane with extractplanes
Extracting the luma component from a YUV video isolates the
brightness information, effectively converting the stream into pure
grayscale while discarding chrominance. This guide explains how to use
FFmpeg's built-in extractplanes bitstream video filter to
separate and output only the Y (luma) plane from any standard
YUV-encoded media file.
The Basic Command
To extract the luma plane, invoke the extractplanes
filter using the -vf flag and specify y as the
target plane:
ffmpeg -i input.mp4 -vf "extractplanes=y" output_luma.mp4How It Works
-i input.mp4: Specifies the source video file containing YUV color data (such asyuv420p,yuv422p, oryuv444p).-vf "extractplanes=y": Instructs FFmpeg to discard the U (Cb) and V (Cr) chroma planes and output only the Y plane. The resulting stream is output as a raw grayscale format (graypixel format).output_luma.mp4: The destination container. FFmpeg will automatically choose an appropriate encoder that supports grayscale.
Ensuring Player Compatibility
Many standard media players and hardware decoders struggle to play
native single-plane grayscale pixel formats like gray
inside an MP4 container. To ensure wide playback compatibility while
maintaining a grayscale image, convert the output pixel format back to a
widely supported YUV format such as yuv420p:
ffmpeg -i input.mp4 -vf "extractplanes=y,format=yuv420p" -c:v libx264 -crf 18 output_compatible.mp4In this command, format=yuv420p takes the extracted
monochrome luma data and assigns neutral (blank) chroma values,
producing a standard H.264 video that displays as black and white across
all devices.
Extracting Luma as Image Files
To extract the luma plane into individual image frames (such as PNG or JPEG), provide an image sequence output pattern:
ffmpeg -i input.mp4 -vf "extractplanes=y" frame_%04d.pngThis writes each frame's Y channel as an 8-bit single-channel grayscale PNG image.