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?

2 Answers 2


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.

  • I tried with this filter, but it seems like it only applies the second colorkey -filter_complex '[1:v]colorkey=0x016733:0.1:0.25:[ckout1];[ckout1]colorkey=0x32AB57:0.1:0.2:[ckout];[0:v][ckout]overlay[out]' -map '[out]' -map 1:a:? Commented Oct 7, 2021 at 22:45

I've been looking for the same question, and saw you almost had it and thanks to that I've found my own answer.

 What would go in place of input1_c3 and input2_c3? 

TOP (or A) and BOTTOM (or B) will have the values you're looking for.

Your Answer

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

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