View Full Version : Fading In/Out a Watermark
dallas_dan
25th May 2006, 18:16
First off, excellent forums here...Very glad I found them! I am new to AviSynth, so this place really helps a ton.
I am attempting to work out a script where I can fade in a watermark at the beginning of a video, fade it out after a few seconds and then repeat the same just before the end of the video. I should say that this will be used on several videos, all of varying lengths. After searching the forums, I found a script for fading in/out an overlay, however I haven't been able to figure out how to time it to fade in/out just before the end of the file. Maybe there is a way to do (end - x)?
Another problem I am running into is when I drop the avs into VirtualDub, I get the following error.
http://img152.imageshack.us/img152/115/assertionerror0xi.gif (http://imageshack.us)
Here is my .avs:
LoadPlugin("c:/avisynth/plugins/immaavs.dll")
clip1 = avisource("d:/video.avi")
clip2 = immareadpic("watermark-alpha.png").changefps(2000).assumefps(25).fadein(60).fadeout(60)
overlay (clip1, clip2, mode="blend", mask=showalpha(clip2), x=0, y=0)
Thanks for any help you may offer! :)
Manao
25th May 2006, 18:30
Use an absolute path for immareadpic, instead of a relative one ?
dallas_dan
25th May 2006, 18:31
Update: I was able to solve one of my problems by downloading a fresh copy of immaavs.dll (http://e-rels.dyndns.org/downloads/immaavs.rar), and replacing the file. VirtualDub no longer crashes with the assertion error! ;)
I could still use some direction with the fade timing though. :)
stickboy
25th May 2006, 21:11
After searching the forums, I found a script for fading in/out an overlay, however I haven't been able to figure out how to time it to fade in/out just before the end of the file. Maybe there is a way to do (end - x)?seg1 = Trim(0, 8999)
seg2 = Trim(9000, 10000)
seg2 = Overlay(seg2, clip2, mode="blend", mask=showalpha(clip2), x=0, y=0)
seg1 + seg2Or:
function ShowWatermark(clip c)
{
return Overlay(c, clip2, mode="blend", mask=showalpha(clip2), x=0, y=0)
}
AVISource("yourFile.avi")
ApplyRange(9000, 10000, "ShowWatermark")
dallas_dan
25th May 2006, 21:36
seg1 = Trim(0, 8999)
seg2 = Trim(9000, 10000)
seg2 = Overlay(seg2, clip2, mode="blend", mask=showalpha(clip2), x=0, y=0)
seg1 + seg2Or:
function ShowWatermark(clip c)
{
return Overlay(c, clip2, mode="blend", mask=showalpha(clip2), x=0, y=0)
}
AVISource("yourFile.avi")
ApplyRange(9000, 10000, "ShowWatermark")
This is very helpful for adding a watermark relative to the start of the file, but what about a watermark that is displayed relative to the end of the file? The tricky part is I will be watermarking multiple files, all of different lengths. So, I'm hoping there is a way to tell avisynth to fade in the watermark at (end of file - 630) and fade out the watermark at (end of file - 30). My goal is to display the watermark for x frames, just before the end of the file. Hopefully my description makes some sense of my delima.
Thanks for your help, and congrats on your 1,000th post Stickboy!
stickboy
26th May 2006, 02:14
This is very helpful for adding a watermark relative to the start of the file, but what about a watermark that is displayed relative to the end of the file? The tricky part is I will be watermarking multiple files, all of different lengths. So, I'm hoping there is a way to tell avisynth to fade in the watermark at (end of file - 630) and fade out the watermark at (end of file - 30).seg1 = Trim(0, FrameCount() - 631)
seg2 = Trim(FrameCount() - 630, 0)etc.
Mug Funky
26th May 2006, 03:32
there's the command "fadeout()" and "fadein()".
apply these to the alpha mask only...
ah, watermarks... to think of the time people spend trying to remove them. one thing that can be fun is to control the opacity of the watermark by the brightness of the scene it's in. that way one can't just subtract the watermark by a constant amount, and it becomes much harder to remove.
another trick might be to use depan to make the watermark move along with the film under it... that'd be almost impossible to remove :).
i have a script for generic watermarking that might be of use, but it doesn't support fading in and out (maybe i should add this?). i use it for screener discs. it has options for where it should be placed (topleft, bottomright, etc) and what aspect it's in. also gives you a choice between different images to place there.
foxyshadis
26th May 2006, 05:03
If you wanted to get really fancy you could dissolve the logo via gassian blurring or some more artistic effect, like AE filters, instead of a simple fadeout. Or use a conditional filter with current_frame and framecount to create an algebraic formula for when to show the mark. :p
dallas_dan
26th May 2006, 18:52
WOW! I'm amazed by the response from you guys! Thanks so much!
Now to integrate this new code into my existing...I'm a bit lost. Here's my attempt at integrating it:LoadPlugin("c:/avisynth/plugins/immaavs.dll")
clip1 = avisource("d:/video.avi")
clip2 = immareadpic("watermark-alpha.png").changefps(2000).assumefps(25).Trim(0, FrameCount() - 631)
clip3 = immareadpic("watermark-alpha.png").changefps(2000).assumefps(25).Trim(FrameCount() - 30)
clip3 = Overlay(clip1, clip2, clip3, mode="blend", mask=showalpha(clip2), x=0, y=0)
clip1 + clip2 + clip3I've tried variations of this, to no avail. Guess the learning curve is a little steep. ;)
dallas_dan
26th May 2006, 18:54
i have a script for generic watermarking that might be of use, but it doesn't support fading in and out (maybe i should add this?). i use it for screener discs. it has options for where it should be placed (topleft, bottomright, etc) and what aspect it's in. also gives you a choice between different images to place there.
I'd love to check out your script, and yes I do think you should add a fade option. :D
peter100m
31st May 2006, 10:22
@Mug_funky: is there a chance you could show us the watermark script you were talking about. would be really neat. :)
Mug Funky
31st May 2006, 11:35
yeah, just let me clean out the more specific stuff and i'll post it.
fading in could be haced into it with a meta-function or some such.
i'm also looking to speed it up (a lot) by chopping the image up and only using overlay (or mt_merge) on the relevant area. but it's fast enough and simple enough as-is...
function watermark (clip c, float "aspect", string "corner",string "mark", int "out_w", int "out_h", int "off_w", int "off_h", int "min")
{
aspect = default(aspect,4/3.0)
min=default(min,50)
corner=default(corner,"topright")
mark = default(mark,"mark1")
# possible marks: "mark1" = your 1st watermark (default)
# "mark2" = your 2nd watermark
# "mark3" = your 3rd watermark
out_w = default(out_w,90)
out_h = default(out_h,90)
off_w = default(off_w,35)
off_h = default(off_h,45)
out_h = mark=="mark2"? out_w : out_h
out_w = mark=="mark3"? 262 : out_w
out_h = mark=="mark3"? 90 : out_h
global mm_c = c
global mm_gamma = c.reduceby2().reduceby2().levels(min,1,255-(2*min),min,255-(2*min),coring=false).temporalsoften(5,255,255,32)
img_mark = imagesource("C:\Program Files\AviSynth 2.5\plugins\logos\mark1.tif")
img_markalpha = imagesource("C:\Program Files\AviSynth 2.5\plugins\logos\mark1_alpha.tif")
img_mark = mark=="mark2"? imagesource("C:\Program Files\AviSynth 2.5\plugins\logos\mark2.tif") : img_mark
img_markalpha = mark=="mark2"? imagesource("C:\Program Files\AviSynth 2.5\plugins\logos\mark2_alpha.tif") : img_markalpha
img_mark = mark=="mark3"? imagesource("C:\Program Files\AviSynth 2.5\plugins\logos\mark3.bmp") : img_mark
img_markalpha = mark=="mark3"? imagesource("C:\Program Files\AviSynth 2.5\plugins\logos\mark3_alpha.bmp") : img_markalpha
in_w = img_mark.width()
in_h = img_mark.height()
out_w = int(c.width*out_w/(c.height*aspect))
out_h = out_h
global mm_posx=(corner=="topright")? c.width-(off_w+out_w) :
\(corner=="bottomright")? c.width-(off_w+out_w) :
\(corner=="topleft")? off_w : off_w
global mm_posy=(corner=="topright")? off_h :
\(corner=="bottomright")? c.height-(off_h+out_h) :
\(corner=="topleft")? off_h : c.height-(off_h+out_h)
global mm_mark = img_mark.bicubicresize(out_w,out_h,1/3.0,1/3.0).blur(0,1)
global mm_markalpha = img_markalpha.bicubicresize(out_w,out_h,1/3.0,1/3.0).blur(0,1)
c.scriptclip("overlay(mm_c,mm_mark,mask=mm_markalpha,opacity=0.8*(mm_gamma.averageluma()/255.0), x=mm_posx, y=mm_posy)")
}
usage:
watermark(mark="whatever", aspect=4/3., corner="topright")
if you read through the script (messy as, i know), you'll also find x and y offsets for placing a watermark exactly (this is good for checking it's inside black mattes, and not chopped or too close to the overscan on a TV). defaults work for a square (or circular...) watermark. you'll need to change the out_w, out_h defaults to reflect your actual watermark (the current values are for 2 variations of the same logo, plus another one that's a lot wider).
variables can and should be renamed too... i don't actually use "mark1" etc at work, but rather "madfilm", or "avchannel" etc. more intuitive that way.
good luck with it :) and if anyone can make it faster, add features, whatever, i'll be glad to use them here as well. more speed is my priority because it sucks waiting for an encode that the PR guys think can be done as fast as copying a file or burning a disc...
takes a lot of tweaking, but once it's set up
dallas_dan
1st June 2006, 18:32
I still haven't figured out how to time my watermark to fade in/out 10 secs before the end of the video. :(
This is my script for fading in/out a watermark, from the start of the video.LoadPlugin("c:/avisynth/plugins/immaavs.dll")
clip1 = avisource("d:/video.avi")
clip2 = immareadpic("watermark-alpha.png").changefps(2000).assumefps(25).fadein(60).fadeout(60)
overlay (clip1, clip2, mode="blend", mask=showalpha(clip2), x=0, y=0)And Stickboy gave me this code.seg1 = Trim(0, FrameCount() - 631)
seg2 = Trim(FrameCount() - 630, 0)But for the life of me, I can not figure out how to combine the two, to make the watermark fade in/out relative to the end of a video. I'll buy a beer for anyone that can help me out. :o
dallas_dan
2nd June 2006, 18:42
Is it okay to offer money for services in this community? If it is, I'll pay $20 (epassporte or paypal) to the first person to come up with a solution. :)
emmel
2nd June 2006, 19:52
Like this?
LoadPlugin("e:/plugins/immaavs.dll")
c1 = Mpeg2Source("clip.d2v")
c2 = immareadpic("e:/figs/tmp.png").changefps(2000).assumefps(25).fadein(60).fadeout(60)
s1 = Trim(c1,0,1000)
s2 = Trim(c1,1001,FrameCount(c1)-1000)
s3 = Trim(c1,FrameCount(c1)-999,FrameCount(c1))
r1 = overlay (s1, c2, mode="blend", mask=showalpha(c2), x=0, y=0)
r2 = s2
r3 = overlay (s3, c2, mode="blend", mask=showalpha(c2), x=0, y=0)
return r1+r2+r3
Modify and check the params.
dallas_dan
2nd June 2006, 21:57
You know, I think that may just do it! I'm just having a problem with setting the correct frame numbers in the trim section. Any chance you could add some #notes to the script, letting me know what each line was doing?
emmel
2nd June 2006, 22:30
You know, I think that may just do it! I'm just having a problem with setting the correct frame numbers in the trim section. Any chance you could add some #notes to the script, letting me know what each line was doing?
Ok. In the sample I just chose by random the parameter 1000. It means 1000 frames/25 fps = 40 seconds. You choose it better. So, s1 is the first 40s of the clip, s2 is the middle part, and s3 is the last 40s. Then you just blend your watwermark in s1 and s3, and return the result.
blubberbirne
4th June 2006, 14:28
I used this one:
quell_video = mpeg2source("g:\cut\clip.d2v").FieldDeinterlace().crop(12,2,706,572).LanczosResize(704,528).FluxSmoothST(7,7).FadeIn(25).FadeOut(25).converttoyuy2()
blabla = AVISource("G:\temp\watermark.avi").Loop(1).ConvertToRGB32.fadein(25, $0000FF).fadeout(10, $0000FF)
maskclip = ColorKeyMask(blabla, $0000FF, 60)
overlay(quell_video, blabla, x=485, y=490, mask=ShowAlpha(maskclip), mode="blend", opacity=1)
ConvertToYV12()
dallas_dan
5th June 2006, 17:53
Ok. In the sample I just chose by random the parameter 1000. It means 1000 frames/25 fps = 40 seconds. You choose it better. So, s1 is the first 40s of the clip, s2 is the middle part, and s3 is the last 40s. Then you just blend your watwermark in s1 and s3, and return the result.
Great, thank you! PM me your epassporte or paypal account.
emmel
5th June 2006, 19:56
Oh come on... you just help me and others next time.
cu,
emmel
dallas_dan
6th June 2006, 20:20
Oh come on... you just help me and others next time.
cu,
emmel
That's what I love about the open source community...The "Pay It Forward" mentality. Thank you so much! :)
lindylex
5th December 2009, 08:47
Emmel, I like your example a lot. I used it recently and it saved me. I made some modifications to it.
#This script will generate three fade in and out watermarks. One at the beginning, middle and end.
#The only variable you have to modify is initialpadding. This will affect when the fade in effect starts and
#it is also reused to set the same position at the end of the video for the watermark.
combined = avisource ("C:\images\192CANON\myavimovie.AVI", false )
#///////// Begin fade in and out of the brand three times. ///////////
themask=imagesource("C:\pathtomask\acroyoga_tutorial_banner_ma.png", end=20, pixel_type = "RGB32").ConvertToRGB32 ()
top_banner = imagesource("C:\pathtowatermark\acroyoga_tutorial_banner.png", end=200, pixel_type = "RGB32").fadein(20).fadeout(20) #Change the fade in and out 20 to match your mood.
initialpadding=.02 #padding before the first watermark appears in percent from .01 - .99
# Be mindful that your movie is long enough to support three watermarks.
# Check the watermark length and your movie length.
endoffirstsection=Round(combined.FrameCount*initialpadding)
first_no_watermark_section = Trim(combined,0,endoffirstsection)
startofsecondsection=endoffirstsection+1
middlesection=(combined.FrameCount/2)-(top_banner.FrameCount/2)
first_watermark_fadein_1 = Trim(combined,startofsecondsection,middlesection)
startofthirdsection=middlesection+1
endofthirdsection=(combined.FrameCount - Round(combined.FrameCount*.05 ) ) - top_banner.FrameCount
second_watermark_fadein = Trim(combined,startofthirdsection,endofthirdsection)
startoffourthsection=endofthirdsection+1
third_watermark_fadein = Trim(combined,startoffourthsection,combined.FrameCount)
combined0 = first_no_watermark_section
combined1 = overlay (first_watermark_fadein_1 , top_banner, mode="blend", mask=top_banner.Mask(themask), x=0, y=0, opacity=0.75)
combined2 = overlay (second_watermark_fadein, top_banner, mode="blend", mask=top_banner.Mask(themask), x=0, y=0, opacity=0.75)
combined3 = overlay (third_watermark_fadein, top_banner, mode="blend", mask=top_banner.Mask(themask), x=0, y=0, opacity=0.75)
combined=combined0+combined1+combined2+combined3
#////////// End of fade in and out of the brand three times. ///////////
Gavino
6th December 2009, 00:31
endoffirstsection=Round(combined.FrameCount*initialpadding)
How is this (and similar lines) intended to work?
'combined' is not defined until the end of the script.
Should it be set to the source?
lindylex
7th December 2009, 07:37
Gavino, I update the script. I added this so it does not seem so confusing.
combined = avisource ("C:\images\192CANON\myavimovie.AVI", false )
The script cuts your entire movie into four sections | fist section with no watermark | second section with watermark | Watermark in the middle of the movie | Watermark at the end |
The variable "initialpadding=.02" will dictate when the "second section with watermark" starts and when the "Watermark at the end" starts.
Gavino
7th December 2009, 11:07
Thanks for the clarification.
A few more observations:
themask=imagesource(" ... ", end=20, pixel_type = "RGB32").ConvertToRGB32 ()
top_banner = imagesource(" ... ", end=200, pixel_type = "RGB32").fadein(20).fadeout(20)
ConvertToRGB32 is unnecessary with pixel_type="RGB32".
A nicer effect would be obtained by applying the fade to the mask instead of to the image - you want the transparency to vary as it fades, not the color.
endofthirdsection=(combined.FrameCount - Round(combined.FrameCount*.05 ) ) ...
Should .05 be replaced by initialpadding here?
third_watermark_fadein = Trim(combined,startoffourthsection,combined.FrameCount)
should be combined.FrameCount-1 (or simply 0 to indicate last frame)
... = overlay (..., mask=top_banner.Mask(themask), ...)
is equivalent to mask=top_banner, since Mask changes only the alpha channel, which Overlay ignores.
Perhaps you want mask=ShowAlpha(themask) or mask=themask, depending on what form your mask clip takes.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.