FFmpeg Colorkey: How to Make a Color Transparent

This guide explains how to use the FFmpeg colorkey filter to target and remove a specific color from a video, rendering it transparent. You will learn the exact command syntax, how to adjust similarity and blend parameters for clean edges, and how to export your final video using a codec that supports alpha channels (transparency).

The Basic Colorkey Syntax

The colorkey filter works by identifying a target color and converting it to transparent black. The basic syntax for the filter is:

colorkey=color:similarity:blend

Step-by-Step Implementation

Because standard MP4 (H.264) files do not support transparency, you must export your output file using a codec and format that supports an alpha channel, such as WebM (VP9) or QuickTime (Animation/PNG).

Example 1: Creating a Transparent WebM (Web-Friendly)

WebM is the ideal format for transparent videos on websites. The following command removes a pure green screen (0x00FF00) and exports a transparent WebM video:

ffmpeg -i input.mp4 -vf "colorkey=0x00FF00:0.3:0.1" -c:v libvpx-vp9 -pix_fmt yuva420p output.webm

Command breakdown: * -i input.mp4: Specifies the input video. * -vf "colorkey=0x00FF00:0.3:0.1": Applies the colorkey filter. It targets green (0x00FF00), sets the similarity tolerance to 0.3, and applies a 0.1 blend to smooth the edges. * -c:v libvpx-vp9: Uses the VP9 codec, which supports transparency. * -pix_fmt yuva420p: Sets the pixel format to include the alpha channel (“a” in yuva represents alpha/transparency).

Example 2: Creating a Transparent QuickTime MOV (Editing-Friendly)

If you need to import the transparent video into a video editor like Premiere Pro, After Effects, or DaVinci Resolve, a QuickTime container with the PNG or QTRLE codec is preferred.

ffmpeg -i input.mp4 -vf "colorkey=green:0.2:0.05" -c:v qtrle output.mov

Command breakdown: * -vf "colorkey=green:0.2:0.05": Targets the color named green with a similarity of 0.2 and a blend of 0.05. * -c:v qtrle: Uses the QuickTime Animation codec, which natively supports alpha channels.

Fine-Tuning Your Key

If you see leftover color halos or parts of your subject are disappearing, adjust your settings using these rules of thumb: