StainlessS
9th May 2020, 21:26
ConcealRange.avs
/*
https://forum.doom9.org/showthread.php?p=1911260#post1911260
Req:- Masktools2, FastBlur, Avs+
YUV444 or RGB Only, 8 -> 32 bit.
*/
Function EllipMsk(clip c,int W, Int H,Bool "Soft") {
# Req mt_tools_2, Returns frame WxH same FPS as c and without audio
Soft=Default(Soft,False)
# INFIX_H="(((x-.5)^2 +(y-.5)^2) < .25 ? 255 : 0"
# Elliptical Disk (Hard Edge) :: mode = "relative", Radius=0.5, Rad^2=0.25 :: SOFT_Inner rad:(Rad*0.9)^2~=0.2
# INFIX_S="((x-.5)^2+(y-.5)^2)<.2?255 : (((x-.5)^2+(y-.5)^2)<.25 ? ((.25-((x-.5)^2+(y-.5)^2))*5100):0)"
# Elliptical Disk (Soft Edge) :: (.25-0.2)*5100=255 : (.25-.25)*5100=0.0] :: mode="relative", 0.25~=1.0 : 0.2~=0.9
rpn = (!Soft)
\ ? "x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 255 0 ? scalef" [* RPN: EllipMsk [Hard Edge] *]
\ : "x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.2 < 255 x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 0.25 x 0.5 - 2 ^ y 0.5 - 2 ^ + - 5100 * 0 ? ? scalef" [* RPN: EllipMsk [Soft Edge] *]
c.Blankclip(width=W,height=H,Length=1).Killaudio
return Last.mt_lutspa(mode = "relative", expr = rpn, chroma = "-128" )
}
Function RectMsk(clip c,int W, Int H,Bool "Soft") {
# Req mt_tools_2, Returns frame WxH same FPS as c and without audio
Soft=Default(Soft,False)
# INFIX_H = "255"
# INFIX_S = "max(abs(x-.5),abs(y-.5)) < .45 ? 255 : ((.5 - max(abs(x-.5),abs(y-.5)) ) * 5100)"
rpn=(!Soft)
\ ? "255 scalef"
\ : "x 0.5 - abs y 0.5 - abs max 0.45 < 255 0.5 x 0.5 - abs y 0.5 - abs max - 5100 * ? scalef"
c.Blankclip(width=W,height=H,Length=1).Killaudio
return Last.mt_lutspa(mode = "relative", expr = rpn, chroma = "-128" )
}
Function Conceal(clip c,clip bc,clip msk, Float x, Float y,Float Opacity) {
mw = Msk.Width mh=Msk.Height
ow=c.width-2*mw oh=c.Height-2*mh
xc = Round(min(max(0.0,x),ow))
yc = Round(min(max(0.0,y),oh))
x = xc + mw/2
y = yc + mh/2
bc=bc.crop(x,y,mw,mh)
c.Overlay(bc,mask=msk,x=x,y=y,opacity=Opacity)
}
Function ConcealRange(clip c,clip bc,clip msk,Int "S", Int "E",float "sx",Float "sy",Float "ex",float "ey", Float "sop",Float "eop") {
/*
Blur/Conceal clip c with blurred clip clip bc using Mask msk, frames S to E, sx,sy start coords, ex,ey end coords.
Start and End Args S & E, are similar but not exactly like trim.
ConcealRange(c,bc,msk, 0,0) # Entire clip
ConcealRange(c,bc,msk, 100,0) # Frame 100 to End of Clip
ConcealRange(c,bc,msk, 0,-1) # Frame 0 Only
ConcealRange(c,bc,msk, 1,1) # Frame 1 Only
ConcealRange(c,bc,msk, 1,-1) # Frame 1 Only
ConcealRange(c,bc,msk, 1) # Frame 1 Only [Not same as Trim()], E defaults to -1 ie single frame.
ConcealRange(c,bc,msk, 1,-3) # Frames 1 to 3 (ie 3 frames)
ConcealRange(c,bc,msk, 100,200) # 101 Frames, 100 to 200
ConcealRange(c,bc,msk, 100,-50) # Frames 100 to 149 ie 50 frames
X coords sx, and ex, allowed range 0 -> c.width.
Y coords sy, and ey, allowed range 0 -> c.height.
sop, eop, Start and End Opacity, Default 1.0, range 0.0 -> 1.0
*/
FMX=c.FrameCount-1
S = Min(Max(Default(S,0),0),FMX) E = Default(E,-1)
sx=Default(sx,0.0) sy=Default(sy,0.0)
ex=Default(ex,0.0) ey=Default(ey,0.0)
sop=min(max(Default(sop,1.0),0.0),1.0) eop=min(max(Default(eop,1.0),0.0),1.0)
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 = (E==0?FMX:E)
mw=Msk.Width mh=Msk.Height
cpad = c.Addborders(mw,mh,mw,mh)
bcpad = bc.Addborders(mw,mh,mw,mh)
CM = cpad.Animate(S,C2E,"Conceal", bcpad,Msk,sx,sy,sop, bcpad,Msk, ex,ey,eop)
CM = CM.Trim(S,C2E).crop(mw,mh,-mw,-mh)
CE = (E==FMX) ? Empty : c.Trim(E+1,0)
CS ++ CM ++ CE
}
##############################################################
AviSource("D:\Parade.avi").Trim(100,0) # Source Clip
# Either YUV444 or RGB
ConvertToYV24.ConvertBits(10)
#ConvertToPlanarRGB.ConvertBits(10)
#ConvertToRGB24
#ConvertToRGB48
#ConvertToRGB64
####### CONFIG ###############################################
DISK = True # True = Disk/Ellipse, Else Rectangle
PIXELATE = False # True = PIXELATE, False=Blur
PIXSZ = 8 # PIXELATE Size, (maybe 8 or 4)
# FastBlur args # Fastblur args if PIXELATE=False
FBlurRad = 5
FBlurIter = 3
# Mask args [size of concealed area]
MWidth = 128
MHeight = MWidth
MSOFT = True # Soft Edge mask
# Opacity of Overlay'd concealment. [You are unlikely to want anything less than about 0.9, usually 1.0]
sop = 1.0 # Start frame Opacity
eop = sop # End frame opacity same as start opacity.
# OTHER STUFF
BLANKFG = false # Show ForeGround(blurred/concealed Area) in Blue [see path traveled better].
BLANKBG = False # Show BackGround in Pink
####### END CONFIG ########################
Assert(IsRGB || (Height==ExtractU.Height&&Width==ExtractU.Width),"YV444 or RGB ONLY")
W = Width
H = Height
BPC = BitsPerComponent
#
BClip = (PIXELATE) ? BilinearResize(W/PIXSZ,H/PIXSZ).PointResize(W,H) : Last.Fastblur(FBlurRad,iterations=FBlurIter) # Concealing clip
MSK = Last.BlankClip(pixel_type="Y8").ConvertBits(BPC) # Mask
MSK = (DISK) ? MSK.EllipMsk(MWidth,MHeight,Soft=MSOFT) : MSK.RectMsk(MWidth,MHeight,Soft=MSOFT)
#
Last = (BLANKBG) ? Last.BlankClip(Color=$C04060) : Last
BCLip= (BLANKFG) ? BCLip.BlankClip(Color=$0000FF) : BClip
#################################################################################
# Demo coords, Start,End Frm, Start X,Y End X,Y Start,End Opacity(default 1.0 if not supplied)
ConcealRange(Last,BClip,Msk, 0, 499, 0, 0, W, H, sop, eop)
ConcealRange(Last,BClip,Msk, 500, 999, W, H, W, 0, sop, eop)
ConcealRange(Last,BClip,Msk, 1000, 1499, W, 0, 0, H, sop, eop)
ConcealRange(Last,BClip,Msk, 1500, 1999, 0, H, 0, 0, sop, eop)
ConcealRange(Last,BClip,Msk, 2000, 2499, 0, 0, W/2,H/2, sop, eop)
#################################################################################
ConvertToRGB32 # For viewing HBD
EDIT: Fastblur and Masktools2 both available in x64 flavours.
Original
https://i.postimg.cc/ydDcfC6B/Conceal-Range-00.jpg (https://postimages.org/)
Pixelated
https://i.postimg.cc/jqJyPTk4/Conceal-Range-01.jpg (https://postimages.org/)
Blurred
https://i.postimg.cc/3J5mZqs5/Conceal-Range-02.jpg (https://postimages.org/)
Pixelated/BlankBG
https://i.postimg.cc/28Qv9wYq/Conceal-Range-03.jpg (https://postimages.org/)
Blurred/BlankBG
https://i.postimg.cc/htMmctfc/Conceal-Range-04.jpg (https://postimages.org/)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.