View Single Post
Old 11th October 2019, 02:06   #16  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
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
}
Demo client
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: For Demo Client, converted mt_lutspa expr from INFIX to RPN, allow use of current versions of mt_lutspa to work on XP. [mt_Polish() dont work on XP]


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.
StainlessS is offline   Reply With Quote