FFmpeg Colorkey: Make a Color Transparent
The colorkey filter in FFmpeg allows you to remove a
specific color from an image or video, turning those pixels transparent.
This technique is commonly used for chroma keying (green or blue screen
effects) to isolate subjects or prepare footage for compositing. This
guide provides the core syntax, parameter options, and practical
command-line examples to quickly make any color transparent and export
the result using alpha-capable formats or overlays.
Understanding the Colorkey Filter Syntax
The basic syntax for the colorkey filter is:
colorkey=color:similarity:blend- color: The target color you want to turn
transparent. You can specify this using a hex code (e.g.,
0x00FF00or#00FF00) or standard color names (e.g.,green,black,white). - similarity: A value between
0.01and1.0(default is0.01). It determines the tolerance for color matching. A higher value removes colors that are close to the target color, compensating for uneven lighting. - blend: A value between
0.0and1.0(default is0.0). It creates a smooth falloff or feathering around the edges to reduce harsh fringing.
Exporting Video with Transparency
Most standard video containers and codecs (such as MP4 with H.264) do not support alpha channels. To preserve transparency, you must export to an alpha-supported codec such as VP9 in WebM, ProRes 4444, or QuickTime Animation.
Exporting to WebM (VP9)
ffmpeg -i input.mp4 -vf "colorkey=0x00FF00:0.3:0.1" -c:v libvpx-vp9 -pix_fmt yuva420p output.webm-vf "colorkey=0x00FF00:0.3:0.1"targets pure green, with a0.3similarity threshold and0.1edge blend.-pix_fmt yuva420pensures the pixel format includes an alpha channel (a).
Exporting to Apple ProRes 4444 (.mov)
ffmpeg -i input.mp4 -vf "colorkey=0x00FF00:0.25:0.05" -c:v prores_ks -profile:v 4 -pix_fmt yuva444p10le output.movMaking a Color Transparent in an Image
For still images, PNG and WebP easily support alpha channels:
ffmpeg -i input.jpg -vf "colorkey=white:0.1:0.0" output.pngThis command replaces the white background of an image with transparent pixels and saves it as a PNG.
Replacing the Background Directly (Overlay)
If your ultimate goal is to put a new background behind the keyed
video without saving an intermediate transparent file, combine
colorkey with the overlay filter in a single
command:
ffmpeg -i background.mp4 -i foreground.mp4 -filter_complex "[1:v]colorkey=0x00FF00:0.3:0.1[keyed];[0:v][keyed]overlay[out]" -map "[out]" -c:v libx264 output.mp4In this pipeline:
[1:v]takes the foreground video and appliescolorkeyto remove green, outputting to a stream labeled[keyed].[0:v][keyed]overlaylayers the keyed video directly on top of the background.- The final result can be saved as a standard H.264 MP4 because the transparency has been filled by the background layer.