Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Import Final Cut Pro X markers from fcpxml files and insert them as markers and subtitles in Blender
import bpy
'''
Project Purpose:
Extract markers and time codes from Final Cut Pro X's FCPXML 1.3 formatted files
Pass an XML element into Marker.scanForMarker(). If markers are found, they are inserted as markers and subtitles in Blender.
'''
import bpy, sys, datetime
from xml.etree.ElementTree import parse
# 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
def get_open_channel(scene):
"""Get a channel with nothing in it"""
channels = []
try:
for strip in scene.sequence_editor.sequences_all:
channels.append(strip.channel)
if len(channels) > 0:
return max(channels) + 1
else:
return 1
except AttributeError:
return 1
# EXAMPLE:
# Import file and convert it to a list of markers sorted by ID and start time
xmlroot = parse("C:\\Users\\User\\Documents\\Blender Scripts\\FCPXML\\fcpx_project.fcpxml").getroot()
markers = sorted(Marker.scanForMarker(xmlroot), key=lambda s: s.startTime)
#scene = context.scene
#markers_sc = scene.timeline_markers
scene = bpy.context.scene
#open_channel = get_open_channel(scene)
if not scene.sequence_editor:
scene.sequence_editor_create()
print ("RESULTING ORDERED LIST:")
for m in markers:
print ("Marker {0} with start time: {1}".format(m.name, datetime.timedelta(seconds=m.startTime)))
bpy.context.scene.timeline_markers.new(m.name, frame=int(m.startTime)*24)# Insert marker
print(str(int(m.startTime)))
#Insert subtitle
text_strip = scene.sequence_editor.sequences.new_effect(
name=m.name,
type='TEXT',
channel=get_open_channel(scene),
frame_start=int(m.startTime)*24,
frame_end=int(m.startTime)*24+300
)
text_strip.font_size = 75
text_strip.text = m.name
text_strip.use_shadow = True
text_strip.select = True
text_strip.blend_type = 'ALPHA_OVER'
#added_strips.append(text_strip)
@b4zz4

This comment has been minimized.

Copy link

b4zz4 commented Nov 26, 2019

Hi.
In which version of blender did you try it?

@tin2tin

This comment has been minimized.

Copy link
Owner Author

tin2tin commented Nov 26, 2019

2.79. I don't have a fcpx file anymore to test if is is still working.

@tin2tin

This comment has been minimized.

Copy link
Owner Author

tin2tin commented Nov 26, 2019

Tested with some fcpx files from the OTIO, and with a minor fix it is working now.

Remember to specify the path with double \

@b4zz4

This comment has been minimized.

Copy link

b4zz4 commented Nov 26, 2019

2019-11-26-093944_1600x900_scrot

I use GNU/Linux.
Is this the correct way to execute it?

It does not give error, but it also does not load the images and sounds.

@tin2tin

This comment has been minimized.

Copy link
Owner Author

tin2tin commented Nov 26, 2019

You need to toggle the system console to see errors:
image

Most likely it's the path failing. If it isn't it may be because it uses a different version of fcpx. I can't remember which one it is made for. (If you need to convert fcpx maybe Davinci Resolve can be used for that)

@b4zz4

This comment has been minimized.

Copy link

b4zz4 commented Nov 28, 2019

I test on gnu/linux with projects of storyboarder. It does not generate error, but neither see the drawings :(

@tin2tin

This comment has been minimized.

Copy link
Owner Author

tin2tin commented Nov 28, 2019

This add-on is not for importing Storyboarder stuff, but import markers from Final Cut Pro, like this one: https://gist.github.com/tin2tin/c3f87754301be38c06356f6cb4676fa8

I once did a Storyboarder to Blender importer, but it doesn't seem to be uploaded anywhere and it isn't on my current computer... Was it this post you saw? https://www.facebook.com/groups/1981104845289453/permalink/2082312818501988/

@b4zz4

This comment has been minimized.

Copy link

b4zz4 commented Nov 28, 2019

I don't use facebook.
Storyboarder exports to Final Cut and I use blender. So thought it would be good to mix them (blender and storyboarder).
Maybe I should do everything in blender.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.