Zastin

SEND BOBS

Aug 17th, 2020 (edited)
1,451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.43 KB | None | 0 0
  1. # 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
  2. # I have very little idea what the optimal radius setting is but its almost certainly higher than what I used which is 5
  3. # supply i.e. dehardsubbed AoD as "alt" because I assume the shitty web source would be a better reference
  4. # min_length ideally removes any string of positive (censored) frames shorter than x
  5. # in reality it checks whether the temporal neighborhood has a majority of positive frames (50% or more in x * 2 + 1)
  6. # so if you have for example a repeating sequence of 2 positive, one negative it wont do anything
  7. # should help with motion artifacts or, god rest your soul, if you use TIVTC or share raws
  8. # 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
  9. # if you use this filter on its own I'd recommend setting it to at least 3 and/or lower thr
  10. # no float clips
  11.  
  12. import vapoursynth as vs
  13.  
  14. def decensor(cr, atx, radius, min_length=0, smooth=0, thr=None, bordfix=10, alt=None, unfuck_mpeg2=None, debug=False):
  15.     from vsutil import split, fallback, iterate
  16.     core = vs.core
  17.    
  18.     fmt = cr.format
  19.     peak = (1 << fmt.bits_per_sample) - 1
  20.     thr = fallback(thr, 24 << (fmt.bits_per_sample - 8))
  21.     alt = fallback(alt, cr)
  22.    
  23.     clip = core.std.Expr([cr, atx], 'x y - abs').std.Binarize(thr)
  24.     clip = core.resize.Point(clip, format=fmt.replace(subsampling_w=0, subsampling_h=0).id)
  25.     clip = core.std.Expr(split(clip), 'x y z max max')
  26.     clip = iterate(clip, core.std.Minimum, radius)
  27.    
  28.     def binarize_frame(n, f, clip=clip): return core.std.BlankClip(clip, 1, 1, color=peak if f.props.PlaneStatsMax else 0)
  29.    
  30.     prop_src = clip.std.Crop(bordfix,bordfix,bordfix,bordfix).std.PlaneStats()
  31.     clip = core.std.FrameEval(core.std.BlankClip(clip, 1, 1), binarize_frame, prop_src=prop_src)
  32.    
  33.     if min_length == 2:
  34.         med = clip.tmedian.TemporalMedian(1) # faster than Clense
  35.         clip = core.std.Expr([clip, med], 'x y min')
  36.     if min_length > 2:
  37.         avg = core.misc.AverageFrames(clip, [1] * ((min_length * 2) + 1)).std.Binarize(peak//2)
  38.         clip = core.std.Expr([clip, avg], 'x y min')
  39.     if smooth > 0:
  40.         # this thing is in alpha stage, dont be surprised if trying to use other zzf stuff explodes your computer
  41.         import zzfunc as zzf # https://github.com/kgrabs/zzfunc/tree/master/zzfunc
  42.         clip = zzf.shiftframes(clip, [-smooth, smooth])
  43.         clip = zzf.combine(clip)
  44.         clip = core.misc.AverageFrames(clip, [1] * ((smooth * 2) + 1))
  45.    
  46.     if unfuck_mpeg2 is not None:
  47.         atx = unfuck_mpeg2(atx)
  48.    
  49.     if debug:
  50.         alt = alt.text.Text('Family Friendly')
  51.         atx = atx.text.Text('SEND BOBS AND VAGENE')
  52.    
  53.     def _merge_tits(n, f):
  54.         weight = f.props.PlaneStatsMax
  55.         if weight == peak:
  56.             return atx
  57.         if weight == 0:
  58.             return alt
  59.         return core.std.Merge(alt, atx, weight/peak)
  60.        
  61.     return core.std.FrameEval(alt, _merge_tits, prop_src=clip.std.PlaneStats())
  62.  
  63. from fvsfunc import AutoDeblock
  64. from havsfunc import FineDehalo, HQDeringmod
  65.  
  66. def mpegnated(clip):
  67.     clip = AutoDeblock(clip)
  68.     clip = FineDehalo(clip, rx=3, ry=3, darkstr=0.1, brightstr=0.75)
  69.     return HQDeringmod(clip, mrad=3, msmooth=3)
  70.  
  71. decensor(cr, atx, radius=5, alt=aod, unfuck_mpeg2=mpegnated)
Add Comment
Please, Sign In to add comment