Advertisement
Guest User

Untitled

a guest
Mar 29th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 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/Support/libtemporalmedian.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
  30. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  31. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  32. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  33. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
  34. # Import scripts
  35. import edi_rpow2
  36. import SpotLess
  37. import chromashift
  38. import havsfunc
  39. # source: 'C:\Users\Selur\Desktop\example.avi'
  40. # current color space: YUV420P8, bit depth: 8, resolution: 720x576, fps: 25, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
  41. # Loading C:\Users\Selur\Desktop\example.avi using LWLibavSource
  42. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/example.avi", format="YUV420P8", stream_index=0, cache=0, prefer_hw=3)
  43. frame = clip.get_frame(0)
  44. # Setting detected color matrix (470bg).
  45. clip = core.std.SetFrameProps(clip, _Matrix=5)
  46. # Setting color transfer (170), if it is not set.
  47. if '_Transfer' not in frame.props or not frame.props['_Transfer']:
  48. clip = core.std.SetFrameProps(clip, _Transfer=6)
  49. # Setting color primaries info (to 470), if it is not set.
  50. if '_Primaries' not in frame.props or not frame.props['_Primaries']:
  51. clip = core.std.SetFrameProps(clip, _Primaries=5)
  52. # Setting color range to TV (limited) range.
  53. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
  54. # making sure frame rate is set to 25
  55. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  56. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
  57. # Deinterlacing using QTGMC
  58. clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=False, opencl=True) # new fps: 50
  59. # Making sure content is preceived as frame based
  60. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
  61. # adjusting color space from YUV420P8 to RGB24 for vsLevels
  62. clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="470bg", range_s="limited")
  63. # Color Adjustment using Levels on RGB24 (8 bit)
  64. clip = core.std.Levels(clip=clip, min_in=0, max_in=255, min_out=16, max_out=235, gamma=0.90)
  65. # adjusting color space from RGB24 to YUV444P16 for vsChromaShiftSP
  66. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  67. # Chroma adjustment using ChromaShiftSP
  68. clip = chromashift.ChromaShiftSP(clip=clip, X=-4.00, Y=-1.00)
  69. # Spot removal using SpotLess
  70. clip = SpotLess.SpotLess(clip=clip, radT=3, pel=1)
  71. from vsdpir import dpir as DPIR
  72. # adjusting color space from YUV444P16 to RGBH for vsDPIRDeblock
  73. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  74. # deblocking using DPIRDeblock
  75. clip = DPIR(clip=clip, strength=50.000, task="deblock", device_index=0)
  76. # adjusting color space from RGBH to YUV444P16 for vsReduceFlicker
  77. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  78. # removing flickering using ReduceFlicker
  79. clip = core.rdfl.ReduceFlicker(clip=clip, strength=3, aggressive=1)
  80. clip = core.std.CropRel(clip=clip, left=10, right=14, top=0, bottom=14)# cropping to 696x562
  81. # Fix bright and dark line artifacts near the border of an image using BalanceBorders
  82. clip = havsfunc.bbmod(c=clip,cLeft=18,cTop=0,cRight=0,cBottom=0)
  83. clip = core.std.AddBorders(clip=clip, left=0, right=0, top=2, bottom=4) # add borders to archive mod 8 (vsBasicVSRPPFilter) - 696x568
  84. # adjusting color space from YUV444P16 to RGBH for vsBasicVSRPPFilter
  85. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  86. # Quality enhancement using BasicVSR++
  87. from vsbasicvsrpp import basicvsrpp as BasicVSRPP
  88. clip = BasicVSRPP(clip=clip, model=6)
  89. clip = core.std.CropRel(clip=clip, left=0, right=0, top=2, bottom=4) # removing borders (vsBasicVSRPPFilter) - 696x562
  90. clip = core.std.AddBorders(clip=clip, left=0, right=0, top=0, bottom=2) # add borders to archive mod 4 (NNEDI3(CL)) - 696x564
  91. # adjusting color space from RGBH to RGB48 for NNEDI3(CL)
  92. clip = core.resize.Bicubic(clip=clip, format=vs.RGB48, range_s="limited")
  93. # resizing using NNEDI3CL
  94. # current: 696x564 target: 1280x970 -> pow: 2
  95. clip = edi_rpow2.nnedi3cl_rpow2(clip=clip, rfactor=2) # 1392x1128
  96. clip = core.std.CropRel(clip=clip, left=0, right=0, top=0, bottom=4) # removing borders (NNEDI3(CL)) - 1392x1124
  97. # adjusting resizing
  98. clip = core.fmtc.resample(clip=clip, w=1280, h=970, kernel="spline64", interlaced=False, interlacedd=False)# before RGB48 after RGB48
  99. # adjusting output color from: RGB48 to YUV420P10 for NVEncModel
  100. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
  101. # set output frame rate to 50fps (progressive)
  102. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  103. # Output
  104. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement