Advertisement
Guest User

Untitled

a guest
Apr 28th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. # Imports
  2. import vapoursynth as vs
  3. # getting Vapoursynth core
  4. import sys
  5. import os
  6. core = vs.core
  7. # Import scripts folder
  8. scriptPath = 'F:/Hybrid/64bit/vsscripts'
  9. sys.path.insert(0, os.path.abspath(scriptPath))
  10. # loading plugins
  11. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  12. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
  13. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libtemporalmedian.dll")
  14. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  15. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
  16. # Import scripts
  17. import havsfunc
  18. import SpotLess
  19. import chromashift
  20. # Source: 'C:\Users\Selur\Desktop\Day.avi'
  21. # Current color space: YUV422P8, bit depth: 8, resolution: 720x480, frame rate: 23.976fps, scanorder: progressive, yuv luminance scale: limited, matrix: 470bg
  22. # Loading C:\Users\Selur\Desktop\Day.avi using LWLibavSource
  23. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/Day.avi", format="YUV422P8", stream_index=0, cache=0, prefer_hw=0)
  24. frame = clip.get_frame(0)
  25. # Setting detected color matrix (470bg).
  26. clip = core.std.SetFrameProps(clip, _Matrix=5)
  27. # setting color transfer (170), if it is not set.
  28. if ('_Transfer' not in frame.props) or (frame.props['_Transfer'] == '') or (frame.props['_Transfer'] == 0):
  29. clip = core.std.SetFrameProps(clip, _Transfer=6)
  30. # setting color primaries info (to 470), if it is not set.
  31. if ('_Primaries' not in frame.props) or (frame.props['_Primaries'] == '') or (frame.props['_Primaries'] == 0):
  32. clip = core.std.SetFrameProps(clip, _Primaries=5)
  33. # setting color range to TV (limited) range.
  34. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
  35. # making sure frame rate is set to 23.976fps
  36. clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
  37. # making sure the detected scan type is set (detected: progressive)
  38. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
  39. # Chroma adjustment using ChromaShiftSP
  40. clip = chromashift.ChromaShiftSP(clip=clip, X=-2.00)
  41. # Spot removal using SpotLess
  42. clip = SpotLess.SpotLess(clip=clip, radT=1, pel=1)
  43. clip = core.std.CropRel(clip=clip, left=10, right=10, top=58, bottom=58)# cropping to 700x364
  44. # Fix bright and dark line artifacts near the border of an image using BalanceBorders
  45. clip = havsfunc.bbmod(c=clip,cLeft=16,cTop=0,cRight=16,cBottom=0)
  46. # changing range from limited to full range
  47. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  48. # setting color range to PC (full) range.
  49. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
  50. # adjusting color space from YUV422P8 to RGBH for VsVSGANFilter
  51. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="full")
  52. # filtering using VSGANFilter
  53. from vsgan import ESRGAN
  54. vsgan = ESRGAN(clip=clip,device="cuda")
  55. model = "F:/Hybrid/64bit/vsgan_models/2x_LD-Anime-Compact.pth"
  56. vsgan.load(model)
  57. vsgan.apply() # 1400x728
  58. clip = vsgan.clip
  59. # undo resizing 1400x728 to 364x700
  60. clip = core.resize.Spline64(clip=clip, width=364, height=700) # resolution 364x700)
  61. # changing range from full to limited range
  62. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  63. # adjusting color space from RGBH to YUV444P16 for vsGLSLDarken
  64. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  65. # Using Anime4k Darken GLSL filter for line darkening
  66. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/Anime4K_Darken_HQ.glsl") as glslf:
  67. glsl = glslf.read()
  68. glsl = glsl.replace('#define STRENGTH 1.5', '#define STRENGTH 1.5')
  69. clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
  70. # fallback - adjusting from 700x364 to output resolution 700x364
  71. clip = core.resize.Spline64(clip=clip, width=700, height=364) # resolution 700x364)
  72. # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
  73. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", dither_type="error_diffusion")
  74. # set output frame rate to 23.976fps (progressive)
  75. clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
  76. # output
  77. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement