Advertisement
AzraelNewtype

JINGA 12

Jan 7th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.73 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import vapoursynth as vs
  4. import sys, os
  5. import functools
  6. sys.path.append(os.getenv('APPDATA') + r"\VapourSynth\scripts")
  7. import audiocutter
  8. import havsfunc as has
  9. import resamplehq as rhq
  10. import fvsfunc as fvf
  11. import mvsfunc as mvf
  12. import ivtc_txt60mc_fast as ivtc
  13.  
  14. def fancy_ivtc(ac, idx, pattern, draft_in=False):
  15.     raw_seg = ac.get_segment(idx)
  16.     cleaned = fancy_ivtc_range(raw_seg, pattern, draft_in)
  17.     ac.write_segment(idx, cleaned)
  18.  
  19. def fancy_ivtc_adv(ac, idx, patterns=[(0,0,-1)], draft_in=False):
  20.     raw_seg = ac.get_segment(idx)
  21.     if(not isinstance(patterns, (list, tuple))):
  22.         ac.write_segment(idx, core.text.Text(raw_seg, "Did not pass a list of lists/tuples to split()", 5))
  23.         return
  24.     else:
  25.         for ptn in patterns:
  26.             if (not isinstance(ptn, (list, tuple))):
  27.                 ac.write_segment(idx, core.text.Text(raw_seg, "One or more trims is not a list/tuple", 5))
  28.                 return
  29.  
  30.     matched = []
  31.     if patterns[len(patterns)-1][2] < 0:
  32.         last_ptn = patterns.pop()
  33.         start, end, _ = last_ptn
  34.         if end == 0:
  35.             end = None
  36.         else:
  37.             end += 1
  38.         seg = raw_seg[start:end]
  39.         ac.write_segment(idx, core.text.Text(seg, 'in the -1 state',5))
  40.         return
  41.     else:
  42.         for ptn in patterns:
  43.             start, end, pt = ptn
  44.             if end == 0:
  45.                 end = None
  46.             else:
  47.                 end += 1
  48.             seg = raw_seg[start:end]
  49.             cleaned = fancy_ivtc_range(seg, pt, draft_in)
  50.             matched.append(cleaned)
  51.         ac.write_segment(idx, core.std.Splice(matched))
  52.    
  53. def fancy_ivtc_range(raw_seg, pattern, draft_in=False):
  54.     regular = fvf.JIVTC(raw_seg, pattern, draft=draft_in, thr=15, tff=True)
  55.     cdec = core.tdm.IsCombed(regular)
  56.     overlaid = ivtc.ivtc_txt60mc(raw_seg, pattern, tff=True, draft=draft_in)
  57.     return core.std.FrameEval(regular, functools.partial(pick_overlay, regular=regular, overlaid=overlaid), cdec)
  58.  
  59. def pick_overlay(n, f, regular, overlaid):
  60.     if f.props._Combed:
  61.         return overlaid#.text.Text('overlay', 5)
  62.     else:
  63.         return regular#.text.Text('norm', 5)
  64.  
  65. def generate_collage(c_in, bc):
  66.     five_pct = core.std.SelectEvery(c_in, 20, 0)
  67.     mod_five = five_pct.num_frames % 5
  68.     if mod_five:
  69.         five_pct = five_pct + bc * (5 - mod_five)
  70.     i = 0
  71.     rows = []
  72.     while i < five_pct.num_frames:
  73.         a_row_single = five_pct[i:i+5]
  74.         a_row = core.std.StackHorizontal([*a_row_single])
  75.         rows.append(a_row)
  76.         i += 5
  77.     return core.std.StackVertical(rows)
  78.    
  79. def generate_comb_checks(c_in, segment, last_uncombed):
  80.     shrunk = core.resize.Point(c_in, 180,136).text.FrameNum(5)
  81.     bc = core.std.BlankClip(shrunk, length=1)
  82.     first_combed = core.std.SelectEvery(shrunk, 5, last_uncombed+1)
  83.     sec_combed = core.std.SelectEvery(shrunk, 5, last_uncombed+2)
  84.    
  85.     collages = generate_collage(first_combed, bc) + generate_collage(sec_combed, bc)
  86.     filename = 'segment-{}-%d.png'.format(segment)
  87.     rgb = core.resize.Bicubic(collages, format=vs.RGB24, matrix_in_s="709")
  88.     return core.imwri.Write(rgb, 'PNG', filename, overwrite=True)
  89.  
  90.  
  91. core = vs.get_core()
  92.  
  93. # ts_file = "JINGA - 01 (BS11).d2v"
  94. ts_file = "神ノ牙-JINGA- episode 12 (BS11 MPEG2-TS 1920x1080 281218)_HD.ts"
  95. ts_in = core.lsmas.LWLibavSource(ts_file)
  96. # ts_in = core.d2v.Source(ts_file, nocrop=False)
  97. ac = audiocutter.AudioCutter()
  98.  
  99. #OP: ~1795
  100. #OChris: 299
  101. #Part B to PV: 1800
  102. #PV: ~450
  103. # (912, 3013), (4810, 31392), (33187, 48263), (51261, 54860)
  104. # ts_in = core.text.FrameNum(ts_in, 5)
  105.  
  106. # dec = ts_in
  107. vid = ac.split(ts_in, [(912,2709, 'Opening'), (4808,31390, 'Part A'), (33190,48263, 'Part B')], join=False)#, doublecheck=True)
  108. # dec = vid
  109.  
  110. # dec = ac.get_segment(3) # 102
  111. # dec = generate_comb_checks(dec, 3, 2)
  112.  
  113. # # IVTC block
  114. fancy_ivtc(ac, 0, 1)
  115. fancy_ivtc(ac, 1, 0)
  116. fancy_ivtc(ac, 2, 2)
  117. # fancy_ivtc(ac, 3, )
  118. # fancy_ivtc(ac, 4, )
  119. dec = ac.join(update_framerate=True)
  120. ac.ready_qp_and_chapters(dec)
  121.  
  122. dlg = core.delogo.EraseLogo(dec, 'bs11-4.lgd')
  123. clean = has.logoNR(dlg,dec)
  124. dec = core.remap.Rfs(clean, dec, mappings="[1414 1438] [22681 22704]")
  125.  
  126. dec = core.std.Crop(dec, 2,2,0,0)
  127. dec = core.resize.Bicubic(dec, format=vs.YUV420P16)
  128. dec = has.SMDegrain(dec, tr=2, contrasharp=True, prefilter=4, thSAD=250)
  129. dec = core.resize.Bicubic(dec, format=vs.YUV420P10, dither_type="ordered")
  130. # dec = core.resize.Bicubic(dec, format=vs.RGB48, matrix_in_s="709")
  131.  
  132. dec.set_output()
  133.  
  134. if __name__ == "__main__":
  135.     prefix = os.path.splitext(__file__)[0]
  136.     ac.cut_audio(prefix + '_aud.mka', video_source=ts_file)
  137.     ac.write_qpfile(prefix + ".qpfile")
  138.     ac.write_chapters(prefix + "-ch.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement