Advertisement
berekescrubs

Saban's Masked Rider VFR Vapoursynth Script

Apr 1st, 2020
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. # This program is free software. It comes without any warranty, to
  2. # the extent permitted by applicable law. You can redistribute it
  3. # and/or modify it under the terms of the Do What The Fuck You Want
  4. # To Public License, Version 2, as published by Sam Hocevar. See
  5. # http://sam.zoy.org/wtfpl/COPYING for more details.
  6.  
  7. # This script is a mix of various functions used by Bereke Scrubs in processing
  8. # a DVD of Saban's Masked Rider. It adjusts the framerate from PAL to NTSC,
  9. # crops, and then deinterlaces either by letting progressive video through,
  10. # QTGMCing field interlaced video to double framerate, or just doing a
  11. # messy deinterlace of 3:2 pulldowns with arbitrary frames dropped we really
  12. # can't do anything else with, and then outputs as VFR.
  13.  
  14. import vapoursynth as vs
  15. import havsfunc
  16. import sys
  17. #easyvfr for vapoursynth is here: https://gist.github.com/chikuzen/5005590
  18. import easyvfr
  19.  
  20. core = vs.get_core()
  21. #Incoming media file. Specify with "-a file=NAME" on command line.
  22. filename = globals()["file"]
  23. #Output timecode file. Specify with "-a time=NAME" on command line.
  24. timecode = globals()["time"]
  25.  
  26. #Number of contiguous interlaced frames to trigger QTGMC.
  27. #Should be 3+ - 2 would go off on 3:2 pulldown'd content.
  28. double_threshold = 4
  29.  
  30. def get_qtgmc(qtgmc, start, stop):
  31. return core.std.Trim(qtgmc, start*2, stop*2 + 1)
  32.  
  33. clip = core.ffms2.Source(filename)
  34.  
  35. #Correct framerate PAL->NTSC.
  36. clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
  37.  
  38. clip = core.std.Crop(clip=clip, left=10, right=8)
  39.  
  40. clip = core.tcomb.TComb(clip=clip)
  41.  
  42. qtgmc = havsfunc.QTGMC(clip, Preset='Slower', SourceMatch=3, TFF=True, opencl=False)
  43.  
  44. #fallback deinterlacing for one or two frames. Doesn't use QTGMC because the noise reduction of that
  45. #is jarring to flip in and out of constantly, even if we drop frames.
  46. deint = core.tdm.TDeintMod(clip=clip, order=1, edeint=core.znedi3.nnedi3(clip=clip, field=1, nns=4))
  47. deint = core.vinverse.Vinverse(clip=deint)
  48.  
  49. combProps = core.tdm.IsCombed(clip=clip, cthresh=5)
  50.  
  51. #deinterlace overrides. Stitch together out of clip and deint cuts as necessary.
  52. clip = clip
  53.  
  54. lastSwitch = 0
  55. lastCombed = None
  56.  
  57. vfr_list = []
  58.  
  59. for i in range(0, clip.num_frames):
  60. isCombed = False
  61. if combProps.get_frame(i).props['_Combed']:
  62. isCombed = True
  63. if i == 0:
  64. continue
  65. elif lastCombed is not None and lastCombed == isCombed:
  66. continue
  67. if lastCombed == False:
  68. #no deinterlace
  69. vfr_list.append(core.std.Trim(clip=clip, first=lastSwitch, last=i-1))
  70. elif i - lastSwitch < double_threshold:
  71. #heuristic, don't double framerate
  72. vfr_list.append(core.std.Trim(clip=deint, first=lastSwitch, last=i-1))
  73. else:
  74. #double framerate.
  75. vfr_list.append(get_qtgmc(qtgmc, lastSwitch, i-1))
  76. lastSwitch = i
  77. lastCombed = isCombed
  78. sys.stderr.write(str(i)+"\n")
  79.  
  80. #get the last bit
  81. if lastCombed == False:
  82. #no deinterlace
  83. vfr_list.append(core.std.Trim(clip=clip, first=lastSwitch, last=clip.num_frames-1))
  84. elif i - lastSwitch <= 3:
  85. #heuristic, don't double framerate
  86. vfr_list.append(core.std.Trim(clip=qtgmc_even, first=lastSwitch, last=clip.num_frames-1))
  87. else:
  88. #double framerate.
  89. vfr_list.append(get_qtgmc(qtgmc, lastSwitch, clip.num_frames-1))
  90. lastSwitch = i
  91. lastCombed = isCombed
  92.  
  93. vfr = easyvfr.EasyVFR(vfr_list, base=qtgmc)
  94.  
  95. vfr.write_timecode(timecode)
  96.  
  97. clip = vfr.splice_clips()
  98.  
  99. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement