chromakey=0x1bb247:0.15:0.05 removes the whole backdrop and keeps nearly all of the subject; 0.10 leaves a green fringe, and despill cleans the edges. Keying a 6-second clip on ReelSDK cost under a third of a cent, at $0.02 per compute minute.
Remove a green screen with ffmpeg
chromakey matches in YUV and colorkey in RGB, so colorkey needs about 0.30 where chromakey gets by on 0.15. ReelSDK's API allows both plus despill, and can write a VP9 WebM with real transparency instead of a new background.
GuidesUpdated
ffmpeg -i fg.mp4 -i bg.mp4 -filter_complex \
"[1:v]scale=1280:720,setsar=1[bg];\
[0:v]chromakey=0x1bb247:0.15:0.05,despill=type=green[fg];\
[bg][fg]overlay=shortest=1[v]" \
-map "[v]" -map 1:a -c:v libx264 -crf 20 -c:a aac -shortest keyed.mp4The background is scaled to the foreground's 1280x720, the green is keyed out and despilled, and the two are laid on top of each other. The audio comes from the background clip.
Variations
The other commands you will need
The same with colorkey
colorkey compares RGB values. On our clip it needed similarity 0.30 to get close to what chromakey did at 0.15.
colorkey ffmpeg -i fg.mp4 -i bg.mp4 -filter_complex \ "[1:v]scale=1280:720,setsar=1[bg];\ [0:v]colorkey=0x1bb247:0.30:0.05,despill=type=green[fg];\ [bg][fg]overlay=shortest=1[v]" \ -map "[v]" -map 1:a -c:v libx264 -crf 20 -c:a aac -shortest colorkeyed.mp4Keep the transparency
No background: the keyed clip goes into a VP9 WebM with an alpha channel, ready for a browser or an editor.
alpha webm ffmpeg -i fg.mp4 -vf "chromakey=0x1bb247:0.15:0.05,despill=type=green,format=yuva420p" \ -c:v libvpx-vp9 -b:v 2M -an alpha.webm
The flags
The options in these commands
| Flag | What it does | Used here |
|---|---|---|
chromakey=0x1bb247 | The color to remove, as RGB hex; compared in YUV | Chromakey, WebM |
:0.15 | Similarity: how far from the key color still counts as key | Chromakey, WebM |
:0.05 | Blend: a soft edge instead of a hard cut | All |
colorkey=0x1bb247:0.30:0.05 | The same idea, compared in RGB | Colorkey |
despill=type=green | Pulls the green tint out of the subject's edges | All |
scale=1280:720,setsar=1 | Brings the background to the clip's size | Background |
overlay=shortest=1 | Puts the keyed clip on top and ends with the shorter input | Background |
format=yuva420p | A pixel format with an alpha channel | WebM |
-c:v libvpx-vp9 | VP9 can store that alpha channel in WebM; H.264 cannot | WebM |
Sources: ffmpeg filters: chromakey, ffmpeg filters: colorkey, ffmpeg filters: despill, checked November 2026.
Pick the key color from the clip
A green screen is never one green. Light falls off across the cloth, so our backdrop ranged from 0x129c3c in the corners to 0x2cc957 in the middle of one frame. Grab a frame with ffmpeg -ss 3 -i fg.mp4 -frames:v 1 frame.png, sample the backdrop in a few places, and key on a value in the middle of the range. We used 0x1bb247.
Finding the similarity
Similarity sets how far from the key color a pixel can be and still be removed: 0.01 matches only the exact color and 1.0 matches everything. We laid each result over magenta and counted the green pixels left in one 1280x720 frame.
At 0.10 with no blend, a few thousand green pixels survived around the edges. At 0.15 with a blend of 0.05, none did, and all but a fraction of a percent of the subject stayed. Going to 0.20 removed nothing more of the green but ate into the subject's edges. Start low and raise it until the green is gone, then stop.
chromakey or colorkey
chromakey works in YUV, the format most video is stored in, and its source code compares only the U and V values of each pixel: the color, not the brightness. That suits a backdrop that is brighter in one place than another. colorkey compares RGB values, where a darker green is further away. On our clip colorkey at 0.15 left about a thousand green pixels; it took 0.30 to get down to a handful.
Edges and spill
Light bouncing off the screen tints the subject's edges green, and the key cannot remove it without removing part of the subject. despill pulls that tint out after keying. The blend value of 0.05 adds a soft edge, so the outline does not look cut out with scissors.
H.264 in MP4 has no alpha channel, so to keep the transparency for later use VP9 in WebM with yuva420p. Our API run of that command wrote a WebM tagged with alpha, with more than nine in ten pixels of a frame transparent.
Without installing ffmpeg
The same command as one API call
Send the same args to POST /v1/ffmpeg with both clip URLs in inputs. chromakey, colorkey and despill are all allowed. Each job runs ffmpeg 8.1 on a fresh machine at $0.02 per compute minute, billed per second; this one finished in about 9 seconds and cost under a third of a cent.
curl "https://api.reelsdk.com/v1/ffmpeg?wait=60" \
-H "Authorization: Bearer $REELSDK_KEY" \
--json '{
"inputs": {
"fg.mp4": "https://api.reelsdk.com/f/lib/in/guides/green-screen-monkey.mp4",
"bg.mp4": "https://api.reelsdk.com/f/lib/demo/landscape.mp4"
},
"args": [
"-i", "fg.mp4", "-i", "bg.mp4", "-filter_complex",
"[1:v]scale=1280:720,setsar=1[bg];[0:v]chromakey=0x1bb247:0.15:0.05,despill=type=green[fg];[bg][fg]overlay=shortest=1[v]",
"-map", "[v]", "-map", "1:a", "-c:v", "libx264", "-crf", "20", "-c:a",
"aac", "-shortest", "keyed.mp4"
],
"outputs": ["keyed.mp4"]
}'FAQ
Questions, answered
How do I remove a green screen with ffmpeg?
Key it and overlay it: ffmpeg -i fg.mp4 -i bg.mp4 -filter_complex "[0:v]chromakey=0x1bb247:0.15:0.05,despill[fg];[1:v][fg]overlay=shortest=1" out.mp4, with your own key color.
Why is there a green outline left?
Raise the similarity a little, add a small blend such as 0.05, and add despill after the key to take the green tint off the edges.
How do I export a video with a transparent background?
Key it, then add format=yuva420p and encode with -c:v libvpx-vp9 into a .webm file. MP4 with H.264 cannot store transparency.
Can I key green screen video with an API?
Yes. POST the same args to https://api.reelsdk.com/v1/ffmpeg with both clip URLs in inputs. It runs ffmpeg 8.1 for $0.02 per compute minute, billed per second.
- Picture-in-picture video with ffmpegPut one video in the corner of another with scale, pad and overlay, end it with the main clip, or bring the inset in later.
- Add a watermark or logo to a video with ffmpegPut a PNG logo in a corner with overlay: scale it, make it semi-transparent, keep it off the edge, or show it only for the first seconds.
- Remove a logo from a video with ffmpegHide a fixed logo or timestamp with delogo or removelogo, find its exact box with show=1, or crop it away, and know what each leaves behind.
- Put two videos side by side with ffmpegPlace videos next to each other with hstack, on top of each other with vstack, or in a 2x2 grid with xstack, after scaling them to match.
- ffmpeg -filter_complex explainedLabels, commas and semicolons: how a filtergraph wires inputs to outputs, with four working graphs and the errors they fix.
- FFmpeg onlineRun your own ffmpeg command on your files in the browser, free and without installing or uploading anything.
- ReelSDK vs self-hosted FFmpegTranscoding a minute of 1080p to 720p takes about 24 seconds of compute: about 0.8 cents on ReelSDK, about a tenth of a cent on a busy 4 vCPU box. Below about 11,000 minutes a month, the API costs less than an always-on box.
Ready to build?
Ship video from your app today
Your first $0.50 is free, and one key covers every endpoint.
