Guest User

Untitled

a guest
Apr 27th, 2026
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. # Imports
  2. import logging
  3. import site
  4. import ctypes
  5. import sys
  6. import os
  7. import vapoursynth as vs
  8. # getting Vapoursynth core
  9. core = vs.core
  10. # Limit frame cache to 48449MB
  11. core.max_cache_size = 48449
  12. # Import scripts folder
  13. scriptPath = 'F:/Hybrid/64bit/vsscripts'
  14. sys.path.insert(0, os.path.abspath(scriptPath))
  15. # Loading Support Files
  16. Dllref = ctypes.windll.LoadLibrary("F:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
  17. os.environ["CUDA_MODULE_LOADING"] = "LAZY"
  18. # Force logging to std:err
  19. logging.StreamHandler(sys.stderr)
  20. # loading plugins
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/libvs_placebo.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vstrt_rtx.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vstrt.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vsort.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/TIVTC/libtivtc.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/znedi3.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/mvtools.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/fmtconv.dll")
  32. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  33. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/eedi3m.dll")
  34. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/akarin/libakarin.dll")
  35. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/zsmooth/zsmooth.dll")
  36. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV_AVX2.dll")
  37. # Import scripts
  38. from importlib.machinery import SourceFileLoader
  39. vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
  40. from vsmlrt import Backend
  41. import qtgmc
  42. import validate
  43. # Source: 'C:\Users\Selur\Desktop\A1_t00.mkv'
  44. # Current color space: YUV420P8, bit depth: 8, resolution: 720x480, frame rate: 29.97fps, scanorder: telecine, yuv luminance scale: limited, matrix: 470bg, format: mpeg-2
  45. # Loading 'C:\Users\Selur\Desktop\A1_t00.mkv' using DGSource
  46. clip = core.dgdecodenv.DGSource("J:/tmp/mkv_4b00747d725da0f5f7d7cfd0d25e8c45_853323747.dgi",fieldop=0) # 29.97 fps, scanorder: telecine
  47. frame = clip.get_frame(0)
  48. # setting color matrix to 470bg.
  49. clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT470_BG)
  50. # setting color transfer (vs.TRANSFER_BT601), if it is not set.
  51. if validate.transferIsInvalid(clip):
  52. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT601)
  53. # setting color primaries info (to vs.PRIMARIES_BT470_BG), if it is not set.
  54. if validate.primariesIsInvalid(clip):
  55. clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT470_BG)
  56. # setting color range to TV (limited) range.
  57. prop_name = '_Range' if core.core_version.release_major >= 74 else '_ColorRange'
  58. clip = core.std.SetFrameProps(clip=clip, **{prop_name: vs.RANGE_LIMITED})
  59. # making sure frame rate is set to 29.97fps
  60. clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
  61. # making sure the detected scan type is set (detected: telecine)
  62. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # scan type: top field first
  63. clip2clip = clip
  64. clip2clip = qtgmc.QTGMC(Input=clip2clip, Preset="fast", TFF=False, FPSDivisor=2)
  65. # Deinterlacing using TIVTC
  66. clip = core.tivtc.TFM(clip, clip2=clip2clip)
  67. clip = core.tivtc.TDecimate(clip) # new fps: 23.976
  68. # Making sure content is preceived as frame based
  69. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # scan type: progressive
  70. clip = core.std.Crop(clip, left=2, right=12, top=0, bottom=0) # cropping to 706x480
  71. clip = core.std.AddBorders(clip=clip, left=2, right=4, top=0, bottom=0) # add borders to archive mod 8 (vsDPIRmlrtDenoise) - 712x480
  72. # changing range from limited to full range for vsDPIRmlrtDenoise
  73. clip = core.resize.Bicubic(clip, format=vs.YUV420P8, range_in_s="limited", range_s="full")
  74. # setting color range to PC (full) range.
  75. prop_name = '_Range' if core.core_version.release_major >= 74 else '_ColorRange'
  76. clip = core.std.SetFrameProps(clip=clip, **{prop_name: vs.RANGE_FULL})
  77. # adjusting color space from YUV420P8 to RGBS for vsDPIRmlrtDenoise
  78. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_in_s="full", range_s="full")
  79. # denoising using DPIR (mlrt)
  80. clip = vsmlrt.DPIR(clip, strength=12.000, overlap=16, model=1, backend=Backend.TRT_RTX(fp16=True,device_id=0,verbose=True,use_cuda_graph=True,num_streams=1,builder_optimization_level=3,engine_folder="J:/TRT"))
  81. clip = core.std.Crop(clip=clip, left=2, right=4, top=0, bottom=0) # removing added borders from mod requirement (vsDPIRmlrtDenoise) - 706x480
  82. # adjusting color space from RGBS to YUV444P16 for vsGLSLLumaSharpen
  83. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_in_s="full", range_s="full", dither_type="error_diffusion") # additional resize to match target color sampling
  84. # Sharpening using GLSL LumaSharpen
  85. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/LumaSharpenHook.glsl") as glslf:
  86. glsl = glslf.read()
  87. glsl = glsl.replace('#define sharp_strength 0.30', '#define sharp_strength 1.5000')
  88. glsl = glsl.replace('#define sharp_clamp 0.035', '#define sharp_clamp 0.0350')
  89. glsl = glsl.replace('#define pattern 2', '#define pattern 4')
  90. glsl = glsl.replace('#define offset_bias 1.0', '#define offset_bias 1.0000')
  91. clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height)
  92. # Resizing using 10 - bicubic spline
  93. clip = core.fmtc.resample(clip, kernel="spline16", w=960, h=734, interlaced=False, interlacedd=False) # resolution 960x734 before YUV444P16 after YUV444P16
  94. ## Starting applying 'EdgeMask (Prewitt)' masked filtering for vsBasicVSRPPFilter
  95. # Creating mask for clip
  96. clipMask = clip
  97. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, range_in_s="full")
  98. clipMask = core.std.Prewitt(clip=clipMask)
  99. clipMask = core.std.Maximum(clipMask)
  100. clipMask = core.std.ShufflePlanes(clips=[clipMask], planes=[0], colorfamily=vs.GRAY)
  101. clipMask = core.std.BinarizeMask(clip=clipMask,threshold=13121.3)
  102. clipFiltered = clip
  103. clipFiltered = core.std.AddBorders(clip=clipFiltered, left=0, right=0, top=0, bottom=2) # add borders to archive mod 8 (vsBasicVSRPPFilter) - 960x736
  104. # adjusting color space from YUV444P16 to RGBH for vsBasicVSRPPFilter
  105. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="470bg", range_in_s="full", range_s="full")
  106. # Quality enhancement using BasicVSR++
  107. from vsbasicvsrpp import basicvsrpp as BasicVSRPP
  108. clipFiltered = BasicVSRPP(clipFiltered, model=4)
  109. clipFiltered = core.std.Crop(clip=clipFiltered, left=0, right=0, top=0, bottom=2) # removing added borders from mod requirement (vsBasicVSRPPFilter) - 960x734
  110. # adjusting clipFiltered color before mask merge
  111. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS)
  112. # adjusting clip color before mask merge
  113. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_in_s="full", range_s="full")
  114. # adjusting mask before mask merge
  115. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_in_s="full")
  116. # Resolution: clip: 960x734 and clipFiltered: 960x734 and clipMask: 960x734
  117. # Merging: clip and clipFiltered based on clipMask
  118. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # PrewittEdgeMask
  119. ## Finished applying 'PrewittEdgeMask' masked filtering for vsBasicVSRPPFilter
  120. # adjusting output color from RGBS to YUV420P10 for NVEncModel
  121. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_in_s="full", range_s="full", dither_type="error_diffusion") # additional resize to match target color sampling
  122. # changing range from full to limited range for to match intended output luma scale
  123. clip = core.resize.Bicubic(clip, format=vs.YUV420P10,range_in_s="full", range_s="limited")
  124. # setting color range to TV (limited) range.
  125. prop_name = '_Range' if core.core_version.release_major >= 74 else '_ColorRange'
  126. clip = core.std.SetFrameProps(clip=clip, **{prop_name: vs.RANGE_LIMITED})
  127. # set output frame rate to 23.976fps (progressive)
  128. clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
  129. # output
  130. clip.set_output()
  131. # script was created by Hybrid 2026.04.26.1
Advertisement
Add Comment
Please, Sign In to add comment