Last updated: August 11

<span aria-hidden="true" id="green-screen-remover-with-ffmpeg-chroma-key-video"></span>

# Green screen remover with FFmpeg: chroma key video

![Joseph Grabski](/assets/images/teammates/joseph2.png?dpl=dpl_3fBRD5jmFtSDABLXGJJyXU1nVXf8)

**Joseph Grabski**

Content Lead · Rochester, United Kingdom · Show bio

[](https://x.com/joe%5Fgrabski)[](https://github.com/Missing-Tech)

Using, and then removing, a green screen can be a tedious process. However, if conditions are favorable, leanings towards some automation can help save a lot of time. Naturally, at Transloadit we love automating the minutiae, so let's take a look at how we can use FFmpeg and Transloadit to automatically chroma key out a green screen from a video – leaving it with a transparent background.

The quickest FFmpeg green screen remover uses the `colorkey` filter to make a selected shade transparent, then encodes the result to a format that supports an alpha channel. Good lighting and an evenly colored background matter as much as the command itself.

![Banner for blog post featuring the botty logo in between half a transparent background and half a green-screen](/_next/static/immutable/media/opengraph-image.43qzyj5itckeq.png)

<span aria-hidden="true" id="how-does-a-green-screen-work"></span>

## How does a green screen work?

Before we can remove a green screen, we need to understand what a green screen really is. A green screen is placed behind a subject, to create a uniform background that can be more easily removed. Normally, the color chosen is a neon green, since it's the furthest from skin-tones, although blue is also commonly used.

When you want to remove the background, you need to use a chroma-key to selectively remove the green colour from each frame of the video, leaving you with a transparent background behind your subject.

<span aria-hidden="true" id="ffmpeg-command"></span>

## FFmpeg command

Before we get into the nuts and bolts of our Assembly Instructions, let's pop open the hood and take a look at what is underneath 🔎

Transloadit uses a selection of CLI tools to help us perform transcoding operations on your files. One of these tools is the highly regarded [FFmpeg⁠](http://ffmpeg.org/), which we use in many of ourRobots for video, audio and image transcoding.

Before we draft up our Template, we can first attempt the operation locally using an FFmpeg command. Then, we convert the FFmpeg command into a set of Assembly Instructions, allowing us to capitalize on the convenience and speed that Transloadit offers.

To remove a green screen from a video, the command is as follows:

```bash
ffmpeg -i input.mp4 -vf 'colorkey=0x00FF00:similarity=0.2:blend=0.3' -c:v libvpx-vp9 -pix_fmt yuva420p -c:a libopus output.webm

```

Let's take it apart.

First, we use the `i` flag to specify our input file. From this, we can pass a series of video filters to the `vf` flag. In our case, we only need to use the [colorkey⁠](https://ffmpeg.org/ffmpeg-filters.html#colorkey) filter, setting the color key to 0x00FF00.

We can then tweak the `colorkey` using the `similarity` and `blend` parameters. These specify how close a color needs to be to the key color to be made transparent, and also how harsh the key is. Feel free to experiment with their values to see how the result changes.

Next, `c:v` selects the VP9 encoder and `pix_fmt` requests a pixel format with an alpha channel. The audio is encoded as Opus. For more information on VP9 and other codecs, check out our [video compression](/blog/2023/05/video-compression-techniques.md)blog.

Finally, the `.webm` output extension selects the WebM format, since this format supports video transparency.

<span aria-hidden="true" id="template"></span>

## Template

Now that we've seen the underlying command, let's see how it looks inside our Template.

```json
{
  "steps": {
    ":original": {
      "robot": "/upload/handle"
    },
    "remove_green_screen": {
      "use": ":original",
      "robot": "/video/encode",
      "result": true,
      "ffmpeg_stack": "v7",
      "preset": "empty",
      "ffmpeg": {
        "vf": "colorkey=0x00FF00:similarity=0.2:blend=0.3",
        "c:v": "libvpx-vp9",
        "pix_fmt": "yuva420p",
        "c:a": "libopus",
        "f": "webm"
      }
    },
    "exported": {
      "use": ["remove_green_screen", ":original"],
      "robot": "/s3/store",
      "credentials": "demo_s3_credentials",
      "url_prefix": "https://demos.transloadit.com/"
    }
  }
}

```

Notice how within the `ffmpeg` parameter, we can specify the exact same flags as in the original command, letting us manipulate the file in the same way, whilst gaining the extra functionality that Transloadit offers.

An important detail to note here is that we are using the `empty` preset, to make sure that no other encoding takes place on the file apart from what we specified. Check out our[presets page](/docs/presets/video.md#video-encoding-presets) to see the specifics on what each preset offers.

<span aria-hidden="true" id="final-results"></span>

## Final results

Below is the result from our Template, when passing in a video of a dinosaur in front of a bright green background.

Looks pretty good! All of this happened automatically too, allowing us to process hundreds of files with ease, and meaning we can export our results to a storage bucket to be retrieved later.

That's all for this blog! Hopefully, it has given a look behind the curtain on how to use FFmpeg within your Templates. To keep up to date with future blogs, and to see articles that our developers find interesting, why not sign up for our newsletter below?

[#assembly](/blog/tags/assembly.md)[#video-encode-robot](/blog/tags/video-encode-robot.md)[#ffmpeg](/blog/tags/ffmpeg.md)

### 👩‍💻 Join 20k+ developers

Sign up for our [monthly newsletter](/newsletters.md) to receive direct links to 3 exclusive tech — and 2 product updates. No less, no more.

Your email:

Get access

## File uploading and encoding. Made simple.

Transloadit streamlines file handling for developers, trusted by brands like Coursera and The New York Times. We’re known for a reliable API, top-notch support, and a strong commitment to open source, with projects like [Uppy⁠](https://uppy.io) and [Tus⁠](https://tus.io) setting standards in file processing.

[Sign up](/c/)[Book a Demo](https://survey.typeform.com/to/kRg47Xi5)

No credit card needed · 5 GB included in the free plan

Cancel anytime
