Guest User

Untitled

a guest
May 10th, 2024
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. # Imports
  2. import vapoursynth as vs
  3. # getting Vapoursynth core
  4. import ctypes
  5. import site
  6. import sys
  7. import os
  8. core = vs.core
  9. # Limit thread count to 1, due to usage of sRestore
  10. core.num_threads = 1
  11. # Import scripts folder
  12. scriptPath = 'F:/Hybrid/64bit/vsscripts'
  13. sys.path.insert(0, os.path.abspath(scriptPath))
  14. # Adding torch dependencies to PATH
  15. path = site.getsitepackages()[0]+'/torch_dependencies/bin/'
  16. ctypes.windll.kernel32.SetDllDirectoryW(path)
  17. path = path.replace('\\', '/')
  18. os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]
  19. # Loading Support Files
  20. Dllref = ctypes.windll.LoadLibrary("F:/Hybrid/64bit/vsfilters/Support/libfftw3-3.dll")
  21. # loading plugins
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DGDenoise/DGDenoise.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DebandFilter/Flash3kDeband/flash3kyuu_deband.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/vcm.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/CAS/CAS.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/ZSmooth/zsmooth.dll")
  32. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  33. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  34. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  35. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV.dll")
  36. # Import scripts
  37. import masked
  38. import mclean
  39. import mvsfunc
  40. import muvsfunc
  41. import SpotLess
  42. import havsfunc
  43. import validate
  44. # Source: 'C:\Users\Selur\Desktop\VTS_27_1 videohelp.mkv'
  45. # Current color space: YUV420P8, bit depth: 8, resolution: 720x576, frame rate: 25fps, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
  46. # Loading C:\Users\Selur\Desktop\VTS_27_1 videohelp.mkv using DGSource
  47. clip = core.dgdecodenv.DGSource("J:/tmp/mkv_341d81bcf45f892aeab6de7279ed50b9_853323747.dgi",fieldop=0)# 25 fps, scanorder: top field first
  48. frame = clip.get_frame(0)
  49. # Setting detected color matrix (470bg).
  50. clip = core.std.SetFrameProps(clip=clip, _Matrix=5)
  51. # setting color transfer (170), if it is not set.
  52. if validate.transferIsInvalid(clip):
  53. clip = core.std.SetFrameProps(clip=clip, _Transfer=6)
  54. # setting color primaries info (to 470), if it is not set.
  55. if validate.primariesIsInvalid(clip):
  56. clip = core.std.SetFrameProps(clip=clip, _Primaries=5)
  57. # setting color range to TV (limited) range.
  58. clip = core.std.SetFrameProps(clip=clip, _ColorRange=1)
  59. # making sure frame rate is set to 25fps
  60. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  61. # making sure the detected scan type is set (detected: top field first)
  62. clip = core.std.SetFrameProps(clip=clip, _FieldBased=2)# tff
  63. # Deinterlace using Bwdif
  64. clip = core.bwdif.Bwdif(clip=clip, field=2, edeint=core.nnedi3cl.NNEDI3CL(clip=clip,field=2)) # new fps: 50
  65. # Making sure content is preceived as frame based
  66. clip = core.std.SetFrameProps(clip=clip, _FieldBased=0)# progressive
  67. # adjusting frame count and rate with sRestore
  68. clip = havsfunc.srestore(source=clip, frate=23.9760, speed=-25)
  69. # Spot removal using SpotLess
  70. clip = SpotLess.SpotLess(clip=clip, radT=3, pel=1, smoother="zsmooth")
  71. from vsdpir import dpir as DPIR
  72. # adjusting color space from YUV420P8 to RGBH for vsDPIRDeblock
  73. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  74. # deblocking using DPIRDeblock
  75. clip = DPIR(clip=clip, strength=50.000, task="deblock", device_index=0, trt=True, trt_cache_path="J:/tmp")
  76. # adjusting color space from RGBH to RGB48 for vsCAS
  77. clip = core.resize.Bicubic(clip=clip, format=vs.RGB48, range_s="limited")
  78. # contrast sharpening using CAS
  79. clip = core.cas.CAS(clip=clip, sharpness=0.800)
  80. # adjusting color space from RGB48 to YUV444P16 for vsMClean
  81. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  82. # denoising using mClean
  83. clip = mclean.mClean(clip=clip, thSAD=600, rn=0)
  84. ## Starting applying 'limit' masked filtering for vsDGDenoise
  85. clipMask = clip
  86. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, range_s="limited")
  87. clipMask = core.std.BinarizeMask(clipMask, 7680)
  88. clipMask = core.std.InvertMask(clipMask)
  89. clipFiltered = clip
  90. # denoising using DGDenoise
  91. clipFiltered = core.dgdenoise.DGDenoise(clip=clipFiltered)
  92. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask)# LimitMask
  93. ## Finished applying 'LimitMask' masked filtering for vsDGDenoise
  94. # Resizing using 10 - bicubic spline
  95. clip = core.fmtc.resample(clip=clip, kernel="spline16", w=1280, h=960, interlaced=False, interlacedd=False)# resolution 1280x960 before YUV444P16 after YUV444P16
  96. ## Starting applying 'limit' masked filtering for vsBasicVSRPPFilter
  97. clipMask = clip
  98. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  99. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, matrix_s="470bg", range_s="limited")
  100. clipMask = core.std.BinarizeMask(clipMask, 30720)
  101. clipFiltered = clip
  102. # adjusting color space from YUV444P16 to RGBH for vsBasicVSRPPFilter
  103. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  104. # Quality enhancement using BasicVSR++
  105. from vsbasicvsrpp import basicvsrpp as BasicVSRPP
  106. clipFiltered = BasicVSRPP(clip=clipFiltered, model=4, tile_w=640, tile_h=480)
  107. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS, range_s="limited")
  108. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_s="limited")
  109. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_s="limited")
  110. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask)# LimitMask
  111. ## Finished applying 'LimitMask' masked filtering for vsBasicVSRPPFilter
  112. # adjusting color space from RGBS to YUV444P16 for vsGLSLFilmGrain
  113. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
  114. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/filmgrain.glsl") as glslf:
  115. glsl = glslf.read()
  116. glsl = glsl.replace('#define INTENSITY 0.05', '#define INTENSITY 0.03')
  117. clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
  118. # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
  119. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", dither_type="error_diffusion")
  120. # set output frame rate to 23.976fps (progressive)
  121. clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
  122. # output
  123. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment