Guest User

Untitled

a guest
Jan 8th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 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/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  19. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")# vsQTGMC
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
  29. # Import scripts
  30. from importlib.machinery import SourceFileLoader
  31. vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
  32. import SpotLess
  33. import chromashift
  34. import havsfunc
  35. import validate
  36. # Source: 'C:\Users\Selur\Desktop\intermediate.demuxed.m2v'
  37. # Current color space: YUV422P8, bit depth: 8, resolution: 720x608, frame rate: 25fps, scanorder: top field first, yuv luminance scale: limited, matrix: 709, format: mpeg-2
  38. # Loading C:\Users\Selur\Desktop\intermediate.demuxed.m2v using LWLibavSource
  39. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/intermediate.demuxed.m2v", format="YUV422P8", stream_index=0, cache=0, prefer_hw=0)
  40. frame = clip.get_frame(0)
  41. # setting color matrix to 709.
  42. clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT709)
  43. # setting color transfer (vs.TRANSFER_BT709), if it is not set.
  44. if validate.transferIsInvalid(clip):
  45. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT709)
  46. # setting color primaries info (to vs.PRIMARIES_BT709), if it is not set.
  47. if validate.primariesIsInvalid(clip):
  48. clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT709)
  49. # setting color range to TV (limited) range.
  50. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_LIMITED)
  51. # making sure frame rate is set to 25fps
  52. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  53. # making sure the detected scan type is set (detected: top field first)
  54. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # tff
  55. # Deinterlacing using QTGMC
  56. clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True, opencl=True) # new fps: 50
  57. # Making sure content is preceived as frame based
  58. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # progressive
  59. # Chroma adjustment using ChromaShiftSP
  60. clip = chromashift.ChromaShiftSP(clip=clip, X=2.00, Y=3.00)
  61. # Spot removal using SpotLess
  62. clip = SpotLess.SpotLess(clip=clip, radT=1, pel=1, smoother="zsmooth")
  63. from vsmlrt import Backend
  64. # adjusting color space from YUV422P8 to RGBH for vsDPIRmlrtDeblock
  65. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="709", range_s="limited")
  66. # adjusting deblocking using DPIR (mlrt)
  67. clip = vsmlrt.DPIR(clip, strength=50.000, overlap=16, model=3, 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"))
  68. clip = core.std.Crop(clip=clip, left=24, right=16, top=34, bottom=2)# cropping to 680x572
  69. clip = core.std.AddBorders(clip=clip, left=0, right=0, top=2, bottom=2) # add borders to archive mod 8 (vsDPIRmlrtDenoise) - 680x576
  70. # denosing using DPIR (mlrt)
  71. clip = vsmlrt.DPIR(clip, strength=7.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"))
  72. clip = core.std.Crop(clip=clip, left=0, right=0, top=2, bottom=2) # removing borders (vsDPIRmlrtDenoise) - 680x572
  73. # changing range from limited to full range for VsVSGANFilter
  74. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  75. # filtering using VSGANFilter
  76. from vsgan import ESRGAN
  77. vsgan = ESRGAN(clip=clip,device="cuda")
  78. model = "F:/Hybrid/64bit/vsgan_models/1x_BleedOut_Compact_300k_net_g.pth"
  79. vsgan.load(model)
  80. vsgan.apply() # 680x572
  81. clip = vsgan.clip
  82. # changing range from full to limited range for VsVSGANFilter
  83. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  84. # Resizing using 10 - bicubic spline
  85. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, range_s="limited")
  86. clip = core.fmtc.resample(clip=clip, kernel="spline16", w=680, h=536, interlaced=False, interlacedd=False) # resolution 680x536
  87. # adjusting output color from: RGBS to YUV420P10 for NVEncModel
  88. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="709", range_s="limited", dither_type="error_diffusion")
  89. # set output frame rate to 50fps (progressive)
  90. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  91. # output
  92. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment