Advertisement
Guest User

Vinverse,QTGMC,Cnr2 and BasicVSR++ (with and edgeMask

a guest
Jan 4th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. # Imports
  2. import vapoursynth as vs
  3. # getting Vapoursynth core
  4. import ctypes
  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. # Loading Support Files
  12. Dllref = ctypes.windll.LoadLibrary("F:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
  13. # Loading Plugins
  14. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/CTMF/CTMF.dll")
  15. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
  16. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ColorFilter/Retinex/Retinex.dll")
  17. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/Cnr2/libcnr2.dll")
  18. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  19. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
  22. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")
  23. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  24. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  25. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
  26. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  27. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  28. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  29. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
  30. # Import scripts
  31. import nnedi3_resample
  32. import mvsfunc
  33. import smdegrain
  34. import mvsfunc as mvf
  35. import masked
  36. import havsfunc
  37. # source: 'C:\Users\Selur\Desktop\Sample Video 1.avi'
  38. # current color space: YUV422P8, bit depth: 8, resolution: 720x576, fps: 25, color matrix: 470bg, yuv luminance scale: limited, scanorder: top field first
  39. # Loading C:\Users\Selur\Desktop\Sample Video 1.avi using LWLibavSource
  40. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/Sample Video 1.avi", format="YUV422P8", stream_index=0, cache=0, prefer_hw=0)
  41. frame = clip.get_frame(0)
  42. # Setting detected color matrix (470bg).
  43. clip = core.std.SetFrameProps(clip, _Matrix=5)
  44. # Setting color transfer (to 470bg), if it is not set.
  45. if '_Transfer' not in frame.props or not frame.props['_Transfer']:
  46. clip = core.std.SetFrameProps(clip, _Transfer=5)
  47. # Setting color primaries info (to 5), if it is not set.
  48. if '_Primaries' not in frame.props or not frame.props['_Primaries']:
  49. clip = core.std.SetFrameProps(clip, _Primaries=5)
  50. # Setting color range to TV (limited) range.
  51. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
  52. # making sure frame rate is set to 25
  53. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  54. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
  55. # converting interlaced to half-height progressive for filtering (vsVinverse2) (separate fields)
  56. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P8, range_s="limited")
  57. clip = core.std.SeparateFields(clip, tff=True)
  58. clipEven = clip[::2] # resolution 720x288
  59. clipEven = core.std.SetFrameProp(clip=clipEven, prop="_FieldBased", intval=0) # progressive
  60. clipOdd = clip[1::2] # resolution 720x288
  61. clipOdd = core.std.SetFrameProp(clip=clipOdd, prop="_FieldBased", intval=0) # progressive
  62. clipEven = havsfunc.Vinverse2(clp=clipEven)
  63. clipOdd = havsfunc.Vinverse2(clp=clipOdd)
  64. # converting half-height progressive to interlacedbefore deinterlacing
  65. clip = core.std.Interleave([clipOdd, clipEven])
  66. clip = core.std.DoubleWeave(clip=clip, tff=True) # resolution 720x576
  67. clip = core.std.SelectEvery(clip, 2, 0)
  68. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
  69. # Deinterlacing using QTGMC
  70. clip = havsfunc.QTGMC(Input=clip, Preset="Faster", TFF=True, opencl=True) # new fps: 50
  71. # Making sure content is preceived as frame based
  72. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
  73. # adjusting color space from YUV444P8 to YUV422P8 for vsCnr2
  74. clip = core.resize.Bicubic(clip=clip, format=vs.YUV422P8, range_s="limited")
  75. # chroma denoising using VsCnr2
  76. clip = core.cnr2.Cnr2(clip=clip, mode="oxx", scenechroma=True)
  77. ## Starting applying 'EdgeMask (Retinex)' masked filtering for vsBasicVSRPPFilter
  78. clipMask = clip
  79. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  80. clipMask = masked.retinex_edgemask(src=clipMask, sigma=1)
  81. clipFiltered = clip
  82. # adjusting color space from YUV422P8 to RGBH for vsBasicVSRPPFilter
  83. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  84. # Quality enhancement using BasicVSR++
  85. from vsbasicvsrpp import basicvsrpp as BasicVSRPP
  86. clipFiltered = BasicVSRPP(clip=clipFiltered, model=4)
  87. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS, range_s="limited")
  88. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_s="limited")
  89. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_s="limited")
  90. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # RetinexEdgeMask
  91. ## Finished applying 'RetinexEdgeMask' masked filtering for vsBasicVSRPPFilter
  92. # adjusting color space from RGBS to YUV444P16 for vsSMDegrain
  93. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
  94. # removing grain using SMDegrain
  95. clip = smdegrain.SMDegrain(input=clip, interlaced=False, opencl=True, device=-1)
  96. # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
  97. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", dither_type="error_diffusion")
  98. # set output frame rate to 50fps (progressive)
  99. clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
  100. # Output
  101. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement