[FFmpeg-user] Remove everything but a single color (range)

Dan Bridges dosdan at gmail.com
Sun Mar 15 12:13:32 EET 2020


>Is it possible to "remove" everything in a video except a specific
color (or maybe a range... ie close to a specific color. By "remove" I
mean covert every that is NOT the color(s) I want to black or
transparent. I have a video that contains a yellowish box that moves
about the screen. I want to isolate ONLY the yellowish box. Everything
else should become black or transparent.

Try the colorhold filter:

>From http://paulbourke.net/miscellaneous/ffmpeg/FFmpeg_Book.pdf

The 3 parameters are:

"color" is the color to be preserved, can be specified by name or by RGB
values, for example "orange" can be replaced by #FFA500
"similarity" is a percentage, 0.01 means only the specified color is
preserved, 1.0 means all colors are preserved.
"blend" is a percentage, 0.0 makes pixels fully gray, higher values
result in more preserved color


ffmpeg -i input_filename  -vf colorhold="FBED54":0.01:0  output_filename

This produces tight colour discrimination.  If too tight, increase the
2nd parameter from 0.01 until you get what you want.

Note, this filter will only make the discriminated stuff gray, not black
or transparent.  Perhaps someone else will be able to help.

A screenshot from an example using similarity=0.5 (a fairly sloppy
match) and your colour:  
https://dl.dropbox.com/s/isipbbtb2bjj7wy/filtered.jpg

Dan.








More information about the ffmpeg-user mailing list