Guest User

Untitled

a guest
Aug 31st, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. LoadCPlugin("C:\AvisynthRepository_351\AVS260_MT\plugins\AVSInpaint.dll")
  2. Import("C:\AvisynthRepository_351\AVS260_MT\plugins\InpaintFunc.avs")
  3.  
  4. Function MakeLoc(clip c,Int x, Int y, Int w, Int h) { # https://forum.doom9.org/showthread.php?p=1893966#post1893966
  5. /*
  6. Make Loc string for VoodooFX InPaintDelogo.
  7. 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.
  8. Input W and H, where 0 or -ve, is relative c.Width or c.Height [as in Crop()],
  9. Where +ve, are converted to -ve W and H in result string [as required by InPaintDelogo].
  10. Allows to make Loc string programmatically using flexible coord system and not locked into hand editing Loc string.
  11.  
  12. ColorBars # 640,480
  13. S=MakeLoc( 0, 0, 0, 0) # "0,0,-0,-0"
  14. S=MakeLoc( 540, 380,-40,-40) # "540,380,-40,-40"
  15. S=MakeLoc(-100,-100, 60, 60) # "540,380,-40,-40"
  16. S=MakeLoc( 540, 380, 60, 60) # "540,380,-40,-40"
  17. S=MakeLoc(-100,-100,-40,-40) # "540,380,-40,-40"
  18. */
  19. c
  20. # First, Ensure/Convert X,Y,W,H ALL +ve
  21. x = (x >= 0) ? x : Width + x
  22. y = (y >= 0) ? y : Height + y
  23. w = (w > 0) ? w : Width - x + w
  24. h = (h > 0) ? h : Height - y + h
  25. # Check validity
  26. Assert(0 <= x < Width ,String(x,"MakeLoc: 0 <= X(%.0f)") + String(Width ," < Width(%.0f)" ))
  27. Assert(0 <= y < Height ,String(y,"MakeLoc: 0 <= Y(%.0f)") + String(Height ," < Height(%.0f)"))
  28. Assert(1 <= w <= Width -x ,String(w,"MakeLoc: 1 <= W(%.0f)") + String(Width ," <= Width-X(%.0f") + String(x ," - %.0f)"))
  29. Assert(1 <= h <= Height-y ,String(h,"MakeLoc: 1 <= H(%.0f)") + String(Height ," <= Height-Y(%.0f") + String(y ," - %.0f)"))
  30. # Output string: +ve X,Y :: -ve W,H, Ensure all (even W=0 and H=0) flagged as -ve eg -0
  31. return String(x,"%.0f") + String(y,",%.0f") + String(Abs(x+w-Width),",-%.0f") +String(Abs(y+h-Height),",-%.0f")
  32. }
  33.  
  34. global x1crp=424
  35. global y1crp=558
  36. global x2crp=392
  37. global y2crp=74
  38. global y2add=40
  39.  
  40. function SimpleApply(clip a, clip c1, clip mask)
  41. {
  42. out = c1.Crop(x2crp/4, y2add/2, x2crp, y2crp)
  43. msk = mask.Crop(0,0,x2crp,y2crp)
  44. return a.Overlay(out, x1crp, y1crp, mask=msk, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
  45. }
  46.  
  47. global thresh_calc_frame_bigger = -1
  48. global thresh_calc_frames = 0
  49. global min_thresh = 1.0 # this threshold is movie depending i think...
  50. global thresh = 0
  51. global thresh_real = 0
  52. global thresh_calc = 0
  53.  
  54. function ConditionalApply(clip a, clip a_inp, clip c1, clip mask, int cnt, int max)
  55. {
  56. #this is a test to just use some parts of the logo inblended clip (clip is divided in 24x3 blocks)
  57. yparts = 3
  58. xparts = max / yparts
  59. cntx = cnt % xparts
  60. cnty = cnt / xparts
  61. partx = x2crp/xparts
  62. party = y2crp/yparts
  63. org = a_inp.Crop(x1crp+cntx*partx, y1crp+cnty*party, partx, party)
  64. out = c1.Crop(x2crp/4+cntx*partx, y2add/2+cnty*party, partx, party)
  65. msk = mask.Crop(cntx*partx,cnty*party,partx,party)
  66.  
  67. SSS = """
  68. thresh_cd = 5 # this threshold is movie depending i think...
  69. diff = out.LumaDifference(org)
  70. 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)
  71. # subx = cnty < 2 ? 120 * cnty : 1000 + 100 * (cnty-2)
  72. # x = x.subtitle("diff " + string(diff), subx, 20+cntx*20)
  73. x
  74. """
  75. ret=ScriptClip(a, SSS, args="a,a_inp,out,org,cntx,cnty,partx,party,msk")
  76. return cnt+1 < max ? ConditionalApply(ret, a_inp, c1, mask, cnt+1, max) : ret
  77. }
  78.  
  79. function SimpleApply(clip a, clip c1, clip mask)
  80. {
  81. out = c1.Crop(x2crp/4, y2add/2, x2crp, y2crp)
  82. msk = mask.Crop(0,0,x2crp,y2crp)
  83. return a.Overlay(out, x1crp, y1crp, mask=msk, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
  84. }
  85.  
  86. function Apply(clip a, clip a_inp, clip c1, clip o1, clip mask)
  87. {
  88. SSS = """
  89. thresh_old = thresh
  90. thresh_calc_old = thresh_calc
  91.  
  92. ldiff = o1.LumaDifference(c1)
  93.  
  94. global thresh_calc = ldiff < thresh || thresh_calc_frame_bigger+5 == current_frame ? thresh_calc + ldiff : thresh_calc
  95. global thresh_calc_frames = thresh_calc_old != thresh_calc ? thresh_calc_frames + 1 : thresh_calc_frames
  96. global thresh_real = thresh_calc_frames % 5 == 0 && thresh_calc > 0 ? (thresh_calc / 5.0) : thresh_real
  97. global thresh = thresh_real * 1.15
  98. global thresh = thresh < min_thresh ? min_thresh : thresh
  99. global thresh_calc = thresh_calc_frames % 5 == 0 ? 0 : thresh_calc
  100. global thresh_calc_frame_bigger = thresh < ldiff ? current_frame : thresh_calc_frame_bigger
  101.  
  102. 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...
  103. #ret = ldiff < thresh ? SimpleApply(a, c1, mask) : ConditionalApply(a, a_inp, c1, mask, 0, 72)
  104. #ret = ret.subtitle("diff" + string(ldiff) + " thresh " + string(thresh) + " thresh_real " + string(thresh_real) + " thresh_calc " + string(thresh_calc), 200, 5)
  105. ret
  106. """
  107. return ScriptClip(a, SSS, args="a,a_inp,c1,o1,mask")
  108. }
  109.  
  110. #this function is used to find the best matching frame of the two clips which are not completely in sync ...
  111. function check(clip a, clip a_inp, clip crp1, clip b1, clip a1, clip aa, clip o1, clip mask, int cnt, int max)
  112. {
  113. crp2=crp1.Trim(1,0,false)
  114. b2=b1.Trim(1,0,false)
  115. a2=aa.Overlay(crp2, x2crp/4, y2add/2, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
  116. c1=ConditionalFilter(o1, a1, a2, "LumaDifference(a1)", "lessthan", "b2.LumaDifference(a2)", false, "a1, a2, b2", true)
  117. 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) : \
  118. Apply(a, a_inp, c1, o1, mask)
  119. }
  120.  
  121. a=DirectShowSource("Z:\test\a.wmv", fps=29.997, audio=false).AssumeFPS(30)
  122. global a_xres = a.Width()
  123. global a_yres = a.Height()
  124.  
  125. b=FFVideoSource("Z:\test\a.mp4", threads=1).Trim(1,0)
  126. global b_xres = b.Width()
  127. global b_yres = b.Height()
  128. msk=ImageSource("Z:\test\hd0000x.bmp", 0, 111864, 150)
  129.  
  130. b=b.Spline64Resize(a_xres,a_yres)
  131.  
  132. b1=b.Crop(x1crp-x2crp/4, y1crp-y2add/2, x2crp+x2crp/2, y2crp+y2add)
  133. 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)
  134. b1=b1.ConvertFPS(150) # convert to 150FPS because 150 is divisible by 30 and 25
  135.  
  136. crp1=b1.Crop(x2crp/4,y2add/2,x2crp,y2crp)
  137. mask=msk.Crop(x1crp,y1crp,x2crp,y2crp)
  138.  
  139. 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)
  140. a_inp = a_inp.SelectEvery(1,0,0,0,0,0) # convert to 150FPS...
  141.  
  142. at=a.Spline36Resize(b_xres, b_yres).Spline64Resize(a_xres, a_yres) # better two identify matching frames?!?
  143. at=at.SelectEvery(1,0,0,0,0,0) # convert to 150FPS...
  144. aa=at.Crop(x1crp-x2crp/4, y1crp-y2add/2, x2crp+x2crp/2, y2crp+y2add)
  145.  
  146. #a=a.SelectEvery(1,0,0,0,0,0) # convert to 150FPS...
  147. #aa=a.Crop(x1crp-x2crp/4, y1crp-y2add/2, x2crp+x2crp/2, y2crp+y2add)
  148.  
  149. a1=aa.Overlay(crp1, x2crp/4, y2crp/4, opacity=1.0, mode="blend", greymask=true, ignore_conditional=false, pc_range=false)
  150.  
  151. 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...
  152.  
Add Comment
Please, Sign In to add comment