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/Support/libvs_placebo.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/DGDecNV/DGDecodeNV.dll")
- # Import scripts
- import edi_rpow2
- import havsfunc
- # Source: 'G:\clips\compression artifacts\Gambala cut2.mpg'
- # Current color space: YUV420P8, bit depth: 8, resolution: 720x576, frame rate: 25fps, scanorder: bottom field first, yuv luminance scale: limited, matrix: 470bg, transfer: bt.470 system b/g, primaries: bt.601 pal
- # Loading G:\clips\compression artifacts\Gambala cut2.mpg using DGSource
- clip = core.dgdecodenv.DGSource("J:/tmp/mpg_bbd204e32fddc5c269f2450ac73db081_853323747.dgi",fieldop=0)# 25 fps, scanorder: bottom field first
- frame = clip.get_frame(0)
- # Setting detected color matrix (470bg).
- clip = core.std.SetFrameProps(clip, _Matrix=5)
- # setting color transfer (601), if it is not set.
- if '_Transfer' not in frame.props or not frame.props['_Transfer']:
- clip = core.std.SetFrameProps(clip, _Transfer=5)
- # 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 25fps
- clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
- # making sure the detected scan type is set
- clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=1) # bff
- # Deinterlacing using QTGMC
- clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=False, opencl=True) # new fps: 50
- # Making sure content is preceived as frame based
- clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
- clip = core.std.CropRel(clip=clip, left=12, right=8, top=2, bottom=0)# cropping to 700x574
- # changing range from limited to full range
- clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
- # setting color range to PC (full) range.
- clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
- # adjusting color space from YUV420P8 to RGB24 for vsCodeFormer
- clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="470bg", range_s="full")
- # Blind Face Restoration using CodeFormer
- # Using background resizer NNEDI3
- clipBG = clip
- clipBG = core.std.AddBorders(clip=clipBG, left=0, right=0, top=0, bottom=2) # add borders to archive mod 4 (NNEDI3(CL)) - 700x576
- # Step 1: current: 700x576, target: 1400x1148
- # resizing using NNEDI3CL
- clipBG = edi_rpow2.nnedi3cl_rpow2(clip=clipBG, rfactor=2) # 1400x1152
- clipBG = core.std.CropRel(clip=clipBG, left=0, right=0, top=0, bottom=4) # removing borders (NNEDI3(CL)) - 1400x1148
- # adjusting resizing
- clipBG = core.fmtc.resample(clip=clipBG, w=1400, h=1148, kernel="spline64", interlaced=False, interlacedd=False)# before RGB24 after RGB48
- 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, weight=1.000, bg_clip=clipBG) # 1400x1148
- # changing range from full to limited range
- clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")
- clip = core.std.AddBorders(clip=clip, left=2, right=2, top=0, bottom=2) # add borders to archive mod 8 (vsBasicVSRPPFilter) - 704x576
- # adjusting color space from RGB24 to RGBH for vsBasicVSRPPFilter
- clip = core.resize.Bicubic(clip=clip, format=vs.RGBH, range_s="limited")
- # Quality enhancement using BasicVSR++
- from vsbasicvsrpp import basicvsrpp as BasicVSRPP
- clip = BasicVSRPP(clip=clip, model=4)
- clip = core.std.CropRel(clip=clip, left=2, right=2, top=0, bottom=2) # removing borders (vsBasicVSRPPFilter) - 700x574
- clip = core.std.AddBorders(clip=clip, left=0, right=0, top=0, bottom=2) # add borders to archive mod 4 (NNEDI3(CL)) - 700x576
- # adjusting color space from RGBH to RGB48 for NNEDI3(CL)
- clip = core.resize.Bicubic(clip=clip, format=vs.RGB48, range_s="limited")
- # resizing using NNEDI3CL
- # current: 700x576 target: 1920x1476 -> pow: 4
- clip = edi_rpow2.nnedi3cl_rpow2(clip=clip, rfactor=4, nsize=3, nns=4) # 2800x2304
- clip = core.std.CropRel(clip=clip, left=0, right=0, top=0, bottom=8) # removing borders (NNEDI3(CL)) - 2800x2296
- # adjusting resizing
- clip = core.fmtc.resample(clip=clip, w=1920, h=1476, kernel="spline64", interlaced=False, interlacedd=False)# before RGB48 after RGB48
- # adjusting color space from RGB48 to YUV444P16 for vsGLSLFilmGrain
- clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="470bg", range_s="limited")
- 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.05')
- 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 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