Guest User

Vapoursynth cleanup

a guest
Jul 19th, 2026
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. # Imports
  2. import ctypes
  3. import sys
  4. import os
  5. import vapoursynth as vs
  6. # using Vapoursynth R77
  7. # getting Vapoursynth core
  8. core = vs.core
  9. # Limit frame cache to 48449MB
  10. core.max_cache_size = 48449
  11. # Import scripts folder
  12. scriptPath = 'F:/Hybrid/64bit/vsscripts'
  13. sys.path.insert(0, os.path.abspath(scriptPath))
  14. # Loading Support Files
  15. Dllref = ctypes.windll.LoadLibrary("F:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
  16. # loading plugins
  17. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/libvs_placebo.dll")
  18. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
  19. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ColorFilter/Retinex/Retinex.dll")
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/dfttest2/dfttest2_nvrtc.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/bwdif.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/fmtconv.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/nnedi3vk/nnedi3vk.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/eedi3vk2.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/vsnlm_cuda.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/addnoise.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/mvtools.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/akarin/libakarin.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/zsmooth/zsmooth.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV_AVX2.dll")
  32. # Import scripts
  33. import masked
  34. import dfttest2
  35. import qtgmc
  36. import validate
  37. # Source: 'C:\Users\Selur\Desktop\B1_t01_2.mkv'
  38. # clip current meta; color space: YUV420P8, bit depth: 8, resolution: 720x576, fps: 25, color matrix: 470bg, color primaries: Unspecific, color transfer: Unspecified, yuv luminance scale: limited, scanorder: top field first, full height: true (Source)
  39. # Loading 'C:\Users\Selur\Desktop\B1_t01_2.mkv' using DGSource
  40. clip = core.dgdecodenv.DGSource("J:/tmp/mkv_749ae5828c3267f057cf88493525e601_853323747.dgi",fieldop=0) # 25 fps, scanorder: top field first
  41. frame = clip.get_frame(0)
  42. # setting color matrix to 470bg.
  43. clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT470_BG)
  44. # setting color transfer (vs.TRANSFER_BT601), if it is not set.
  45. if validate.transferIsInvalid(clip):
  46. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT601)
  47. # setting color primaries info (to vs.PRIMARIES_BT470_BG), if it is not set.
  48. if validate.primariesIsInvalid(clip):
  49. clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT470_BG)
  50. # setting color range to TV (limited) range.
  51. prop_name = '_Range' if core.core_version.release_major >= 74 else '_ColorRange'
  52. clip = core.std.SetFrameProps(clip=clip, **{prop_name: vs.RANGE_LIMITED})
  53. # making sure frame rate is set to 25fps
  54. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  55. # making sure the detected scan type is set (detected: top field first)
  56. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # scan type: top field first
  57. # Deinterlacing using QTGMC
  58. clip = qtgmc.QTGMC(Input=clip, Preset="Slower", InputType=0, TFF=True, TR2=1, SourceMatch=0, Lossless=0, EZDenoise=5.00, NoisePreset="Fast", opencl=True, Denoiser="KNLMeansCL") # new fps: 50
  59. # Making sure content is preceived as frame based
  60. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # scan type: progressive
  61. clip = core.std.Crop(clip, left=10, right=8, top=0, bottom=2) # cropping to 702x574
  62. clipMask = clip
  63. ## Starting applying 'EdgeMask (Retinex)' masked filtering for vsBasicVSRPPFilter
  64. # Creating mask for clip
  65. clipMask = masked.retinex_edgemask(src=clipMask, sigma=1)
  66. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, range_in_s="limited")
  67. clipMask = core.std.Maximum(clipMask)
  68. clipFiltered = clip
  69. clipFiltered = core.std.AddBorders(clip=clipFiltered, left=0, right=2, top=0, bottom=2) # add borders to archive mod 8 (vsBasicVSRPPFilter) - 704x576
  70. # adjusting color space from YUV420P8 to RGBH for vsBasicVSRPPFilter
  71. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="470bg", range_in_s="limited", range_s="full")
  72. # Quality enhancement using BasicVSR++
  73. from vsbasicvsrpp import basicvsrpp as BasicVSRPP
  74. clipFiltered = BasicVSRPP(clipFiltered, model=4)
  75. clipFiltered = core.std.Crop(clip=clipFiltered, left=0, right=2, top=0, bottom=2) # removing added borders from mod requirement (vsBasicVSRPPFilter) - 702x574
  76. # adjusting clipFiltered color before mask merge
  77. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS)
  78. # adjusting clip color before mask merge
  79. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_in_s="limited", range_s="full")
  80. # adjusting mask before mask merge
  81. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_in_s="limited")
  82. # Resolution: clip: 702x574 and clipFiltered: 702x574 and clipMask: 702x574
  83. # Color: clip: RGBS and clipFiltered: RGBS and clipMask: GRAYS
  84. # Merging: clip and clipFiltered based on clipMask
  85. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # RetinexEdgeMask
  86. ## Finished applying 'RetinexEdgeMask' masked filtering for vsBasicVSRPPFilter
  87. # adjusting color space from RGBS to YUV444P16 for vsGLSLAdaptiveSharpen
  88. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_in_s="full", range_s="limited", dither_type="error_diffusion")
  89. # sharpening using GLSL Adaptive Sharpening
  90. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/adaptive-sharpen.glsl") as glslf:
  91. glsl = glslf.read()
  92. glsl = glsl.replace('#define curve_height 1.0', '#define curve_height 1.0000')
  93. glsl = glsl.replace('#define anime_mode false', '#define anime_mode true')
  94. glsl = glsl.replace('#define overshoot_ctrl false', '#define overshoot_ctrl true')
  95. glsl = glsl.replace('#define video_level_out false', '#define video_level_out true')
  96. clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height)
  97. # Using Anime4k Darken GLSL filter for line darkening
  98. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/Anime4K_Darken_HQ.glsl") as glslf:
  99. glsl = glslf.read()
  100. glsl = glsl.replace('#define STRENGTH 1.5', '#define STRENGTH 1.5')
  101. clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height)
  102. # Resizing using 10 - bicubic spline
  103. clip = core.fmtc.resample(clip, kernel="spline16", w=1280, h=960, interlaced=False, interlacedd=False) # resolution 1280x960 before YUV444P16 after YUV444P16
  104. # adjusting output color from YUV444P16 to YUV420P10 for NVEncModel
  105. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, dither_type="error_diffusion")
  106. # set output frame rate to 50fps (progressive)
  107. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  108. # output
  109. clip.set_output()
  110. # clip current meta; color space: YUV420P10, bit depth: 10, resolution: 1280x960, fps: 50, color matrix: 470bg, color primaries: Unspecific, color transfer: Unspecified, yuv luminance scale: limited, scanorder: progressive, full height: true (Meta)
  111. # script was created by Hybrid 2026.07.19.1
Advertisement
Add Comment
Please, Sign In to add comment