Log in

View Full Version : How to chroma key one video over another in VS?


SilSinn9801
31st March 2023, 20:12
I want to overlay one video (video2) over another video (video1) & have video2’s solid-black background act as chroma key (be treated as transparent background instead) so that portions of video1 can be seen through video2. For example, I have as video1 an oscilloscope view (generated by nyanpasu64’s corrscope program) of a blue-colored waveform that only swings from 0 to positive (no negative swings = DC-biased), & I have as video2 the same waveform except it has been recolored to white & fed through a 10-Hz high-pass filter in Audacity (so that the DC bias is removed & the signal now swings from negative to positive). Now how to transparently overlay that HPF’d oscview over the DC-biased original?

poisondeathray
31st March 2023, 20:33
You can use a luma mask approach , assuming your FG waveform doesn't have "black" as well

There are probably many slight variations of luma masking; here is one mwlmask in xvs func
https://github.com/xyx98/my-vapoursynth-script/blob/master/xvs.py

SilSinn9801
31st March 2023, 21:10
I downloaded & copied xvs.py to the same directory where I installed havsfunc.py, mvsfunc.py, etc. to try mwlmask on my script. But now I am getting an error about rgvs not existing (even after correctly importing the necessary PY scripts) when opening my script with VirtualDub2:
Avisynth open failure:
Python exception: There is no attribute or namespace named rgvs
Traceback (most recent call last):
File "src\cython\vapoursynth.py", line 2890, in vapoursynth._vpy_evaluate
File "src\cython\vapoursynth.py", line 2891, in vapoursynth._vpy_evaluate
File "D:\Users\SilSinn9821\Music\Silent Sinner in Scarlet\Test Files\SSGTEST4.VPY", line 44, in <module>
CorrscopeMask = xvs.mwlmask(Corrscope2)
File "C:\Program Files\Python310\lib\site-packages\xvs.py", line 1756, in mwlmask
clip = clip.rgvs.RemoveGrain(4)
File "src\cython\vapoursynth.pyx", line 1821, in vapoursynth.VideoNode.__getattr__
AttributeError: There is no attribute or namespace named rgvs

_Al_
31st March 2023, 22:15
If you want to go using expressions:

import vapoursynth as vs
from vapoursynth import core
video1 = some_source_plugin(r'C:\path\video1.png') #RGB24
video2 = some_source_plugin(r'C:\path\video2.png') #RGB24
th = 5
#if r,g,b values are all smaller than threashold (th), it is a background pixel, if not it is a mask pixel
expr = f'x {th} < y {th} < and z {th} < and 0 255 ?'
mask = core.std.Expr([video1.std.ShufflePlanes(plane, vs.GRAY) for plane in [0,1,2]], expr)
out = core.std.MaskedMerge(video2, video1, mask=mask)
out.set_output()

poisondeathray
31st March 2023, 22:17
AttributeError: There is no attribute or namespace named rgvs[/CODE]


rgvs is from removegrain
https://github.com/vapoursynth/vs-removegrain/releases