Guest User

Untitled

a guest
Jul 5th, 2026
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 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.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ColorFilter/Retinex/Retinex.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/bwdif.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/fmtconv.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/sneedif/libsneedif.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libeedi3vk.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/addnoise.dll")
  32. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/mvtools.dll")
  33. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/akarin/libakarin.dll")
  34. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/zsmooth/zsmooth.dll")
  35. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV_AVX2.dll")
  36. # Import scripts
  37. import linedarken
  38. from importlib.machinery import SourceFileLoader
  39. vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
  40. import masked
  41. import qtgmc
  42. import validate
  43. # Source: 'C:\Users\Selur\Desktop\sample.ts'
  44. # clip current meta; color space: YUV420P8, bit depth: 8, resolution: 1440x1080, fps: 29.97, color matrix: 709, color primaries: Unspecific, color transfer: BT.709, yuv luminance scale: limited, scanorder: top field first, full height: true (Source)
  45. # Loading 'C:\Users\Selur\Desktop\sample.ts' using DGSource
  46. clip = core.dgdecodenv.DGSource("J:/tmp/ts_3591dab47f54c59fc132a441faa50717_853323747.dgi",fieldop=0) # 29.97 fps, scanorder: top field first
  47. frame = clip.get_frame(0)
  48. # setting color matrix to 709.
  49. clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT709)
  50. # setting color transfer (vs.TRANSFER_BT709), if it is not set.
  51. if validate.transferIsInvalid(clip):
  52. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT709)
  53. # setting color primaries info (to vs.PRIMARIES_BT709), if it is not set.
  54. if validate.primariesIsInvalid(clip):
  55. clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT709)
  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: top field first)
  62. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # scan type: top field first
  63. # Deinterlacing using QTGMC
  64. clip = qtgmc.QTGMC(clip, Preset="Fast", TFF=True, opencl=True) # new fps: 59.94
  65. # Making sure content is preceived as frame based
  66. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # scan type: progressive
  67. clipMask = clip
  68. ## Starting applying 'EdgeMask (Retinex)' masked filtering for vsDPIRmlrtDenoise
  69. # Creating mask for clip
  70. clipMask = masked.retinex_edgemask(src=clipMask, sigma=1)
  71. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, range_in_s="limited")
  72. for i in range(2):
  73. clipMask = core.std.Maximum(clipMask)
  74. clipMask = core.std.BinarizeMask(clip=clipMask,threshold=54144)
  75. clipFiltered = clip
  76. # changing range from limited to full range for vsDPIRmlrtDenoise
  77. clipFiltered = core.resize.Bicubic(clipFiltered, format=vs.YUV420P8, range_in_s="limited", range_s="full")
  78. # setting color range to PC (full) range.
  79. prop_name = '_Range' if core.core_version.release_major >= 74 else '_ColorRange'
  80. clipFiltered = core.std.SetFrameProps(clip=clipFiltered, **{prop_name: vs.RANGE_FULL})
  81. # adjusting color space from YUV420P8 to RGBH for vsDPIRmlrtDenoise
  82. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="709", range_in_s="full", range_s="full")
  83. # denoising using DPIR (mlrt)
  84. from vsmlrt import Backend
  85. clipFiltered = vsmlrt.DPIR(clipFiltered, strength=55.000, model=1, overlap=16, backend=Backend.TRT(fp16=True,device_id=0,bf16=False,use_cuda_graph=False,num_streams=3,verbose=True,builder_optimization_level=3,engine_folder="J:/TRT",output_format=1))
  86. # adjusting clipFiltered color before mask merge
  87. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS)
  88. # adjusting clip color before mask merge
  89. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="709", range_in_s="limited", range_s="full")
  90. # adjusting mask before mask merge
  91. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_in_s="limited")
  92. # Resolution: clip: 1440x1080 and clipFiltered: 1440x1080 and clipMask: 1440x1080
  93. # Merging: clip and clipFiltered based on clipMask
  94. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # RetinexEdgeMask
  95. ## Finished applying 'RetinexEdgeMask' masked filtering for vsDPIRmlrtDenoise
  96. # adjusting color space from RGBS to YUV444P16 for vsGLSLAdaptiveSharpen
  97. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="709", range_in_s="full", range_s="full", dither_type="error_diffusion")
  98. # sharpening using GLSL Adaptive Sharpening
  99. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/adaptive-sharpen.glsl") as glslf:
  100. glsl = glslf.read()
  101. glsl = glsl.replace('#define curve_height 1.0', '#define curve_height 1.0000')
  102. glsl = glsl.replace('#define anime_mode false', '#define anime_mode true')
  103. glsl = glsl.replace('#define overshoot_ctrl false', '#define overshoot_ctrl true')
  104. glsl = glsl.replace('#define video_level_out false', '#define video_level_out true')
  105. clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height)
  106. # Using FastLineDarkenMOD for line darkening
  107. clip = linedarken.FastLineDarkenMOD(clip)
  108. # adjusting output color from YUV444P16 to YUV420P10 for NVEncModel
  109. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, dither_type="error_diffusion")
  110. # set output frame rate to 59.94fps (progressive)
  111. clip = core.std.AssumeFPS(clip=clip, fpsnum=60000, fpsden=1001)
  112. # output
  113. clip.set_output()
  114. # clip current meta; color space: YUV420P10, bit depth: 10, resolution: 1440x1080, fps: 59.94, color matrix: 709, color primaries: Unspecific, color transfer: BT.709, yuv luminance scale: full, scanorder: progressive, full height: true (Meta)
  115. # script was created by Hybrid 2026.07.05.1
Advertisement
Add Comment
Please, Sign In to add comment