Guest User

Untitled

a guest
Feb 10th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 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/ReduceFlicker/ReduceFlicker.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/CTMF/CTMF.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libtemporalmedian.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/CCD/ccd.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  32. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
  33. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  34. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  35. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  36. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
  37. # Import scripts
  38. import SpotLess
  39. import chromashift
  40. import havsfunc
  41. # source: 'C:\Users\Selur\Desktop\Go Fishing.avi'
  42. # current color space: YUV422P8, bit depth: 8, resolution: 720x576, fps: 25, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
  43. # Loading C:\Users\Selur\Desktop\Go Fishing.avi using LWLibavSource
  44. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/Go Fishing.avi", format="YUV422P8", stream_index=0, cache=0, prefer_hw=0)
  45. frame = clip.get_frame(0)
  46. # Setting detected color matrix (470bg).
  47. clip = core.std.SetFrameProps(clip, _Matrix=5)
  48. # Setting color transfer (170), if it is not set.
  49. if '_Transfer' not in frame.props or not frame.props['_Transfer']:
  50. clip = core.std.SetFrameProps(clip, _Transfer=6)
  51. # Setting color primaries info (to 470), if it is not set.
  52. if '_Primaries' not in frame.props or not frame.props['_Primaries']:
  53. clip = core.std.SetFrameProps(clip, _Primaries=5)
  54. # Setting color range to TV (limited) range.
  55. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
  56. # making sure frame rate is set to 25
  57. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  58. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
  59. # Deinterlacing using QTGMC
  60. clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=False, opencl=True) # new fps: 50
  61. # Making sure content is preceived as frame based
  62. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
  63. # Chroma adjustment using ChromaShiftSP
  64. clip = chromashift.ChromaShiftSP(clip=clip, Y=2.00)
  65. # adjusting color space from YUV422P8 to RGBS for vsCCD
  66. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_s="limited")
  67. # chroma denoising using CCD
  68. clip = core.ccd.CCD(clip=clip, threshold=15.00)
  69. from vsdpir import dpir as DPIR
  70. # adjusting color space from RGBS to RGBH for vsDPIRDeblock
  71. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, range_s="limited", dither_type="error_diffusion")
  72. # deblocking using DPIRDeblock
  73. clip = DPIR(clip=clip, strength=25.000, task="deblock", device_index=0)
  74. clip = core.std.CropRel(clip=clip, left=12, right=12, top=2, bottom=0)# cropping to 696x574
  75. # adjusting color space from RGBH to YUV444P16 for vsBalanceBorders
  76. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  77. # Fix bright and dark line artifacts near the border of an image using BalanceBorders
  78. clip = havsfunc.bbmod(c=clip,cLeft=4,cTop=6,cRight=4,cBottom=0,thresh=355)
  79. # changing range from limited to full range
  80. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  81. # Setting color range to PC (full) range.
  82. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
  83. # adjusting color space from YUV444P16 to RGB24 for vsCodeFormer
  84. clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="470bg", range_s="full", dither_type="error_diffusion")
  85. # Blind Face Restoration using CodeFormer
  86. # Using background resizer FeMaSR(2x)
  87. clipBG = clip
  88. from vsfemasr import femasr as FeMaSR
  89. clipBG = core.std.AddBorders(clip=clipBG, left=0, right=0, top=0, bottom=2) # add borders to archive mod 4 (vsFeMaSR) - 696x576
  90. # adjusting color space from RGB24 to RGBS for vsFeMaSR
  91. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGBS, range_s="full")
  92. # Step 1: current: 696x576, target: 1392x1148
  93. # resizing using FeMaSR
  94. clipBG = FeMaSR(clip=clipBG, device_index=0) # 1392x1152
  95. # resizing 1392x1152 to 1392x1148
  96. clipBG = core.std.CropRel(clip=clipBG, left=0, right=0, top=0, bottom=4) # removing borders (vsFeMaSR) - 1392x1148
  97. # adjusting resizing
  98. clipBG = core.fmtc.resample(clip=clipBG, w=1392, h=1148, kernel="spline64", interlaced=False, interlacedd=False)
  99. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGB24, range_s="full", dither_type="error_diffusion")
  100. from vscodeformer import codeformer as CodeFormer
  101. clip = CodeFormer(clip=clip, upscale=2, weight=1.000, bg_clip=clipBG) # 1392x1148
  102. # Undo internal upscaling of CodeFormer using Bicubic
  103. clip = core.resize.Bicubic(clip, width=696, height=574) # 696x574
  104. # changing range from full to limited range
  105. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  106. # adjusting color space from RGB24 to YUV444P16 for vsSpotLess
  107. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  108. # Spot removal using SpotLess
  109. clip = SpotLess.SpotLess(clip=clip, radT=3, pel=1)
  110. # applying dehalo using YAHR
  111. clip = havsfunc.YAHR(clip)
  112. # removing flickering using ReduceFlicker
  113. clip = core.rdfl.ReduceFlicker(clip=clip, strength=3, aggressive=1)
  114. # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
  115. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", dither_type="error_diffusion")
  116. # set output frame rate to 50fps (progressive)
  117. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  118. # Output
  119. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment