Page 2 of 2

Re: Alpha Video to Luma Key

Posted: Tue Jan 11, 2022 2:01 pm
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.

Re: Alpha Video to Luma Key

Posted: Wed Jan 12, 2022 2:09 pm
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

Re: Alpha Video to Luma Key

Posted: Thu Jan 13, 2022 9:21 am
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)

Re: Alpha Video to Luma Key

Posted: Sat Jan 15, 2022 6:17 pm
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.

Re: Alpha Video to Luma Key

Posted: Sun Jan 16, 2022 10:54 am
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

Re: Alpha Video to Luma Key

Posted: Sun Jan 16, 2022 4:37 pm
by video_m
i make the mistake with AV Decoder NICE THIS WORK!!!! THANK you