Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This program is free software. It comes without any warranty, to
- # the extent permitted by applicable law. You can redistribute it
- # and/or modify it under the terms of the Do What The Fuck You Want
- # To Public License, Version 2, as published by Sam Hocevar. See
- # http://sam.zoy.org/wtfpl/COPYING for more details.
- # This script is a mix of various functions used by Bereke Scrubs in processing
- # a DVD of Saban's Masked Rider. It adjusts the framerate from PAL to NTSC,
- # crops, and then deinterlaces either by letting progressive video through,
- # QTGMCing field interlaced video to double framerate, or just doing a
- # messy deinterlace of 3:2 pulldowns with arbitrary frames dropped we really
- # can't do anything else with, and then outputs as VFR.
- import vapoursynth as vs
- import havsfunc
- import sys
- #easyvfr for vapoursynth is here: https://gist.github.com/chikuzen/5005590
- import easyvfr
- core = vs.get_core()
- #Incoming media file. Specify with "-a file=NAME" on command line.
- filename = globals()["file"]
- #Output timecode file. Specify with "-a time=NAME" on command line.
- timecode = globals()["time"]
- #Number of contiguous interlaced frames to trigger QTGMC.
- #Should be 3+ - 2 would go off on 3:2 pulldown'd content.
- double_threshold = 4
- def get_qtgmc(qtgmc, start, stop):
- return core.std.Trim(qtgmc, start*2, stop*2 + 1)
- clip = core.ffms2.Source(filename)
- #Correct framerate PAL->NTSC.
- clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
- clip = core.std.Crop(clip=clip, left=10, right=8)
- clip = core.tcomb.TComb(clip=clip)
- qtgmc = havsfunc.QTGMC(clip, Preset='Slower', SourceMatch=3, TFF=True, opencl=False)
- #fallback deinterlacing for one or two frames. Doesn't use QTGMC because the noise reduction of that
- #is jarring to flip in and out of constantly, even if we drop frames.
- deint = core.tdm.TDeintMod(clip=clip, order=1, edeint=core.znedi3.nnedi3(clip=clip, field=1, nns=4))
- deint = core.vinverse.Vinverse(clip=deint)
- combProps = core.tdm.IsCombed(clip=clip, cthresh=5)
- #deinterlace overrides. Stitch together out of clip and deint cuts as necessary.
- clip = clip
- lastSwitch = 0
- lastCombed = None
- vfr_list = []
- for i in range(0, clip.num_frames):
- isCombed = False
- if combProps.get_frame(i).props['_Combed']:
- isCombed = True
- if i == 0:
- continue
- elif lastCombed is not None and lastCombed == isCombed:
- continue
- if lastCombed == False:
- #no deinterlace
- vfr_list.append(core.std.Trim(clip=clip, first=lastSwitch, last=i-1))
- elif i - lastSwitch < double_threshold:
- #heuristic, don't double framerate
- vfr_list.append(core.std.Trim(clip=deint, first=lastSwitch, last=i-1))
- else:
- #double framerate.
- vfr_list.append(get_qtgmc(qtgmc, lastSwitch, i-1))
- lastSwitch = i
- lastCombed = isCombed
- sys.stderr.write(str(i)+"\n")
- #get the last bit
- if lastCombed == False:
- #no deinterlace
- vfr_list.append(core.std.Trim(clip=clip, first=lastSwitch, last=clip.num_frames-1))
- elif i - lastSwitch <= 3:
- #heuristic, don't double framerate
- vfr_list.append(core.std.Trim(clip=qtgmc_even, first=lastSwitch, last=clip.num_frames-1))
- else:
- #double framerate.
- vfr_list.append(get_qtgmc(qtgmc, lastSwitch, clip.num_frames-1))
- lastSwitch = i
- lastCombed = isCombed
- vfr = easyvfr.EasyVFR(vfr_list, base=qtgmc)
- vfr.write_timecode(timecode)
- clip = vfr.splice_clips()
- clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement