Convert Video to Grayscale using FFmpeg lutyuv
Converting a video to grayscale is a common video editing task that
can be easily achieved using FFmpeg. This article provides a quick and
direct guide on how to use the lutyuv filter to set the U
and V chrominance channels to 128, effectively removing all color data
from your video while preserving the luminance channel.
To convert a video to black and white (grayscale) using the YUV color space, you need to strip the color (chrominance) information while keeping the brightness (luminance) intact. In the YUV color model, the Y channel represents luminance, while the U and V channels represent color. Setting both U and V to their neutral midpoint value of 128 in an 8-bit color space removes all color, resulting in a grayscale image.
The FFmpeg Command
Use the following command to apply the lutyuv filter and
set the U and V channels to 128:
ffmpeg -i input.mp4 -vf "lutyuv=u=128:v=128" -c:a copy output.mp4Command Breakdown
-i input.mp4: Specifies your source video file.-vf "lutyuv=u=128:v=128": Applies the YUV lookup table filter.u=128sets the U color channel to a constant value of 128.v=128sets the V color channel to a constant value of 128.- The
yparameter is omitted, meaning the original luminance values are passed through unchanged.
-c:a copy: Copies the audio stream directly without re-encoding, preserving the original audio quality and speeding up the process.output.mp4: The path for the newly generated grayscale video.
This method is highly efficient because it directly manipulates the pixel values of the color channels, making it one of the fastest ways to desaturate a video in FFmpeg.