Guest User

Untitled

a guest
Oct 24th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 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/vs-mlrt/vstrt.dll")
  17. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/ZSmooth/zsmooth.dll")
  18. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
  19. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")# vsQTGMC
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV.dll")
  32. # Import scripts
  33. import edi_rpow2
  34. from importlib.machinery import SourceFileLoader
  35. vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
  36. import G41Fun
  37. import SpotLess
  38. import havsfunc
  39. import validate
  40. # Source: 'C:\Users\Selur\Desktop\Kaskito part.mpg'
  41. # Current color space: YUV420P8, bit depth: 8, resolution: 720x576, frame rate: 25fps, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg, transfer: bt.470 system b/g, primaries: bt.601 pal, format: mpeg-2
  42. # Loading C:\Users\Selur\Desktop\Kaskito part.mpg using DGSource
  43. clip = core.dgdecodenv.DGSource("J:/tmp/mpg_a0561860d3e94768ed280117ab3e6f3b_853323747.dgi",fieldop=0)# 25 fps, scanorder: top field first
  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_BT470_BG), if it is not set.
  48. if validate.transferIsInvalid(clip):
  49. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT470_BG)
  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. # sharpening using AWarpSharp2
  64. clip = core.warp.AWarpSharp2(clip=clip, blur=2, depth=48, chroma=True, planes=[1,2])
  65. # changing range from limited to full range for VsVSGANFilter
  66. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  67. # setting color range to PC (full) range.
  68. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_FULL)
  69. # adjusting color space from YUV420P8 to RGBH for VsVSGANFilter
  70. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="full")
  71. # filtering using VSGANFilter
  72. from vsgan import ESRGAN
  73. vsgan = ESRGAN(clip=clip,device="cuda")
  74. model = "C:/Users/Selur/Desktop/testing/1x_OverExposureCorrection_compact.pth"
  75. vsgan.load(model)
  76. vsgan.apply() # 720x576
  77. clip = vsgan.clip
  78. # changing range from full to limited range for VsVSGANFilter
  79. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  80. # adjusting color space from RGBH to YUV444P16 for vsGLSLSaturation
  81. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  82. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/bSat.hook.glsl") as glslf:
  83. glsl = glslf.read()
  84. glsl = glsl.replace('#define SatFactor 2.43', '#define SatFactor 0.75')
  85. clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
  86. # Spot removal using SpotLess
  87. clip = SpotLess.SpotLess(clip=clip, radT=3, pel=1, smoother="zsmooth")
  88. clip = core.std.Crop(clip=clip, left=4, right=14, top=0, bottom=4)# cropping to 702x572
  89. # sharpening using FineSharp
  90. clip = G41Fun.FineSharp(clip=clip, mode=3)
  91. from vsmlrt import Backend
  92. clip = core.std.AddBorders(clip=clip, left=0, right=2, top=2, bottom=2) # add borders to archive mod 8 (vsSCUNetmlrt) - 704x576
  93. # changing range from limited to full range for vsSCUNetmlrt
  94. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  95. # setting color range to PC (full) range.
  96. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_FULL)
  97. # adjusting color space from YUV444P16 to RGBH for vsSCUNetmlrt
  98. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="full")
  99. # denosing using SCUNet (mlrt)
  100. 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"))
  101. clip = core.std.Crop(clip=clip, left=0, right=2, top=2, bottom=2) # removing borders (vsSCUNetmlrt) - 702x572
  102. # changing range from full to limited range for vsSCUNetmlrt
  103. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  104. clip = core.std.AddBorders(clip=clip, left=0, right=2, top=0, bottom=0) # add borders to archive mod 4 (NNEDI3(CL)) - 704x572
  105. # adjusting color space from RGBH to RGB48 for NNEDI3(CL)
  106. clip = core.resize.Bicubic(clip=clip, format=vs.RGB48, range_s="limited")
  107. # resizing using NNEDI3CL
  108. # current: 704x572 target: 1920x1468 -> pow: 4
  109. clip = edi_rpow2.nnedi3cl_rpow2(clip=clip, rfactor=4, nsize=1, nns=4) # 2816x2288
  110. clip = core.std.Crop(clip=clip, left=0, right=8, top=0, bottom=0) # removing borders (NNEDI3(CL)) - 2808x2288
  111. # adjusting resizing
  112. clip = core.fmtc.resample(clip=clip, w=1920, h=1468, kernel="spline64", interlaced=False, interlacedd=False)# before RGB48 after RGB48
  113. # adjusting output color from: RGB48 to YUV420P10 for NVEncModel
  114. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
  115. # set output frame rate to 50fps (progressive)
  116. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  117. # output
  118. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment