Last active
February 27, 2021 04:08
-
-
Save quietvoid/b4a35f0552f797848dcfd85da6ad6458 to your computer and use it in GitHub Desktop.
BDSup2Sup XML to timestamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
import math | |
tree = ET.parse('timestamps.xml') | |
in_format = tree.find('Description/Format') | |
fps = float(in_format.attrib['FrameRate']) | |
lines = tree.findall('Events/Event') | |
with open("timestamps-text.txt", "w") as outf: | |
for (i, line) in enumerate(lines): | |
(start, end) = (line.attrib['InTC'].split(':'), line.attrib['OutTC'].split(':')) | |
start_ms = ".{:03d}".format(math.floor(int(start.pop()) * (1000 / (1000 * fps)) * 1000) + 1) | |
end_ms = ".{:03d}".format(math.floor(int(end.pop()) * (1000 / (1000 * fps)) * 1000) + 1) | |
start = ':'.join(start) | |
end = ':'.join(end) | |
start += start_ms | |
end += end_ms | |
outf.write("{}\n{} --> {}\n\n".format(i + 1, start, end)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment