Guest User

Untitled

a guest
Apr 26th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 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/Support/libvs_placebo.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 havsfunc
  36. # Source: 'G:\clips\compression artifacts\Gambala cut2.mpg'
  37. # Current color space: YUV420P8, bit depth: 8, resolution: 720x576, frame rate: 25fps, scanorder: bottom field first, yuv luminance scale: limited, matrix: 470bg, transfer: bt.470 system b/g, primaries: bt.601 pal
  38. # Loading G:\clips\compression artifacts\Gambala cut2.mpg using DGSource
  39. clip = core.dgdecodenv.DGSource("J:/tmp/mpg_bbd204e32fddc5c269f2450ac73db081_853323747.dgi",fieldop=0)# 25 fps, scanorder: bottom field first
  40. frame = clip.get_frame(0)
  41. # Setting detected color matrix (470bg).
  42. clip = core.std.SetFrameProps(clip, _Matrix=5)
  43. # setting color transfer (601), if it is not set.
  44. if '_Transfer' not in frame.props or not frame.props['_Transfer']:
  45. clip = core.std.SetFrameProps(clip, _Transfer=5)
  46. # setting color primaries info (to 470), if it is not set.
  47. if '_Primaries' not in frame.props or not frame.props['_Primaries']:
  48. clip = core.std.SetFrameProps(clip, _Primaries=5)
  49. # setting color range to TV (limited) range.
  50. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
  51. # making sure frame rate is set to 25fps
  52. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  53. # making sure the detected scan type is set
  54. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=1) # bff
  55. # Deinterlacing using QTGMC
  56. clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=False, opencl=True) # new fps: 50
  57. # Making sure content is preceived as frame based
  58. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
  59. clip = core.std.CropRel(clip=clip, left=12, right=8, top=2, bottom=0)# cropping to 700x574
  60. # changing range from limited to full range
  61. clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
  62. # setting color range to PC (full) range.
  63. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
  64. # adjusting color space from YUV420P8 to RGB24 for vsCodeFormer
  65. clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="470bg", range_s="full")
  66. # Blind Face Restoration using CodeFormer
  67. # Using background resizer NNEDI3
  68. clipBG = clip
  69. clipBG = core.std.AddBorders(clip=clipBG, left=0, right=0, top=0, bottom=2) # add borders to archive mod 4 (NNEDI3(CL)) - 700x576
  70. # Step 1: current: 700x576, target: 1400x1148
  71. # resizing using NNEDI3CL
  72. clipBG = edi_rpow2.nnedi3cl_rpow2(clip=clipBG, rfactor=2) # 1400x1152
  73. clipBG = core.std.CropRel(clip=clipBG, left=0, right=0, top=0, bottom=4) # removing borders (NNEDI3(CL)) - 1400x1148
  74. # adjusting resizing
  75. clipBG = core.fmtc.resample(clip=clipBG, w=1400, h=1148, kernel="spline64", interlaced=False, interlacedd=False)# before RGB24 after RGB48
  76. clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGB24, range_s="full", dither_type="error_diffusion")
  77. from vscodeformer import codeformer as CodeFormer
  78. clip = CodeFormer(clip=clip, upscale=2, weight=1.000, bg_clip=clipBG) # 1400x1148
  79. # changing range from full to limited range
  80. clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
  81. clip = core.std.AddBorders(clip=clip, left=2, right=2, top=0, bottom=2) # add borders to archive mod 8 (vsBasicVSRPPFilter) - 704x576
  82. # adjusting color space from RGB24 to RGBH for vsBasicVSRPPFilter
  83. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, range_s="limited")
  84. # Quality enhancement using BasicVSR++
  85. from vsbasicvsrpp import basicvsrpp as BasicVSRPP
  86. clip = BasicVSRPP(clip=clip, model=4)
  87. clip = core.std.CropRel(clip=clip, left=2, right=2, top=0, bottom=2) # removing borders (vsBasicVSRPPFilter) - 700x574
  88. clip = core.std.AddBorders(clip=clip, left=0, right=0, top=0, bottom=2) # add borders to archive mod 4 (NNEDI3(CL)) - 700x576
  89. # adjusting color space from RGBH to RGB48 for NNEDI3(CL)
  90. clip = core.resize.Bicubic(clip=clip, format=vs.RGB48, range_s="limited")
  91. # resizing using NNEDI3CL
  92. # current: 700x576 target: 1920x1476 -> pow: 4
  93. clip = edi_rpow2.nnedi3cl_rpow2(clip=clip, rfactor=4, nsize=3, nns=4) # 2800x2304
  94. clip = core.std.CropRel(clip=clip, left=0, right=0, top=0, bottom=8) # removing borders (NNEDI3(CL)) - 2800x2296
  95. # adjusting resizing
  96. clip = core.fmtc.resample(clip=clip, w=1920, h=1476, kernel="spline64", interlaced=False, interlacedd=False)# before RGB48 after RGB48
  97. # adjusting color space from RGB48 to YUV444P16 for vsGLSLFilmGrain
  98. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
  99. with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/filmgrain.glsl") as glslf:
  100. glsl = glslf.read()
  101. glsl = glsl.replace('#define INTENSITY 0.05', '#define INTENSITY 0.05')
  102. clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
  103. # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
  104. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", dither_type="error_diffusion")
  105. # set output frame rate to 50fps (progressive)
  106. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  107. # output
  108. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment