anton_foy
13th May 2022, 00:04
Trying to knead out a script for a long time now for cleaning up SLog-2 footage. But the material is very uneven, dark noisy to bright and pretty clean. I have 3 test clips I link to here. Came up with a script I use and I find the prefiltering is very simple but also effective although I think this script can get better quality and speedwise. My question is if you have any ideas of how to improve my script in any ways, every little thing is appreciated. Thanks!
Required:
Lsmash, fastblur, deblock_qed_mt or deblock_qed (from deblockpack by dogway, but I cannot get it to work on my comp), extools, fft3dfilter, sharpenerspack (mix mods by dogway), rgtools, neo_fk3db, sysinfo (if you want to use SI_physicalcores)
Script:
SetMemoryMax(16384/1)
#Index
LSMASHVideoSource("C:\Users\comp\Videos\C0135.mp4", decoder="h264_cuvid")
convertbits(16)
Levels(0, 1, 255*256, 0, 235*256, coring=false, dither=false)
Deblock_QED_mt(quant1=26, aOff1=1, aOff2=1, bOff1=2, bOff2=2, uv=3)
o=last
nc = si_physicalcores()
#Prefilter:
b=fastblur(3)
P=merge(o,b,0.5).ex_levels(12,1.2,100)
pk = converttoRGB()
pl = pk.converttoPlanarRGB()
in = pl.ex_invert()
t=ScriptClip(function[in,pl,pk,p] () {
lum = in.averageR()
rgb = pk.RGBDifferenceFromPrevious()
luma = int(lum + rgb)
ttr = int(luma*0.0001)
ths = int(luma*0.0067)
TSMC(tradius=ttr,lumathresh=ths,auxclip=p)
} )
ex_ReduceFlicker(strength=1)
m=ex_levels(40,2.02,160,0,200)
mt_merge(last,t,m.ex_invert(),Y=3,U=3,V=3, luma=true)
BSharp(pblur=0.5,str=0.9)
fft3dfilter(bt=1,plane=0,sigma=0.2,sigma2=0.4,sigma3=1,sigma4=1,ncpu=nc)
uband()
#BSharp - sharpen
function bsharp(clip c, float "str", float "pblur"){
str = Default(str, 0.5)
pblur = Default(pblur, 0.7)
B = merge(c,c.removegrain(20),(pblur))
S = B.sharpen(0.7).CASP(strength=str,UV=2)
M = C.greyscale().ex_levels(47,0.76,170)
mt_merge(c,s,m,luma=false,Y=3,U=2,V=2)
return last
}
#Uband - debanding
function Uband(clip c){
nc = si_physicalcores()
O = c.bicubicresize(c.width/3,c.height/3).ex_edge(scale=3,"qprewitt").ex_expand().ex_invert().ex_levels(0,0.1,212).bicubicresize(c.width(),c.height())
N = c.fft3dfilter(sigma=0,sigma2=0,sigma3=0,sigma4=3,bt=1,plane=3,ncpu=nc).neo_f3kdb(grainY=23,grainC=3,mt=true)
M = mt_merge(c,n,o,luma=true,Y=3,U=3,V=3)
S = c.bicubicresize(c.width/4,c.height/4).greyscale().ex_levels(36,0.16,70,0,100).ex_invert().bicubicresize(c.width(),c.height())
mt_merge(c,m,s,luma=true,Y=3,U=3,V=3)
return last}
#TSMC - mocomped temporalsoften
# TSMC (Temporal Soften Motion Compensated) by althor1138 (18-03-2021)
#
# TSMC mod by Dogway (26-08-2021)
# -Optimization for UHD clips
# -Higher defaults
# -Tweaked settings (mt, levels, truemotion, chroma)
function TSMC(clip input, int "tradius", int "mthresh", int "lumathresh", int "blocksize",clip "auxclip", bool "pref", int "Y", int "UV")
{
pref = Default(pref, true)
Y = Default(Y, 3)
UV = Default(UV, 2)
t=Defined(tradius)
tradius=t ? tradius : 6
# temporal radius-number of frames analyzed before/after current frame.
m=Defined(mthresh)
mthresh=m ? mthresh : 180
# motion threshold-higher numbers denoise areas with higher motion.
#Anything above this number does not get denoised.
l=Defined(lumathresh)
lumathresh=l ? lumathresh : 255
# luma threshold- Denoise pixels that match in surrounding frames.
#255 is the maximum and default. 0-255 are valid numbers.
#Also adjusts chroma threshold.
b=Defined(blocksize)
blocksize=b ? blocksize : 16
#larger numbers = faster processing times
chroma = UV == 3
aux=Defined(auxclip)
w = width(input)
h = height(input)
isUHD = (w > 2599 || h > 1499)
nw = round(w/2.0)
nh = round(h/2.0)
inputA = aux ? auxclip : input
inputA = isUHD ? inputA.ConvertBits(8,dither=-1).BilinearResize(nw+nw%2, nh+nh%2) : inputA
super = MSuper(input, pel=1, hpad = 0, vpad = 0, chroma=true, mt=true, levels=1)
superfilt = MSuper(inputA,pel=1, hpad = 0, vpad = 0, chroma=true, mt=true) # bug can't disable chroma otherwise luma isn't processed
vmulti = Manalyse(superfilt,multi=true,delta=tradius,temporal=true,truemotion=true,blksize=blocksize,overlap=blocksize/2, mt=true, chroma=true)
vmulti2 = Mrecalculate(superfilt,vmulti,thsad=mthresh,truemotion=true,tr=tradius,blksize=blocksize/2,overlap=blocksize/4, mt=true, chroma=true)
vmulti2 = isUHD ? vmulti2.MScaleVect() : vmulti2
mocomp = Mcompensate(input,super,vmulti2,thsad=mthresh,tr=tradius,center=true,mt=true) # recursion=50 is bugged
dnmc = mocomp.temporalsoften(tradius,lumathresh,lumathresh,15,2)
dec = selectevery(dnmc,tradius * 2 + 1,tradius)
Y != 3 ? input.mergechroma(dec) : dec }
ConverttoYUV444()
Convertbits(10,dither=1)
Prefetch (SI_PhysicalCores ())
I output to prores444 10-bit UHD through ffmpeg. (Maybe this is a bottleneck?)
Test clips:
https://we.tl/t-O3jvjqBWAN
Required:
Lsmash, fastblur, deblock_qed_mt or deblock_qed (from deblockpack by dogway, but I cannot get it to work on my comp), extools, fft3dfilter, sharpenerspack (mix mods by dogway), rgtools, neo_fk3db, sysinfo (if you want to use SI_physicalcores)
Script:
SetMemoryMax(16384/1)
#Index
LSMASHVideoSource("C:\Users\comp\Videos\C0135.mp4", decoder="h264_cuvid")
convertbits(16)
Levels(0, 1, 255*256, 0, 235*256, coring=false, dither=false)
Deblock_QED_mt(quant1=26, aOff1=1, aOff2=1, bOff1=2, bOff2=2, uv=3)
o=last
nc = si_physicalcores()
#Prefilter:
b=fastblur(3)
P=merge(o,b,0.5).ex_levels(12,1.2,100)
pk = converttoRGB()
pl = pk.converttoPlanarRGB()
in = pl.ex_invert()
t=ScriptClip(function[in,pl,pk,p] () {
lum = in.averageR()
rgb = pk.RGBDifferenceFromPrevious()
luma = int(lum + rgb)
ttr = int(luma*0.0001)
ths = int(luma*0.0067)
TSMC(tradius=ttr,lumathresh=ths,auxclip=p)
} )
ex_ReduceFlicker(strength=1)
m=ex_levels(40,2.02,160,0,200)
mt_merge(last,t,m.ex_invert(),Y=3,U=3,V=3, luma=true)
BSharp(pblur=0.5,str=0.9)
fft3dfilter(bt=1,plane=0,sigma=0.2,sigma2=0.4,sigma3=1,sigma4=1,ncpu=nc)
uband()
#BSharp - sharpen
function bsharp(clip c, float "str", float "pblur"){
str = Default(str, 0.5)
pblur = Default(pblur, 0.7)
B = merge(c,c.removegrain(20),(pblur))
S = B.sharpen(0.7).CASP(strength=str,UV=2)
M = C.greyscale().ex_levels(47,0.76,170)
mt_merge(c,s,m,luma=false,Y=3,U=2,V=2)
return last
}
#Uband - debanding
function Uband(clip c){
nc = si_physicalcores()
O = c.bicubicresize(c.width/3,c.height/3).ex_edge(scale=3,"qprewitt").ex_expand().ex_invert().ex_levels(0,0.1,212).bicubicresize(c.width(),c.height())
N = c.fft3dfilter(sigma=0,sigma2=0,sigma3=0,sigma4=3,bt=1,plane=3,ncpu=nc).neo_f3kdb(grainY=23,grainC=3,mt=true)
M = mt_merge(c,n,o,luma=true,Y=3,U=3,V=3)
S = c.bicubicresize(c.width/4,c.height/4).greyscale().ex_levels(36,0.16,70,0,100).ex_invert().bicubicresize(c.width(),c.height())
mt_merge(c,m,s,luma=true,Y=3,U=3,V=3)
return last}
#TSMC - mocomped temporalsoften
# TSMC (Temporal Soften Motion Compensated) by althor1138 (18-03-2021)
#
# TSMC mod by Dogway (26-08-2021)
# -Optimization for UHD clips
# -Higher defaults
# -Tweaked settings (mt, levels, truemotion, chroma)
function TSMC(clip input, int "tradius", int "mthresh", int "lumathresh", int "blocksize",clip "auxclip", bool "pref", int "Y", int "UV")
{
pref = Default(pref, true)
Y = Default(Y, 3)
UV = Default(UV, 2)
t=Defined(tradius)
tradius=t ? tradius : 6
# temporal radius-number of frames analyzed before/after current frame.
m=Defined(mthresh)
mthresh=m ? mthresh : 180
# motion threshold-higher numbers denoise areas with higher motion.
#Anything above this number does not get denoised.
l=Defined(lumathresh)
lumathresh=l ? lumathresh : 255
# luma threshold- Denoise pixels that match in surrounding frames.
#255 is the maximum and default. 0-255 are valid numbers.
#Also adjusts chroma threshold.
b=Defined(blocksize)
blocksize=b ? blocksize : 16
#larger numbers = faster processing times
chroma = UV == 3
aux=Defined(auxclip)
w = width(input)
h = height(input)
isUHD = (w > 2599 || h > 1499)
nw = round(w/2.0)
nh = round(h/2.0)
inputA = aux ? auxclip : input
inputA = isUHD ? inputA.ConvertBits(8,dither=-1).BilinearResize(nw+nw%2, nh+nh%2) : inputA
super = MSuper(input, pel=1, hpad = 0, vpad = 0, chroma=true, mt=true, levels=1)
superfilt = MSuper(inputA,pel=1, hpad = 0, vpad = 0, chroma=true, mt=true) # bug can't disable chroma otherwise luma isn't processed
vmulti = Manalyse(superfilt,multi=true,delta=tradius,temporal=true,truemotion=true,blksize=blocksize,overlap=blocksize/2, mt=true, chroma=true)
vmulti2 = Mrecalculate(superfilt,vmulti,thsad=mthresh,truemotion=true,tr=tradius,blksize=blocksize/2,overlap=blocksize/4, mt=true, chroma=true)
vmulti2 = isUHD ? vmulti2.MScaleVect() : vmulti2
mocomp = Mcompensate(input,super,vmulti2,thsad=mthresh,tr=tradius,center=true,mt=true) # recursion=50 is bugged
dnmc = mocomp.temporalsoften(tradius,lumathresh,lumathresh,15,2)
dec = selectevery(dnmc,tradius * 2 + 1,tradius)
Y != 3 ? input.mergechroma(dec) : dec }
ConverttoYUV444()
Convertbits(10,dither=1)
Prefetch (SI_PhysicalCores ())
I output to prores444 10-bit UHD through ffmpeg. (Maybe this is a bottleneck?)
Test clips:
https://we.tl/t-O3jvjqBWAN