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.mp4Key Parameters of the Despill Filter
You can fine-tune the despill effect using several parameters:
type(ort): Sets the color of the spill you want to remove. Usegfor green (default) orbfor blue.mix(orm): Controls the strength of the despill effect. The value ranges from0.0(no effect) to1.0(maximum despill). The default value is0.5.expand(ore): Speeds up or slows down the spill protection zone expansion. The value ranges from0.0to100.0(default is0.0).red/green/blue: Adjusts the brightness of individual color channels within the despilled areas.
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.mp42. 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.mp43. 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.mp4In 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.