Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import vapoursynth as vs
- import sys, os
- import functools
- sys.path.append(os.getenv('APPDATA') + r"\VapourSynth\scripts")
- import audiocutter
- import havsfunc as has
- import resamplehq as rhq
- import fvsfunc as fvf
- import mvsfunc as mvf
- import ivtc_txt60mc_fast as ivtc
- def fancy_ivtc(ac, idx, pattern, draft_in=False):
- raw_seg = ac.get_segment(idx)
- cleaned = fancy_ivtc_range(raw_seg, pattern, draft_in)
- ac.write_segment(idx, cleaned)
- def fancy_ivtc_adv(ac, idx, patterns=[(0,0,-1)], draft_in=False):
- raw_seg = ac.get_segment(idx)
- if(not isinstance(patterns, (list, tuple))):
- ac.write_segment(idx, core.text.Text(raw_seg, "Did not pass a list of lists/tuples to split()", 5))
- return
- else:
- for ptn in patterns:
- if (not isinstance(ptn, (list, tuple))):
- ac.write_segment(idx, core.text.Text(raw_seg, "One or more trims is not a list/tuple", 5))
- return
- matched = []
- if patterns[len(patterns)-1][2] < 0:
- last_ptn = patterns.pop()
- start, end, _ = last_ptn
- if end == 0:
- end = None
- else:
- end += 1
- seg = raw_seg[start:end]
- ac.write_segment(idx, core.text.Text(seg, 'in the -1 state',5))
- return
- else:
- for ptn in patterns:
- start, end, pt = ptn
- if end == 0:
- end = None
- else:
- end += 1
- seg = raw_seg[start:end]
- cleaned = fancy_ivtc_range(seg, pt, draft_in)
- matched.append(cleaned)
- ac.write_segment(idx, core.std.Splice(matched))
- def fancy_ivtc_range(raw_seg, pattern, draft_in=False):
- regular = fvf.JIVTC(raw_seg, pattern, draft=draft_in, thr=15, tff=True)
- cdec = core.tdm.IsCombed(regular)
- overlaid = ivtc.ivtc_txt60mc(raw_seg, pattern, tff=True, draft=draft_in)
- return core.std.FrameEval(regular, functools.partial(pick_overlay, regular=regular, overlaid=overlaid), cdec)
- def pick_overlay(n, f, regular, overlaid):
- if f.props._Combed:
- return overlaid#.text.Text('overlay', 5)
- else:
- return regular#.text.Text('norm', 5)
- def generate_collage(c_in, bc):
- five_pct = core.std.SelectEvery(c_in, 20, 0)
- mod_five = five_pct.num_frames % 5
- if mod_five:
- five_pct = five_pct + bc * (5 - mod_five)
- i = 0
- rows = []
- while i < five_pct.num_frames:
- a_row_single = five_pct[i:i+5]
- a_row = core.std.StackHorizontal([*a_row_single])
- rows.append(a_row)
- i += 5
- return core.std.StackVertical(rows)
- def generate_comb_checks(c_in, segment, last_uncombed):
- shrunk = core.resize.Point(c_in, 180,136).text.FrameNum(5)
- bc = core.std.BlankClip(shrunk, length=1)
- first_combed = core.std.SelectEvery(shrunk, 5, last_uncombed+1)
- sec_combed = core.std.SelectEvery(shrunk, 5, last_uncombed+2)
- collages = generate_collage(first_combed, bc) + generate_collage(sec_combed, bc)
- filename = 'segment-{}-%d.png'.format(segment)
- rgb = core.resize.Bicubic(collages, format=vs.RGB24, matrix_in_s="709")
- return core.imwri.Write(rgb, 'PNG', filename, overwrite=True)
- core = vs.get_core()
- # ts_file = "JINGA - 01 (BS11).d2v"
- ts_file = "神ノ牙-JINGA- episode 12 (BS11 MPEG2-TS 1920x1080 281218)_HD.ts"
- ts_in = core.lsmas.LWLibavSource(ts_file)
- # ts_in = core.d2v.Source(ts_file, nocrop=False)
- ac = audiocutter.AudioCutter()
- #OP: ~1795
- #OChris: 299
- #Part B to PV: 1800
- #PV: ~450
- # (912, 3013), (4810, 31392), (33187, 48263), (51261, 54860)
- # ts_in = core.text.FrameNum(ts_in, 5)
- # dec = ts_in
- vid = ac.split(ts_in, [(912,2709, 'Opening'), (4808,31390, 'Part A'), (33190,48263, 'Part B')], join=False)#, doublecheck=True)
- # dec = vid
- # dec = ac.get_segment(3) # 102
- # dec = generate_comb_checks(dec, 3, 2)
- # # IVTC block
- fancy_ivtc(ac, 0, 1)
- fancy_ivtc(ac, 1, 0)
- fancy_ivtc(ac, 2, 2)
- # fancy_ivtc(ac, 3, )
- # fancy_ivtc(ac, 4, )
- dec = ac.join(update_framerate=True)
- ac.ready_qp_and_chapters(dec)
- dlg = core.delogo.EraseLogo(dec, 'bs11-4.lgd')
- clean = has.logoNR(dlg,dec)
- dec = core.remap.Rfs(clean, dec, mappings="[1414 1438] [22681 22704]")
- dec = core.std.Crop(dec, 2,2,0,0)
- dec = core.resize.Bicubic(dec, format=vs.YUV420P16)
- dec = has.SMDegrain(dec, tr=2, contrasharp=True, prefilter=4, thSAD=250)
- dec = core.resize.Bicubic(dec, format=vs.YUV420P10, dither_type="ordered")
- # dec = core.resize.Bicubic(dec, format=vs.RGB48, matrix_in_s="709")
- dec.set_output()
- if __name__ == "__main__":
- prefix = os.path.splitext(__file__)[0]
- ac.cut_audio(prefix + '_aud.mka', video_source=ts_file)
- ac.write_qpfile(prefix + ".qpfile")
- ac.write_chapters(prefix + "-ch.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement