Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- import sys
- import os
- import vapoursynth as vs
- # using Vapoursynth R79
- # 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/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/zsmooth/zsmooth.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DerainbowFilter/SmoothUV/libsmoothuv.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/akarin/libakarin.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/edgefixer.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/tivtc.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV_AVX2.dll")
- # Import scripts
- import sharpen
- import linedarken
- import masked
- import RainbowSmooth
- import validate
- # Source: 'C:\Users\Selur\Desktop\removeheavyanalogartifacts.ts'
- # clip current meta; color space: YUV420P8, bit depth: 8, resolution: 1440x1080, fps: 29.97, color matrix: 709, color primaries: Unspecific, color transfer: BT.709, yuv luminance scale: limited, scanorder: telecine, full height: true (Source)
- # Loading 'C:\Users\Selur\Desktop\removeheavyanalogartifacts.ts' using DGSource
- clip = core.dgdecodenv.DGSource("J:/tmp/ts_541bdebe8c57c01d2fbdb83685d70881_853323747.dgi",fieldop=0) # 29.97 fps, scanorder: telecine
- frame = clip.get_frame(0)
- # setting color matrix to 709.
- clip = core.std.SetFrameProps(clip, _Matrix=vs.MATRIX_BT709)
- # setting color transfer (vs.TRANSFER_BT709), if it is not set.
- if validate.transferIsInvalid(clip):
- clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT709)
- # 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 29.97fps
- clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
- # making sure the detected scan type is set (detected: telecine)
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # scan type: top field first
- # Deinterlacing using TIVTC
- clip = core.tivtc.TFM(clip)
- clip = core.tivtc.TDecimate(clip) # new fps: 23.976
- # Making sure content is perceived as frame based
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # scan type: progressive
- clip = core.std.Crop(clip, left=186, right=186, top=4, bottom=0) # cropping to 1068x1076
- # Fix bright and dark line artifacts near the border of an image using EdgeFixer
- clip = core.edgefixer.Continuity(clip, left=6, top=6, right=4, bottom=6, radius=3)
- clip = core.std.AddBorders(clip=clip, left=2, right=2, top=6, bottom=6) # add borders to archive mod 16 (vsRainbowSmooth) - 1072x1088
- # rainbow removal using RainbowSmooth
- clip = RainbowSmooth.RainbowSmooth(clip, radius=7, lthresh=50)
- clip = core.std.Crop(clip=clip, left=2, right=2, top=6, bottom=6) # removing added borders from mod requirement (vsRainbowSmooth) - 1068x1076
- ## Starting applying (experimental) 'Finegrain Mask' masked filtering for vsBasicVSRPPFilter
- # Creating mask for clip
- clipMask = clip
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.YUV444P8)
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY8, range_in_s="limited")
- clipMask = masked.FinegrainMask(clip=clipMask, mode="RemoveGrain")
- clipMask = core.std.Maximum(clipMask)
- EXPR = core.akarin.Expr if hasattr(core, 'akarin') else core.std.Expr
- clipMask = EXPR(clipMask, expr=f"x 100 *")
- clipFiltered = clip
- clipFiltered = core.std.AddBorders(clip=clipFiltered, left=2, right=2, top=2, bottom=2) # add borders to archive mod 8 (vsBasicVSRPPFilter) - 1072x1080
- # adjusting color space from YUV420P8 to RGBH for vsBasicVSRPPFilter
- clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="709", range_in_s="limited", range_s="full")
- # Quality enhancement using BasicVSR++
- from vsbasicvsrpp import basicvsrpp as BasicVSRPP
- clipFiltered = BasicVSRPP(clipFiltered, model=4)
- clipFiltered = core.std.Crop(clip=clipFiltered, left=2, right=2, top=2, bottom=2) # removing added borders from mod requirement (vsBasicVSRPPFilter) - 1068x1076
- # adjusting clip color before mask merge
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="709", range_in_s="limited", range_s="full")
- # adjusting mask before mask merge
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYH, range_in_s="limited")
- # Resolution: clip: 1068x1076 and clipFiltered: 1068x1076 and clipMask: 1068x1076
- # Color: clip: RGBH and clipFiltered: RGBH and clipMask: GRAYH
- # Merging: clip and clipFiltered based on clipMask
- clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # FinegrainMask
- ## Finished applying 'FinegrainMask' masked filtering for vsBasicVSRPPFilter
- # adjusting color space from RGBH to YUV444P16 for vsToon
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="709", range_in_s="full", range_s="limited")
- # line darkening using Toon
- clip = linedarken.Toon(clip, str=1.50)
- # Resizing using 10 - bicubic spline
- clip = core.fmtc.resample(clip, kernel="spline16", w=1068, h=808, interlaced=False, interlacedd=False) # resolution 1068x808 before YUV444P16 after YUV444P16
- # adjusting output color from YUV444P16 to YUV420P10 for NVEncModel
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, dither_type="error_diffusion")
- # set output frame rate to 23.976fps (progressive)
- clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
- # output
- clip.set_output()
- # clip current meta; color space: YUV420P10, bit depth: 10, resolution: 1068x808, fps: 23.976, color matrix: 709, color primaries: Unspecific, color transfer: BT.709, yuv luminance scale: limited, scanorder: progressive, full height: true (Meta)
- # script was created by Hybrid 2026.08.21.1
Advertisement
Add Comment
Please, Sign In to add comment