Advertisement
Guest User

Untitled

a guest
Jul 20th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. # Imports
  2. import vapoursynth as vs
  3. # getting Vapoursynth core
  4. import site
  5. import ctypes
  6. import sys
  7. import os
  8. core = vs.core
  9. # Import scripts folder
  10. scriptPath = 'F:/Hybrid/64bit/vsscripts'
  11. sys.path.insert(0, os.path.abspath(scriptPath))
  12. # Loading Support Files
  13. Dllref = ctypes.windll.LoadLibrary("F:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
  14. os.environ["CUDA_MODULE_LOADING"] = "LAZY"
  15. # loading plugins
  16. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
  17. core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vstrt.dll")
  18. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  19. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")# vsQTGMC
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
  30. # Import scripts
  31. from importlib.machinery import SourceFileLoader
  32. vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
  33. import adjust
  34. import chromashift
  35. import havsfunc
  36. import validate
  37. # Source: 'C:\Users\Selur\Desktop\halo.avi'
  38. # Current color space: YUV420P8, bit depth: 8, resolution: 720x576, frame rate: 25fps, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
  39. # Loading C:\Users\Selur\Desktop\halo.avi using LWLibavSource
  40. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/halo.avi", format="YUV420P8", stream_index=0, cache=0, prefer_hw=0)
  41. frame = clip.get_frame(0)
  42. # Setting detected color matrix (470bg).
  43. clip = core.std.SetFrameProps(clip=clip, _Matrix=5)
  44. # setting color transfer (170), if it is not set.
  45. if validate.transferIsInvalid(clip):
  46. clip = core.std.SetFrameProps(clip=clip, _Transfer=6)
  47. # setting color primaries info (to 470), if it is not set.
  48. if validate.primariesIsInvalid(clip):
  49. clip = core.std.SetFrameProps(clip=clip, _Primaries=5)
  50. # setting color range to TV (limited) range.
  51. clip = core.std.SetFrameProps(clip=clip, _ColorRange=1)
  52. # making sure frame rate is set to 25fps
  53. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  54. # making sure the detected scan type is set (detected: top field first)
  55. clip = core.std.SetFrameProps(clip=clip, _FieldBased=2) # tff
  56. # Deinterlacing using QTGMC
  57. clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True, opencl=True) # new fps: 50
  58. # Making sure content is preceived as frame based
  59. clip = core.std.SetFrameProps(clip=clip, _FieldBased=0) # progressive
  60. # Chroma adjustment using ChromaShiftSP
  61. clip = chromashift.ChromaShiftSP(clip=clip, X=2.50, Y=2.50)
  62. # changing range from limited to full range for VsVSGANFilter
  63. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  64. # setting color range to PC (full) range.
  65. clip = core.std.SetFrameProps(clip=clip, _ColorRange=0)
  66. # adjusting color space from YUV420P8 to RGBH for VsVSGANFilter
  67. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="full")
  68. # filtering using VSGANFilter
  69. from vsgan import ESRGAN
  70. vsgan = ESRGAN(clip=clip,device="cuda")
  71. model = "C:/Users/Selur/Desktop/testing/1x_DeHalo_v1_Compact.pth"
  72. vsgan.load(model)
  73. vsgan.apply() # 720x576
  74. clip = vsgan.clip
  75. # changing range from full to limited range for VsVSGANFilter
  76. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  77. # adjusting color space from RGBH to YUV444P16 for vsTweak
  78. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  79. # adjusting color using Tweak
  80. clip = adjust.Tweak(clip=clip, hue=0.00, sat=0.50, cont=1.00, coring=True)
  81. clip = core.std.CropRel(clip=clip, left=4, right=22, top=2, bottom=14)# cropping to 694x560
  82. # Fix bright and dark line artifacts near the border of an image using BalanceBorders
  83. clip = havsfunc.bbmod(c=clip,cLeft=0,cTop=0,cRight=8,cBottom=0)
  84. from vsmlrt import Backend
  85. clip = core.std.AddBorders(clip=clip, left=0, right=2, top=0, bottom=0) # add borders to archive mod 8 (vsSCUNetmlrt) - 696x560
  86. # adjusting color space from YUV444P16 to RGBH for vsSCUNetmlrt
  87. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  88. # denosing using SCUNet (mlrt)
  89. clip = vsmlrt.SCUNet(clip, model=4, overlap=16, backend=Backend.TRT(fp16=True,device_id=0,verbose=True,use_cuda_graph=False, num_streams=3,builder_optimization_level=3,engine_folder="J:/tmp"))
  90. clip = core.std.CropRel(clip=clip, left=0, right=2, top=0, bottom=0) # removing borders (vsSCUNetmlrt) - 694x560
  91. # adjusting color space from RGBH to YUV444P16 for vsGLSLLumaSharpen
  92. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  93. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/LumaSharpenHook.glsl") as glslf:
  94. glsl = glslf.read()
  95. glsl = glsl.replace('#define sharp_strength 0.30', '#define sharp_strength 0.8000')
  96. glsl = glsl.replace('#define sharp_clamp 0.035', '#define sharp_clamp 0.0350')
  97. glsl = glsl.replace('#define pattern 2', '#define pattern 4')
  98. glsl = glsl.replace('#define offset_bias 1.0', '#define offset_bias 1.0000')
  99. clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
  100. # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
  101. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", dither_type="error_diffusion")
  102. # set output frame rate to 50fps (progressive)
  103. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  104. # output
  105. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement