How to Use FFmpeg Despill Filter for Green Screen

When shooting with a green or blue screen, color spill often reflects onto the actor’s skin, hair, and clothing, ruining the realism of your composition. This article provides a straightforward guide on how to use FFmpeg’s powerful despill video filter to detect and eliminate these unwanted color fringes, ensuring a clean and professional chroma key composition.

What is the FFmpeg Despill Filter?

The despill filter in FFmpeg is designed to remove green or blue light reflections (spill) from a subject after they have been filmed in front of a chroma key background. It works by analyzing the pixels and reducing the intensity of the target color (green or blue) relative to the other color channels, neutralizing the color cast without affecting the rest of the image.

Basic Syntax

To use the despill filter, you must apply it using the -vf (video filter) flag. The basic syntax is:

ffmpeg -i input.mp4 -vf "despill=type=g" output.mp4

Key Parameters of the Despill Filter

You can fine-tune the despill effect using several parameters:

Practical Examples

1. Removing Green Spill with Default Settings

If you shot your footage on a standard green screen, use the following command to apply a moderate despill effect:

ffmpeg -i actor_green.mp4 -vf "despill=type=g" output.mp4

2. Removing Blue Spill with Maximum Strength

For actors filmed against a blue screen where the blue reflection is highly visible on their hair or shoulders, change the type to b and increase the mix to 1.0:

ffmpeg -i actor_blue.mp4 -vf "despill=type=b:mix=1.0" output.mp4

3. Combining Despill with Chromakey in a Single Command

To key out the background and remove the color spill simultaneously, you can chain the chromakey and despill filters together. This command keys out the green screen, applies despill to the actor, and overlays them onto a background image:

ffmpeg -i foreground.mp4 -i background.png -filter_complex "[0:v]chromakey=0x00FF00:0.15:0.1[keyed]; [keyed]despill=type=g:mix=0.8[despilled]; [1:v][despilled]overlay=shortest=1[out]" -map "[out]" output.mp4

In this pipeline, the chromakey filter removes the solid green background, the despill filter cleans up the green edges on the actor, and the overlay filter places the cleaned-up actor onto the new background.