Search code examples
image-processingfilterffmpegvideo-processingchromakey

FFMPEG: chroma key / greenscreen filter for images / video


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


Solution

  • 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).