Guest User

Untitled

a guest
Dec 14th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # MotionThresh by mf
  2. # Simple scenechange-proof motion threshold
  3. # Tile outputs 16x16 clip for speed
  4. # Use tile=true for conditional filtering, tile=false for masking
  5.  
  6. function MotionThresh(clip input, float thresh, bool "tile") {
  7. tile = Default(tile, false)
  8.  
  9. black = BlankClip(input, width=16, height=16)
  10. white = BlankClip(input, width=16, height=16, color=$FFFFFF)
  11. cond1 = ConditionalFilter(input, white, black, "YDifferenceFromPrevious()", "greaterthan", String(thresh))
  12. cond2 = ConditionalFilter(input, white, black, "YDifferenceToNext()", "greaterthan", String(thresh))
  13. Overlay(cond1, cond2, mode="darken")
  14. tile ? last : PointResize(input.width, input.height)
  15. }
  16.  
  17.  
  18. ######################################################################
  19. # MotionRamp by mf
  20. # Average motion soft-thresholding based on 5 thresholds
  21. # Dependancies: MotionThresh, BlendMulti
  22.  
  23. function MotionRamp(clip input, int thresh1, int thresh2, int thresh3, int thresh4, int thresh5, int "min", int "max", int "floor", int "ceil", int "radius", bool "tile") {
  24. min = Default(min, 0)
  25. max = Default(max, 255)
  26. floor = Default(floor, 0)
  27. ceil  = Default(ceil, 255)
  28. radius = Default(radius, 2)
  29. tile = Default(tile, false)
  30.  
  31. input
  32. Interleave(MotionThresh(thresh3, tile=true), MotionThresh(thresh2, tile=true), MotionThresh(thresh4, tile=true), MotionThresh(thresh1, tile=true), MotionThresh(thresh5, tile=true)).ParameterisedBlend(0.20, 0.20, 0.20, 0.20, 0.20, gamma=1, scaleweights=false).SelectEvery(5,0)
  33. TemporalSoften(radius,255,0,255,2)
  34. Levels(floor, 1, ceil, min, max)
  35. ColorYUV(levels="TV->PC")
  36. tile ? last : PointResize(input.width, input.height)
  37. }
  38.  
  39.  
  40. ##########
  41. function admfilter(clip input, bool "mc", float "f", bool "DarkPreserve", float "rStr", float "amp", bool "lsb", bool "lsb_in", bool "lsb_out", bool "luma_rebuild", bool "u", bool "v", string "pp", string "dfttest_params", string "mcdfttest_params", string "custom_filter", clip "MotionRampadc") {
  42. d = default (DarkPreserve      , true)
  43. mc = default (mc      , true)
  44. f = Default(f, 16.0)
  45. lsb = default (lsb      , true)
  46. lsb_in = default (lsb_in      , false)
  47. lsb_out = default (lsb_out      , lsb_in)
  48. lsb = lsb_in || lsb_out ? true : lsb
  49. luma_rebuild = default (luma_rebuild      , true)
  50. u = default (u      , true)
  51. v = default (v      , true)
  52. dfttest_params = default(dfttest_params, "")
  53. mcdfttest_params = default(mcdfttest_params, "")
  54. pp = default (pp, "blur(1.53)")
  55.  
  56. custom_filter = defined(custom_filter) ? custom_filter : \
  57.                                                          mc ? "dfttestmc(pp=Eval(pp),lsb=lsb, Sigma=adSigma/f,rStr=rStr,amp=amp,lsb_in=lsb_in,luma_rebuild=luma_rebuild,u=u,v=v,dfttest_params=dfttest_params" + mcdfttest_params + ")" : \
  58.                                                               "dfttest(lsb=lsb, Sigma=adSigma/f, lsb_in=lsb_in,u=u,v=v" + dfttest_params + ")"
  59.  
  60. input
  61. MotionRampadc = defined(MotionRampadc) ? MotionRampadc : last.MotionRamp(5,10,15,20,25,Max=255,Tile=True)
  62. lsb_out && !lsb_in ? Dither_convert_8_to_16() : lsb_in && !lsb_out ? Ditherpost(mode=-1, y=1, u=1,v=1) : last
  63. return GScriptClip("""
  64.                     adSigma = AverageLuma(MotionRampadc)
  65.                     (lsb_out && !lsb_in) || (lsb_in && !lsb_out) ? input : last
  66.                     adden = Eval(custom_filter)
  67.                     d ? DarkPreserve_function(filtered=adden, original=last, u=u ? 3 : 4, v=v ? 3 : 4, lsb=lsb, lsb_in=lsb_in, lsb_out=lsb_out) : adden
  68.                     !d && !lsb_out && lsb ? Ditherpost(mode=7, slice=false) : last
  69.                     """, args="MotionRampadc, f, d, rStr, amp, lsb_in, lsb_out, lsb, luma_rebuild, u, v,dfttest_params,mcdfttest_params,pp,input,custom_filter")
  70. }
  71.  
  72.  
  73. #######
  74. function DarkPreserve_function(clip "filtered", clip "original", bool "merge16_8", int "u", int "v", bool "lsb", bool "lsb_in", bool "lsb_out") {
  75. lsb_in    = default (lsb_in                       , false) #for original
  76. F_lsb_in  = lsb_in ? (Height(filtered)) == (Height(original)) : (Height(filtered)) == (Height(original)*2)
  77. lsb_out   = default (lsb_out         , F_lsb_in || lsb_in)
  78. lsb       = default (lsb ,  lsb_in || lsb_out || F_lsb_in)
  79. merge16_8 = default (merge16_8                     , true)
  80. u         = default (u                                , 3)
  81. v         = default (v                                , u)
  82. chroma    = !(u != 3 && v != 3)
  83.  
  84. F_lsb_in        ? Assert(lsb,                          "16stacked filtered clip requires: lsb=true")                : nop()
  85. lsb_in          ? Assert(lsb,                          "lsb_in  requires: lsb=true")                                : nop()
  86. lsb_out         ? Assert(lsb,                          "lsb_out requires: lsb=true")                                : nop()
  87.  
  88. dp_lut = lsb_in ? original.Dither_lut16("x 4096 < 65535 x 19200 > 0 65535 x 4096 - 65535 19200 4096 - / * - ? ?",u=1,v=1) : original.mt_lut("x 16 < 255 x 75 > 0 255 x 16 - 255 75 16 - / * - ? ?",u=1,v=1)
  89.  
  90. dp_lut = lsb_in && merge16_8 ? dp_lut.Ditherpost(mode=6, slice=false, u=1, v=1) : dp_lut
  91.  
  92. dp_merge = lsb ? merge16_8 ? Dither_merge16_8(F_lsb_in ? filtered : filtered.Dither_convert_8_to_16(), lsb_in ? original : original.Dither_convert_8_to_16(), dp_lut, luma=chroma, u=u,v=v) : \
  93.                              Dither_merge16(F_lsb_in ? filtered : filtered.Dither_convert_8_to_16(), lsb_in ? original : original.Dither_convert_8_to_16(), dp_lut, luma=chroma, u=u,v=v) : \
  94.                              mt_merge(filtered, original, dp_lut, luma=chroma, u=u,v=v)
  95. lsb ? lsb_out ? dp_merge : dp_merge.Ditherpost(mode=7, slice=false) : dp_merge
  96. }
  97.  
  98.  
  99. ##########
  100. #edge side bleed
  101. ##########
  102. function edgesidebleed(clip input, float "w32", float "w16", float "w8", float "w4", float "w2", int "y", int "u", int "v") {
  103. w2 = Default(w2, 0.001)
  104. w4 = Default(w4, 0.055)
  105. w8 = Default(w8, 0.015)
  106. w16 = Default(w16, 0.02)
  107. w32 = Default(w32, 0.001)
  108. input
  109. shift32 = Crop(Width()-32,0,32,0,true).StackHorizontal(Crop(0,0,-32,0,true))
  110. w32==0 ? last : raveragew(last,1+w32,shift32,-w32,y=y,u=u,v=v)
  111. shift16 = Crop(Width()-16,0,16,0,true).StackHorizontal(Crop(0,0,-16,0,true))
  112. w16==0 ? last : raveragew(last,1+w16,shift16,-w16,y=y,u=u,v=v)
  113. shift8 = Crop(Width()-8,0,8,0,true).StackHorizontal(Crop(0,0,-8,0,true))
  114. w8==0 ? last : raveragew(last,1+w8,shift8,-w8,y=y,u=u,v=v)
  115. shift4 = Crop(Width()-4,0,4,0,true).StackHorizontal(Crop(0,0,-4,0,true))
  116. w4==0 ? last : raveragew(last,1+w4,shift4,-w4,y=y,u=u,v=v)
  117. shift2 = Crop(Width()-2,0,2,0,true).StackHorizontal(Crop(0,0,-2,0,true))
  118. w2==0 ? last : raveragew(last,1+w2,shift2,-w2,y=y,u=u,v=v)
  119. }
  120.  
  121.  
  122. ###############
  123. # Hqdn3d_2
  124.  
  125. function Hqdn3d_2(clip clip, float "ls", float "cs", float "lt", float "ct", int "UV", bool "lsb", bool "lsb_in", bool "i16") {
  126. cs        = default (cs              , 3.0)
  127. ct        = default (ct              , 4.5)
  128. UV        = default (UV               , 3)
  129. UV        = !(VersionNumber() < 2.60) ? isY8(clip) ? 1 : UV : UV
  130. lsb_in    = default (lsb_in          , false)
  131. i16       = default (i16             , false)
  132. lsb_out   = default (lsb             , lsb_in)
  133.  
  134. i16b      = lsb_out || i16 || lsb_in
  135.  
  136. isrgb(clip) ? Assert(!i16b, "no 16bit for RGB, but you can use some trickes for that (see dither doc)") : nop()
  137.  
  138. yString = VersionNumber() < 2.60 ? "yv12" : "Y8"
  139.  
  140. pclip   = isYUV(clip) && i16b && isYUY2(clip) && !(VersionNumber() < 2.60) ? clip.ConvertToYV16() : clip
  141.  
  142. i16clip = isYUV(clip) ? i16b ? lsb_in ? pclip.Bitdepth(from=88, to=16) : i16 ? clip : pclip.Bitdepth(from=8, to=16) : nop() : nop()
  143.  
  144.     y = isYUV(clip) ? VersionNumber() < 2.60 ? i16b ? i16clip : clip : i16b ? ConvertToY8(i16clip) : ConvertToY8(clip) : nop()
  145.     u = isYUV(clip) && UV != 1 ? VersionNumber() < 2.60 ? i16b ? UToY(i16clip) : UToY(clip) : i16b ? UToY8(i16clip) : UToY8(clip) : nop()
  146.     v = isYUV(clip) && UV != 1 ? VersionNumber() < 2.60 ? i16b ? VToY(i16clip) : VToY(clip) : i16b ? VToY8(i16clip) : VToY8(clip) : nop()
  147.     y = isYUV(clip) ? VersionNumber() < 2.60 ? isclip(i16clip) ? y.converttoyv12().Hqdn3d16Y(sp=ls, tp=lt) : y.converttoyv12().Hqdn3dY(sp=ls, tp=lt) : isclip(i16clip) ? y.Hqdn3d16Y(sp=ls, tp=lt) : y.Hqdn3dY(sp=ls, tp=lt) : nop()
  148.     u = isYUV(clip) ? UV == 3 ? VersionNumber() < 2.60 ? isclip(i16clip) ? u.converttoyv12().Hqdn3d16Y(sp=cs, tp=ct) : u.converttoyv12().Hqdn3dY(sp=cs, tp=ct) : isclip(i16clip) ? u.Hqdn3d16Y(sp=cs, tp=ct) : u.Hqdn3dY(sp=cs, tp=ct) : u : nop()
  149.     v = isYUV(clip) ? UV == 3 ? VersionNumber() < 2.60 ? isclip(i16clip) ? v.converttoyv12().Hqdn3d16Y(sp=cs, tp=ct) : v.converttoyv12().Hqdn3dY(sp=cs, tp=ct) : isclip(i16clip) ? v.Hqdn3d16Y(sp=cs, tp=ct) : v.Hqdn3dY(sp=cs, tp=ct) : v : nop()
  150.     isYUV(clip) ? (VersionNumber() < 2.60) && isYUY2(clip) ? UV == 1 ? y : YToUV(u.converttoyuy2(),v.converttoyuy2(),y.converttoyuy2()) : UV == 1 ? y : YToUV(u,v,y) : nop()
  151.         isYUV(clip) ? i16b && !i16 && lsb_out ? Bitdepth(from=16, to=88) : last : last
  152.     isYUV(clip) ? !i16b || lsb_out || i16 ? last : Bitdepth(from=16, to=8) : last
  153.     isYUY2(clip) ? VersionNumber() < 2.60 ? last : converttoyuy2() : last
  154.  
  155.     A = isrgb32(clip) ? clip.ShowAlpha(yString) : nop()
  156.     r = isrgb(clip) ? clip.ShowRed(yString) : nop()
  157.     g = isrgb(clip) ? clip.ShowGreen(yString) : nop()
  158.     b = isrgb(clip) ? clip.ShowBlue(yString) : nop()
  159.     A = isrgb32(clip) ? A.Hqdn3dY(sp=ls, tp=lt) : nop()
  160.     r = isrgb(clip) ? r.Hqdn3dY(sp=ls, tp=lt) : nop()
  161.     g = isrgb(clip) ? g.Hqdn3dY(sp=ls, tp=lt) : nop()
  162.     b = isrgb(clip) ? b.Hqdn3dY(sp=ls, tp=lt) : nop()
  163.     isYUV(clip) ? last : isrgb32(clip) ? MergeARGB(A,r,g,b) : MergeRGB(r,g,b,"RGB24")
  164. }
  165.  
  166.  
  167. ###############
  168. #motion adaptive by A.SONY
  169.  
  170. function smam(clip input, clip "prefilter", val "filter", int "pel", int "blksize", clip "motionmask", float "Str", float "Amp", bool "TV_range", bool "qtgmc_lsb") {
  171.  
  172. ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
  173. qtgmc_lsb = default(qtgmc_lsb, ssispmt ? input.BitsPerComponent() > 8 ? false : true : true)
  174.  
  175. defined(filter) ? Assert((Isclip(filter) || IsString(filter)),        "'filter' only accepts clip or string") : nop()
  176.  
  177. Str             = default (Str,                                                           1.5)
  178.  
  179. filclip= defined(filter) ? isclip(filter) ? filter : eval("input." + filter) : input.QTGMC(InputType=1, tr0=0, tr1=1, tr2=1, lsb=qtgmc_lsb, rep0=11, rep1=11, rep2=11, Sharpness=0.0, TV_range=TV_range, Str=Str, Amp=Amp).daa3mod()
  180.  
  181. csaa   = filclip
  182. momask = !defined(motionmask) ? input.smam_mask(prefilter,pel,blksize) : motionmask #if you deal with YUY2 then it should be Planar YUY2 in avs2.5 and yv16 in avs2.6
  183. isyuy2(input) && VersionNumber() < 2.60 ? mt_merge(input.Interleaved2Planar(),csaa.Interleaved2Planar(),momask,u=3,v=3).Planar2Interleaved() : isyuy2(input) ? mt_merge(input.converttoyv16(),csaa.converttoyv16(),momask,u=3,v=3).converttoyuy2() : mt_merge(input,csaa,momask,u=3,v=3)
  184. }
  185.  
  186.  
  187. ###############
  188. #smam_mask
  189. # if input is YUY2 the output will be Planar YUY2 in avs 2.5 and yv16 in avs 2.6
  190.  
  191. function smam_mask(clip input, clip "prefilter", int "pel", int "blksize") {
  192.     ox = input.width()
  193.     oy = input.height()
  194.     HD = (ox > 1099 || oy > 599)
  195.     pel = default( pel, HD ? 1 : 2 )
  196.     blksize = default(blksize,HD ? 16:8)
  197. preclip= defined(prefilter) ? prefilter : (VersionNumber() < 2.60) && isyv12(input) ? input.HQdn3d().FFT3DFilter() : input.HQdn3d_2().FFT3DFilter()
  198. sup    = preclip.MSuper(pel=pel,sharp=1)
  199. fv1    = sup.MAnalyse(isb=false,delta=1,DCT=2,Truemotion=false,blksize=blksize)
  200. fv2    = sup.MAnalyse(isb=true,delta=1,DCT=2,Truemotion=true,blksize=blksize)
  201.  
  202. momask1 = input.MMask(fv1, kind = 1, ml=2)
  203. momask2 = input.MMask(fv2, kind = 1, ml=3)
  204. momask1 =isyuy2(input) && VersionNumber() < 2.60 ? momask1.Interleaved2Planar() : isyuy2(input) ? momask1.converttoyv16() : momask1
  205. momask2 =isyuy2(input) && VersionNumber() < 2.60 ? momask2.Interleaved2Planar() : isyuy2(input) ? momask2.converttoyv16() : momask2
  206. mt_average(momask1,momask2,u=3,v=3)
  207. }
  208.  
  209.  
  210. ##############
  211. # sanimebob by A.SONY
  212.  
  213. function sanimebob(clip i, int "useqtgmc", val "bobpresmooth", float "Str", float "Amp", bool "TV_range", bool "qtgmc_lsb") {
  214.  
  215. ssispmt   = Findstr(VersionString(), "AviSynth+") != 0 && Findstr(VersionString(), "r1576") == 0
  216. qtgmc_lsb = default(qtgmc_lsb, ssispmt ? i.BitsPerComponent() > 8 ? false : true : true)
  217.  
  218. bobpresmbool    = default (isbool(bobpresmooth) ? bobpresmooth : defined(bobpresmooth), false)
  219. useqtgmc        = default (useqtgmc                                                       , 0)
  220. Str             = default (Str,                                                           1.5)
  221.  
  222. prefiltered_i   = defined(bobpresmooth) ? isclip(bobpresmooth) ? bobpresmooth : IsString(bobpresmooth) ? Eval("i." + bobpresmooth) : undefined() : undefined()
  223.  
  224. iforbob = bobpresmbool ? defined(prefiltered_i) ? prefiltered_i : i.QTGMC_bob(0,0.5).reduceflicker(strength=2).interlaced60or50(BFF=!(GetParity(i))) : i
  225. iforbob = bobpresmbool && !defined(prefiltered_i) ? isyuy2(i) ? iforbob.SeparateFields().Interleaved2Planar().Repair(i.SeparateFields().Interleaved2Planar(),Planar=true).Planar2Interleaved().weave() : iforbob.SeparateFields().Repair(i.SeparateFields()).weave() : iforbob
  226.  
  227. pi      =      i.pointresize(width(i),height(i)+8,0,-4,width(i),height(i)+8.0001)
  228.  
  229. yadifclip= isyuy2(i) ? pi.yadifmod(mode=3, edeint=i.eedi3(-2,sclip=iforbob.nnedi3(-2)).pointresize(width(i),height(i)+8,0,-4,width(i),height(i)+8.0001)).crop(0,4,-0,-4).Interleaved2Planar().Repair(i.TDeint(1,emask=iforbob.tmm(1)).Interleaved2Planar(),Planar=true).Planar2Interleaved() : \
  230.                        pi.yadifmod(mode=3, edeint=i.eedi3(-2,sclip=iforbob.nnedi3(-2)).pointresize(width(i),height(i)+8,0,-4,width(i),height(i)+8.0001)).crop(0,4,-0,-4).Repair(i.TDeint(1,emask=iforbob.tmm(1)))
  231. useqtgmc==0 ? yadifclip : \
  232. useqtgmc==1 ? iforbob.QTGMC(SourceMatch=3, Lossless=2, EdiExt=yadifclip, tr0=1, tr1=1, tr2=1, lsb=qtgmc_lsb, rep0=11, rep1=11, rep2=11, Sharpness=0.1, TV_range=TV_range, Str=Str, Amp=Amp) : \
  233. useqtgmc==2 ? yadifclip.smam(filter=iforbob.QTGMC(SourceMatch=3, Lossless=2, EdiExt=yadifclip, tr0=1, tr1=1, tr2=1, lsb=qtgmc_lsb, rep0=11, rep1=11, rep2=11, Sharpness=0.1, TV_range=TV_range, Str=Str, Amp=Amp)) : \
  234. useqtgmc==3 ? yadifclip.smam(filter=yadifclip.QTGMC(InputType=1, tr0=1, tr1=1, tr2=1, lsb=qtgmc_lsb, rep0=11, rep1=11, rep2=11, Sharpness=0.1, TV_range=TV_range, Str=Str, Amp=Amp)) : \
  235. useqtgmc==4 ? yadifclip.smam(filter=iforbob.QTGMC(SourceMatch=3, Lossless=2, EdiExt=yadifclip, tr0=1, tr1=1, tr2=1, lsb=qtgmc_lsb, rep0=11, rep1=11, rep2=11, Sharpness=0.1, TV_range=TV_range, Str=Str, Amp=Amp).daa3mod) : \
  236. useqtgmc==5 ? yadifclip.smam(filter=yadifclip.QTGMC(InputType=1, tr0=1, tr1=1, tr2=1, lsb=qtgmc_lsb, rep0=11, rep1=11, rep2=11, Sharpness=0.1, TV_range=TV_range, Str=Str, Amp=Amp).daa3mod) : \
  237. useqtgmc==6 ? yadifclip.smam(filter=yadifclip.QTGMC(InputType=1, tr0=0, lsb=qtgmc_lsb, Sharpness=0.1, TV_range=TV_range, Str=Str, Amp=Amp)) : \
  238.               yadifclip.smam(filter=yadifclip.QTGMC(InputType=1, tr0=0, lsb=qtgmc_lsb, Sharpness=0.0, TV_range=TV_range, Str=Str, Amp=Amp).daa3mod)
  239. }
Advertisement
Add Comment
Please, Sign In to add comment