Advertisement
Guest User

Untitled

a guest
Nov 29th, 2023
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 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. # Adding torch dependencies to PATH
  15. path = site.getsitepackages()[0]+'/torch_dependencies/bin/'
  16. ctypes.windll.kernel32.SetDllDirectoryW(path)
  17. path = path.replace('\\', '/')
  18. os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]
  19. # Loading Plugins
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/CAS/CAS.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.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/MiscFilter/MiscFilters/MiscFilters.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  32. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV.dll")
  33. # Import scripts
  34. import edi_rpow2
  35. import masked
  36. import havsfunc
  37. # source: 'C:\Users\Selur\Desktop\Yanni - Tribute (1997 DVD-9 720 x480)__00012.mkv'
  38. # current color space: YUV420P8, bit depth: 8, resolution: 720x480, fps: 29.97, color matrix: 470bg, yuv luminance scale: limited, scanorder: top field first
  39. # Loading C:\Users\Selur\Desktop\Yanni - Tribute (1997 DVD-9 720 x480)__00012.mkv using DGSource
  40. clip = core.dgdecodenv.DGSource("J:/tmp/mkv_d603b0d1a8552802aa433b7391d38442_853323747.dgi",fieldop=0)# 29.97 fps, scanorder: top field first
  41. # Setting detected color matrix (470bg).
  42. clip = core.std.SetFrameProps(clip, _Matrix=5)
  43. # Setting color transfer info (470bg), when it is not set
  44. clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=5)
  45. # Setting color primaries info (), when it is not set
  46. clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=5)
  47. # Setting color range to TV (limited) range.
  48. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
  49. # making sure frame rate is set to 29.97
  50. clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
  51. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
  52. # Deinterlacing using QTGMC
  53. clip = havsfunc.QTGMC(Input=clip, Preset="Faster", TFF=True, opencl=True) # new fps: 59.94
  54. # Making sure content is preceived as frame based
  55. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
  56. clip = core.std.CropRel(clip=clip, left=12, right=6, top=0, bottom=0)# cropping to 702x480
  57. # changing range from limited to full range
  58. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  59. # Setting color range to PC (full) range.
  60. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
  61. # adjusting color space from YUV420P8 to RGB24 for vsCodeFormer
  62. clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="470bg", range_s="full")
  63. # Blind Face Restoration using CodeFormer
  64. from vscodeformer import codeformer as CodeFormer
  65. clip = CodeFormer(clip=clip, upscale=1, weight=1.000) # 702x480
  66. # changing range from full to limited range
  67. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  68. from vsdpir import dpir as DPIR
  69. ## Starting applying 'limit' masked filtering for vsDPIRDenoise
  70. clipMask = clip
  71. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.RGBH, range_s="full")
  72. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, matrix_s="470bg", range_s="full")
  73. clipMask = core.std.BinarizeMask(clipMask, 20480)
  74. clipMask = core.std.InvertMask(clipMask)
  75. clipFiltered = clip
  76. # adjusting color space from RGB24 to RGBH for vsDPIRDenoise
  77. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, range_s="full")
  78. # denoising using DPIRDenoise
  79. clipFiltered = DPIR(clip=clipFiltered, strength=15.000, task="denoise", device_index=0)
  80. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS, range_s="full")
  81. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, range_s="full")
  82. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_s="full")
  83. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # LimitMask
  84. ## Finished applying 'LimitMask' masked filtering for vsDPIRDenoise
  85. # contrast sharpening using CAS
  86. clip = core.cas.CAS(clip=clip, sharpness=0.600)
  87. clip = core.std.AddBorders(clip=clip, left=0, right=2, top=0, bottom=0) # add borders to archive mod 4 (NNEDI3(CL)) - 704x480
  88. # resizing using NNEDI3CL
  89. # current: 704x480 target: 1920x1478 -> pow: 4
  90. clip = edi_rpow2.nnedi3cl_rpow2(clip=clip, rfactor=4) # 2816x1920
  91. clip = core.std.CropRel(clip=clip, left=0, right=8, top=0, bottom=0) # removing borders (NNEDI3(CL)) - 2808x1920
  92. # adjusting resizing
  93. clip = core.fmtc.resample(clip=clip, w=1920, h=1478, kernel="spline64", interlaced=False, interlacedd=False)
  94. # adjusting output color from: RGBS to YUV420P10 for NVEncModel
  95. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_s="full", dither_type="error_diffusion")
  96. # set output frame rate to 59.94fps (progressive)
  97. clip = core.std.AssumeFPS(clip=clip, fpsnum=60000, fpsden=1001)
  98. # Output
  99. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement