Alpha Video to Luma Key

Use this forum to request features. Maybe you'll get lucky!
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Alpha Video to Luma Key

Post by emcodem »

While we wait for Frank, maybe meanwhile just try ffmpeg in a cmd executor:

"%s_ffmpeg%" -i "%s_source%" -vf format=yuva444p16le,alphaextract,format=yuv420p "%s_source%_alpha.mov"

Note that we seem to have to trick ffmpeg to assume another pixel format in order to be able to retrieve alpha only.
emcodem, wrapping since 2009 you got the rhyme?
User avatar
FranceBB
Posts: 264
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: Alpha Video to Luma Key

Post by FranceBB »

video_m wrote: Mon Jan 10, 2022 5:39 pm Hello Frank,
the key stays black.
Thanks for the insight, now I know exactly what you mean: you wanna color the image with green using the transparency layer.
I came up with the right script for you:

Code: Select all

#Indexing
FFMpegSource2("Wvd3_clean.mov", atrack=-1)

#Getting rid of evil frame properties
propClearAll()

#Keeping the alpha channel
ConverttoRGB32()

#Collecting data
my_width=Width()
my_height=Height()
my_framerate=FrameRate()
my_frames=FrameCount()

#Substituting the alpha channel with a custom image
mk=ExtractA().ConverttoRGB32()
bg=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)
top=last.Mask(mk)
Layer(bg, top)

#Going to 4:2:2 planar
Converttoyv16()

in FFAStrans, this would be:

Code: Select all

#Keeping the alpha channel
ConverttoRGB32(m_clip)

#Getting rid of evil frame properties
propClearAll()

#Collecting data
my_width=Width()
my_height=Height()
my_framerate=FrameRate()
my_frames=FrameCount()

#Substituting the alpha channel with a custom image
mk=ExtractA().ConverttoRGB32()
bg=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)
top=last.Mask(mk)
Layer(bg, top)

#Going to 4:2:2 planar
m_clip=Converttoyv16()

return m_clip

and this will achieve the right result, so from this:

Image

to this:

Image



and as I always say: anything is possible with Avisynth eheheheheeh


if you want to keep audio, you need:

Code: Select all

#Keeping the alpha channel
ConverttoRGB32(m_clip)

#Getting rid of evil frame properties
propClearAll()

#Collecting data
my_width=Width()
my_height=Height()
my_framerate=FrameRate()
my_frames=FrameCount()
my_audio_channels=AudioChannels()
my_audio=GetChannels(my_audio_channels)

#Substituting the alpha channel with a custom image
mk=ExtractA().ConverttoRGB32()
bg=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)
top=last.Mask(mk)
video=Layer(bg, top)
audio=my_audio
AudioDub(video, audio)

#Going to 4:2:2 planar
m_clip=Converttoyv16()

return m_clip

if you're using an Avisynth version prior to 3.7.1, you can toss "propClearAll()", so:

Code: Select all

#Keeping the alpha channel
ConverttoRGB32(m_clip)

#Collecting data
my_width=Width()
my_height=Height()
my_framerate=FrameRate()
my_frames=FrameCount()
my_audio_channels=AudioChannels()
my_audio=GetChannels(my_audio_channels)

#Substituting the alpha channel with a custom image
mk=ExtractA().ConverttoRGB32()
bg=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)
top=last.Mask(mk)
video=Layer(bg, top)
audio=my_audio
AudioDub(video, audio)

#Going to 4:2:2 planar
m_clip=Converttoyv16()

return m_clip
User avatar
FranceBB
Posts: 264
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: Alpha Video to Luma Key

Post by FranceBB »

As a side note, since emcodem says that I have no love for ffmpeg and algie said that we should provide an alternative way to Avisynth to do it for educational purposes, he (algie) created the command line to do the same thing in FFMpeg:

Code: Select all

ffmpeg.exe -i "source_with_alpha.mov"  -i "fill.mxf" -filter_complex "[0]alphaextract[a];[1][a]alphamerge[mask];[mask][0]overlay[v]" -map [v]  -y "out.mp4"
Cheers,
Frank (FranceBB) and Livio (algie)
video_m
Posts: 22
Joined: Fri Dec 17, 2021 6:07 pm

Re: Alpha Video to Luma Key

Post by video_m »

Thank you!!

but if i use the script than get i the error: "there is no function named 'ImageSource"

When i add: LoadPlugin("%s_ffastrans_dir%\processors\ffmpeg\x64\plugins+\ImageSeq.dll") to the script then is the key black and not green.
User avatar
FranceBB
Posts: 264
Joined: Sat Jun 25, 2016 3:43 pm
Contact:

Re: Alpha Video to Luma Key

Post by FranceBB »

video_m wrote: Sat Jan 15, 2022 6:17 pm Thank you!!

but if i use the script than get i the error: "there is no function named 'ImageSource"

When i add: LoadPlugin("%s_ffastrans_dir%\processors\ffmpeg\x64\plugins+\ImageSeq.dll") to the script then is the key black and not green.
Yeah loadplugin was implied.
About the key, make sure that AV Decoder is set to no decode, same as source for both video and audio
video_m
Posts: 22
Joined: Fri Dec 17, 2021 6:07 pm

Re: Alpha Video to Luma Key

Post by video_m »

i make the mistake with AV Decoder NICE THIS WORK!!!! THANK you
Post Reply