View Full Version : Replace colour in video clip with transparency?
buffyangel108
19th September 2008, 23:43
Hi all,
I'm trying to replace the red background of a video clip with transparency (with a view to overlaying the resulting clip over another video, eg. a beach). The red background has a hex value of $B30101, so I thought the following script should suffice:
video = DirectShowSource("clip.mkv").ConvertToRGB32()
ColorKeyMask(video,$B30101,200,200,200)
Unfortunately, this just returns the original clip untouched. Could anyone perhaps point me in the right direction? Any help would be much appreciated! :)
Gavino
20th September 2008, 00:27
I'm trying to replace the red background of a video clip with transparency
...
ColorKeyMask(video,$B30101,200,200,200)
Unfortunately, this just returns the original clip untouched.
Perhaps you already know this, but ColorKeyMask itself doesn't replace the given color (it doesn't change any of the RGB pixels), it just sets the appropriate pixels of the alpha channel to be transparent. So if just looking at the clip on its own, it will look unchanged.
Your thresholds (200) are way too high - the default values (10) should be enough if your red is a uniform shade. Too high means you risk including other parts of the image in the transparent part.
How are you doing the overlay? Note that if using the Overlay function, you need to use mask=ShowAlpha(ColorKeyMask(...)).
sidewinder711
20th September 2008, 01:24
Here is an example I used for substituting the color of one picture using the color of a second picture. But you can easily change the sources for clip1 and clip2. Hopefully your color to be sustituted is easy to define, which will be the case if there aren't a lot of nuances of that color. Otherwise you have to increase the threshold number... and if your threshold number gets too high, then other parts of your clip1 will be masked and become transparent, too.
#ColorKeyMasking
#{1.base clip with color to substituted}
clip1 = ImageReader("On the beach.jpg").BilinearResize(640,520).ConvertToRGB32()
#{1a.define the color which shall be substituted with ColorKeyMask and define its threshold}
transparent=resetmask(clip1).colorkeymask($FEE7C5,32)
#{2.target clip/pic color}
clip2=ImageReader("maskleftblack.png").BilinearResize(640,520).ConvertToRGB32()
#{3.use Layer to substitute the clip1-mask-area with the new target color of clip2}
layer(clip2, transparent)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.