Guest User

Untitled

a guest
Jun 17th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. # Imports
  2. import vapoursynth as vs
  3. # getting Vapoursynth core
  4. import site
  5. import sys
  6. import os
  7. core = vs.core
  8. # Import scripts folder
  9. scriptPath = 'F:/Hybrid/64bit/vsscripts'
  10. sys.path.insert(0, os.path.abspath(scriptPath))
  11. os.environ["CUDA_MODULE_LOADING"] = "LAZY"
  12. # loading plugins
  13. core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vstrt.dll")
  14. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  15. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/FrameFilter/RIFE/librife_r9_mod_v6.dll")
  16. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  17. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/TIVTC/libtivtc.dll")
  18. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
  19. # Import scripts
  20. from importlib.machinery import SourceFileLoader
  21. vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
  22. import validate
  23. # Source: 'C:\Users\Selur\Desktop\VH.avi'
  24. # Current color space: YUV444P10, bit depth: 10, resolution: 760x488, frame rate: 29.97fps, scanorder: telecine, yuv luminance scale: limited, matrix: 470bg
  25. # Loading C:\Users\Selur\Desktop\VH.avi using LWLibavSource
  26. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/VH.avi", format="YUV444P10", stream_index=0, cache=0, prefer_hw=0)
  27. frame = clip.get_frame(0)
  28. # Setting detected color matrix (470bg).
  29. clip = core.std.SetFrameProps(clip=clip, _Matrix=5)
  30. # setting color transfer (170), if it is not set.
  31. if validate.transferIsInvalid(clip):
  32. clip = core.std.SetFrameProps(clip=clip, _Transfer=6)
  33. # setting color primaries info (to 470), if it is not set.
  34. if validate.primariesIsInvalid(clip):
  35. clip = core.std.SetFrameProps(clip=clip, _Primaries=5)
  36. # setting color range to TV (limited) range.
  37. clip = core.std.SetFrameProps(clip=clip, _ColorRange=1)
  38. # making sure frame rate is set to 29.97fps
  39. clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
  40. # making sure the detected scan type is set (detected: telecine)
  41. clip = core.std.SetFrameProps(clip=clip, _FieldBased=2) # tff
  42. clip = core.tivtc.TFM(clip=clip)
  43. # Making sure content is preceived as frame based
  44. clip = core.std.SetFrameProps(clip=clip, _FieldBased=0) # progressive
  45. # adjusting color space from YUV444P10 to RGBS for vsFillDuplicateFrames
  46. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_s="limited")
  47. from FillDuplicateFrames import FillDuplicateFrames
  48. fdf = FillDuplicateFrames(clip=clip, method="RIFE", thresh=0.020000)
  49. clip = fdf.out
  50. # changing range from limited to full range for vsCodeFormer
  51. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  52. # adjusting color space from RGBS to RGB24 for vsCodeFormer
  53. clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, range_s="full", dither_type="error_diffusion")
  54. # Blind Face Restoration using CodeFormer
  55. # Using background resizer FeMaSR(2x)
  56. clipBG = clip
  57. from vsfemasr import femasr as FeMaSR
  58. # adjusting color space from RGB24 to RGBH for vsFeMaSR
  59. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGBH, range_s="full")
  60. # Step 1: current: 760x488, target: 1520x976
  61. # resizing using FeMaSR
  62. clipBG = FeMaSR(clip=clipBG, device_index=0) # 1520x976
  63. # resizing 1520x976 to 1520x976
  64. # adjusting resizing
  65. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGBS, range_s="full")
  66. clipBG = core.fmtc.resample(clip=clipBG, w=1520, h=976, kernel="spline64", interlaced=False, interlacedd=False)
  67. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGB24, range_s="full", dither_type="error_diffusion")
  68. from vscodeformer import codeformer as CodeFormer
  69. clip = CodeFormer(clip=clip, upscale=2, detector=1, weight=1.000, bg_clip=clipBG) # 1520x976
  70. # changing range from full to limited range for vsCodeFormer
  71. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  72. from vsmlrt import Backend
  73. # adjusting color space from RGB24 to RGBH for vsSCUNetmlrt
  74. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, range_s="limited")
  75. # denosing using SCUNet (mlrt)
  76. clip = vsmlrt.SCUNet(clip, model=4, overlap=16, backend=Backend.TRT(fp16=True,device_id=0,verbose=True,use_cuda_graph=False, num_streams=3,builder_optimization_level=3,engine_folder="J:/tmp"))
  77. # Resizing using 10 - bicubic spline
  78. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, range_s="limited")
  79. clip = core.fmtc.resample(clip=clip, kernel="spline16", w=1280, h=822, interlaced=False, interlacedd=False) # resolution 1280x822
  80. # adjusting output color from: RGBS to YUV420P10 for NVEncModel
  81. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
  82. # set output frame rate to 29.97fps (progressive)
  83. clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
  84. # output
  85. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment