Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this thing seems to work very well despite the fact that I barely tweaked the settings so if nothing else the underlying idea is quite solid
- # I have very little idea what the optimal radius setting is but its almost certainly higher than what I used which is 5
- # supply i.e. dehardsubbed AoD as "alt" because I assume the shitty web source would be a better reference
- # min_length ideally removes any string of positive (censored) frames shorter than x
- # in reality it checks whether the temporal neighborhood has a majority of positive frames (50% or more in x * 2 + 1)
- # so if you have for example a repeating sequence of 2 positive, one negative it wont do anything
- # should help with motion artifacts or, god rest your soul, if you use TIVTC or share raws
- # smooth is a lazy way to deal with fades by making positive frames fade into the clean video by x * 2 frames in either direction
- # if you use this filter on its own I'd recommend setting it to at least 3 and/or lower thr
- # no float clips
- import vapoursynth as vs
- def decensor(cr, atx, radius, min_length=0, smooth=0, thr=None, bordfix=10, alt=None, unfuck_mpeg2=None, debug=False):
- from vsutil import split, fallback, iterate
- core = vs.core
- fmt = cr.format
- peak = (1 << fmt.bits_per_sample) - 1
- thr = fallback(thr, 24 << (fmt.bits_per_sample - 8))
- alt = fallback(alt, cr)
- clip = core.std.Expr([cr, atx], 'x y - abs').std.Binarize(thr)
- clip = core.resize.Point(clip, format=fmt.replace(subsampling_w=0, subsampling_h=0).id)
- clip = core.std.Expr(split(clip), 'x y z max max')
- clip = iterate(clip, core.std.Minimum, radius)
- def binarize_frame(n, f, clip=clip): return core.std.BlankClip(clip, 1, 1, color=peak if f.props.PlaneStatsMax else 0)
- prop_src = clip.std.Crop(bordfix,bordfix,bordfix,bordfix).std.PlaneStats()
- clip = core.std.FrameEval(core.std.BlankClip(clip, 1, 1), binarize_frame, prop_src=prop_src)
- if min_length == 2:
- med = clip.tmedian.TemporalMedian(1) # faster than Clense
- clip = core.std.Expr([clip, med], 'x y min')
- if min_length > 2:
- avg = core.misc.AverageFrames(clip, [1] * ((min_length * 2) + 1)).std.Binarize(peak//2)
- clip = core.std.Expr([clip, avg], 'x y min')
- if smooth > 0:
- # this thing is in alpha stage, dont be surprised if trying to use other zzf stuff explodes your computer
- import zzfunc as zzf # https://github.com/kgrabs/zzfunc/tree/master/zzfunc
- clip = zzf.shiftframes(clip, [-smooth, smooth])
- clip = zzf.combine(clip)
- clip = core.misc.AverageFrames(clip, [1] * ((smooth * 2) + 1))
- if unfuck_mpeg2 is not None:
- atx = unfuck_mpeg2(atx)
- if debug:
- alt = alt.text.Text('Family Friendly')
- atx = atx.text.Text('SEND BOBS AND VAGENE')
- def _merge_tits(n, f):
- weight = f.props.PlaneStatsMax
- if weight == peak:
- return atx
- if weight == 0:
- return alt
- return core.std.Merge(alt, atx, weight/peak)
- return core.std.FrameEval(alt, _merge_tits, prop_src=clip.std.PlaneStats())
- from fvsfunc import AutoDeblock
- from havsfunc import FineDehalo, HQDeringmod
- def mpegnated(clip):
- clip = AutoDeblock(clip)
- clip = FineDehalo(clip, rx=3, ry=3, darkstr=0.1, brightstr=0.75)
- return HQDeringmod(clip, mrad=3, msmooth=3)
- decensor(cr, atx, radius=5, alt=aod, unfuck_mpeg2=mpegnated)
Add Comment
Please, Sign In to add comment