Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- import vapoursynth as vs
- # getting Vapoursynth core
- import ctypes
- import site
- import sys
- import os
- core = vs.core
- # Limit thread count to 1, due to usage of sRestore
- core.num_threads = 1
- # Import scripts folder
- scriptPath = 'F:/Hybrid/64bit/vsscripts'
- sys.path.insert(0, os.path.abspath(scriptPath))
- # Adding torch dependencies to PATH
- path = site.getsitepackages()[0]+'/torch_dependencies/bin/'
- ctypes.windll.kernel32.SetDllDirectoryW(path)
- path = path.replace('\\', '/')
- os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]
- # Loading Support Files
- Dllref = ctypes.windll.LoadLibrary("F:/Hybrid/64bit/vsfilters/Support/libfftw3-3.dll")
- # loading plugins
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DGDenoise/DGDenoise.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DebandFilter/Flash3kDeband/flash3kyuu_deband.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/vcm.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/CAS/CAS.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/ZSmooth/zsmooth.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV.dll")
- # Import scripts
- import masked
- import mclean
- import mvsfunc
- import muvsfunc
- import SpotLess
- import havsfunc
- import validate
- # Source: 'C:\Users\Selur\Desktop\VTS_27_1 videohelp.mkv'
- # Current color space: YUV420P8, bit depth: 8, resolution: 720x576, frame rate: 25fps, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
- # Loading C:\Users\Selur\Desktop\VTS_27_1 videohelp.mkv using DGSource
- clip = core.dgdecodenv.DGSource("J:/tmp/mkv_341d81bcf45f892aeab6de7279ed50b9_853323747.dgi",fieldop=0)# 25 fps, scanorder: top field first
- frame = clip.get_frame(0)
- # Setting detected color matrix (470bg).
- clip = core.std.SetFrameProps(clip=clip, _Matrix=5)
- # setting color transfer (170), if it is not set.
- if validate.transferIsInvalid(clip):
- clip = core.std.SetFrameProps(clip=clip, _Transfer=6)
- # setting color primaries info (to 470), if it is not set.
- if validate.primariesIsInvalid(clip):
- clip = core.std.SetFrameProps(clip=clip, _Primaries=5)
- # setting color range to TV (limited) range.
- clip = core.std.SetFrameProps(clip=clip, _ColorRange=1)
- # 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=2)# tff
- # Deinterlace using Bwdif
- clip = core.bwdif.Bwdif(clip=clip, field=2, edeint=core.nnedi3cl.NNEDI3CL(clip=clip,field=2)) # new fps: 50
- # Making sure content is preceived as frame based
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=0)# progressive
- # adjusting frame count and rate with sRestore
- clip = havsfunc.srestore(source=clip, frate=23.9760, speed=-25)
- # Spot removal using SpotLess
- clip = SpotLess.SpotLess(clip=clip, radT=3, pel=1, smoother="zsmooth")
- from vsdpir import dpir as DPIR
- # adjusting color space from YUV420P8 to RGBH for vsDPIRDeblock
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
- # deblocking using DPIRDeblock
- clip = DPIR(clip=clip, strength=50.000, task="deblock", device_index=0, trt=True, trt_cache_path="J:/tmp")
- # adjusting color space from RGBH to RGB48 for vsCAS
- clip = core.resize.Bicubic(clip=clip, format=vs.RGB48, range_s="limited")
- # contrast sharpening using CAS
- clip = core.cas.CAS(clip=clip, sharpness=0.800)
- # adjusting color space from RGB48 to YUV444P16 for vsMClean
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
- # denoising using mClean
- clip = mclean.mClean(clip=clip, thSAD=600, rn=0)
- ## Starting applying 'limit' masked filtering for vsDGDenoise
- clipMask = clip
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, range_s="limited")
- clipMask = core.std.BinarizeMask(clipMask, 7680)
- clipMask = core.std.InvertMask(clipMask)
- clipFiltered = clip
- # denoising using DGDenoise
- clipFiltered = core.dgdenoise.DGDenoise(clip=clipFiltered)
- clip = core.std.MaskedMerge(clip, clipFiltered, clipMask)# LimitMask
- ## Finished applying 'LimitMask' masked filtering for vsDGDenoise
- # Resizing using 10 - bicubic spline
- clip = core.fmtc.resample(clip=clip, kernel="spline16", w=1280, h=960, interlaced=False, interlacedd=False)# resolution 1280x960 before YUV444P16 after YUV444P16
- ## Starting applying 'limit' masked filtering for vsBasicVSRPPFilter
- clipMask = clip
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAY16, matrix_s="470bg", range_s="limited")
- clipMask = core.std.BinarizeMask(clipMask, 30720)
- clipFiltered = clip
- # adjusting color space from YUV444P16 to RGBH for vsBasicVSRPPFilter
- clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBH, matrix_in_s="470bg", range_s="limited")
- # Quality enhancement using BasicVSR++
- from vsbasicvsrpp import basicvsrpp as BasicVSRPP
- clipFiltered = BasicVSRPP(clip=clipFiltered, model=4, tile_w=640, tile_h=480)
- clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS, range_s="limited")
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_s="limited")
- clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, range_s="limited")
- clip = core.std.MaskedMerge(clip, clipFiltered, clipMask)# LimitMask
- ## Finished applying 'LimitMask' masked filtering for vsBasicVSRPPFilter
- # adjusting color space from RGBS to YUV444P16 for vsGLSLFilmGrain
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited", dither_type="error_diffusion")
- with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/filmgrain.glsl") as glslf:
- glsl = glslf.read()
- glsl = glsl.replace('#define INTENSITY 0.05', '#define INTENSITY 0.03')
- clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
- # adjusting output color from: YUV444P16 to YUV420P10 for NVEncModel
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited", 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()
Advertisement
Add Comment
Please, Sign In to add comment