HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
John does this meet with your approval [dated 30 Oct 2021, about 40 mins from now].
Code:
#########################################################################################
#
# FillDrops.avsi
#
# An AviSynth filter to detect and replace duplicate frames
# with a motion-interpolation of the adjacent frames.
#
# mod 2021-07-10 by Selur
# mod 29 Oct 2021, Added ThreshIs8Bit arg. ssS. https://forum.doom9.org/showthread.php?p=1956020#post1956020
# mod 30 Oct 2021, ssS:- https://forum.doom9.org/showthread.php?p=1956096#post1956096
# Corrected original odd Delta=1 to Delta=2 (see:- https://forum.doom9.org/showthread.php?p=1409378#post1409378 )
# Added ShowDot, arg.
#
# - based on Mug Funky's FillDrops
# - FillDrops by johnmeyer on Doom9's forum
# https://forum.doom9.org/showthread.php?p=1775184#post1775184
# - mod by Selur to parametrize Luma Difference Threshold
# https://forum.videohelp.com/threads/402416-repair-Videos-with-duplicates-and-dropped-frames#post2624936
#
### Requirements ###
#-------------------
# Avs v2.60/+
# MvTools2 (https://github.com/pinterf/mvtools)
#
### Arguments ###
#-----------------
# thresh (default=0.1) - Luma Difference Threshold
# Lets you specify how different a frame has to be (from the previous frame)
# before it's considered not to be a duplicate, and therefore not replaced with a motion interpolated frame.
# If the threshold is too small, some duplicate will not be replaced.
# If it's too large, many frames which aren't duplicates (just having very small motions) will be replaced.
# (explanation by jagabo on VideoHelp)
#
# ---------------
# ThreshIs8Bit, Default False, If True and bit depth > 8 bit, then thresh is converted to current bit depth threshold.
### Changelog ###
#---------------
# ShowDot, If True, Subtitle "*" on frame Bottom Left of interpolated frames. [Interlaced Even field "*-" and Odd field "-*"]
#---------------
# Changed requirements: from MvTools to MvTools2 (johnmeyer)
# Parametrized Luma Difference Threshold (Selur)
# ssS: Added Bool arg "ThreshIs8Bit", default = False. Added ShowDot default False.
#########################################################################################
Function FillDrops (clip c, float "thresh",Bool "ThreshIs8Bit",Bool "ShowDot") {
thresh = Default(thresh, 0.1)
ThreshIs8Bit = Default(ThreshIs8Bit,False) # False = thresh is in current bit depth range
ShowDot = Default(ShowDot,false)
try { bpc=c.BitsPerComponent } catch(msg) { bpc=8 }
thresh = (ThreshIs8Bit) ? thresh * BitLShift(1,bpc-8) : thresh
super = MSuper(c, pel=2,hpad=16,vpad=16,sharp=1,rfilter=4)
vfe = MAnalyse(super, truemotion=true, isb=false, delta=2,blksize=16,blksizeV=16,Overlap=8,OverlapV=8,search=4, dct=0)
vbe = MAnalyse(super, truemotion=true, isb=true, delta=2,blksize=16,blksizeV=16,Overlap=8,OverlapV=8,search=4, dct=0)
filldrops = MFlowInter(c, super, vbe, vfe, time=50,blend=false) # Dont blend at scene change : Generate interpolated frame n at filldrops frame n-1.
# SHIFT n-1 to frame n, and Maintain original length, ConditionalFilter returns length of 2nd (filldrops) clip.
filldrops = filldrops.DuplicateFrame(0).DeleteFrame(c.FrameCount)
filldrops = (ShowDot) ? filldrops.Subtitle("*",align=1,font="Courier New") : filldrops # If ShowDot, then subtitle Single asterisk at bottom left.
fixed = ConditionalFilter(c, filldrops, c, "YDifferenceFromPrevious()", "lessthan", String(thresh))
return fixed.AudioDubEx(c) # ConditionalFilter returns audio from filldrops clip which is shifted. [Should not be necessary, Safety Measure only]
}
Function FilldropsI (clip c, float "thresh",Bool "ThreshIs8Bit",Bool "ShowDot") {
thresh = Default(thresh, 0.1)
ThreshIs8Bit = Default(ThreshIs8Bit,False) # False = thresh is in current bit depth range
ShowDot = Default(ShowDot,false)
try { bpc=c.BitsPerComponent } catch(msg) { bpc=8 }
thresh = (ThreshIs8Bit) ? thresh * BitLShift(1,bpc-8) : thresh
#
even = c.SeparateFields().SelectEven()
super_even=MSuper(even,pel=2,hpad=16,vpad=8,sharp=1,rfilter=4)
vfe=manalyse(super_even,truemotion=true,isb=false,delta=2,blksize=16,blksizeV=8,Overlap=8,OverlapV=4,search=4, dct=0)
vbe=manalyse(super_even,truemotion=true,isb=true, delta=2,blksize=16,blksizeV=8,Overlap=8,OverlapV=4,search=4, dct=0)
filldrops_e = mflowinter(even,super_even,vbe,vfe,time=50,blend=false) # dont blend at scene change
filldrops_e = filldrops_e.DuplicateFrame(0).DeleteFrame(c.FrameCount)
filldrops_e = (ShowDot) ? filldrops_e.Subtitle("*-",align=1,font="Courier New") : filldrops_e # EVEN, If ShowDot, then subtitle asterisk + hyphen (*-) at bottom left.
#
odd = c.SeparateFields().SelectOdd()
super_odd=MSuper(odd,pel=2,hpad=16,vpad=8,sharp=1,rfilter=4)
vfo=manalyse(super_odd,truemotion=true,isb=false,delta=2,blksize=16,blksizeV=8,Overlap=8,OverlapV=4,search=4, dct=0)
vbo=manalyse(super_odd,truemotion=true,isb=true, delta=2,blksize=16,blksizeV=8,Overlap=8,OverlapV=4,search=4, dct=0)
filldrops_o = mflowinter(odd,super_odd,vbo,vfo,time=50,blend=false) # dont blend at scene change
filldrops_o = filldrops_o.DuplicateFrame(0).DeleteFrame(c.FrameCount)
filldrops_o = (ShowDot) ? filldrops_o.Subtitle("-*",align=1,font="Courier New") : filldrops_o # ODD, If ShowDot, then subtitle hyphen + asterisk (-*) at bottom left.
#
evenfixed = ConditionalFilter(even, filldrops_e, even, "YDifferenceFromPrevious()", "lessthan", String(thresh))
oddfixed = ConditionalFilter(odd, filldrops_o, odd, "YDifferenceFromPrevious()", "lessthan", String(thresh))
Interleave(evenfixed,oddfixed)
Weave()
return Last.AudioDubEx(c) # ConditionalFilter returns audio from filldrops clip which is shifted. [Should not be necessary, Safety Measure only]
}
EDIT:
I've used eg BlkSize=16, BlkSizeV=8, Overlap=8,OverlapV=4, for Interlaced, is that OK. [I get rid of interlaced stuff at earliest opportunity]
Also Added a ShowDot whatsit [EDIT: At Bottom left, to distinguish from other ShowDots, Interlaced showdot different for Even/Odd].
Last edited by StainlessS; 29th October 2021 at 23:54.
|