Guest User

Untitled

a guest
Jun 6th, 2026
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. # Imports
  2. import sys
  3. import os
  4. import vapoursynth as vs
  5. # getting Vapoursynth core
  6. core = vs.core
  7. # Limit frame cache to 48449MB
  8. core.max_cache_size = 48449
  9. # Import scripts folder
  10. scriptPath = 'F:/Hybrid/64bit/vsscripts'
  11. sys.path.insert(0, os.path.abspath(scriptPath))
  12. # loading plugins
  13. core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/fmtconv.dll")
  14. core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV_AVX2.dll")
  15. # defining beforeDeCross-function - START
  16. def beforeDeCross(clip):
  17. edges = core.std.Prewitt(clip.std.ShufflePlanes(0, vs.GRAY))
  18.  
  19. bits = clip.format.bits_per_sample
  20. thr = 32 << (bits - 8) # scale threshold to bitdepth
  21.  
  22. mask = core.std.Binarize(edges, threshold=thr)
  23.  
  24. increase = 0
  25. for _ in range(increase):
  26. mask = core.std.Maximum(mask)
  27.  
  28. mask = core.std.BoxBlur(mask, hradius=1, vradius=1)
  29.  
  30. mid = 1 << (bits - 1)
  31. mult = 0.5 # 0.0 = grayscale chroma, 1.0 = unchanged
  32.  
  33. desat = core.std.Expr(
  34. [clip],
  35. expr=[
  36. "", # keep luma unchanged
  37. f"x {mid} - {mult} * {mid} +",
  38. f"x {mid} - {mult} * {mid} +"
  39. ]
  40. )
  41.  
  42. clip = core.std.MaskedMerge(clip, desat, mask)
  43. return [clip]
  44. # defining beforeDeCross-function - END
  45.  
  46. # Import scripts
  47. import validate
  48. # Source: 'G:\clips\colored halo\sanguo-ep01-10min.mp4'
  49. # clip current meta; color space: YUV420P8, bit depth: 8, resolution: 1920x1080, fps: 25, color matrix: 470bg, color primaries: Unspecific, color transfer: BT.470 System B/G, yuv luminance scale: limited, scanorder: progressive, full height: true (Source)
  50. # Loading 'G:\clips\colored halo\sanguo-ep01-10min.mp4' using DGSource
  51. clip = core.dgdecodenv.DGSource("J:/tmp/mp4_08bb26588468158a406792d1bfad9cc8_853323747.dgi") # 25 fps, scanorder: progressive
  52. frame = clip.get_frame(0)
  53. # setting color matrix to 470bg.
  54. clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT470_BG)
  55. # setting color transfer (vs.TRANSFER_BT470_BG), if it is not set.
  56. if validate.transferIsInvalid(clip):
  57. clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT470_BG)
  58. # setting color primaries info (to vs.PRIMARIES_BT709), if it is not set.
  59. if validate.primariesIsInvalid(clip):
  60. clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT709)
  61. # setting color range to TV (limited) range.
  62. prop_name = '_Range' if core.core_version.release_major >= 74 else '_ColorRange'
  63. clip = core.std.SetFrameProps(clip=clip, **{prop_name: vs.RANGE_LIMITED})
  64. # making sure frame rate is set to 25fps
  65. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  66. # making sure the detected scan type is set (detected: progressive)
  67. clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # scan type: progressive
  68. [clip] = beforeDeCross(clip)
  69. # clip current meta; color space: YUV420P8, bit depth: 8, resolution: 1920x1080, fps: 25, color matrix: 470bg, color primaries: Unspecific, color transfer: BT.470 System B/G, yuv luminance scale: limited, scanorder: progressive, full height: true
  70. clipMerge = clip
  71. clip = core.fmtc.resample(clip=clip, w=720, h=404, kernel="cubic", interlaced=False, interlacedd=False) # resizing for 'Gimmick' (vsBasicVSRPPFilter)
  72. # adjusting color space from YUV420P16 to RGBH for vsBasicVSRPPFilter
  73. clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_in_s="limited", range_s="full")
  74. # Quality enhancement using BasicVSR++
  75. from vsbasicvsrpp import basicvsrpp as BasicVSRPP
  76. clip = BasicVSRPP(clip, model=4)
  77. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS)
  78. clip = core.fmtc.resample(clip=clip, w=1920, h=1080, kernel="cubic", interlaced=False, interlacedd=False) # undo resizing for 'Gimmick' (vsBasicVSRPPFilter)
  79. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, matrix_s="470bg", range_in_s="full", range_s="limited", dither_type="error_diffusion")
  80. clip = core.std.Merge(clipMerge,clip,[0, 1, 1]) # merge filtered and unfiltered by plane
  81. # adjusting output color from YUV420P8 to YUV420P10 for NVEncModel
  82. clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10)
  83. # set output frame rate to 25fps (progressive)
  84. clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
  85. # output
  86. clip.set_output()
  87. # clip current meta; color space: YUV420P10, bit depth: 10, resolution: 1920x1080, fps: 25, color matrix: 470bg, color primaries: Unspecific, color transfer: BT.470 System B/G, yuv luminance scale: limited, scanorder: progressive, full height: true (Meta)
  88. # script was created by Hybrid 2026.06.06.1
Advertisement
Add Comment
Please, Sign In to add comment