Advertisement
Guest User

SpotLess+TIVTC+Santiag+masked BasicVSR++

a guest
Mar 6th, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. # Imports
  2. import vapoursynth as vs
  3. # getting Vapoursynth core
  4. import sys
  5. import os
  6. core = vs.core
  7. # Import scripts folder
  8. scriptPath = 'F:/Hybrid/64bit/vsscripts'
  9. sys.path.insert(0, os.path.abspath(scriptPath))
  10. # loading plugins
  11. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
  12. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ColorFilter/Retinex/Retinex.dll")
  13. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libsangnom.dll")
  14. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  15. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI2.dll")
  16. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")
  17. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  18. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/TIVTC/libtivtc.dll")
  19. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/ZSmooth/zsmooth.dll")
  20. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  21. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
  22. # Import scripts
  23. import mvsfunc as mvf
  24. import masked
  25. import antiAliasing
  26. import SpotLess
  27. import validate
  28. # Source: 'C:\Users\Selur\Desktop\defect.avi'
  29. # Current color space: YUV420P8, bit depth: 8, resolution: 720x576, frame rate: 30fps, scanorder: telecine, yuv luminance scale: limited, matrix: 470bg, format: ULH0
  30. # Loading C:\Users\Selur\Desktop\defect.avi using LWLibavSource
  31. clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/defect.avi", format="YUV420P8", stream_index=0, cache=0, prefer_hw=0)
  32. frame = clip.get_frame(0)
  33. # setting color matrix to 470bg.
  34. clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT470_BG)
  35. # setting color transfer (vs.TRANSFER_BT601), if it is not set.
  36. if validate.transferIsInvalid(clip):
  37. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT601)
  38. # setting color primaries info (to vs.PRIMARIES_BT470_BG), if it is not set.
  39. if validate.primariesIsInvalid(clip):
  40. clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT470_BG)
  41. # setting color range to TV (limited) range.
  42. clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_LIMITED)
  43. # making sure frame rate is set to 30fps
  44. clip = core.std.AssumeFPS(clip=clip, fpsnum=30, fpsden=1)
  45. # making sure the detected scan type is set (detected: telecine)
  46. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # tff
  47. # converting interlaced to half-height progressive for filtering (vsSpotLess) (separate fields)
  48. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P8, range_s="limited")
  49. clip = core.std.SeparateFields(clip, tff=False)
  50. clipEven = clip[::2] # resolution 720x288
  51. clipEven = core.std.SetFrameProps(clip=clipEven, _FieldBased=vs.FIELD_PROGRESSIVE) # progressive
  52. clipOdd = clip[1::2] # resolution 720x288
  53. clipOdd = core.std.SetFrameProps(clip=clipOdd, _FieldBased=vs.FIELD_PROGRESSIVE) # progressive
  54. # Spot removal using SpotLess
  55. clipEven = SpotLess.SpotLess(clip=clipEven, radT=3, pel=1, smoother="zsmooth")
  56. # Spot removal using SpotLess
  57. clipOdd = SpotLess.SpotLess(clip=clipOdd, radT=3, pel=1, smoother="zsmooth")
  58. # converting half-height progressive to interlacedbefore deinterlacing
  59. clip = core.std.Interleave([clipOdd, clipEven])
  60. clip = core.std.DoubleWeave(clip=clip, tff=False) # resolution 720x576
  61. clip = core.std.SelectEvery(clip, 2, 0)
  62. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # tff
  63. # Deinterlacing using TIVTC
  64. clip = core.tivtc.TFM(clip=clip, chroma=True)
  65. clip = core.tivtc.TDecimate(clip=clip, mode=7, rate=23.9760, dupThresh=0.04, vidThresh=3.50, sceneThresh=15.00)# new fps: 23.976
  66. # Making sure content is preceived as frame based
  67. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # progressive
  68. # applying anti aliasing using santiag
  69. clip = antiAliasing.santiag(c=clip, strh=3, strv=3, nns=2, qual=2, pscrn=2, opencl=True)
  70. ## Starting applying 'EdgeMask (Retinex)' masked filtering for vsBasicVSRPPFilter
  71. clipMask = clip
  72. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  73. clipMask = masked.retinex_edgemask(src=clipMask, sigma=1)
  74. clipMask = core.std.Maximum(clipMask)
  75. clipMask = core.std.BinarizeMask(clip=clipMask,threshold=30080)
  76. clipFiltered = clip
  77. # adjusting color space from YUV444P8 to RGBH for vsBasicVSRPPFilter
  78. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
  79. # Quality enhancement using BasicVSR++
  80. from vsbasicvsrpp import basicvsrpp as BasicVSRPP
  81. clipFiltered = BasicVSRPP(clip=clipFiltered, model=4)
  82. clipMask = core.std.BinarizeMask(clip=clipMask,threshold=30080)
  83. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS, range_s="limited")
  84. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_s="limited")
  85. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_s="limited")
  86. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # RetinexEdgeMask
  87. ## Finished applying 'RetinexEdgeMask' masked filtering for vsBasicVSRPPFilter
  88. # adjusting output color from: RGBS to YUV420P10 for NVEncModel
  89. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
  90. # set output frame rate to 23.976fps (progressive)
  91. clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
  92. # output
  93. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement