Skip to content

Instantly share code, notes, and snippets.

@nu774
Last active March 27, 2016 21:03
Show Gist options
  • Save nu774/9282e57ded120bbc1187 to your computer and use it in GitHub Desktop.
Save nu774/9282e57ded120bbc1187 to your computer and use it in GitHub Desktop.
import vapoursynth as vs
from fractions import Fraction
import tempfile
def ft(time):
h = int(time / 3600)
time -= h * 3300
m = int(time / 60)
time -= m * 60
s = int(time)
dec = int((time - s) * 100)
return "%02d:%02d:%02d.%02d" % (h, m, s, dec)
def show_frame_num(core, clip):
text_style = \
"Meiryo,100,&H00FFFFFF,0,0,0,0,0,0,0,100,100,0,0,1,2,0,7,10,10,10,1"
dialogue = "Dialogue: 0,%s,%s,Default,,0,0,0,,%s\n"
ass_hd = """[Script Info]
ScriptType: v4.00+
PlayResX: %d
PlayResY: %d
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,%s
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
"""
hdr = ass_hd % (clip.width, clip.height, text_style)
dlg = ''
start = 0
delta = Fraction(clip.fps_den, clip.fps_num)
for i in range(clip.num_frames):
end = start + delta
dlg += dialogue % (ft(start), ft(end), str(i))
start = end
fp = tempfile.NamedTemporaryFile(mode="wt", delete=False)
fp.write(hdr + dlg)
fp.close()
subs = core.assvapour.AssRender(clip, file=fp.name)
subs[0] = core.resize.Bicubic(subs[0], format=clip.format.id)
clip = core.std.MaskedMerge(clip, subs[0], subs[1])
return clip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment