rendered paste body###############################################################################################################
#
# Smartfade v0.1
#
# Aimed at removing interlaced fades in anime. Uses luma difference between two fields as activation threshold.
#
# Parameters:
#
# threshold (default: 0.4): Threshold for fade detection.
# tempsmooth (default: false): Enables temporalsoften on anything but fades (temporalsoften tends to create
# artifacts in fades).
# show (default: false): Displays luma difference between fields without processing anything.
#
###############################################################################################################
loadplugin("lmflicker.dll")
loadplugin("degrainmedian.dll")
loadplugin("convolution3d.dll")
loadplugin("sangnom.dll")
function smartfade(clip clip, float "threshold", bool "tempsmooth", bool "show") {
global threshold = default(threshold,0.4)
global tempsmooth = default(tempsmooth,false)
show = default(show,false)
global c = clip.isYV12() ? clip : clip.converttoyv12()
show ? scriptclip(c, "subtitle(string(c.separatefields().selectodd().averageluma() \
- c.separatefields().selecteven().averageluma()))") : \
scriptclip(c, "sep = c.separatefields() \
avg = sep.selectodd().averageluma() - sep.selecteven().averageluma() \
abs(avg) > threshold ? interleave(sep.selecteven(),sep.selectodd()). \
weave().fieldfade().lanczosresize(width(c)*2,height(c)*2).sangnom(). \
lanczosresize(width(c),height(c)).degrainmedian(mode=3).converttoyuy2(). \
convolution3d(0,floor(abs(avg/2)),0,0,0,2.8,0).converttoyv12() : \
tempsmooth ? temporalsoften(3,3,5,8,2) : last")
final = clip.isYV12() ? last : clip.isYUY2() ? converttoyuy2() : converttorgb32()
return final
}