Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 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/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
  17. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/CTMF/CTMF.dll")
  18. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
  19. core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vstrt.dll")
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/FrameFilter/ReduceFlicker/ReduceFlicker.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")# vsQTGMC
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  32. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
  33. # Import scripts
  34. from importlib.machinery import SourceFileLoader
  35. vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
  36. import chromashift
  37. import adjust
  38. import havsfunc
  39. import validate
  40. # Source: 'C:\Users\Selur\Desktop\halo.avi'
  41. # Current color space: YUV420P8, bit depth: 8, resolution: 720x576, frame rate: 25fps, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
  42. # Loading C:\Users\Selur\Desktop\halo.avi using LWLibavSource
  43. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/halo.avi", format="YUV420P8", stream_index=0, cache=0, prefer_hw=0)
  44. frame = clip.get_frame(0)
  45. # setting color matrix to 470bg.
  46. clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT470_BG)
  47. # setting color transfer (vs.TRANSFER_BT601), if it is not set.
  48. if validate.transferIsInvalid(clip):
  49. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT601)
  50. # setting color primaries info (to vs.PRIMARIES_BT470_BG), if it is not set.
  51. if validate.primariesIsInvalid(clip):
  52. clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT470_BG)
  53. # setting color range to TV (limited) range.
  54. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_LIMITED)
  55. # making sure frame rate is set to 25fps
  56. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  57. # making sure the detected scan type is set (detected: top field first)
  58. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # tff
  59. # Deinterlacing using QTGMC
  60. clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True, opencl=True) # new fps: 50
  61. # Making sure content is preceived as frame based
  62. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # progressive
  63. # adjusting color using Tweak
  64. clip = adjust.Tweak(clip=clip, hue=0.00, sat=0.50, cont=1.00, coring=True)
  65. # Chroma adjustment using ChromaShiftSP
  66. clip = chromashift.ChromaShiftSP(clip=clip, X=3.00, Y=2.50)
  67. # changing range from limited to full range for VsVSGANFilter
  68. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  69. # setting color range to PC (full) range.
  70. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_FULL)
  71. # adjusting color space from YUV420P8 to RGBH for VsVSGANFilter
  72. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="full")
  73. # filtering using VSGANFilter
  74. from vsgan import ESRGAN
  75. vsgan = ESRGAN(clip=clip,device="cuda")
  76. model = "C:/Users/Selur/Desktop/testing/1x_DeHalo_v1_Compact.pth"
  77. vsgan.load(model)
  78. vsgan.apply() # 720x576
  79. clip = vsgan.clip
  80. # changing range from full to limited range for VsVSGANFilter
  81. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  82. # adjusting color space from RGBH to YUV444P16 for vsReduceFlicker
  83. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  84. # removing flickering using ReduceFlicker
  85. clip = core.rdfl.ReduceFlicker(clip=clip, strength=3, aggressive=1)
  86. clip = core.std.CropRel(clip=clip, left=4, right=22, top=2, bottom=14)# cropping to 694x560
  87. # Fix bright and dark line artifacts near the border of an image using BalanceBorders
  88. clip = havsfunc.bbmod(c=clip,cLeft=0,cTop=0,cRight=8,cBottom=0)
  89. from vsmlrt import Backend
  90. clip = core.std.AddBorders(clip=clip, left=0, right=2, top=0, bottom=0) # add borders to archive mod 8 (vsSCUNetmlrt) - 696x560
  91. # changing range from limited to full range for vsSCUNetmlrt
  92. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  93. # setting color range to PC (full) range.
  94. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_FULL)
  95. # adjusting color space from YUV444P16 to RGBH for vsSCUNetmlrt
  96. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="full")
  97. # denosing using SCUNet (mlrt)
  98. 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:/TRT"))
  99. clip = core.std.CropRel(clip=clip, left=0, right=2, top=0, bottom=0) # removing borders (vsSCUNetmlrt) - 694x560
  100. # changing range from full to limited range for vsSCUNetmlrt
  101. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  102. # adjusting color space from RGBH to YUV444P16 for vsGLSLLumaSharpen
  103. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  104. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/LumaSharpenHook.glsl") as glslf:
  105. glsl = glslf.read()
  106. glsl = glsl.replace('#define sharp_strength 0.30', '#define sharp_strength 0.8000')
  107. glsl = glsl.replace('#define sharp_clamp 0.035', '#define sharp_clamp 0.0350')
  108. glsl = glsl.replace('#define pattern 2', '#define pattern 4')
  109. glsl = glsl.replace('#define offset_bias 1.0', '#define offset_bias 1.0000')
  110. clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
  111. # applying dehalo using DeHalo_alpha
  112. clip = havsfunc.DeHalo_alpha(clip, ry=3.00, brightstr=1.50)
  113. # applying dehalo using YAHR
  114. clip = havsfunc.YAHR(clip, depth=16)
  115. clip = havsfunc.YAHR(clip, depth=16)
  116. # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
  117. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", dither_type="error_diffusion")
  118. # set output frame rate to 50fps (progressive)
  119. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  120. # output
  121. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement