dubhater / vapoursynth-cnr2 Goto Github PK
View Code? Open in Web Editor NEWChroma noise reducer
Chroma noise reducer
Currently, CNR2 becomes a bottleneck, especially when used in conjunction with slow filters.
Example script:
src=r'test.avi'
import vapoursynth as vs
import havsfunc as haf
core = vs.get_core()
clip = core.lsmas.LWLibavSource(src)
## Test 0 (no filters)
## Test 1 (QTGMC)
#clip = haf.QTGMC(clip, Preset='Slower', TFF=True)
## Test 2 (QTGMC + CNR2)
#clip = haf.QTGMC(clip, Preset='Slower', TFF=True)
#clip = core.cnr2.Cnr2(clip,"oxx",8,16,191,100,255,32,255,False) #VHS
## Test 3 (CNR2)
#clip = core.cnr2.Cnr2(clip,"oxx",8,16,191,100,255,32,255,False) #VHS
clip.set_output()
The results are:
Test 0 (no filters): ~920 fps, ~100% CPU
Test 1 (QTGMC): ~50 fps, ~100% CPU
Test 2 (QTGMC + CNR2): ~25 fps, ~40% CPU
Test 3 (CNR2): ~540 fps, ~60% CPU
Due to CNR2 being fmSerial, it prevents QTGMC from using all available CPU.
Changing filter mode to fmUnordered (or even fmParallelRequests) should resolve the problem.
using:
# Imports
import vapoursynth as vs
import os
import ctypes
# Loading Support Files
Dllref = ctypes.windll.LoadLibrary("i:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
import sys
# getting Vapoursynth core
core = vs.core
# Import scripts folder
scriptPath = 'i:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/Cnr2/libcnr2.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/DePan.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DebandFilter/Flash3kDeband/flash3kyuu_deband.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/EEDI3m.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/vsznedi3.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/temporalsoften.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/SourceFilter/d2vSource/d2vsource.dll")
# Import scripts
import lostfunc
import autowhite
import havsfunc
# source: 'C:\Users\Selur\Desktop\VTS_01_1.MPG'
# current color space: YUV420P8, bit depth: 8, resolution: 720x576, fps: 25, color matrix: 470bg, yuv luminance scale: limited, scanorder: top field first
# Loading C:\Users\Selur\Desktop\VTS_01_1.MPG using D2VSource
clip = core.d2v.Source(input="E:/Temp/mpg_f02df6982fa4b3a8d498a0ad5b138442_853323747.d2v", rff=False)
# Setting color matrix to 470bg.
clip = core.std.SetFrameProps(clip, _Matrix=5)
clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=5)
clip = clip if not core.text.FrameProps(clip,'_Primaries') else 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 25
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
# setting field order to what QTGMC should assume (top field first)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2)
# Deinterlacing using QTGMC
clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True) # new fps: 50
# make sure content is preceived as frame based
clip = core.std.SetFieldBased(clip, 0)
# Color Adjustment using SmoothLevels
clip = havsfunc.SmoothLevels(input=clip, output_low=16, output_high=235, Ecurve=0)
# adjusting color space from YUV420P8 to RGB24 for vsAutoWhite
clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="470bg", range_s="limited")
# Color Adjustment
clip = autowhite.AutoWhite(clip=clip)
# adjusting color space from RGB24 to YUV444P8 for vsFixChromaBleeding
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P8, matrix_s="470bg", range_s="limited")
# Fixing chroma bleeding using FixChromaBleedingMod
clip = havsfunc.FixChromaBleedingMod(input=clip)
# stabilizing using Stab
clip = lostfunc.Stab(clp=clip,range=4,mirror=0,dxmax=16,dymax=16)
# cropping the video to 624x556
clip = core.std.CropRel(clip=clip, left=48, right=48, top=4, bottom=16)
# chroma denoising using VsCnr2
# clip = core.resize.Bicubic(clip=clip, format=vs.YUV422P8)
clip = core.cnr2.Cnr2(clip=clip, mode="oxx")
# adjusting output color to YUV420P10 for x265Model
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited")
# set output frame rate to 50.000fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
# Output
clip.set_output()
I get random crashs (vspipe simply closes with out any error messages) unless I add:
clip = core.resize.Bicubic(clip=clip, format=vs.YUV422P8)
or clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8)
before the clip = core.cnr2.Cnr2(clip=clip, mode="oxx")
call.
-> seems like something is wrong with the YUV444P8 support.
https://github.com/dubhater/vapoursynth-cnr2/blob/master/Makefile.am#L2
$(MFLAGS)
makes gcc output various errors about unknown flags, removing that variable solves it.
The port of this port, Avisynth's vsCnr2 supports 8-16 bit depths, but as the README here states, this only supports 8-bit.
Please add support for 16-bit. :)
Reference: https://github.com/Asd-g/AviSynth-vsCnr2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.