-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_timestamps.py
24 lines (18 loc) · 1.01 KB
/
get_timestamps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from fractions import Fraction
from video_timestamps import FPSTimestamps, TimeType, RoundingMethod
def main() -> None:
fps = Fraction(24000, 1001)
time_scale = Fraction(1000)
# Read the documentation to find out which RoundingMethod suits your needs.
# You can also create a Timestamps instance with TextFileTimestamps, VideoTimestamps
timestamps = FPSTimestamps(RoundingMethod.ROUND, time_scale, fps)
frame = 10
# Max precision
start_time_in_seconds = timestamps.frame_to_time(frame, TimeType.START)
end_time_in_seconds = timestamps.frame_to_time(frame, TimeType.END)
print(f"For the fps {fps}, the frame {frame} start at {start_time_in_seconds} s and end at {end_time_in_seconds} s.")
start_time_in_ms = timestamps.frame_to_time(frame, TimeType.START, 3)
end_time_in_ms = timestamps.frame_to_time(frame, TimeType.END, 3)
print(f"For the fps {fps}, the frame {frame} start at {start_time_in_ms} ms and end at {end_time_in_ms} ms.")
if __name__ == "__main__":
main()