StifflerStealth
12th December 2007, 02:40
EDIT: I stopped working on this and now decided to work on DissolveMod. Search for it. :)
I am still new to AVS and I have read avisynth.org and looked at the internal filters, but I do no know where to begin on validating a complex function. I need to know if all the frames are properly cut and aligned, the values of the functions, and so forth. What are y'all's suggestions on how to start writing debug statements for this?
I guess I should explain the function before I show it. This relates to a previous post I made about wanting help on how to have video cut, but have the audio blend. I wanted more features than just what dissolve had. My attempt at this function is to combine three fairly simple, specific functions into one. The goal was to create a function that will take audio from from clip_1 and have it stop at the video cut point, or fade down to the cut point, but allow audio from clip_2 to be blended into the last part of clip_1, or have the audio from clip one to keep playing past the cut point into clip_2 where clip_2's audio would start at the cut point or fade in from the cut point, or have the audio from both clips be blended with each other, or if you want, have the audio from clip_1 stop playing before the cut point and the audio from clip_2 to start playing long after the cut point ... well ... it doesn't matter where they start and stop as long as there is a blank spot in between. This function would allow me the freedom to choose how much audio gets blended before and after the main video cut point. Sounds complex? I think you may be able to see how I tried to write, but I hope that people here can give me pointers on how to 1) simplify this thing and 2) make sure it is working perfectly.
My main problem is that I have audio going here, so I can't tell which frame the audio is starting and stopping at. Is there a way to throw debug statements onto the screen that come up when the audio is blended? I need to make sure my math was correct.
The function *I take no responsibility if you get a headache from trying to understand this one :P *:
function AudioBlend(clip cLeft, clip cRight,
\ int cLeftStartFadeOut, int cLeftEndFadeOut, int cLeftVidCut,
\ int cRightStartFadeIn, int cRightEndFadeIn, int CRightVidCut,
\ float fps)
{
# This function allows audio from one clip to bleed into another clip.
# The video is cut with no transition. Maybe in a future version of this function.
# NOTE: The cLeft audio can fade out before the end of the cut and the
# cRight audio can start the fade in after the cut. That is why
# I have the fadein end and the fadeout begin variables rather than
# always using the end and beginning of the clips.
# cLeft = The video/audio clip that is on the left side of the cut.
# cRight = The video/audio clip that is on the right side of the cut.
# cLeftStartFadeOut = The number of frames from the _end_ of the clip the fade is to begin.
# cLeftEndFadeOut = The number of frames from the _end_ of the clip the fade ends.
# cLeftVidCut = The number of frames from the _end_ of the clip the video is cut.
# cRightStartFadeIn = The number of frames from the _beginning_ of the clip the fade is to begin.
# cRightEndFadeIn = The number of frames from the _beginning_ of the clip the fade ends.
# cRightVidCut = The number of frames from the _beginning_ of the clip the video is cut.
# Frame counts needed for calculations. Last frame of clip is FC* - 1.
FCLeft = FrameCount(cLeft)
FCRight = FrameCount(cRight)
TotalLen = (FCLeft - cLeftVidCut) + (FCRight - cRightVidCut)
cLeftOffset = TotalLen - (FCLeft - cLeftEndFadeOut)
cRightOffset = TotalLen - FCRight + cRightStartFadeIn
fps = cLeft.FrameRate()
# Convert the frame pointers
cLeftStartFadeOut = FCLeft - cLeftStartFadeOut - 1
cLeftEndFadeOut = FCLeft - cLeftEndFadeOut - 1
cLeftVidCut = FCLeft - cLeftVidCut -1
cRightStartFadeIn = cRightOffset
cRightEndFadeIn = TotalLen - FCRight + cRightEndFadeIn
cRightVidCut = TotalLen - FCRight + cRightVidCut
cLeftFL = cLeftEndFadeOut - cLeftStartFadeOut
cRightFL = cRightEndFadeIn - cRightStartFadeIn
cLeft = cLeft + BlankClip(cLeft,length=(TotalLen - FCLeft),color=$000000)
cRight = BlankClip(cRight,length=(TotalLen - FCRight),color=$000000) + cRight
cLeftAudio = FadeOut0(cLeft.Trim(0,cLeftEndFadeOut),cLeftFL,0,fps) +
\ BlankClip(cLeft,length=cLeftOffset,color=$000000)
cRightAudio = BlankClip(cRight,length=cRightOffset,color=$000000) +
\ FadeIn0(cRight.Trim(cRightStartFadeIn,0),cRightFL,0,fps)
# Overlap occures if the right clip's fade starts before the left clip ends.
# If no overlap, then there is a gap in Audio and that must be taken into account.
# Break audio up into 3 blocks. The middle block has the offset or audio gap.
# MixAudio takes a long time for me, so that's why I want to break things up.
Block1End = (cRightStartFadeIn < cLeftEndFadeOut) ? cRightStartFadeIn - 1 : cLeftEndFadeOut
Block2End = (cRightStartFadeIn < cLeftEndFadeOut) ? cLeftEndFadeOut : cRightStartFadeIn - 1
# Construct the now audio clip with only one use of MixAudio for the overlapping part. :)
Block2Audio = (Block1End == Block2End) ?
\ BlankClip(cLeft, length=0) :
\ MixAudio(cLeftAudio.Trim(Block1End + 1,Block2End),cRightAudio.Trim(Block1End + 1,Block2End),1,1)
V = cLeft.Trim(0,cLeftVidCut) + cRight.Trim(cRightVidCut,0)
A = cLeftAudio.Trim(0,Block1End) + Block2Audio + cRightAudio.Trim(Block2End + 1, 0)
return AudioDub(V,A)
}
EDIT: This should be fully working, but I would like test cases to prove it. :) If this works, you all are welcome to use it in your projects or improve upon it or make it part of AVS. :P
I am still new to AVS and I have read avisynth.org and looked at the internal filters, but I do no know where to begin on validating a complex function. I need to know if all the frames are properly cut and aligned, the values of the functions, and so forth. What are y'all's suggestions on how to start writing debug statements for this?
I guess I should explain the function before I show it. This relates to a previous post I made about wanting help on how to have video cut, but have the audio blend. I wanted more features than just what dissolve had. My attempt at this function is to combine three fairly simple, specific functions into one. The goal was to create a function that will take audio from from clip_1 and have it stop at the video cut point, or fade down to the cut point, but allow audio from clip_2 to be blended into the last part of clip_1, or have the audio from clip one to keep playing past the cut point into clip_2 where clip_2's audio would start at the cut point or fade in from the cut point, or have the audio from both clips be blended with each other, or if you want, have the audio from clip_1 stop playing before the cut point and the audio from clip_2 to start playing long after the cut point ... well ... it doesn't matter where they start and stop as long as there is a blank spot in between. This function would allow me the freedom to choose how much audio gets blended before and after the main video cut point. Sounds complex? I think you may be able to see how I tried to write, but I hope that people here can give me pointers on how to 1) simplify this thing and 2) make sure it is working perfectly.
My main problem is that I have audio going here, so I can't tell which frame the audio is starting and stopping at. Is there a way to throw debug statements onto the screen that come up when the audio is blended? I need to make sure my math was correct.
The function *I take no responsibility if you get a headache from trying to understand this one :P *:
function AudioBlend(clip cLeft, clip cRight,
\ int cLeftStartFadeOut, int cLeftEndFadeOut, int cLeftVidCut,
\ int cRightStartFadeIn, int cRightEndFadeIn, int CRightVidCut,
\ float fps)
{
# This function allows audio from one clip to bleed into another clip.
# The video is cut with no transition. Maybe in a future version of this function.
# NOTE: The cLeft audio can fade out before the end of the cut and the
# cRight audio can start the fade in after the cut. That is why
# I have the fadein end and the fadeout begin variables rather than
# always using the end and beginning of the clips.
# cLeft = The video/audio clip that is on the left side of the cut.
# cRight = The video/audio clip that is on the right side of the cut.
# cLeftStartFadeOut = The number of frames from the _end_ of the clip the fade is to begin.
# cLeftEndFadeOut = The number of frames from the _end_ of the clip the fade ends.
# cLeftVidCut = The number of frames from the _end_ of the clip the video is cut.
# cRightStartFadeIn = The number of frames from the _beginning_ of the clip the fade is to begin.
# cRightEndFadeIn = The number of frames from the _beginning_ of the clip the fade ends.
# cRightVidCut = The number of frames from the _beginning_ of the clip the video is cut.
# Frame counts needed for calculations. Last frame of clip is FC* - 1.
FCLeft = FrameCount(cLeft)
FCRight = FrameCount(cRight)
TotalLen = (FCLeft - cLeftVidCut) + (FCRight - cRightVidCut)
cLeftOffset = TotalLen - (FCLeft - cLeftEndFadeOut)
cRightOffset = TotalLen - FCRight + cRightStartFadeIn
fps = cLeft.FrameRate()
# Convert the frame pointers
cLeftStartFadeOut = FCLeft - cLeftStartFadeOut - 1
cLeftEndFadeOut = FCLeft - cLeftEndFadeOut - 1
cLeftVidCut = FCLeft - cLeftVidCut -1
cRightStartFadeIn = cRightOffset
cRightEndFadeIn = TotalLen - FCRight + cRightEndFadeIn
cRightVidCut = TotalLen - FCRight + cRightVidCut
cLeftFL = cLeftEndFadeOut - cLeftStartFadeOut
cRightFL = cRightEndFadeIn - cRightStartFadeIn
cLeft = cLeft + BlankClip(cLeft,length=(TotalLen - FCLeft),color=$000000)
cRight = BlankClip(cRight,length=(TotalLen - FCRight),color=$000000) + cRight
cLeftAudio = FadeOut0(cLeft.Trim(0,cLeftEndFadeOut),cLeftFL,0,fps) +
\ BlankClip(cLeft,length=cLeftOffset,color=$000000)
cRightAudio = BlankClip(cRight,length=cRightOffset,color=$000000) +
\ FadeIn0(cRight.Trim(cRightStartFadeIn,0),cRightFL,0,fps)
# Overlap occures if the right clip's fade starts before the left clip ends.
# If no overlap, then there is a gap in Audio and that must be taken into account.
# Break audio up into 3 blocks. The middle block has the offset or audio gap.
# MixAudio takes a long time for me, so that's why I want to break things up.
Block1End = (cRightStartFadeIn < cLeftEndFadeOut) ? cRightStartFadeIn - 1 : cLeftEndFadeOut
Block2End = (cRightStartFadeIn < cLeftEndFadeOut) ? cLeftEndFadeOut : cRightStartFadeIn - 1
# Construct the now audio clip with only one use of MixAudio for the overlapping part. :)
Block2Audio = (Block1End == Block2End) ?
\ BlankClip(cLeft, length=0) :
\ MixAudio(cLeftAudio.Trim(Block1End + 1,Block2End),cRightAudio.Trim(Block1End + 1,Block2End),1,1)
V = cLeft.Trim(0,cLeftVidCut) + cRight.Trim(cRightVidCut,0)
A = cLeftAudio.Trim(0,Block1End) + Block2Audio + cRightAudio.Trim(Block2End + 1, 0)
return AudioDub(V,A)
}
EDIT: This should be fully working, but I would like test cases to prove it. :) If this works, you all are welcome to use it in your projects or improve upon it or make it part of AVS. :P