Skip to content

Instantly share code, notes, and snippets.

@tallguyjenks
Forked from tin2tin/fcpx_markers_import.py
Last active May 22, 2023 00:32
Show Gist options
  • Save tallguyjenks/c088efa831d4c3d90506641c6c2ccc99 to your computer and use it in GitHub Desktop.
Save tallguyjenks/c088efa831d4c3d90506641c6c2ccc99 to your computer and use it in GitHub Desktop.
Grab Marker time stamps and text from Final Cut Pro X XML export and format for youtube timestamps in an output text file
#!/usr/bin/env python
import sys, datetime
from xml.etree.ElementTree import parse
xmlfile = raw_input()
if xmlfile == "":
exit()
# Converts the '64bit/32bits' timecode format into seconds
def parseFCPTimeSeconds (timeString):
vals = [float(n) for n in timeString.replace('s','').split('/')]
if 1 == len(vals):
val = vals[0]
else:
val = vals[0]/vals[1]
return val
class Marker:
def __init__(self, name, startTime):
self._name = name
self._startTime = startTime
@property
def startTime(self):
return self._startTime
@property
def name(self):
return self._name
@staticmethod
def scanForMarker(element, time=[]):
start = offset = 0
try:
start = parseFCPTimeSeconds(element.attrib['start'])
except:
pass
try:
offset = parseFCPTimeSeconds(element.attrib['offset'])
except:
pass
m = []
if 'marker' == element.tag:
m.append(Marker(element.attrib['value'], start + sum(time)))
else:
time.append(offset - start)
for el in element:
m.extend(Marker.scanForMarker(el, list(time)))
return m
# EXAMPLE:
# Import file and convert it to a list of markers sorted by ID and start time
xmlroot = parse(xmlfile).getroot()
markers = sorted(Marker.scanForMarker(xmlroot), key=lambda s: s.startTime)
for m in markers:
print ("{1} {0}".format(m.name, datetime.timedelta(seconds=m.startTime)))
#!/usr/bin/env bash
file="$1"
if [ -z "$1" ]; then
echo "No FCPX XML File Specified"
exit 1
fi
echo "$file" | ./mark.py | awk -F. '{print $1,$2}' | cut -d" " -f1,3- > "YouTube Timestamps.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment