Guest User

Untitled

a guest
Aug 15th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.79 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/Support/libvs_placebo.dll")
  17. core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vstrt.dll")
  18. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/ZSmooth/zsmooth.dll")
  19. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/TIVTC/libtivtc.dll")
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")# DeinterlaceFilter-Selector
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.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/SourceFilter/LSmashSource/LSMASHSource.dll")
  31. # Import scripts
  32. import edi_rpow2
  33. from importlib.machinery import SourceFileLoader
  34. vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
  35. import SpotLess
  36. import havsfunc
  37. import validate
  38. # Source: 'C:\Users\Selur\Desktop\2024-08-14_180028_478.avi'
  39. # Current color space: YUV422P8, bit depth: 8, resolution: 720x480, frame rate: 29.97fps, scanorder: telecine, yuv luminance scale: limited, matrix: 470bg
  40. # Loading C:\Users\Selur\Desktop\2024-08-14_180028_478.avi using LWLibavSource
  41. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/2024-08-14_180028_478.avi", format="YUV422P8", stream_index=0, cache=0, prefer_hw=0)
  42. frame = clip.get_frame(0)
  43. # setting color matrix to 470bg.
  44. clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT470_BG)
  45. # setting color transfer (vs.TRANSFER_BT601), if it is not set.
  46. if validate.transferIsInvalid(clip):
  47. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT601)
  48. # setting color primaries info (to vs.PRIMARIES_BT470_BG), if it is not set.
  49. if validate.primariesIsInvalid(clip):
  50. clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT470_BG)
  51. # setting color range to TV (limited) range.
  52. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_LIMITED)
  53. # making sure frame rate is set to 29.97fps
  54. clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
  55. # making sure the detected scan type is set (detected: telecine)
  56. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # tff
  57. clip2clip = clip
  58. clip2clip = havsfunc.QTGMC(Input=clip2clip, Preset="fast", opencl=True, TFF=False, FPSDivisor=2)
  59. # Deinterlacing using TIVTC
  60. clip = core.tivtc.TFM(clip=clip, mChroma=False, clip2=clip2clip)
  61. clip = core.tivtc.TDecimate(clip=clip)# new fps: 23.976
  62. # Making sure content is preceived as frame based
  63. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # progressive
  64. # changing color matrix from '470bg' to '709' for vsDeOldify
  65. clip = core.resize.Bicubic(clip, matrix_in_s="470bg", matrix_s="709")
  66. # changing range from limited to full range for vsDeOldify
  67. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  68. # setting color range to PC (full) range.
  69. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_FULL)
  70. # adjusting color space from YUV422P8 to RGB24 for vsDeOldify
  71. clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="709", range_s="full")
  72. # adding colors using DeOldify
  73. from vsdeoldify import HAVC_ddeoldify
  74. clip = HAVC_ddeoldify(clip=clip, deoldify_p=[0, 28, 1, 0], ddcolor_p=[1, 32, 1, 0, True], ddtweak=True, ddtweak_p=[0.0, 1.0, 2.5, True, 0.3, 0.6, 0.7, 0.5, "300:360|0.8,0.1"])
  75. from vsdeoldify import HAVC_stabilizer
  76. clip = HAVC_stabilizer(clip=clip, dark=True, smooth=True, stab=True, stab_p=[3, 'A', 1, 0, 0, 0], colormap="none", render_factor=32)
  77. # internally changing color matrix for YUV<>RGB to '470bg' undoing color matrix change for vsDeOldify
  78. # changing range from full to limited range for vsDeOldify
  79. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  80. # adjusting color space from RGB24 to YUV444P16 for vsSpotLess
  81. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  82. # Spot removal using SpotLess
  83. clip = SpotLess.SpotLess(clip=clip, radT=3, rec=True, pel=1, smoother="zsmooth")
  84. from vsmlrt import Backend
  85. # adjusting color space from YUV444P16 to RGBH for vsDPIRmlrtDenoise
  86. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  87. # denosing using DPIR (mlrt)
  88. clip = vsmlrt.DPIR(clip, strength=5.000, overlap=16, model=1, 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"))
  89. # adjusting color space from RGBH to YUV444P16 for vsGLSLCAS
  90. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  91. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/CAS.glsl") as glslf:
  92. glsl = glslf.read()
  93. glsl = glsl.replace('#define SHARPENING 0.0', '#define SHARPENING 0.6')
  94. glsl = glsl.replace('#define CAS_BETTER_DIAGONALS 1', '#define CAS_BETTER_DIAGONALS 1')
  95. glsl = glsl.replace('#define CAS_GO_SLOWER 0', '#define CAS_GO_SLOWER 1')
  96. glsl = glsl.replace('#define SOURCE_TRC 0', '#define SOURCE_TRC 0')
  97. glsl = glsl.replace('#define TARGET_TRC 0', '#define TARGET_TRC 0')
  98. clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
  99. # resizing using NNEDI3CL
  100. # current: 720x480 target: 1920x1280 -> pow: 4
  101. clip = edi_rpow2.nnedi3cl_rpow2(clip=clip, rfactor=4, nns=4) # 2880x1920
  102. # adjusting resizing
  103. clip = core.fmtc.resample(clip=clip, w=1920, h=1280, kernel="spline64", interlaced=False, interlacedd=False)# before YUV444P16 after YUV444P16
  104. # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
  105. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", dither_type="error_diffusion")
  106. # set output frame rate to 23.976fps (progressive)
  107. clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
  108. # output
  109. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment