Convert Color Video to Grayscale with FFmpeg
Applying a grayscale filter to a color video is a common task in
video post-production, often used to achieve an artistic aesthetic or to
reduce visual noise. Using FFmpeg, a powerful command-line tool
available on Linux, you can easily strip the color information from a
video using the hue or format video filters.
This article provides a quick overview of the required terminal
commands, explains how the filters work, and demonstrates how to process
your video files efficiently.
The Standard FFmpeg Grayscale Command
The most straightforward way to convert a video to black and white in
FFmpeg is by using the hue filter and
setting the saturation to zero. Open your Linux terminal and run the
following command:
ffmpeg -i input.mp4 -vf "hue=s=0" output.mp4Here is a breakdown of what each part of the command does:
-i input.mp4: Specifies the path to your source color video.-vf "hue=s=0": Activates the video filter (-vf) graph and applies thehuefilter, setting the saturation (s) to0.output.mp4: The name and format of your newly created grayscale video.
Alternative Method: Pixel Format Conversion
Another highly efficient method involves changing the pixel format of
the video directly to a grayscale format using the
format filter. This completely removes the
chroma (color) channels, which can sometimes result in faster processing
times:
ffmpeg -i input.mp4 -vf "format=gray" output.mp4Using format=gray forces FFmpeg to output a video that
only contains the luminance (brightness) channel, ensuring absolute
black and white conversion without any accidental color bleeding.
Tweaking Contrast and Brightness
If your resulting grayscale video looks a bit flat, you can chain the
eq (equation) filter right after the grayscale filter to
boost the contrast and adjust the brightness:
ffmpeg -i input.mp4 -vf "hue=s=0,eq=contrast=1.2:brightness=0.05" output.mp4In this chained filter example, the video is first desaturated, and
then the contrast is increased by 20% (1.2) while the
brightness is bumped up slightly (0.05) to make the
highlights pop.