Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- import logging
- import site
- import ctypes
- 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 Support Files
- Dllref = ctypes.windll.LoadLibrary("F:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
- os.environ["CUDA_MODULE_LOADING"] = "LAZY"
- # Force logging to std:err
- logging.StreamHandler(sys.stderr)
- # loading plugins
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/libvs_placebo.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vstrt.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ColorFilter/Retinex/Retinex.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/bwdif.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/fmtconv.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/sneedif/libsneedif.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libeedi3vk.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/addnoise.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/mvtools.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/zsmooth/zsmooth.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV_AVX2.dll")
- # Import scripts
- import linedarken
- from importlib.machinery import SourceFileLoader
- vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
- import masked
- import qtgmc
- import validate
- # Source: 'C:\Users\Selur\Desktop\sample.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: top field first, full height: true (Source)
- # Loading 'C:\Users\Selur\Desktop\sample.ts' using DGSource
- clip = core.dgdecodenv.DGSource("J:/tmp/ts_3591dab47f54c59fc132a441faa50717_853323747.dgi",fieldop=0) # 29.97 fps, scanorder: top field first
- 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: top field first)
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # scan type: top field first
- # Deinterlacing using QTGMC
- clip = qtgmc.QTGMC(clip, Preset="Fast", TFF=True, opencl=True) # new fps: 59.94
- # Making sure content is preceived as frame based
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # scan type: progressive
- clipMask = clip
- ## Starting applying 'EdgeMask (Retinex)' masked filtering for vsDPIRmlrtDenoise
- # Creating mask for clip
- clipMask = masked.retinex_edgemask(src=clipMask, sigma=1)
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, range_in_s="limited")
- for i in range(2):
- clipMask = core.std.Maximum(clipMask)
- clipMask = core.std.BinarizeMask(clip=clipMask,threshold=54144)
- clipFiltered = clip
- # changing range from limited to full range for vsDPIRmlrtDenoise
- clipFiltered = core.resize.Bicubic(clipFiltered, format=vs.YUV420P8, range_in_s="limited", range_s="full")
- # setting color range to PC (full) range.
- prop_name = '_Range' if core.core_version.release_major >= 74 else '_ColorRange'
- clipFiltered = core.std.SetFrameProps(clip=clipFiltered, **{prop_name: vs.RANGE_FULL})
- # adjusting color space from YUV420P8 to RGBH for vsDPIRmlrtDenoise
- clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="709", range_in_s="full", range_s="full")
- # denoising using DPIR (mlrt)
- from vsmlrt import Backend
- clipFiltered = vsmlrt.DPIR(clipFiltered, strength=55.000, model=1, overlap=16, backend=Backend.TRT(fp16=True,device_id=0,bf16=False,use_cuda_graph=False,num_streams=3,verbose=True,builder_optimization_level=3,engine_folder="J:/TRT",output_format=1))
- # adjusting clipFiltered color before mask merge
- clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS)
- # adjusting clip color before mask merge
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="709", range_in_s="limited", range_s="full")
- # adjusting mask before mask merge
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_in_s="limited")
- # Resolution: clip: 1440x1080 and clipFiltered: 1440x1080 and clipMask: 1440x1080
- # Merging: clip and clipFiltered based on clipMask
- clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # RetinexEdgeMask
- ## Finished applying 'RetinexEdgeMask' masked filtering for vsDPIRmlrtDenoise
- # adjusting color space from RGBS to YUV444P16 for vsGLSLAdaptiveSharpen
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="709", range_in_s="full", range_s="full", dither_type="error_diffusion")
- # sharpening using GLSL Adaptive Sharpening
- with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/adaptive-sharpen.glsl") as glslf:
- glsl = glslf.read()
- glsl = glsl.replace('#define curve_height 1.0', '#define curve_height 1.0000')
- glsl = glsl.replace('#define anime_mode false', '#define anime_mode true')
- glsl = glsl.replace('#define overshoot_ctrl false', '#define overshoot_ctrl true')
- glsl = glsl.replace('#define video_level_out false', '#define video_level_out true')
- clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height)
- # Using FastLineDarkenMOD for line darkening
- clip = linedarken.FastLineDarkenMOD(clip)
- # 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 59.94fps (progressive)
- clip = core.std.AssumeFPS(clip=clip, fpsnum=60000, fpsden=1001)
- # output
- clip.set_output()
- # clip current meta; color space: YUV420P10, bit depth: 10, resolution: 1440x1080, fps: 59.94, color matrix: 709, color primaries: Unspecific, color transfer: BT.709, yuv luminance scale: full, scanorder: progressive, full height: true (Meta)
- # script was created by Hybrid 2026.07.05.1
Advertisement
Add Comment
Please, Sign In to add comment