6

ffmpeg does a very good job of getting rid of a green screen, with a command like this:

ffmpeg -f lavfi -i color=c=black:s=606x1080 
       -i input.mp4  
       -filter_complex 
            "[1:v]chromakey=0x70de77:0.1:0.2[ckout];
            [0:v][ckout]overlay[out]" 
       -map "[out]"  output.mp4

but it replaces the green screen with solid black, whereas I would like it replaced with a transparent background, alpha = 0.

I tried setting the color to #00000000 (8 zeroes indicating a zero alpha), but that still resulted in a black background.

Strangely, when I set the color to say red, it gives a red tint to many unfiltered areas.

So I would like a transparent background, but I'm also curious what the color option is doing.

1 Answer 1

4

Output by MP4 defaults to the H.264 codec for the video. H.264 does not support alpha.

You can output to .mov with a video codec -c:v of png or qtrle. There are others but they have restrictions on resolution and framerate.

You can't use the overlay filter as it doesn't output to a pixel format with alpha. So, just the chromakey filter, and no color source.

7
  • Thanks. So something like this? 'ffmpeg -f lavfi -i color=c=#00000000:s=606x1080 -i input.mp4 -c: png -filter_complex "[1:v]chromakey=0x70de77:0.1:0.2[out]" -map "[out]" output.mov' Jun 5, 2017 at 4:04
  • ffmpeg -i input.mp4 -vf "chromakey=0x70de77:0.1:0.2" -c copy -c:v png output.mov
    – Gyan
    Jun 5, 2017 at 4:16
  • That indeed works -thanks! But the .mov file is a huge! 2 min of video which is 58MB as mp4 turns into 15GB of mov. And then I need to display it on the web, and it seems only webm will handle alpha channel video in a browser. And that is multiples larger. (Can't give an exact figure because I haven't got it to complete yet!). Jun 7, 2017 at 4:33
  • VP8 shouldn't be multiples larger. Somewhat, yes. PNG or QTRLE will be much larger; they are intra-frame lossless codecs. QTRLE employ very basic compression. PNG is better.
    – Gyan
    Jun 7, 2017 at 4:44
  • Tried various permutations. keep getting "Transparency encoding with auto_alt_ref does not work" and "maybe incorrect parameters such as bit_rate, rate, width or height". This was one thing I tried that gave those errors: 'ffmpeg -i input.mp4 -vf "chromakey=0x70de77:0.1:0.2" -c copy -c:v libvpx -b:v 1M output.webm' Jun 8, 2017 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.