Replace Color in Video Using FFmpeg Chromakey

This article explains how to replace a specific color in a video with a new color using the FFmpeg chromakey filter. You will learn the exact command-line syntax required to make a target color transparent and overlay your video onto a new, solid-colored background.

To replace a color in a video, you cannot simply swap one color value for another in a single step. Instead, you must use a two-step process within an FFmpeg filtergraph: first, use the chromakey filter to make the target color transparent, and second, use the overlay filter to place the keyed video on top of a newly generated background color.

Here is the standard command to achieve this:

ffmpeg -i input.mp4 -f lavfi -i "color=color=blue:size=1920x1080:rate=30" -filter_complex "[0:v]chromakey=color=0x00FF00:similarity=0.1:blend=0.1[keyed];[1:v][keyed]overlay=shortest=1[out]" -map "[out]" -map 0:a? -c:a copy output.mp4

How the Command Works

Fine-Tuning the Color Replacement

If the wrong areas of your video are being replaced, adjust the similarity and blend parameters.