Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- import ctypes
- import sys
- import os
- import vapoursynth as vs
- # using Vapoursynth R77
- # 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")
- # 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/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/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/dfttest2/dfttest2_nvrtc.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/nnedi3vk/nnedi3vk.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/eedi3vk2.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/Vapoursynth/Lib/site-packages/vapoursynth/plugins2/vsnlm_cuda.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 masked
- import dfttest2
- import qtgmc
- import validate
- # Source: 'C:\Users\Selur\Desktop\B1_t01_2.mkv'
- # clip current meta; color space: YUV420P8, bit depth: 8, resolution: 720x576, fps: 25, color matrix: 470bg, color primaries: Unspecific, color transfer: Unspecified, yuv luminance scale: limited, scanorder: top field first, full height: true (Source)
- # Loading 'C:\Users\Selur\Desktop\B1_t01_2.mkv' using DGSource
- clip = core.dgdecodenv.DGSource("J:/tmp/mkv_749ae5828c3267f057cf88493525e601_853323747.dgi",fieldop=0) # 25 fps, scanorder: top field first
- 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_BT601), if it is not set.
- if validate.transferIsInvalid(clip):
- clip = core.std.SetFrameProps(clip=clip, _Transfer=vs.TRANSFER_BT601)
- # setting color primaries info (to vs.PRIMARIES_BT470_BG), if it is not set.
- if validate.primariesIsInvalid(clip):
- clip = core.std.SetFrameProps(clip=clip, _Primaries=vs.PRIMARIES_BT470_BG)
- # 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: top field first)
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_TOP) # scan type: top field first
- # Deinterlacing using QTGMC
- clip = qtgmc.QTGMC(Input=clip, Preset="Slower", InputType=0, TFF=True, TR2=1, SourceMatch=0, Lossless=0, EZDenoise=5.00, NoisePreset="Fast", opencl=True, Denoiser="KNLMeansCL") # new fps: 50
- # Making sure content is preceived as frame based
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # scan type: progressive
- clip = core.std.Crop(clip, left=10, right=8, top=0, bottom=2) # cropping to 702x574
- clipMask = clip
- ## Starting applying 'EdgeMask (Retinex)' masked filtering for vsBasicVSRPPFilter
- # 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")
- clipMask = core.std.Maximum(clipMask)
- clipFiltered = clip
- clipFiltered = core.std.AddBorders(clip=clipFiltered, left=0, right=2, top=0, bottom=2) # add borders to archive mod 8 (vsBasicVSRPPFilter) - 704x576
- # adjusting color space from YUV420P8 to RGBH for vsBasicVSRPPFilter
- clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="470bg", 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=0, right=2, top=0, bottom=2) # removing added borders from mod requirement (vsBasicVSRPPFilter) - 702x574
- # 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="470bg", 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: 702x574 and clipFiltered: 702x574 and clipMask: 702x574
- # Color: clip: RGBS and clipFiltered: RGBS and clipMask: GRAYS
- # Merging: clip and clipFiltered based on clipMask
- clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # RetinexEdgeMask
- ## Finished applying 'RetinexEdgeMask' masked filtering for vsBasicVSRPPFilter
- # adjusting color space from RGBS to YUV444P16 for vsGLSLAdaptiveSharpen
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_in_s="full", range_s="limited", 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 Anime4k Darken GLSL filter for line darkening
- with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/Anime4K_Darken_HQ.glsl") as glslf:
- glsl = glslf.read()
- glsl = glsl.replace('#define STRENGTH 1.5', '#define STRENGTH 1.5')
- clip = core.placebo.Shader(clip, shader_s=glsl, width=clip.width, height=clip.height)
- # Resizing using 10 - bicubic spline
- clip = core.fmtc.resample(clip, kernel="spline16", w=1280, h=960, interlaced=False, interlacedd=False) # resolution 1280x960 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 50fps (progressive)
- clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
- # output
- clip.set_output()
- # clip current meta; color space: YUV420P10, bit depth: 10, resolution: 1280x960, fps: 50, color matrix: 470bg, color primaries: Unspecific, color transfer: Unspecified, yuv luminance scale: limited, scanorder: progressive, full height: true (Meta)
- # script was created by Hybrid 2026.07.19.1
Advertisement
Add Comment
Please, Sign In to add comment