Skip to content

Instantly share code, notes, and snippets.

@quietvoid
Last active February 27, 2021 04:08
Show Gist options
  • Save quietvoid/b4a35f0552f797848dcfd85da6ad6458 to your computer and use it in GitHub Desktop.
Save quietvoid/b4a35f0552f797848dcfd85da6ad6458 to your computer and use it in GitHub Desktop.
BDSup2Sup XML to timestamps
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