w1kl4s
w1kl4s

Reputation: 137

Get timestamp of video frame using VapourSynth ffms2 plugin

I'm using this snippet as video source to mess with it later:

import vapoursynth as vs
core = vs.core
core.std.LoadPlugin("/usr/local/lib/libffms2.so")

video = core.ffms2.Source("videotest.mkv")

How can i get timestamp of specified frame or get list of timestamps for every frame?

Upvotes: 2

Views: 623

Answers (1)

StuxCrystal
StuxCrystal

Reputation: 876

According to the docs of FFMS2 and The VapourSynth API-Reference the timestamp of the frame can be obtained by accessing the _AbsoluteTime prop of each frame.

Use video.frames() to get an iterator over every frame:

for frame in video.frames():
    print(frame.props["_AbsoluteTime"])

Here another example:

>>> import vapoursynth
>>> s = vapoursynth.core.ffms2.Source(r"Z:\Anime\Serien\Incomplete\Akanesasu Shoujo\[HorribleSubs] Akanesasu Shoujo - 01 [1080p].mkv")
>>> f = s.get_frame(0)
>>> f.props
<vapoursynth.VideoProps {'_AbsoluteTime': 0.043, '_ChromaLocation': 0, '_ColorRange': 1, '_DurationDen': 1000, '_DurationNum': 41, '_FieldBased': 0, '_Matrix': 2, '_PictType': b'I', '_Primaries': 2, '_SARDen': 1, '_SARNum': 1, '_Transfer': 2}>
>>> f.props._AbsoluteTime
0.043

Upvotes: 3

Related Questions