Guide

Put a green screen meme over a video with FFmpeg

One FFmpeg command keys a green screen meme over any photo or video: chromakey removes the green, overlay puts the clip on your background, and -map 1:a? keeps the clip's sound. Here it is for a vertical 1080×1920 video:

Terminal
ffmpeg -loop 1 -i background.jpg -i greenscreen.mp4 -filter_complex \
 "[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1[bg];\
  [1:v]chromakey=0x00ff00:0.3:0.08,scale=1080:-2[fg];\
  [bg][fg]overlay=(W-w)/2:H-h:shortest=1,format=yuv420p[v]" \
 -map "[v]" -map "1:a?" -c:v libx264 -crf 20 -c:a aac meme.mp4

The rest of this guide gets you a clip, explains each part, and covers video backgrounds, mixed audio, captions, other key colors and green edges. Everything here was run with FFmpeg 7.1 on a clip from the API.

1Get a green screen clip

Any green screen video works. To search for one, the Green Screen Memes API has over 2,000 reaction meme clips, most with sound; a free Sandbox key covers 50 downloads a month. Search by the feeling or action you want, and list what came back (needs curl and jq):

Terminal
export GSM_API_KEY=gsm_live_...   # free Sandbox key from https://api.greenscreenmemes.app/dashboard

curl -fsS -G -H "Authorization: Bearer $GSM_API_KEY" \
  --data-urlencode "q=side eye" --data-urlencode "limit=3" \
  https://api.greenscreenmemes.app/v1/memes > results.json

jq -r '.data[] | "\(.id)  \(.chromaKeyColor)  \(.durationSeconds)s"' results.json
Output
Tung Tung Side Eye  green  2s
Dog giving awkward side eye  green  6s
Guy giving a sideeye  green  6s

Each result has a videoUrl, its chromaKeyColor, durationSeconds and a thumbnailUrl to look at before you choose. Download the first one (change 0 to pick another):

Terminal
# Signed link, good for about 6 hours: keep the file, not the link.
curl -fsSL -o greenscreen.mp4 "$(jq -r '.data[0].videoUrl' results.json)"

Links expire after a few hours. For a fresh one, fetch the clip again by id with GET /v1/memes/{id}.

2Key it over a photo

Terminal
ffmpeg -loop 1 -i background.jpg -i greenscreen.mp4 -filter_complex \
 "[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1[bg];\
  [1:v]chromakey=0x00ff00:0.3:0.08,scale=1080:-2[fg];\
  [bg][fg]overlay=(W-w)/2:H-h:shortest=1,format=yuv420p[v]" \
 -map "[v]" -map "1:a?" -c:v libx264 -crf 20 -c:a aac meme.mp4

What each part does:

  • -loop 1 -i background.jpg turns the photo into an endless video; shortest=1 stops at the end of the clip.
  • scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920 fills a vertical 9:16 frame without stretching the photo.
  • chromakey=0x00ff00:0.3:0.08 makes the green transparent. 0.3 is the similarity (how far from pure green still counts as green) and 0.08 the blend (how soft the edge is).
  • scale=1080:-2 makes the clip full width; use a smaller width for a smaller clip.
  • overlay=(W-w)/2:H-h centers the clip at the bottom. It's x:y, so overlay=0:0 puts it at the top left.
  • format=yuv420p and -c:v libx264 make an MP4 that plays everywhere, phones included.
  • -map "1:a?" keeps the clip's sound, and the ? means a silent clip doesn't fail.

3Over a video, with both soundtracks

For a video background, swap -loop 1 for -stream_loop -1 so a short background loops for as long as the clip runs, and mix the background's sound in quietly under the clip's:

Terminal
ffmpeg -stream_loop -1 -i background.mp4 -i greenscreen.mp4 -filter_complex \
 "[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1[bg];\
  [1:v]chromakey=0x00ff00:0.3:0.08,scale=1080:-2[fg];\
  [bg][fg]overlay=(W-w)/2:H-h:shortest=1,format=yuv420p[v];\
  [0:a]volume=0.35[bga];[1:a][bga]amix=inputs=2:duration=first:normalize=0[a]" \
 -map "[v]" -map "[a]" -c:v libx264 -crf 20 -c:a aac meme.mp4
  • volume=0.35 sets the background's level; the clip stays at full volume.
  • amix=…:duration=first ends the audio with the clip, like shortest=1 does for the picture. normalize=0 needs FFmpeg 5 or later.
  • amix needs both files to have sound. If the background is silent, drop the audio part of the graph and use -map "[v]" -map "1:a?", as in the photo recipe.

4Add a caption

Add drawtext after format=yuv420p. It doesn't wrap text, so use one drawtext per line, about 100 px apart, and keep each line under about 26 characters:

Terminal
ffmpeg -loop 1 -i background.jpg -i greenscreen.mp4 -filter_complex \
 "[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1[bg];\
  [1:v]chromakey=0x00ff00:0.3:0.08,scale=1080:-2[fg];\
  [bg][fg]overlay=(W-w)/2:H-h:shortest=1,format=yuv420p,\
drawtext=text='when the invoice':fontcolor=white:fontsize=64:box=1:boxcolor=black:boxborderw=18:x=(w-text_w)/2:y=200,\
drawtext=text='arrives':fontcolor=white:fontsize=64:box=1:boxcolor=black:boxborderw=18:x=(w-text_w)/2:y=300[v]" \
 -map "[v]" -map "1:a?" -c:v libx264 -crf 20 -c:a aac meme.mp4

Some FFmpeg builds can't find a default font; add fontfile=/path/to/font.ttf to each drawtext. An apostrophe in the text needs escaping, so it's easier to leave it out or use a typographic one (’).

5Blue and red screens

Most clips are on green, a few on blue or red. The API's chromaKeyColor tells you which, so swap the color in chromakey:

chromaKeyColorFilter
greenchromakey=0x00ff00:0.3:0.08
bluechromakey=0x0000ff:0.3:0.08
redchromakey=0xff0000:0.3:0.08
noneNo key: drop chromakey and use the clip as it is

6Fixing green edges

  • A green fringe stays: raise the similarity a little, from 0.3 to 0.35.
  • The subject loses color or gets holes: lower it, to 0.25.
  • A green tint on hair or edges: add despill right after the key:
The clip line of the filter graph
  [1:v]chromakey=0x00ff00:0.3:0.08,despill=type=green,scale=1080:-2[fg];\

Check the clip's thumbnail before you commit to it: most clips are clean cut-outs, but a few are a framed video on green, or a head-and-shoulders shot that ends partway down the frame.

7Doing it from an AI agent

Over MCP, the get_green_screen tool returns these commands already filled in for the clip: howToComposite.overImage and overVideo, with the right key color, the download command and notes on captions and placement. An agent with a shell (Claude Code, Cursor) can run them as they are.

Connect Claude Code
claude mcp add --transport http green-screen-memes https://api.greenscreenmemes.app/mcp \
  --header "Authorization: Bearer $GSM_API_KEY"

Before you publish

These are internet memes: Green Screen Memes makes the green screen versions, but the original footage isn't ours and isn't licensed with the clips, so how you use one is up to you. On Starter and up you can publish videos with them, for yourself or clients. Don't put clips of identifiable people in paid ads, sponsored posts or endorsements; animals, objects and cartoons are fine there. The terms have the details.

Shell scripts for all of this (search, download, key over a photo or a video) are in the examples on GitHub. Rendering in React instead? See the Remotion guide.

Get a free key

Sandbox: 50 video downloads and 30,000 calls a month, for building and testing.

Get a free key