Jesse James Richard
Jesse James Richard

Reputation: 493

FFmpeg & Black and White Conversion

How to convert a video to black and white using ffmpeg?

Upvotes: 16

Views: 35079

Answers (2)

jason gilbert
jason gilbert

Reputation: 183

Assuming a YUV video format like mp4, you likely don't want to use format=gray.

format=gray adds a 0 usage of every 7th pixel. This slightly shifts the image brighter and leaves gaps in the intensities.

Instead use extractplanes=y. It works correctly and maybe less processing. It's also better than the other options, like hue=s=0 or monothat keep 3 planes instead of 1 for memory usage, etc.

ffmpeg -i input.mp4 -vf extractplanes=y output.mp4

It's easiest to see using a histogram comparison.

ffmpeg -i input.mp4 -filter_complex "split [s1][s2]; [s1] format=gray,histogram [so1]; [s2] extractplanes=y,histogram [so2]; [so1][so2] vstack" histogram.mp4

Upvotes: 2

llogan
llogan

Reputation: 134083

Desaturate

Use the hue filter if you want to desaturate:

ffmpeg -i input -vf hue=s=0 output

This is like using ColorsSaturation in the GIMP.

Grayscale

Use the format filter if you want to convert to grayscale format:

ffmpeg -i input -vf format=gray output

This is like using ImageModeGrayscale in the GIMP.

Threshold

See FFmpeg convert video to Black & White with threshold?

This is like using ColorsThreshold in the GIMP.

Upvotes: 46

Related Questions