AnswerBun.com

How to apply multiple chroma keys in ffmpeg?

Video Production Asked on October 28, 2021

I tried creating two separate colorkey filters (as these seem to work better than chromakey filters) like this:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex '[1:v]colorkey=0x6AA999:0.1:0.2[ckout1];[0:v][ckout1]overlay[out1];[1:v]colorkey=0x4D827A:0.1:0.2[ckout2];[out1][ckout2]overlay[out2]' -map '[out2]' output.mp4

But this does not seem to filter on both keys. In thinking about why, I think the issue is that both filters are creating transparency in the pixels that match that key, but then the overlay is combining the pixels that weren’t filtered out from both keys, so I’m really only getting transparency for pixels which match BOTH filters, instead of those which match either.

I also looked at the blend filter, with the idea that perhaps I could do something like this in the filter complex:

'[0:v]colorkey='$KEY1':0.1:0.2[ckout1];[0:v]colorkey='$KEY2':0.1:0.2[ckout2];[ckout1][ckout2]blend=c3_expr=min(input1_c3,input2_c3)[out2]' -map '[out2]'

The idea being that I would take the minimum alpha value (opacity) of each input source for each pixel and make that the alpha value for the output for that pixel. I am assuming (it’s not clear from the text) that the “c3” channel is referring to the alpha channel, but I don’t see how to get the alpha value from each input. What would go in place of input1_c3 and input2_c3?

Or is there another way to do this that is better?

One Answer

Instead of always using [1:v], you would use the output of the previous one e.g. [ckout1]

My guess, you want this:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex '[1:v]colorkey=0x6AA999:0.1:0.2[ckout1];[ckout1]colorkey=0x4D827A:0.1:0.2[ckout2];[0:v][ckout2]overlay[out2]' -map '[out2]' output.mp4

(Maybe the inputs switched around)

The overlay you are using is from https://ffmpeg.org/ffmpeg-filters.html#colorkey? My guess is, that you misunderstood, what the overlay does in the example there. The example describes overlaying 2 opaque videos on top of each other, where the upper video receives transparency first.
What you are doing is overlay the transparent version of input2 onto input1 and then colorkeying input2 again and putting that also on top of input1 and the first colorkey.

Answered by Pingger Shikkoken on October 28, 2021

Add your own answers!

Related Questions

How to use FFmpeg Command for Reverse Video?

1  Asked on November 11, 2021 by ravi-vaghela

   

Adobe Premiere Pro Green Lines Problem

1  Asked on October 28, 2021 by afel

 

HLS.js player dropping frames at discontinuities in HLS stream

1  Asked on October 28, 2021 by james-mc

   

How to track and zoom in AE

1  Asked on October 28, 2021 by egorst

 

Does HEVC Support 16-Bit RGB Color Format?

2  Asked on October 28, 2021 by user30535

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP