Alpha Video to Luma Key

Use this forum to request features. Maybe you'll get lucky!
video_m
Posts: 19
Joined: Fri Dec 17, 2021 6:07 pm

Alpha Video to Luma Key

Post by video_m »

Hello All,

I have been using ffastrans for a while for various purposes. Now I just wanted to convert a video with alpha key to a luma key. How can I best do this I couldn't find a filter for it.

Kr,
User avatar
FranceBB
Posts: 230
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: Alpha Video to Luma Key

Post by FranceBB »

Can you elaborate this a bit?
Do you mean using a mask to overlay a foreground in a background?
If that's the case that might be done within an Avisynth Script but I can see several ways in which it could go wrong unless the mask of the green screen is consistent once you automatize it.

P.s almost forgot: welcome to the forum! :D

What I had in mind was something like this:

Code: Select all

clip1 = LWLibavVideoSource("background.mov")
clip2 = LWLibavVideoSource("greenscreen.mov")
maskclip = ColorKeyMask(clip2, $125d12, 40)
Overlay(clip1, clip2, mask=ShowAlpha(maskclip), mode="blend", opacity=1)
So what you would do in FFAStrans would be to use the A/V Decoder to index the file for you so that you can use a Custom Avisynth Script. Before that, we need to save the second input file into a variable, we'll call this one %s_myvariable% and we can use the populate variable to populate such a variable with a string. Technically we could either have a watchfolder that monitors something and writes a .txt and then we read such a txt from our workflow or we can just hardcode it for this example just to be sure it works, like: populate variable %s_myvariable% set to \\whatever_share\whatever_path\greenscreen.mov At this point, you can use a Custom Avisynth Script node in which you can feed the two inputs, so we're gonna grab the clip 1 from the indexed source and the clip2 from our path, so we're gonna have something like:

Code: Select all

# Variables: m_clip = The last returned AviSynth media
# Do NOT change any of the following variables!!!
# _ffas_video = <original video>
# _ffas_audio = <original audio>
# _ffas_height = <source height>
# _ffas_width = <source width>
# _m_clip_a_channels = <total channels>
# _ffas_work_fdr = Working folder for the workflow

LoadPlugin("\\yourffastransdir\processors\avs_plugins\ffms2\x64\ffms2.dll")
LoadPlugin("\\yourffastransdir\processors\avs_plugins\MaskTools\x64\masktools2.dll")
Import("\\yourffastransdir\processors\avs_plugins\ffms2\FFMS2.avsi")

clip1=m_clip
clip2 = FFVideoSource("%s_myvariable%").AssumeFieldBased() #filter_builder workaround
maskclip = ColorKeyMask(clip2, $125d12, 40)
m_clip=Overlay(clip1, clip2, mask=ShowAlpha(maskclip), mode="blend", opacity=1)

# The following MUST be the last line of your script

Return m_clip
then you can feed it to any encoder node within FFAStrans and it will deliver the result. :)
video_m
Posts: 19
Joined: Fri Dec 17, 2021 6:07 pm

Re: Alpha Video to Luma Key

Post by video_m »

Thank you FanceBB for your welcome and reaction!

What I have is a apple pross 444 with alpha key.

I will transcoding only the alpha channel to luma key (black and white)
User avatar
FranceBB
Posts: 230
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: Alpha Video to Luma Key

Post by FranceBB »

video_m wrote: Wed Dec 22, 2021 5:01 pm
What I have is a apple pross 444 with alpha key.

I will transcoding only the alpha channel to luma key (black and white)
Ah, ok! Now it makes sense!
So you have a 4:4:4:4 file where the 4:4:4 stand for the luma/chroma components at full resolution and the last 4, the fourth 4, stands for the alpha channel and you wanna take the alpha channel only and encode it in a 4:0:0 video, got it.
In this very moment I'm on my mobile so I can't fire up AVSPmod and test, however the easiest thing that comes up in my mind is a workflow with just an indexer (i.e AV Decoder set with everything as "same as source") and then a Custom Avisynth Script node with:

Code: Select all

m_clip=ExtractA(m_clip)

return m_clip
And then an encoder node and a delivery node.
Technically this should extract the alpha channel.
Let me know how it goes. :)
video_m
Posts: 19
Joined: Fri Dec 17, 2021 6:07 pm

Re: Alpha Video to Luma Key

Post by video_m »

Nice it work!!!
Thank you!

Tomorrow I wil looking for a chroma key
User avatar
FranceBB
Posts: 230
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: Alpha Video to Luma Key

Post by FranceBB »

video_m wrote: Wed Dec 22, 2021 6:47 pm Nice it work!!!
Thank you!
Image
video_m
Posts: 19
Joined: Fri Dec 17, 2021 6:07 pm

Re: Alpha Video to Luma Key

Post by video_m »

Now will i make from 444 video source a video with the alpha is green. I have try different script's but nothing works...
User avatar
FranceBB
Posts: 230
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: Alpha Video to Luma Key

Post by FranceBB »

video_m wrote: Thu Jan 06, 2022 8:22 pm Now will i make from 444 video source a video with the alpha is green. I have try different script's but nothing works...
I have seen your PM about what you wanna do next and I don't get it.
I'll contact you back via PM, I just didn't have any push notifications for the forum so I failed to read it till now eheheheh
User avatar
FranceBB
Posts: 230
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: Alpha Video to Luma Key

Post by FranceBB »

video_m wrote: Thu Jan 06, 2022 8:22 pm Now will i make from 444 video source a video with the alpha is green. I have try different script's but nothing works...
Ok, so, thank you for the PM.
I'm gonna share the solution here only 'cause others might need it in the future, dunno.

So what you wanna do is to swap the Alpha Channel of the clip with Green picked from an image.
What you were using in the code you sent me was the "Layer" function, however such a function is meant to be used to "overlay" something on top of something else, which is not what we're trying to do here.
So, first things first, let's take care of your input, which is 4:4:4:4 and to make things easier we're gonna use the good old RGB32 so that I can use MergeARGB().

The idea is to:

1) Index your source file
2) Convert to RGB32
3) Extract the R, G, B components and save them in a variable
4) Save the resolution, framerate and duration in variables
5) Index the image you wanna use
6) Convert the image to RGB32 too
7) Have as many frames as the input, at the same fps as the input at the same resolution as the input
8) Toss the Alpha Channel of the originally indexed clip and swap it with the one of the image you indexed

This can be accomplished in Avisynth with the following AVS Script:

Code: Select all

#Indexing the original clip
ColorBars(848, 480, pixel_type="YV24")
ConverttoRGB32()

#Extraction and Metadata
my_Red=ExtractR()
my_Green=ExtractG()
my_Blue=ExtractB()
my_width=Width()
my_height=Height()
my_framerate=FrameRate()
my_frames=FrameCount()

#Indexing the image you want to use
my_alpha=ImageSource("\\mibctvan000.avid.mi.bc.sky.it\Ingest\MEDIA\temp\green_screen_sample.png", fps=my_framerate, start=0, end=my_frames, pixel_type="RGB32").Spline64Resize(my_width, my_height)

#Swap the alpha channel
MergeARGB(my_alpha, my_Red, my_Green, my_Blue)

Now, since you're using FFAStrans, the hard part is already accomplished by the A/V Decoder, therefore you would have to use m_clip instead, namely:

Code: Select all

#Indexing the original clip
ConverttoRGB32(m_clip)

#Extraction and Metadata
my_Red=ExtractR()
my_Green=ExtractG()
my_Blue=ExtractB()
my_width=Width()
my_height=Height()
my_framerate=FrameRate()
my_frames=FrameCount()

#Indexing the image you want to use
my_alpha=ImageSource("\\mibctvan000.avid.mi.bc.sky.it\Ingest\MEDIA\temp\green_screen_sample.png", fps=my_framerate, start=0, end=my_frames, pixel_type="RGB32").Spline64Resize(my_width, my_height)

#Swap the alpha channel
MergeARGB(my_alpha, my_Red, my_Green, my_Blue)
This way you have an ARGB file with the alpha channel swapped, however to confirm this I would need a proper alpha channel file and you're the only one who has it.
I know there's DRM and everything, but if you could share a tiny sample like honestly 5-10 seconds privately I could test it.

Thanks,
Frank ;)
video_m
Posts: 19
Joined: Fri Dec 17, 2021 6:07 pm

Re: Alpha Video to Luma Key

Post by video_m »

Hello Frank,

I get the error "there is no function named 'ImageSource'", for this problem i have add:
LoadPlugin("%s_ffastrans_dir%\processors\ffmpeg\x64\plugins+\ImageSeq.dll")

But the key stays black.
is the problem that i'm loading the wrong plugin?

Thank you!
Post Reply