Log in

View Full Version : FadeIn/FadeOut to transparent


codemonkey76
29th October 2008, 02:29
I have created an avisynth function (below) that creates a scoreboard that fades in and fades out, i want to overlay it onto another video. My problem is if i do a straightoverlay with no mask it fades in from a black square and fades out to a black square. If i use the ShowAlpha() it doesn't appear at all, i think the fade in/fade out is fading to black, i need it to fade to transparent:

function Scoreboard(string "p1a", string "a1a", string "p2a", string "a2a", string "p1b", string "a1b", string "p2b", string "a2b")
{
FramesBefore = 100
FramesAfter = 300
fps = 25
fadeSpeed = 30
LeftScore = 82
RightScore = 171
ScoreHeight = 94
AdvHeight = 183

blankboard = ImageSource("C:\Video\Scoring\Scoreboard\Blank.png", 0, FramesBefore, fps, use_DevIL = false, info = false, pixel_type = "RGB32")
p1Clip1 = ImageSource("C:\Video\Scoring\Scoreboard\Numbers\" + p1a + ".png", 0, 1, fps, use_DevIL = false, info = false, pixel_type = "RGB32")
p2Clip1 = ImageSource("C:\Video\Scoring\Scoreboard\Numbers\" + p2a + ".png", 0, 1, fps, use_DevIL = false, info = false, pixel_type = "RGB32")
a1Clip1 = ImageSource("C:\Video\Scoring\Scoreboard\Numbers\" + a1a + ".png", 0, 1, fps, use_DevIL = false, info = false, pixel_type = "RGB32")
a2Clip1 = ImageSource("C:\Video\Scoring\Scoreboard\Numbers\" + a2a + ".png", 0, 1, fps, use_DevIL = false, info = false, pixel_type = "RGB32")

p1Clip2 = ImageSource("C:\Video\Scoring\Scoreboard\Numbers\" + p1b + ".png", 0, 1, fps, use_DevIL = false, info = false, pixel_type = "RGB32")
p2Clip2 = ImageSource("C:\Video\Scoring\Scoreboard\Numbers\" + p2b + ".png", 0, 1, fps, use_DevIL = false, info = false, pixel_type = "RGB32")
a1Clip2 = ImageSource("C:\Video\Scoring\Scoreboard\Numbers\" + a1b + ".png", 0, 1, fps, use_DevIL = false, info = false, pixel_type = "RGB32")
a2Clip2 = ImageSource("C:\Video\Scoring\Scoreboard\Numbers\" + a2b + ".png", 0, 1, fps, use_DevIL = false, info = false, pixel_type = "RGB32")

blankboard2 = ImageSource("C:\Video\Scoring\Scoreboard\Blank.png", 0, FramesAfter, fps, use_DevIL = false, info = false, pixel_type = "RGB32")

scoreboard1 = overlay(blankboard,p1Clip1,mode="blend", mask=showalpha(p1Clip1),x=LeftScore,y=ScoreHeight)
scoreboard1 = overlay(scoreboard1,p2Clip1,mode="blend", mask=showalpha(p2Clip1),x=RightScore,y=ScoreHeight)
scoreboard1 = overlay(scoreboard1,a1Clip1,mode="blend", mask=showalpha(a1Clip1),x=LeftScore,y=AdvHeight)
scoreboard1 = overlay(scoreboard1,a2Clip1,mode="blend", mask=showalpha(a2Clip1),x=RightScore,y=AdvHeight)

scoreboard2 = overlay(blankboard2,p1Clip2,mode="blend", mask=showalpha(p1Clip2),x=LeftScore,y=ScoreHeight)
scoreboard2 = overlay(scoreboard2,p2Clip2,mode="blend", mask=showalpha(p2Clip2),x=RightScore,y=ScoreHeight)
scoreboard2 = overlay(scoreboard2,a1Clip2,mode="blend", mask=showalpha(a1Clip1),x=LeftScore,y=AdvHeight)
scoreboard2 = overlay(scoreboard2,a2Clip2,mode="blend", mask=showalpha(a2Clip2),x=RightScore,y=AdvHeight)
scoreboardClip = scoreboard1+scoreboard2

return scoreboardClip.FadeIn(fadespeed).FadeOut(fadespeed)
}

codemonkey76
29th October 2008, 02:40
oh i forgot to mention the usage of the function is
Scoreboard("0","0","0","0","1","1","1","1")
where 0:0 - 0:0 is the previous score and 1:1 = 1:1 is the new score
it fades in the scoreboard with the previous score, changes the score to the new score then fades the scoreboard out after a little while

mikeytown2
29th October 2008, 04:38
Apply the fade in/out on the mask
http://avisynth.org/mediawiki/Mask
http://avisynth.org/mediawiki/Overlay

Another option is to Animate the opacity
http://avisynth.org/mediawiki/Animate

ps
ImageSource((...,0,0,...) is one frame
ImageSource((...,0,1,...) is two frames

codemonkey76
29th October 2008, 04:49
Apply the fade in/out on the mask
http://avisynth.org/mediawiki/Mask
http://avisynth.org/mediawiki/Overlay

Another option is to Animate the opacity
http://avisynth.org/mediawiki/Animate

ps
ImageSource((...,0,0,...) is one frame
ImageSource((...,0,1,...) is two frames

sorry i am a bit of a newb still and it has taken me days to get that function to sort of work. So I just replace that last return line with what?

EDIT:
OK, i am researching what you have suggested, so should i create a clip, say 30 seconds of white and fade to black and vice-versa and use mask to apply it to the score clip? am i on the right track?

codemonkey76
29th October 2008, 05:18
thanks, I guess all i needed was pointing in the right direction, i replaced the last line in the function with

fadeClip = BlankClip(scoreboardclip,length=framesBefore+framesAfter, pixel_type="RGB32", fps=25,color=$ffffff).Fadein(30).FadeOut(30)
return Mask(scoreboardClip,fadeClip)

IanB
29th October 2008, 09:31
@codemonkey76,

Read the fine print to do with FadeIn/FadeOut with regards to them adding an extra frame, it may throw off your calculations for edit points in your scripts.

Also there is a FadeIO variant.