Advertisement
AzraelNewtype

31.vpy

Apr 21st, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.57 KB | None | 0 0
  1. import sys, os
  2. sys.path.append(os.getenv('APPDATA') + r"\VapourSynth\scripts")
  3. import vapoursynth as vs
  4. import havsfunc as haf
  5. from fractions import Fraction
  6.  
  7.  
  8. def select30(vid, start, end, a=0, b=0, c=0, d=0, show=None):
  9.     core = vs.get_core()
  10.     if end == 0:
  11.         end = vid.num_frames - 1
  12.     return vid[start:end+1:2]
  13.    
  14. def select60(vid, start, end, a=0, b=0, c=0, d=0, show=None):
  15.     core = vs.get_core()
  16.     if end == 0:
  17.         end = vid.num_frames - 1
  18.     return vid[start:end+1]
  19.    
  20. def select24_naive(vid, start, end, a=0, b=0, c=0, d=0, show=None):
  21.     core = vs.get_core()
  22.     v2 = vid[start:end+1]
  23.     return core.std.SelectEvery(v2, 10, [a,b,c,d])
  24.    
  25. def select24(vid, start, end, a=0, b=0, c=0, d=0, show=None):
  26.     core = vs.get_core()
  27.     if end == 0:
  28.         end = vid.num_frames - 1
  29.     vclip = vid[start:end+1]
  30.     if not show or show == 1:
  31.         if vclip.num_frames % 10 == 0:
  32.             return select24_naive(vid, start, end, a, b, c, d)
  33.         else:
  34.             split_point = vclip.num_frames - (vclip.num_frames % 10)
  35.             round_part = vclip[:split_point]
  36.             messy_part = vclip[split_point:]
  37.             clean_picked = core.std.SelectEvery(round_part, 10, [a,b,c,d])
  38.             messy_picked = core.std.SelectEvery(messy_part, 10, [a,b,c,d])
  39.             inframes = messy_part.num_frames
  40.             vid_spf = Fraction(1001, 60000)
  41.             new_spf = vid_spf * inframes / messy_picked.num_frames
  42.             messy_picked =  core.std.AssumeFPS(messy_picked, fpsnum=new_spf.denominator,
  43.                                                fpsden=new_spf.numerator)
  44.             return core.std.Splice([clean_picked, messy_picked])
  45.     elif show == 4:
  46.         return show4(vclip, a, b, c, d).text.Text('{}-{}: {},{},{},{}'.format(start,end,a,b,c,d), 9)
  47.     elif show == 10:
  48.         return show10(vclip, a, b, c, d)
  49.     else:
  50.         return core.text.Text(vid, 'Invalid value for "show"')
  51.  
  52.  
  53. def select24blur(vid, start, end):
  54.     core = vs.get_core()
  55.     trimmed = vid[start:end+1]
  56.     super = core.mv.Super(trimmed)
  57.     bvec = core.mv.Analyse(super, isb=True, delta=2)
  58.     fvec = core.mv.Analyse(super, delta=2)
  59.     blur = core.mv.FlowBlur(trimmed, super, bvec, fvec, blur=105)
  60.     flowed = core.mv.FlowFPS(blur, super, bvec, fvec, num=24000, den=1001)
  61.     return flowed
  62.        
  63. def show10(vid, a, b, c, d):
  64.     core = vs.get_core()
  65.     w_out = int(vid.width * .6)
  66.     h_out = int(vid.height * .6)
  67.     if w_out % 2 == 1:
  68.         w_out += 1
  69.     if h_out % 2 == 1:
  70.         h_out += 1
  71.     svid = core.resize.Bilinear(vid, w_out, h_out, filter_param_a=-.5, filter_param_b=0.25)
  72.     splitframes = []
  73.     for i in range(10):
  74.         splitframes.append(core.std.SelectEvery(svid, 10, i))
  75.     bclip = core.std.BlankClip(splitframes[0])
  76.     splitframes[a] = highlight_edge(splitframes[a])
  77.     splitframes[b] = highlight_edge(splitframes[b])
  78.     splitframes[c] = highlight_edge(splitframes[c])
  79.     splitframes[d] = highlight_edge(splitframes[d])
  80.     r1 = core.std.StackHorizontal(splitframes[0:4])
  81.     r2 = core.std.StackHorizontal(splitframes[4:7] + [bclip])
  82.     r3 = core.std.StackHorizontal(splitframes[7:10] + [bclip])
  83.     return core.std.StackVertical([r1,r2,r3])
  84.  
  85. def highlight_edge(vid):
  86.     core = vs.get_core()
  87.     return core.std.CropRel(vid, 6,6,4,4).std.AddBorders(6,6,4,4, [19456,21504,65535])
  88.    
  89. def show4(vid, a, b, c, d):
  90.     core = vs.get_core()
  91.     fa = core.std.SelectEvery(vid, 10, a).text.Text(str(a))
  92.     fb = core.std.SelectEvery(vid, 10, b).text.Text(str(b))
  93.     fc = core.std.SelectEvery(vid, 10, c).text.Text(str(c))
  94.     fd = core.std.SelectEvery(vid, 10, d).text.Text(str(d))
  95.    
  96.     t = core.std.StackHorizontal([fa, fb])
  97.     b = core.std.StackHorizontal([fc, fd])
  98.     return core.std.StackVertical([t, b])
  99.    
  100. def zoom(vid, l, t, r, b):
  101.     core = vs.get_core()
  102.     w_out = vid.width - l - abs(r)
  103.     h_out = vid.height - t - abs(b)
  104.     return core.resize.Spline36(vid, src_top=t, src_left=l, src_width=w_out, src_height=h_out)
  105.  
  106. def manual_frame_adjust(raw, picked):
  107.     core = vs.get_core()
  108.     vid_spf = Fraction(1001, 60000)
  109.     new_spf = vid_spf * raw.num_frames / picked.num_frames
  110.     #print(new_spf)
  111.     #return(core.text.Text(picked, str(new_spf.denominator)))
  112.     return core.std.AssumeFPS(picked, fpsnum=new_spf.denominator, fpsden=new_spf.numerator)
  113.  
  114.  
  115.  
  116. core = vs.get_core()
  117.  
  118. vid = core.lsmas.LWLibavSource('disc7.mkv')
  119.  
  120. vid = vid[0:43310]
  121.  
  122. # vid = core.tcomb.TComb(vid, mode=2)
  123. # vid = core.nnedi3.nnedi3(vid, field=3)
  124. vid = haf.QTGMC(vid, Preset="very slow", TFF=True, Denoiser="dfttest")
  125. # vid = core.std.SetFieldBased(vid, 0)
  126.  
  127. #vid = core.lsmas.LibavSMASHSource("30_lossless_bobbed.mp4")
  128.  
  129. #vid = core.resize.Bilinear(vid, format=vs.YUV420P16)
  130.  
  131. vid = core.std.CropRel(vid, 4, 12, 6, 0)
  132.  
  133. oin = vid[:5156]#.text.FrameNum(5)
  134. ain = vid[5156:42920]#.text.FrameNum(5)
  135. bin = vid[42920:80864]#.text.FrameNum(5)
  136. ein = vid[80864:85720]#.text.FrameNum(5)
  137. pin = vid[85720:]#.text.FrameNum(5)
  138.  
  139. op = []
  140. op.append(select30(oin, 0,179))
  141. op.append(zoom(select24(oin, 180,1649, 1,3,5,9), 2, 2, -2, -3))
  142. op.append(zoom(select24(oin, 1650, 1833, 1, 3, 5, 7), 0, 0, 0, 0)) # 3.070
  143. op.append(select30(oin, 1834, 1905))
  144. op.append(select24(oin, 1906, 2081, 0, 2, 4, 8))
  145. op.append(select30(oin, 2082, 2133))
  146. op.append(select24(oin, 2134, 2343, 0, 2, 4, 6))
  147. op.append(select30(oin, 2344, 2403))
  148. op.append(select24(oin, 2404, 2477, 0, 2, 4, 6))
  149. op.append(select24(oin, 2478, 2653, 0, 2, 4, 8))
  150. op.append(zoom(select30(oin, 2654, 2695), 12, 0, 0, -13))
  151. op.append(select24(oin, 2696,2759,0,2,4,8))
  152. op.append(select24(oin, 2760, 2931, 0, 2, 4, 6))
  153. op.append(select30(oin, 2932, 2981))
  154. op.append(select24(oin, 2982, 3053, 0, 2, 4, 6))
  155. r = oin[3054:3125]
  156. swoop_a = core.std.SelectEvery(r, 10, [1,2,4,6,8,9])
  157. op.append(manual_frame_adjust(r, swoop_a))
  158. r = oin[3126:3139]
  159. swoop_b = core.std.SelectEvery(r, 10, [1,2,4,6,7,9])
  160. op.append(manual_frame_adjust(r, swoop_b))
  161. r = oin[3140:3208]
  162. runner = core.std.DeleteFrames(r, [3,4,7,8,11,12,15,16,18,20,23,24,27,28,30,32,34,36,38,40,42,44,46,48,51,52,54,56,58,60,62,64,66])
  163. op.append(manual_frame_adjust(r, runner))
  164. op.append(select30(oin, 3210, 3255))
  165. op.append(select24(oin, 3256,3475, 0,3,5,8)) #check me
  166. op.append(select24(oin, 3476,3643, 2,4,6,8))
  167. op.append(select30(oin, 3644, 3783))
  168. op.append(select24(oin, 3784,3915, 0,4,6,8))
  169. op.append(select24(oin, 3916,3999, 0,2,4,8))
  170. op.append(select24(oin, 4000,4107, 0,2,6,8))
  171. op.append(select30(oin, 4108,4181))
  172. op.append(select24(oin, 4182,4209, 0,2,4,6))
  173. op.append(select24(oin, 4210,4311, 0,2,4,8))
  174. op.append(select24(oin, 4312,4629, 0,2,4,6))
  175. op.append(zoom(select24(oin, 4630,0, 0,2,4,6), 2,0,-2,-4))
  176.  
  177.  
  178. oout = core.std.Splice(op, mismatch=True)
  179. oout = core.std.FreezeFrames(oout, [58], [89], [76])
  180. vid = oout
  181.  
  182.  
  183. # apart = []
  184. aout = select24(ain, 0,0, 2,4,7,9)
  185. # aout = core.std.Splice(apart, mismatch=True)
  186. aout = core.std.FreezeFrames(aout, [2033,2323,11680,11702,11716,11733,15090], [2055,2404,11692,11707,11724,11761,15104], [2035,2325,11682,11704,11718,11736,15092])
  187.  
  188.  
  189. #bpart = []
  190. bout = select24(bin, 0,0, 2,4,7,9)
  191. # freeze starting two, ~27402, ~27607, ~30342
  192. bout = core.std.FreezeFrames(bout, [0,51,10960,11042,12136,], [26,70,10983,11061,12159], [26,53,10962,11061,12138])
  193.  
  194. ed = []
  195. ed.append(select30(ein, 0,919))
  196. ed.append(zoom(select30(ein, 920,959), 16, 0, 0, -4))
  197. ed.append(select30(ein, 960,1113))
  198. ed.append(zoom(select30(ein, 1114, 1173), 16,0,0,-5))
  199. ed.append(select30(ein, 1174, 1381))
  200. ed.append(zoom(select30(ein, 1382, 1401), 0, 0, -13, -6))
  201. ed.append(zoom(select30(ein, 1402,1441),16,0,0,-5))
  202. ed.append(select30(ein, 1442,1639))
  203. ed.append(select24(ein, 1640,2143, 1,3,7,9))
  204. ed.append(select30(ein, 2144,2665))
  205. ed.append(select24(ein, 2666,2751, 0,2,4,8))
  206. ed.append(select24(ein, 2752,2839, 1,3,5,7))
  207. ed.append(select30(ein, 2840,3293))
  208. ed.append(select24(ein, 3294,3381, 0,4,6,8))
  209. ed.append(select24(ein, 3382,3469, 0,2,4,6))
  210. ed.append(select30(ein, 3470,3887))
  211. ed.append(select24(ein, 3888,4163, 0,2,4,6))
  212. ed.append(zoom(select24(ein, 4164,4225, 0,2,4,8), 15, 0,0, -7))
  213. ed.append(zoom(select24(ein, 4226,4295, 0,2,4,6), 15, 0,0, -7))
  214. ed.append(select24(ein, 4296,4371, 0,4,6,8))
  215. ed.append(zoom(select24(ein, 4372,4443, 0,2,4,6), 16,3,0,-5))
  216. ed.append(select24(ein, 4444,4627, 0,2,4,8))
  217. ed.append(select24(ein,4628,4851, 0,2,4,6))
  218. eout = core.std.Splice(ed, mismatch=True)
  219. eout = core.std.FreezeFrames(eout, [0], [16], [2])
  220.  
  221.  
  222. pv = []
  223. pv.append(select24(pin, 0,685, 1,4,6,9))
  224. t = select60(pin, 686,759, 0,2,4,8)
  225. t2 = core.std.DeleteFrames(t, [0,2,5,6,8,10,11,13,14,15,17,19,21,22,23,25,27,28,31,33,34,36,38,39,40,42,44,45,46,48,49,51,53,55,56,57,59,61,62,64,65,66,68,70,73])
  226. inframes = t.num_frames
  227. vid_spf = Fraction(1001, 60000)
  228. new_spf = vid_spf * inframes / t2.num_frames
  229. pv.append(core.std.AssumeFPS(t2, fpsnum=new_spf.denominator, fpsden=new_spf.numerator))
  230. pv.append(select24(pin, 760,0, 2,4,7,9))
  231. pout = core.std.Splice(pv, mismatch=True)
  232. pout = core.std.FreezeFrames(pout, [357], [358], [357])
  233.  
  234. #vid = core.std.Splice([oout,aout,bout,eout,pout])
  235. #
  236. vid = core.resize.Spline36(vid, 640, 480)
  237. #vid.set_output(1)
  238. #vid = haf.SMDegrain(vid, contrasharp=True, RefineMotion=True)
  239. #
  240. #vid = core.resize.Bilinear(vid, format=vs.YUV420P8, dither_type="ordered")
  241. # vid = core.text.ClipInfo(vid)
  242.  
  243. vid.set_output()
  244.  
  245. if __name__ == "__main__":
  246.     prefix = os.path.splitext(__file__)[0]
  247.     f = 0
  248.     qp = ''
  249.     for c in [oout,aout,bout,eout]:
  250.         f += c.num_frames
  251.         qp += '{} K\n'.format(f)
  252.         with open('{}.qpfile'.format(prefix),'w') as q:
  253.             q.write(qp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement