Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LoadCPlugin("C:\AvisynthRepository_351\AVS260_MT\plugins\AVSInpaint.dll")
- Import("C:\AvisynthRepository_351\AVS260_MT\plugins\InpaintFunc.avs")
- Function MakeLoc(clip c,Int x, Int y, Int w, Int h) { # https://forum.doom9.org/showthread.php?p=1893966#post1893966
- /*
- Make Loc string for VoodooFX InPaintDelogo.
- Input X and Y, where -ve, is relative to c.Width or c.Height, and are converted to +ve X and Y in result string.
- Input W and H, where 0 or -ve, is relative c.Width or c.Height [as in Crop()],
- Where +ve, are converted to -ve W and H in result string [as required by InPaintDelogo].
- Allows to make Loc string programmatically using flexible coord system and not locked into hand editing Loc string.
- ColorBars # 640,480
- S=MakeLoc( 0, 0, 0, 0) # "0,0,-0,-0"
- S=MakeLoc( 540, 380,-40,-40) # "540,380,-40,-40"
- S=MakeLoc(-100,-100, 60, 60) # "540,380,-40,-40"
- S=MakeLoc( 540, 380, 60, 60) # "540,380,-40,-40"
- S=MakeLoc(-100,-100,-40,-40) # "540,380,-40,-40"
- */
- c
- # First, Ensure/Convert X,Y,W,H ALL +ve
- x = (x >= 0) ? x : Width + x
- y = (y >= 0) ? y : Height + y
- w = (w > 0) ? w : Width - x + w
- h = (h > 0) ? h : Height - y + h
- # Check validity
- Assert(0 <= x < Width ,String(x,"MakeLoc: 0 <= X(%.0f)") + String(Width ," < Width(%.0f)" ))
- Assert(0 <= y < Height ,String(y,"MakeLoc: 0 <= Y(%.0f)") + String(Height ," < Height(%.0f)"))
- Assert(1 <= w <= Width -x ,String(w,"MakeLoc: 1 <= W(%.0f)") + String(Width ," <= Width-X(%.0f") + String(x ," - %.0f)"))
- Assert(1 <= h <= Height-y ,String(h,"MakeLoc: 1 <= H(%.0f)") + String(Height ," <= Height-Y(%.0f") + String(y ," - %.0f)"))
- # Output string: +ve X,Y :: -ve W,H, Ensure all (even W=0 and H=0) flagged as -ve eg -0
- return String(x,"%.0f") + String(y,",%.0f") + String(Abs(x+w-Width),",-%.0f") +String(Abs(y+h-Height),",-%.0f")
- }
- global x1crp=424
- global y1crp=558
- global x2crp=392
- global y2crp=74
- global y2add=40
- function SimpleApply(clip a, clip c1, clip mask)
- {
- out = c1.Crop(x2crp/4, y2add/2, x2crp, y2crp)
- msk = mask.Crop(0,0,x2crp,y2crp)
- return a.Overlay(out, x1crp, y1crp, mask=msk, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
- }
- global thresh_calc_frame_bigger = -1
- global thresh_calc_frames = 0
- global min_thresh = 1.0 # this threshold is movie depending i think...
- global thresh = 0
- global thresh_real = 0
- global thresh_calc = 0
- function ConditionalApply(clip a, clip a_inp, clip c1, clip mask, int cnt, int max)
- {
- #this is a test to just use some parts of the logo inblended clip (clip is divided in 24x3 blocks)
- yparts = 3
- xparts = max / yparts
- cntx = cnt % xparts
- cnty = cnt / xparts
- partx = x2crp/xparts
- party = y2crp/yparts
- org = a_inp.Crop(x1crp+cntx*partx, y1crp+cnty*party, partx, party)
- out = c1.Crop(x2crp/4+cntx*partx, y2add/2+cnty*party, partx, party)
- msk = mask.Crop(cntx*partx,cnty*party,partx,party)
- SSS = """
- thresh_cd = 5 # this threshold is movie depending i think...
- diff = out.LumaDifference(org)
- x = a.Overlay(diff < thresh_cd ? out : org, x1crp+cntx*partx, y1crp+cnty*party, mask=msk, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
- # subx = cnty < 2 ? 120 * cnty : 1000 + 100 * (cnty-2)
- # x = x.subtitle("diff " + string(diff), subx, 20+cntx*20)
- x
- """
- ret=ScriptClip(a, SSS, args="a,a_inp,out,org,cntx,cnty,partx,party,msk")
- return cnt+1 < max ? ConditionalApply(ret, a_inp, c1, mask, cnt+1, max) : ret
- }
- function SimpleApply(clip a, clip c1, clip mask)
- {
- out = c1.Crop(x2crp/4, y2add/2, x2crp, y2crp)
- msk = mask.Crop(0,0,x2crp,y2crp)
- return a.Overlay(out, x1crp, y1crp, mask=msk, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
- }
- function Apply(clip a, clip a_inp, clip c1, clip o1, clip mask)
- {
- SSS = """
- thresh_old = thresh
- thresh_calc_old = thresh_calc
- ldiff = o1.LumaDifference(c1)
- global thresh_calc = ldiff < thresh || thresh_calc_frame_bigger+5 == current_frame ? thresh_calc + ldiff : thresh_calc
- global thresh_calc_frames = thresh_calc_old != thresh_calc ? thresh_calc_frames + 1 : thresh_calc_frames
- global thresh_real = thresh_calc_frames % 5 == 0 && thresh_calc > 0 ? (thresh_calc / 5.0) : thresh_real
- global thresh = thresh_real * 1.15
- global thresh = thresh < min_thresh ? min_thresh : thresh
- global thresh_calc = thresh_calc_frames % 5 == 0 ? 0 : thresh_calc
- global thresh_calc_frame_bigger = thresh < ldiff ? current_frame : thresh_calc_frame_bigger
- ret = ldiff < thresh ? SimpleApply(a, c1, mask) : a_inp # always use the inpainted frame to better show the flickering... use next line for smaller parts...
- #ret = ldiff < thresh ? SimpleApply(a, c1, mask) : ConditionalApply(a, a_inp, c1, mask, 0, 72)
- #ret = ret.subtitle("diff" + string(ldiff) + " thresh " + string(thresh) + " thresh_real " + string(thresh_real) + " thresh_calc " + string(thresh_calc), 200, 5)
- ret
- """
- return ScriptClip(a, SSS, args="a,a_inp,c1,o1,mask")
- }
- #this function is used to find the best matching frame of the two clips which are not completely in sync ...
- function check(clip a, clip a_inp, clip crp1, clip b1, clip a1, clip aa, clip o1, clip mask, int cnt, int max)
- {
- crp2=crp1.Trim(1,0,false)
- b2=b1.Trim(1,0,false)
- a2=aa.Overlay(crp2, x2crp/4, y2add/2, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
- c1=ConditionalFilter(o1, a1, a2, "LumaDifference(a1)", "lessthan", "b2.LumaDifference(a2)", false, "a1, a2, b2", true)
- return cnt < max ? check(a, a_inp, crp2, b2, c1, aa, ConditionalFilter(c1.Crop(x2crp/4,y2add/2,x2crp,y2crp), o1, b2, "LumaDifference(crp2)", ">", "0", false, "crp2", true), mask, cnt+1, max) : \
- Apply(a, a_inp, c1, o1, mask)
- }
- a=DirectShowSource("Z:\test\a.wmv", fps=29.997, audio=false).AssumeFPS(30)
- global a_xres = a.Width()
- global a_yres = a.Height()
- b=FFVideoSource("Z:\test\a.mp4", threads=1).Trim(1,0)
- global b_xres = b.Width()
- global b_yres = b.Height()
- msk=ImageSource("Z:\test\hd0000x.bmp", 0, 111864, 150)
- b=b.Spline64Resize(a_xres,a_yres)
- b1=b.Crop(x1crp-x2crp/4, y1crp-y2add/2, x2crp+x2crp/2, y2crp+y2add)
- b1=b1.Tweak(hue=0.0, sat=1.0, bright=-1, cont=1.0, coring=True, sse=False, startHue=0, endHue=360, maxSat=150, minSat=0, interp=16)
- b1=b1.ConvertFPS(150) # convert to 150FPS because 150 is divisible by 30 and 25
- crp1=b1.Crop(x2crp/4,y2add/2,x2crp,y2crp)
- mask=msk.Crop(x1crp,y1crp,x2crp,y2crp)
- a_inp = a.InpaintDelogo( mask="Z:\test\hd0000.bmp", Automask=0, aMix=0, Loc=MakeLoc(a,x1crp,y1crp,x2crp,y2crp), Deep=4, Interp=3, Reanalyze=0, Mode="Deblend", Analyze=4, Fr1=0, Fr2=22373, FrS=0)
- a_inp = a_inp.SelectEvery(1,0,0,0,0,0) # convert to 150FPS...
- at=a.Spline36Resize(b_xres, b_yres).Spline64Resize(a_xres, a_yres) # better two identify matching frames?!?
- at=at.SelectEvery(1,0,0,0,0,0) # convert to 150FPS...
- aa=at.Crop(x1crp-x2crp/4, y1crp-y2add/2, x2crp+x2crp/2, y2crp+y2add)
- #a=a.SelectEvery(1,0,0,0,0,0) # convert to 150FPS...
- #aa=a.Crop(x1crp-x2crp/4, y1crp-y2add/2, x2crp+x2crp/2, y2crp+y2add)
- a1=aa.Overlay(crp1, x2crp/4, y2crp/4, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
- return ConditionalFilter(a, check(a, a_inp, crp1, b1, a1, aa, b1, mask, 0, 20), a, "current_frame % 5", "==", "0", false, "a", true).SelectEvery(5,0) # convert back to 30FPS...
Add Comment
Please, Sign In to add comment