FFmpeg Chromakey Tutorial: How to Remove Green Screen

This article provides a straightforward guide on how to use the chromakey filter in FFmpeg to remove solid-color backgrounds, such as green screens, from your videos. You will learn the basic command syntax, how to adjust similarity and blend parameters to fine-tune your key, and how to overlay your green screen footage onto a new background image or video.

Understanding the Chromakey Filter

The chromakey filter in FFmpeg makes a specified color in your video transparent. It is primarily used for green screens or blue screens.

The basic syntax for the filter is:

chromakey=color:similarity:blend

Key Parameters:


Example 1: Basic Green Screen Removal

To remove a standard green screen and output the video with an alpha (transparent) channel, use the following command. Note that the output format must support transparency (like QuickTime .mov using the png or prores_ks codecs):

ffmpeg -i input.mp4 -vf "chromakey=0x00FF00:0.3:0.1" -c:v qtrle output.mov

Example 2: Overlaying Green Screen Footage onto a Background

Most of the time, you want to replace the green screen with a new background image or video immediately. You can achieve this in a single command using FFmpeg’s filter_complex and the overlay filter.

Overlaying onto a Video Background:

ffmpeg -i background.mp4 -i greenscreen.mp4 -filter_complex "[1:v]chromakey=0x00FF00:0.3:0.1[keyed];[0:v][keyed]overlay=shortest=1[out]" -map "[out]" output.mp4

How this command works:

  1. -i background.mp4: Input 0 (the background).
  2. -i greenscreen.mp4: Input 1 (the green screen foreground).
  3. [1:v]chromakey=...[keyed]: Applies the chromakey filter to Input 1 and names the output stream keyed.
  4. [0:v][keyed]overlay...[out]: Places the keyed stream on top of Input 0.
  5. shortest=1: Tells the output to stop when the shortest input video ends.
  6. -map "[out]": Maps the final combined video stream to the output file.

Tips for Getting a Clean Key