Advertisement
Zastin

subpixel descale example

May 28th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1. from vapoursynth import core, GRAY8, GRAY16
  2. from math import ceil
  3.  
  4. w, h =
  5.  
  6. b, c =
  7.  
  8. cw, ch = ceil(w), ceil(h)
  9.  
  10. avs = "c.DeBicubicResizeMT({w}, {h}, {b} ,{c}, 0, 0, {sw}, {sh})".format(w=cw, h=ch, b=b, c=c, sw=w, sh=h)
  11.    
  12. debic = core.avsw.Eval(avs, clips=[clip], clip_names=["c"])
  13.  
  14. upscaled = debic.std.Transpose()
  15. upscaled = upscaled.nnedi3.nnedi3(1, True, 0, nsize=0, nns=4, qual=2)
  16. upscaled = upscaled.std.Transpose()
  17. upscaled = upscaled.resize.Spline36(height=1920, src_top=-0.5, src_height=w*2)
  18. upscaled = upscaled.nnedi3.nnedi3(1, True, 0, nsize=0, nns=4, qual=2)
  19. upscaled = upscaled.resize.Spline36(height=1080, src_top=-0.5, src_height=h*2)
  20.  
  21. rebic = debic.resize.Bicubic(1920, 1080, filter_param_a=b, filter_param_b=c, src_width=w, src_height=h)
  22.  
  23. error = core.std.Expr([clip,rebic],'x y - abs 2560 < 0 255 ?', GRAY8)
  24. error = error.std.Maximum().std.Maximum().std.Maximum()
  25. error = error.std.Inflate().std.Inflate().std.Inflate()
  26.  
  27. edges = upscaled.whatever_the_fuck()
  28. mask = core.std.Expr([edges, error],'x y 257 * -',)
  29.  
  30. clip = clip.std.MaskeMerge(upscaled, mask)
  31.  
  32.  
  33. '''
  34.    cw, ch = [x * 2 for x in [ceil(w/2), ceil(h/2)]]
  35.    
  36.    avs = "c.ConvertToYV12().DebicubicY16({w}, {h}, 0, 0, {sw}, {sh}, True, {b}, {c}, iter=True, Y8=True)".format(w=cw, h=ch, b=b, c=c, sw=1920 / w * cw, sh=1080 / h * ch)
  37.    
  38.    debic = core.avsw.Eval(avs, clips=[core.fmtc.nativetostack16(clip)], clip_names=["c"]).fmtc.stack16tonative()
  39. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement