Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
7th February 2016, 09:33 | #1 | Link |
Registered User
Join Date: Jan 2012
Posts: 23
|
First\last frame of Overlay
Hi everyone
I have question regarding Overlay function this my simple code Code:
a1 = FFVideoSource("Oh!.mp4").ConvertToRGB32().AssumeFPS(24000,1001) a2 = AVISource("logo.avi").ConvertToRGB32() mask_clip = Mask(a2, a2.GreyScale.Levels(0, 1.112, 35, 0, 255)).blur(1.5) Overlay(a1, a2, mask= showalpha(mask_clip), y=0, x=0, mode="blend", opacity=1.0) is there anyway I can make a First\last frame for my logo.avi clip or just int first frame? or if it's possible to edit overlay script ?! I know there's insertsign function, but I want to use overlay only for some reasons. thank you. |
7th February 2016, 17:41 | #2 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
You can cut the overlay in and out with this function:
Code:
# http://atlas.kennesaw.edu/~dhirschl/avisynth.html function sceneinsert(clip a1, clip a2, int f1, int f2) { # a1=main movie, a2=angle2 segment=a2.trim(f1,f2) return a1.trim(0,f1-1) + segment + a1.trim(f2+1,0) } You use it like this: Code:
## test clip with visible frame numbers base = ColorBars.Trim(0, 299).ShowFrameNumber(x=16, y=32) ## test overlay over = base.Overlay(base.Invert.BicubicResize(base.Width/2, base.Height/2), x=128, y=128) ## cut to overlay at frame 30; cut back to non-overlay at frame 91 return sceneinsert(base, over, 30, 90) ...but wait, wouldn't it be great to *fade* the alternate clip in and out? Yeah, I thought so too. Code:
## fade in return UUInsertFade(base, over, markIn=30, fadeIn=15) ## fade out return UUInsertFade(base, over, markOut=90, fadeOut=35) ## fade in, fade out return UUInsertFade(base, over, markIn=30, markOut=90, fadeIn=10, fadeOut=35) ## cut in, cut out (same as 'sceneinsert') return UUInsertFade(base, over, 30, 90) ## fade out (negative markOut sets duration) return UUInsertFade(base, over, 0, -30, fadeOut=15) ## default: show overlay clip always return UUInsertFade(base, over) ####################################### ### insert an alternate clip ### (cut or dissolve to alternate clip and back again) ## ## @ A - main movie ## @ B - alternate clip (synchronized with clip A) ## @ markIn - frame where A->B fade begins ## (default 0; start of clip 'A') ## @ markOut - frame where B->A fade begins ## (default 0; B remains 'on' until end of clip 'A') ## (negative markOut sets duration) ## @ fadeIn - number of frames for A->B fade ## (default 0; cut to clip 'B' at frame markIn) ## @ fadeOut - number of frames for B->A fade ## (default 0; cut to clip 'A' at frame markOut+1) ## ## DISALLOWED INPUTS: ## * if A.FrameCount < markIn+fadeIn+1, an error occurs ## * if B.FrameCount < markOut+fadeOut+1, an error occurs ## * if markOut>=0 and markIn > markOut, an error occurs ## * if duration is negative, an error occurs ## function UUInsertFade(clip A, clip B, \ int "markIn", int "markOut", \ int "fadeIn", int "fadeOut") { markIn = Max(0, Default(markIn, 0)) markOut = Default(markOut, 0) fadeIn = Max(0, Default(fadeIn, 0)) fadeOut = Max(0, Default(fadeOut, 0)) Assert(markIn>0 || Abs(markOut)!=1, \ "UUInsertFade: markOut cannot be +/-1 if markIn=0") markOut = (markOut>=0) ? markOut : (markIn - markOut - 1) Assert(A.FrameCount>=markIn+fadeIn+1, \ "UUInsertFade: clip A too short"+Chr(10) \ + "(FrameCount < markIn+fadeIn+1)") Assert(B.FrameCount>=markOut+fadeOut+1, \ "UUInsertFade: clip B too short"+Chr(10) \ + "(FrameCount < markOut+fadeOut+1)") Assert(markIn<=markOut, \ "UUInsertFade: duration is negative") R = ((markIn+fadeIn)==0) ? B \ : Dissolve(A.Trim(0, ((markIn+fadeIn)==1) ? -1 : markIn+fadeIn-1), \ B.Trim(markIn, 0), \ fadeIn) R = ((markOut+fadeOut)==0) ? R \ : Dissolve(R.Trim(0, markOut+fadeOut), \ A.Trim(markOut+1, 0), \ fadeOut) return R } Last edited by raffriff42; 18th February 2016 at 02:46. Reason: negative markOut sets duration |
7th February 2016, 18:47 | #3 | Link | |
Registered User
Join Date: Jan 2012
Posts: 23
|
Thank you very much man
I used it, but I got 1 more frame, my video frame is 5551, but I got 1 more when I used sceneinsert 5552 so do you think it's ok to use trim like Quote:
|
|
7th February 2016, 19:04 | #4 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
Aha, it seems frame 0 is repeated.
(UUInsertFade handles this case correctly, ...EDIT but has trouble with markIn=1 ...EDIT fixed) EDIT agree, Trim(1, 0) seems to be the right way to fix sceneinsert where markIn=0. For markIn=1, this does not work however. Last edited by raffriff42; 7th February 2016 at 19:25. |
7th February 2016, 19:25 | #5 | Link | |
Registered User
Join Date: Jan 2012
Posts: 23
|
I just did this
function sceneinsert(clip a1, clip a2, int f1, int f2) { segment=a2.trim(f1,f2) return a1.trim(0,f1-1) + segment + a1.trim(f2+2,0) } Ok I have another question, If I want add another logo, I used insertsign, but only one logo appeared, which is a2 !_! Quote:
|
|
7th February 2016, 19:36 | #6 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
I had never heard of insertsign, but here it is.
It seems to require a valid alpha channel for the overlay to work. EDIT see related post here, where I create a "fake" mask, which you would then add to a3's alpha channel with Mask. Last edited by raffriff42; 7th February 2016 at 19:48. |
14th February 2016, 09:36 | #8 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
It gives the wrong result if f1 is 0 or 1, or if f2 is the last frame. See stickboy's classic Caveats of using Trim in functions. In functions, you should generally use the form Trim(0, -N) instead of Trim(0, N-1), which gives the wrong result for N=1. An improved version (but still without error checking) is Code:
function sceneinsert(clip a1, clip a2, int f1, int f2) { # a1=main movie, a2=angle2 segment=a2.trim(f1,f2) result = (f1==0 ? segment : a1.trim(0,-f1) + segment) result = (f2+1 < a1.framecount ? result + a1.trim(f2+1,0) : result) return result } |
|
16th February 2016, 00:13 | #9 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
I needed a mod of this (a few posts after RaffRiff link in post #6) just now and so thought I might post it.
Feel free to improve. EDIT: SEE LATER Post #16. Made mask externally supplied, and removed RGB requirement. Code:
Function OverlayClip(clip c,clip c2,Int "S", Int "E", Int "X", Int "Y",Float "Opacity",String "Mode",clip "Mask") { /* OverlayClip v1.01, http://forum.doom9.org/showthread.php?p=1757408#post1757408 ColorSpace, as for Overlay. Overlay clip c with clip c2 using Mask mask if supplied, frames S to E, @ clip c overlay coords X and Y. Start and End Args S & E, are similar but not exactly like trim. OverlayClip(c,c2, 0,0) # Entire clip OverlayClip(c,c2, 100,0) # Frame 100 to End of Clip OverlayClip(c,c2, 0,-1) # Frame 0 Only OverlayClip(c,c2, 1,1) # Frame 1 Only OverlayClip(c,c2, 1,-1) # Frame 1 Only OverlayClip(c,c2, 1) # Frame 1 Only [Not same as Trim()], E defaults to -1 ie single frame. OverlayClip(c,c2, 1,-3) # Frames 1 to 3 (ie 3 frames) OverlayClip(c,c2, 100,200) # Frames 100 to 200 OverlayClip(c,c2, 100,-50) # Frames 100 to 149 ie 50 frames X and Y are OverLay x & y offsets, and can be -ve where is relative to c.Width & c.Height, use eg x = -(c2.Width+16) If c2.Framecount is shorter than S,E specified range, then final c2 frame will be used for remainder of overlay range, so if c2 clip is single frame, then that frame will be used for entire overlay range. Opacity=Overlay::Opacity and Mode=Overlay::Mode. Mask, This will be used as the transparency mask for the overlay image. The mask must be the same size as the overlay clip, only the greyscale (luma) components are used from the image. The darker the image is, the more transparent will the overlay image be. Not specitying Mask is equivalent to supplying a 255 clip. */ FMX=c.FrameCount-1 S = Min(Max(Default(S,0),0),FMX) E = Default(E,-1) X=Default(X,0) Y=Default(Y,0) Opacity=Float(Default(Opacity,1.0)) Mode=Default(Mode,"Blend") X = (X<0) ? c.Width + X : X Y = (Y<0) ? c.Height + Y : Y E = (E==0) ? FMX : E E = Min(((E < 0) ? S-E-1 : E),FMX) # S <= E <= FMX : E is +ve END Frame number (may be 0) Empty = c.BlankClip(Length=0) CS = (S==0) ? Empty : c.Trim(0,-S) CM = c.Trim(S,E==0?FMX:E).Overlay(c2,x=X,y=Y,mask=Mask,opacity=Opacity,mode=Mode) CE = (E==FMX) ? Empty : c.Trim(E+1,0) CS ++ CM ++ CE } Code:
Avisource("D:\V\StarWars.avi") # Source YV12 Sym=Avisource("D:\V\XMen2.avi").Trim(5000,0) # Overlay clip W=(Width/16) * 4 H=(Height/16) * 4 Sym=Sym.BilinearResize(W,H) #S="(((x-.5)^2 +(y-.5)^2) < .25 ? 255 : 0" # Elliptical Disk (Hard Edge) S="((x-.5)^2+(y-.5)^2)>.25?0:(((x-.5)^2+(y-.5)^2)<.2?255:(.25-((x-.5)^2+(y-.5)^2))*5100)" # Elliptical Disk (Soft Edge) # Create Elliptical Disk ElipDisk = Sym.trim(0,-1).mt_lutspa(mode = "relative", expr = Mt_Polish(S), chroma = "-128" ).Loop(Sym.framecount,0,0) # Start @ frame 100, End at end of Sym Clip, Rel Bottom RHS with 16 pixels GAP Return OverlayClip(Last,Sym,S=100,E= -Sym.FrameCount,x= -(Sym.Width+16),y= -(Sym.Height+16),mask=ElipDisk)
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 11th October 2019 at 02:13. |
17th February 2016, 03:04 | #11 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Quote:
No, I did not want nor intend any right justification, -ve is only relative to source width/height but still for overlay top/left x/y coords. (I guess that it is not such a bad idea though). Post your modified version + any other mods you may have made. (A sister function to use same range of start S and end E could be used as for InsertSign, with an alternate angle of same scene from the Overlay clip).
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 19th February 2016 at 20:43. |
|
17th February 2016, 17:52 | #14 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
RR, We must never forget that he is eternally watching for our mistakes, we really have to be more careful.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
11th October 2019, 02:06 | #16 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Mod of post #9. Added args, Bool "Rgt_Rel"=False,Bool "Bot_Rel"=False,Bool "AltAngle"=False.
OverlayClip.avsi Code:
# OverlayClip.avsi Function OverlayClip(clip c,clip c2,Int "S", Int "E", Int "X", Int "Y",Float "Opacity",String "Mode",clip "Mask",Bool "Rgt_Rel",Bool "Bot_Rel",Bool "AltAngle") { /* OverlayClip v1.02, https://forum.doom9.org/showthread.php?p=1887123#post1887123 ColorSpace, as for Overlay. Overlay clip c with clip c2 using Mask mask if supplied, frames S to E, @ clip c overlay coords X and Y. Start and End Args S & E, are similar but not exactly like trim. OverlayClip(c,c2, 0,0) # Entire clip OverlayClip(c,c2, 100,0) # Frame 100 to End of Clip OverlayClip(c,c2, 0,-1) # Frame 0 Only OverlayClip(c,c2, 1,1) # Frame 1 Only OverlayClip(c,c2, 1,-1) # Frame 1 Only OverlayClip(c,c2, 1) # Frame 1 Only [Not same as Trim()], E defaults to -1 ie single frame. OverlayClip(c,c2, 1,-3) # Frames 1 to 3 (ie 3 frames) OverlayClip(c,c2, 100,200) # 101 Frames, 100 to 200 OverlayClip(c,c2, 100,-50) # Frames 100 to 149 ie 50 frames NOTE, X and Y, changed functionality, we use Rgt_Rel and Bot_Rel for Right/Bot Justify Overlay clip. X is OverLay x offsets, and where Rgt_Rel = true and X = 0, then is hard against right hand side edge. Where Rgt_Rel=true and eg x = -16, then leaves 16 pixel gap between overlay clip and Right edge. Y is OverLay y offsets, and where Bot_Rel = true and Y = 0, then is hard against Bottom edge. Where Bot_Rel=true and eg y = -16, then leaves 16 pixel gap between overlay clip and bottom edge. If c2.Framecount is shorter than S,E specified range, then final c2 frame will be used for remainder of overlay range, so if c2 clip is single frame, then that frame will be used for entire overlay range. Opacity=Overlay::Opacity and Mode=Overlay::Mode. Mask, This will be used as the transparency mask for the overlay image. The mask must be the same size as the overlay clip, only the greyscale (luma) components are used from the image. The darker the image is, the more transparent will the overlay image be. Not specitying Mask is equivalent to supplying a 255 clip. Rgt_Rel, Bot_Rel, Default false, if both true, then x and y, are relative Right Bottom aligned. AltAngle, Default false. If true, then c2 and Mask are trim'ed to match c clip so that they correspond to same time as c when Overlaying. (Otherwise, overlays from beginning of c2 clip) */ FMX=c.FrameCount-1 S = Min(Max(Default(S,0),0),FMX) E = Default(E,-1) X=Default(X,0) Y=Default(Y,0) Opacity=Float(Default(Opacity,1.0)) Mode=Default(Mode,"Blend") Rgt_Rel = Default(Rgt_rel,False) Bot_Rel = Default(Bot_rel,False) AltAngle = Default(AltAngle,False) X = (RGT_REL) ? (c.Width - c2.Width + X) : X Y = (BOT_REL) ? (c.Height - c2.Height + Y) : Y E = (E==0) ? FMX : E E = Min(((E < 0) ? S-E-1 : E),FMX) # S <= E <= FMX : E is +ve END Frame number (may be 0) Empty = c.BlankClip(Length=0) CS = (S==0) ? Empty : c.Trim(0,-S) C2E = (AltAngle) ? (E==0?FMX:E) : 0 c2 = (AltAngle) ? c2.Trim(S,C2E) : c2 Mask = (AltAngle && Mask.Defined) ? Mask.Trim(S,C2E) : Mask CM = c.Trim(S,C2E).Overlay(c2,x=X,y=Y,mask=Mask,opacity=Opacity,mode=Mode) CE = (E==FMX) ? Empty : c.Trim(E+1,0) CS ++ CM ++ CE } Code:
# OverlayClip_Client.avs #Import(".\OverlayClip.avsi") #Avisource("D:\Parade.avi") # Source YV12 #Sym=Avisource("D:\Parade.avi") # Overlay clip Colorbars(Pixel_Type="YV12") Sym=Last X = -16 Y = -16 RGT_REL = True BOT_REL = True ALTANGLE = False # If true, then Sym clip is temporally aligned (trim'ed) to match source clip (START,END) when Overlay (otherwise overlayed from beginning of Sym clip). START = 100 # Start frame of overlay END = 1000 # End frame of overlay ###### W = (Width/16) * 4 H = (Height/16) * 4 Sym=Sym.BilinearResize(W,H) # .Loop() # Very long clip #INFIX="(((x-.5)^2 +(y-.5)^2) < .25 ? 255 : 0" # INFIX: Elliptical Disk (Hard Edge) : Req mt_Polish() #INFIX="((x-.5)^2+(y-.5)^2)>.25?0:(((x-.5)^2+(y-.5)^2)<.2?255:(.25-((x-.5)^2+(y-.5)^2))*5100)" # INFIX: Elliptical Disk (Soft Edge) : Req mt_Polish() #RPN="x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 255 0 ?" # RPN: Elliptical Disk (Hard Edge) RPN="x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 > 0 x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.2 < 255 0.25 x 0.5 - 2 ^ y 0.5 - 2 ^ + - 5100 * ? ?" # RPN: Elliptical Disk (Soft Edge) # Create Elliptical Disk ElipDisk = Sym.BlankClip(Length=1).mt_lutspa(mode = "relative", expr = RPN, chroma = "-128" ) # .Loop() # Very long clip # Start @ frame START, End at END, Rel Bottom RHS with 16 pixels GAP Return OverlayClip(Last,Sym,S=START,E=END,x=X,y=Y,mask=ElipDisk,Rgt_rel=RGT_REL,bot_Rel=BOT_REL,Altangle=ALTANGLE) EDIT: AltAngle=False AltAngle=True
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 14th October 2019 at 16:44. |
|
|