FFMPEG: chroma key / greenscreen filter for images / video

Daniel Ruf picture Daniel Ruf · Nov 28, 2011 · Viewed 23.7k times · Source

I need for a video to use chroma key filter / greenscreen filter and overlay it over another video and output it as new video.

Are there any existing libraries, scripts, filters or solutions for this purpose?

Answer

jladan picture jladan · Aug 30, 2015

I realize this is an old question, but it still comes up near the top when I search for ffmpeg chromakey.

The answer (now) is yes, there is a filter for generating chroma-keys and overlaying them. The filter name is "color key". There are examples on the site, here's the command:

ffmpeg -i <base-video> -i <overlay-video> -filter_complex '[1:v]colorkey=0x<color>:<similarity>:<blend>[ckout];[0:v][ckout]overlay[out]' -map '[out]' <output-file>

where <color> is the rgb color to match in hex (ex: 0x000000 for black), <similarity> is a tolerance on the color-match (ex: 0.3), and <blend> (ex: 0.2) controls whether the opacity is on-off or how gradual it is. (See the documentation for more).