How to Adjust FFmpeg Chromakey Similarity and Blend

This article provides a straightforward guide on how to fine-tune green screen removal in FFmpeg by adjusting the similarity and blend parameters of the chromakey filter. You will learn what these parameters do, how they affect your video output, and how to apply them using practical command-line examples to achieve clean, professional-looking overlays.

Understanding the Chromakey Parameters

The chromakey filter in FFmpeg is used to make a specific color in a video transparent (usually green or blue). To get a clean key without harsh edges or leftover background colors, you must adjust two critical parameters: similarity and blend.

FFmpeg Command Syntax

The basic syntax for applying the chromakey filter with named parameters is:

-vf "chromakey=color=COLOR:similarity=VALUE:blend=VALUE"

Example 1: Outputting a Transparent Video

To key out a pure green screen (0x00FF00) with a similarity of 0.15 and a blend of 0.08, and output it to a format that supports transparency (like Apple ProRes or VP9):

ffmpeg -i input.mp4 -vf "chromakey=color=0x00FF00:similarity=0.15:blend=0.08" -c:v prores_ks -pix_fmt yuva444p10le output.mov

Example 2: Overlaying Onto a New Background

Most of the time, you will want to key the green screen video and immediately place it over a background image or video. This is done using a filtergraph (-filter_complex) with the overlay filter:

ffmpeg -i background.mp4 -i greenscreen.mp4 -filter_complex "[1:v]chromakey=color=0x3b7a57:similarity=0.2:blend=0.1[keyed];[0:v][keyed]overlay=x=0:y=0[out]" -map "[out]" output.mp4

In this command: * 0x3b7a57 is the hex code for the specific shade of green in the video. * similarity=0.2 expands the color range to catch shadows. * blend=0.1 smooths out the edges of the subject.

How to Dial in the Perfect Settings

Since every video has different lighting, follow these steps to find the optimal values for your footage:

  1. Identify the exact key color: Use a color picker tool on your source video to find the hex code of the green screen closest to your subject’s edge.
  2. Start with similarity: Set blend to 0.0 and increase similarity incrementally (e.g., 0.10, 0.12, 0.15) until the green background completely disappears. Stop before your foreground subject begins to fade.
  3. Adjust the blend: Once the background is gone, look closely at the edges of your subject. They will likely look pixelated or sharp. Slowly increase the blend value (e.g., 0.05, 0.10) until the edges look soft and natural.