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")
- # 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 Plugins
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/FrameFilter/Interframe/svpflow2_vs64.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/FrameFilter/Interframe/svpflow1_vs64.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/RemoveDirt/RemoveDirtVS.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/Cnr2/libcnr2.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/MSmooth/libmsmoosh.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/temporalsoften.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/FrameFilter/ReduceFlicker/ReduceFlicker.dll")
- core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libtemporalmedian.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")
- 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
- import removeDirt
- import fromDoom9
- import SpotLess
- import havsfunc
- # source: 'C:\Users\Selur\Desktop\woodstock99-3.avi'
- # current color space: YUV422P8, bit depth: 8, resolution: 720x480, fps: 29.97, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
- # Loading C:\Users\Selur\Desktop\woodstock99-3.avi using LWLibavSource
- clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/woodstock99-3.avi", format="YUV422P8", stream_index=0, cache=0, prefer_hw=3)
- frame = clip.get_frame(0)
- # Setting detected color matrix (470bg).
- clip = core.std.SetFrameProps(clip, _Matrix=5)
- # Setting color transfer (170), if it is not set.
- if '_Transfer' not in frame.props or not frame.props['_Transfer']:
- clip = core.std.SetFrameProps(clip, _Transfer=6)
- # Setting color primaries info (to 470), if it is not set.
- if '_Primaries' not in frame.props or not frame.props['_Primaries']:
- clip = core.std.SetFrameProps(clip, _Primaries=5)
- # Setting color range to TV (limited) range.
- clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
- # making sure frame rate is set to 29.97
- clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
- clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
- # Deinterlacing using QTGMC
- clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True, opencl=True) # new fps: 59.94
- # Making sure content is preceived as frame based
- clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
- # Spot removal using SpotLess
- clip = SpotLess.SpotLess(clip=clip, radT=3, pel=1)
- # removing flickering using ReduceFlicker
- clip = core.rdfl.ReduceFlicker(clip=clip, strength=3, aggressive=1)
- # removing flickering using Small Deflicker
- clip = fromDoom9.Small_Deflicker(clip=clip, preset=3, cnr=True)
- clip = core.std.CropRel(clip=clip, left=20, right=20, top=6, bottom=6)# cropping to 680x468
- # Fix bright and dark line artifacts near the border of an image using BalanceBorders
- clip = havsfunc.bbmod(c=clip,cLeft=0,cTop=24,cRight=0,cBottom=0)
- clip = core.std.AddBorders(clip=clip, left=0, right=0, top=2, bottom=2) # add borders to archive mod 8 (vsRemoveDirtMC) - 680x472
- # adjusting color space from YUV422P8 to YUV420P8 for vsRemoveDirtMC
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, range_s="limited")
- # denoising using VsRemoveDirtMC
- clip = removeDirt.RemoveDirtMC(input=clip, limit=10, block_over=0, gpu=True)
- clip = core.std.CropRel(clip=clip, left=0, right=0, top=2, bottom=2) # removing borders (vsRemoveDirtMC) - 680x468
- from vsscunet import scunet as SCUNet
- # adjusting color space from YUV420P8 to RGBS for vsSCUNet
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="470bg", range_s="limited")
- # denoising using SCUNet
- clip = SCUNet(clip=clip, model=4, cuda_graphs=True)
- # changing range from limited to full range
- clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
- # adjusting color space from RGBS to RGB24 for vsCodeFormer
- clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, range_s="full", dither_type="error_diffusion")
- # Blind Face Restoration using CodeFormer
- # Using background resizer FeMaSR(2x)
- clipBG = clip
- from vsfemasr import femasr as FeMaSR
- # adjusting color space from RGB24 to RGBH for vsFeMaSR
- clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGBH, range_s="full")
- # Step 1: current: 680x468, target: 1360x936
- # resizing using FeMaSR
- clipBG = FeMaSR(clip=clipBG, device_index=0) # 1360x936
- # resizing 1360x936 to 1360x936
- # adjusting resizing
- clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGBS, range_s="full")
- clipBG = core.fmtc.resample(clip=clipBG, w=1360, h=936, kernel="spline64", interlaced=False, interlacedd=False)
- clipBG = core.resize.Bicubic(clip=clipBG, format=vs.RGB24, range_s="full", dither_type="error_diffusion")
- from vscodeformer import codeformer as CodeFormer
- clip = CodeFormer(clip=clip, upscale=2, detector=1, weight=1.000, bg_clip=clipBG) # 1360x936
- # Undo internal upscaling of CodeFormer using Spline64
- clip = core.resize.Spline64(clip, width=680, height=468) # 680x468
- # changing range from full to limited range
- clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
- # Resizing using 10 - bicubic spline
- clip = core.fmtc.resample(clip=clip, kernel="spline16", w=1280, h=882, interlaced=False, interlacedd=False) # resolution 1280x882 before RGB24 after RGB48
- # adjusting output color from: RGB48 to YUV420P10 for NVEncModel
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, matrix_s="470bg", range_s="limited", 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement