Advertisement
Guest User

Untitled

a guest
Mar 21st, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.05 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/FrameFilter/Interframe/svpflow2_vs64.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/FrameFilter/Interframe/svpflow1_vs64.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/RemoveDirt/RemoveDirtVS.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/Cnr2/libcnr2.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/MSmooth/libmsmoosh.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/temporalsoften.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/FrameFilter/ReduceFlicker/ReduceFlicker.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libtemporalmedian.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  32. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")
  33. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  34. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  35. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
  36. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  37. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  38. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  39. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
  40. # Import scripts
  41. import removeDirt
  42. import fromDoom9
  43. import SpotLess
  44. import havsfunc
  45. # source: 'C:\Users\Selur\Desktop\woodstock99-3.avi'
  46. # current color space: YUV422P8, bit depth: 8, resolution: 720x480, fps: 29.97, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
  47. # Loading C:\Users\Selur\Desktop\woodstock99-3.avi using LWLibavSource
  48. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/woodstock99-3.avi", format="YUV422P8", stream_index=0, cache=0, prefer_hw=3)
  49. frame = clip.get_frame(0)
  50. # Setting detected color matrix (470bg).
  51. clip = core.std.SetFrameProps(clip, _Matrix=5)
  52. # Setting color transfer (170), if it is not set.
  53. if '_Transfer' not in frame.props or not frame.props['_Transfer']:
  54. clip = core.std.SetFrameProps(clip, _Transfer=6)
  55. # Setting color primaries info (to 470), if it is not set.
  56. if '_Primaries' not in frame.props or not frame.props['_Primaries']:
  57. clip = core.std.SetFrameProps(clip, _Primaries=5)
  58. # Setting color range to TV (limited) range.
  59. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
  60. # making sure frame rate is set to 29.97
  61. clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
  62. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
  63. # Deinterlacing using QTGMC
  64. clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True, opencl=True) # new fps: 59.94
  65. # Making sure content is preceived as frame based
  66. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
  67. # Spot removal using SpotLess
  68. clip = SpotLess.SpotLess(clip=clip, radT=3, pel=1)
  69. # removing flickering using ReduceFlicker
  70. clip = core.rdfl.ReduceFlicker(clip=clip, strength=3, aggressive=1)
  71. # removing flickering using Small Deflicker
  72. clip = fromDoom9.Small_Deflicker(clip=clip, preset=3, cnr=True)
  73. clip = core.std.CropRel(clip=clip, left=20, right=20, top=6, bottom=6)# cropping to 680x468
  74. # Fix bright and dark line artifacts near the border of an image using BalanceBorders
  75. clip = havsfunc.bbmod(c=clip,cLeft=0,cTop=24,cRight=0,cBottom=0)
  76. clip = core.std.AddBorders(clip=clip, left=0, right=0, top=2, bottom=2) # add borders to archive mod 8 (vsRemoveDirtMC) - 680x472
  77. # adjusting color space from YUV422P8 to YUV420P8 for vsRemoveDirtMC
  78. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, range_s="limited")
  79. # denoising using VsRemoveDirtMC
  80. clip = removeDirt.RemoveDirtMC(input=clip, limit=10, block_over=0, gpu=True)
  81. clip = core.std.CropRel(clip=clip, left=0, right=0, top=2, bottom=2) # removing borders (vsRemoveDirtMC) - 680x468
  82. from vsscunet import scunet as SCUNet
  83. # adjusting color space from YUV420P8 to RGBS for vsSCUNet
  84. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_s="limited")
  85. # denoising using SCUNet
  86. clip = SCUNet(clip=clip, model=4, cuda_graphs=True)
  87. # changing range from limited to full range
  88. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  89. # adjusting color space from RGBS to RGB24 for vsCodeFormer
  90. clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, range_s="full", dither_type="error_diffusion")
  91. # Blind Face Restoration using CodeFormer
  92. # Using background resizer FeMaSR(2x)
  93. clipBG = clip
  94. from vsfemasr import femasr as FeMaSR
  95. # adjusting color space from RGB24 to RGBH for vsFeMaSR
  96. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGBH, range_s="full")
  97. # Step 1: current: 680x468, target: 1360x936
  98. # resizing using FeMaSR
  99. clipBG = FeMaSR(clip=clipBG, device_index=0) # 1360x936
  100. # resizing 1360x936 to 1360x936
  101. # adjusting resizing
  102. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGBS, range_s="full")
  103. clipBG = core.fmtc.resample(clip=clipBG, w=1360, h=936, kernel="spline64", interlaced=False, interlacedd=False)
  104. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGB24, range_s="full", dither_type="error_diffusion")
  105. from vscodeformer import codeformer as CodeFormer
  106. clip = CodeFormer(clip=clip, upscale=2, detector=1, weight=1.000, bg_clip=clipBG) # 1360x936
  107. # Undo internal upscaling of CodeFormer using Spline64
  108. clip = core.resize.Spline64(clip, width=680, height=468) # 680x468
  109. # changing range from full to limited range
  110. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  111. # Resizing using 10 - bicubic spline
  112. clip = core.fmtc.resample(clip=clip, kernel="spline16", w=1280, h=882, interlaced=False, interlacedd=False) # resolution 1280x882 before RGB24 after RGB48
  113. # adjusting output color from: RGB48 to YUV420P10 for NVEncModel
  114. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
  115. # set output frame rate to 59.94fps (progressive)
  116. clip = core.std.AssumeFPS(clip=clip, fpsnum=60000, fpsden=1001)
  117. # Output
  118. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement