Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- import vapoursynth as vs
- # getting Vapoursynth core
- import site
- import ctypes
- import sys
- import os
- core = vs.core
- # 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"
- # loading plugins
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/CTMF/CTMF.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vs-mlrt/vstrt.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/FrameFilter/ReduceFlicker/ReduceFlicker.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")# vsQTGMC
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/LSMASHSource.dll")
- # Import scripts
- from importlib.machinery import SourceFileLoader
- vsmlrt = SourceFileLoader('vsmlrt', 'F:/Hybrid/64bit/vs-mlrt/vsmlrt.py').load_module()
- import chromashift
- import adjust
- import havsfunc
- import validate
- # Source: 'C:\Users\Selur\Desktop\halo.avi'
- # 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\halo.avi using LWLibavSource
- clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/halo.avi", format="YUV420P8", stream_index=0, cache=0, prefer_hw=0)
- 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.
- clip = core.std.SetFrameProps(clip=clip, _ColorRange=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) # tff
- # Deinterlacing using QTGMC
- clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True, opencl=True) # new fps: 50
- # Making sure content is preceived as frame based
- clip = core.std.SetFrameProps(clip=clip, _FieldBased=vs.FIELD_PROGRESSIVE) # progressive
- # adjusting color using Tweak
- clip = adjust.Tweak(clip=clip, hue=0.00, sat=0.50, cont=1.00, coring=True)
- # Chroma adjustment using ChromaShiftSP
- clip = chromashift.ChromaShiftSP(clip=clip, X=3.00, Y=2.50)
- # changing range from limited to full range for VsVSGANFilter
- clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
- # setting color range to PC (full) range.
- clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_FULL)
- # adjusting color space from YUV420P8 to RGBH for VsVSGANFilter
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="full")
- # filtering using VSGANFilter
- from vsgan import ESRGAN
- vsgan = ESRGAN(clip=clip,device="cuda")
- model = "C:/Users/Selur/Desktop/testing/1x_DeHalo_v1_Compact.pth"
- vsgan.load(model)
- vsgan.apply() # 720x576
- clip = vsgan.clip
- # changing range from full to limited range for VsVSGANFilter
- clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
- # adjusting color space from RGBH to YUV444P16 for vsReduceFlicker
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
- # removing flickering using ReduceFlicker
- clip = core.rdfl.ReduceFlicker(clip=clip, strength=3, aggressive=1)
- clip = core.std.CropRel(clip=clip, left=4, right=22, top=2, bottom=14)# cropping to 694x560
- # Fix bright and dark line artifacts near the border of an image using BalanceBorders
- clip = havsfunc.bbmod(c=clip,cLeft=0,cTop=0,cRight=8,cBottom=0)
- from vsmlrt import Backend
- clip = core.std.AddBorders(clip=clip, left=0, right=2, top=0, bottom=0) # add borders to archive mod 8 (vsSCUNetmlrt) - 696x560
- # changing range from limited to full range for vsSCUNetmlrt
- clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
- # setting color range to PC (full) range.
- clip = core.std.SetFrameProps(clip=clip, _ColorRange=vs.RANGE_FULL)
- # adjusting color space from YUV444P16 to RGBH for vsSCUNetmlrt
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, matrix_in_s="470bg", range_s="full")
- # denosing using SCUNet (mlrt)
- clip = vsmlrt.SCUNet(clip, model=4, overlap=16, backend=Backend.TRT(fp16=True,device_id=0,verbose=True,use_cuda_graph=False, num_streams=3,builder_optimization_level=3,engine_folder="J:/TRT"))
- clip = core.std.CropRel(clip=clip, left=0, right=2, top=0, bottom=0) # removing borders (vsSCUNetmlrt) - 694x560
- # changing range from full to limited range for vsSCUNetmlrt
- clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
- # adjusting color space from RGBH to YUV444P16 for vsGLSLLumaSharpen
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
- with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/LumaSharpenHook.glsl") as glslf:
- glsl = glslf.read()
- glsl = glsl.replace('#define sharp_strength 0.30', '#define sharp_strength 0.8000')
- glsl = glsl.replace('#define sharp_clamp 0.035', '#define sharp_clamp 0.0350')
- glsl = glsl.replace('#define pattern 2', '#define pattern 4')
- glsl = glsl.replace('#define offset_bias 1.0', '#define offset_bias 1.0000')
- clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
- # applying dehalo using DeHalo_alpha
- clip = havsfunc.DeHalo_alpha(clip, ry=3.00, brightstr=1.50)
- # applying dehalo using YAHR
- clip = havsfunc.YAHR(clip, depth=16)
- clip = havsfunc.YAHR(clip, depth=16)
- # 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 50fps (progressive)
- clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
- # output
- clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement