Reputation: 493
How to convert a video to black and white using ffmpeg
?
Upvotes: 16
Views: 35079
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
Reputation: 134083
Use the hue filter if you want to desaturate:
ffmpeg -i input -vf hue=s=0 output
This is like using Colors → Saturation in the GIMP.
Use the format filter if you want to convert to grayscale format:
ffmpeg -i input -vf format=gray output
This is like using Image → Mode → Grayscale in the GIMP.
See FFmpeg convert video to Black & White with threshold?
This is like using Colors → Threshold in the GIMP.
Upvotes: 46