Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- import sys
- import os
- import vapoursynth as vs
- # getting Vapoursynth core
- core = vs.core
- # Limit frame cache to 48449MB
- core.max_cache_size = 48449
- # Import scripts folder
- scriptPath = 'F:/Hybrid/64bit/vsscripts'
- sys.path.insert(0, os.path.abspath(scriptPath))
- # loading plugins
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/fmtconv.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV_AVX2.dll")
- # defining beforeDeCross-function - START
- def beforeDeCross(clip):
- edges = core.std.Prewitt(clip.std.ShufflePlanes(0, vs.GRAY))
- bits = clip.format.bits_per_sample
- thr = 32 << (bits - 8) # scale threshold to bitdepth
- mask = core.std.Binarize(edges, threshold=thr)
- increase = 0
- for _ in range(increase):
- mask = core.std.Maximum(mask)
- mask = core.std.BoxBlur(mask, hradius=1, vradius=1)
- mid = 1 << (bits - 1)
- mult = 0.5 # 0.0 = grayscale chroma, 1.0 = unchanged
- desat = core.std.Expr(
- [clip],
- expr=[
- "", # keep luma unchanged
- f"x {mid} - {mult} * {mid} +",
- f"x {mid} - {mult} * {mid} +"
- ]
- )
- clip = core.std.MaskedMerge(clip, desat, mask)
- return [clip]
- # defining beforeDeCross-function - END
- # Import scripts
- import validate
- # Source: 'G:\clips\colored halo\sanguo-ep01-10min.mp4'
- # 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)
- # Loading 'G:\clips\colored halo\sanguo-ep01-10min.mp4' using DGSource
- clip = core.dgdecodenv.DGSource("J:/tmp/mp4_08bb26588468158a406792d1bfad9cc8_853323747.dgi") # 25 fps, scanorder: progressive
- frame = clip.get_frame(0)
- # setting color matrix to 470bg.
- clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT470_BG)
- # setting color transfer (vs.TRANSFER_BT470_BG), if it is not set.
- if validate.transferIsInvalid(clip):
- clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT470_BG)
- # setting color primaries info (to vs.PRIMARIES_BT709), if it is not set.
- if validate.primariesIsInvalid(clip):
- clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT709)
- # setting color range to TV (limited) range.
- prop_name = '_Range' if core.core_version.release_major >= 74 else '_ColorRange'
- clip = core.std.SetFrameProps(clip=clip, **{prop_name: vs.RANGE_LIMITED})
- # making sure frame rate is set to 25fps
- clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
- # making sure the detected scan type is set (detected: progressive)
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # scan type: progressive
- [clip] = beforeDeCross(clip)
- # 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
- clipMerge = clip
- clip = core.fmtc.resample(clip=clip, w=720, h=404, kernel="cubic", interlaced=False, interlacedd=False) # resizing for 'Gimmick' (vsBasicVSRPPFilter)
- # adjusting color space from YUV420P16 to RGBH for vsBasicVSRPPFilter
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_in_s="limited", range_s="full")
- # Quality enhancement using BasicVSR++
- from vsbasicvsrpp import basicvsrpp as BasicVSRPP
- clip = BasicVSRPP(clip, model=4)
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBS)
- clip = core.fmtc.resample(clip=clip, w=1920, h=1080, kernel="cubic", interlaced=False, interlacedd=False) # undo resizing for 'Gimmick' (vsBasicVSRPPFilter)
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, matrix_s="470bg", range_in_s="full", range_s="limited", dither_type="error_diffusion")
- clip = core.std.Merge(clipMerge,clip,[0, 1, 1]) # merge filtered and unfiltered by plane
- # adjusting output color from YUV420P8 to YUV420P10 for NVEncModel
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10)
- # set output frame rate to 25fps (progressive)
- clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
- # output
- clip.set_output()
- # 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)
- # script was created by Hybrid 2026.06.06.1
Advertisement
Add Comment
Please, Sign In to add comment