opentimelineio.adapters package

Expose the adapter interface to developers.

To read from an existing representation, use the read_from_string and read_from_file functions. To query the list of adapters, use the available_adapter_names function.

The otio_json adapter is provided as a the canonical, lossless, serialization of the in-memory otio schema. Other adapters are to varying degrees lossy. For more information, consult the documentation in the individual adapter modules.

opentimelineio.adapters.available_adapter_names()

Return a string list of the available adapters.

opentimelineio.adapters.from_filepath(filepath)

Guess the adapter object to use for a given filepath.

example:

“foo.otio” returns the “otio_json” adapter.

opentimelineio.adapters.from_name(name)

Fetch the adapter object by the name of the adapter directly.

opentimelineio.adapters.read_from_file(filepath, adapter_name=None, media_linker_name='__default', media_linker_argument_map=None, **adapter_argument_map)

Read filepath using adapter_name.

If adapter_name is None, try and infer the adapter name from the filepath.

For example:

timeline = read_from_file(“example_trailer.otio”) timeline = read_from_file(“file_with_no_extension”, “cmx_3600”)

opentimelineio.adapters.read_from_string(input_str, adapter_name='otio_json', media_linker_name='__default', media_linker_argument_map=None, **adapter_argument_map)

Read a timeline from input_str using adapter_name.

This is useful if you obtain a timeline from someplace other than the filesystem.

Example:

raw_text = urlopen(my_url).read() timeline = read_from_string(raw_text, “otio_json”)

opentimelineio.adapters.suffixes_with_defined_adapters(read=False, write=False)

Return a set of all the suffixes that have adapters defined for them.

opentimelineio.adapters.write_to_file(input_otio, filepath, adapter_name=None, **adapter_argument_map)

Write input_otio to filepath using adapter_name.

If adapter_name is None, infer the adapter_name to use based on the filepath.

Example:

otio.adapters.write_to_file(my_timeline, “output.otio”)

opentimelineio.adapters.write_to_string(input_otio, adapter_name='otio_json', **adapter_argument_map)

Return input_otio written to a string using adapter_name.

Example:

raw_text = otio.adapters.write_to_string(my_timeline, “otio_json”)

Submodules

opentimelineio.adapters.adapter module

Implementation of the OTIO internal Adapter system.

For information on writing adapters, please consult:

https://opentimelineio.readthedocs.io/en/latest/tutorials/write-an-adapter.html# # noqa

class opentimelineio.adapters.adapter.Adapter(*args, **kwargs)

Bases: opentimelineio.plugins.python_plugin.PythonPlugin

Adapters convert between OTIO and other formats.

Note that this class is not subclassed by adapters. Rather, an adapter is a python module that implements at least one of the following functions:

write_to_string(input_otio) write_to_file(input_otio, filepath) (optionally inferred) read_from_string(input_str) read_from_file(filepath) (optionally inferred)

…as well as a small json file that advertises the features of the adapter to OTIO. This class serves as the wrapper around these modules internal to OTIO. You should not need to extend this class to create new adapters for OTIO.

For more information: https://opentimelineio.readthedocs.io/en/latest/tutorials/write-an-adapter.html# # noqa

has_feature(feature_string)

return true if adapter supports feature_string, which must be a key of the _FEATURE_MAP dictionary.

Will trigger a call to self.module(), which imports the plugin.

plugin_info_map()

Adds extra adapter-specific information to call to the parent fn.

read_from_file(filepath, media_linker_name='__default', media_linker_argument_map=None, hook_function_argument_map=None, **adapter_argument_map)

Execute the read_from_file function on this adapter.

If read_from_string exists, but not read_from_file, execute that with a trivial file object wrapper.

read_from_string(input_str, media_linker_name='__default', media_linker_argument_map=None, hook_function_argument_map=None, **adapter_argument_map)

Call the read_from_string function on this adapter.

property suffixes

File suffixes associated with this adapter.

write_to_file(input_otio, filepath, hook_function_argument_map=None, **adapter_argument_map)

Execute the write_to_file function on this adapter.

If write_to_string exists, but not write_to_file, execute that with a trivial file object wrapper.

write_to_string(input_otio, hook_function_argument_map=None, **adapter_argument_map)

Call the write_to_string function on this adapter.

opentimelineio.adapters.cmx_3600 module

OpenTimelineIO CMX 3600 EDL Adapter

class opentimelineio.adapters.cmx_3600.ClipHandler(line, comment_data, rate=24)

Bases: object

create_imagesequence_reference(comment_data)
image_sequence_pattern = re.compile('.*\\.(?P<range>\\[(?P<start>[0-9]+)-(?P<end>[0-9]+)\\])\\.\\w+$')
is_image_sequence(comment_data)
make_clip(comment_data)
parse(line)
class opentimelineio.adapters.cmx_3600.CommentHandler(comments)

Bases: object

comment_id_map = {'ASC_SAT': 'asc_sat', 'ASC_SOP': 'asc_sop', 'FROM CLIP': 'media_reference', 'FROM CLIP NAME': 'clip_name', 'FROM FILE': 'media_reference', 'LOC': 'locators', 'M2': 'motion_effect', 'TO CLIP NAME': 'dest_clip_name', '\\* FREEZE FRAME': 'freeze_frame'}
parse(comment)
regex_template = '\\*?\\s*{id}:?\\s*(?P<comment_body>.*)'
class opentimelineio.adapters.cmx_3600.DissolveEvent(a_side_event, transition, b_side_clip, tracks, kind, rate, style, reelname_len)

Bases: object

to_edl_format()

Example output:

Cross dissolve… 002 Clip1 V C 00:00:07:08 00:00:07:08 00:00:01:21 00:00:01:21 002 Clip2 V D 100 00:00:09:07 00:00:17:15 00:00:01:21 00:00:10:05 * FROM CLIP NAME: Clip1 * FROM CLIP: /var/tmp/clip1.001.exr * TO CLIP NAME: Clip2 * TO CLIP: /var/tmp/clip2.001.exr

Fade in… 001 BL V C 00:00:00:00 00:00:00:00 00:00:00:00 00:00:00:00 001 My_Clip V D 012 00:00:02:02 00:00:03:04 00:00:00:00 00:00:01:02 * TO CLIP NAME: My Clip * TO FILE: /var/tmp/clip.001.exr

Fade out… 002 My_Clip V C 00:00:01:12 00:00:01:12 00:00:00:12 00:00:00:12 002 BL V D 012 00:00:00:00 00:00:00:12 00:00:00:12 00:00:01:00 * FROM CLIP NAME: My Clip * FROM FILE: /var/tmp/clip.001.exr

exception opentimelineio.adapters.cmx_3600.EDLParseError

Bases: opentimelineio._otio.OTIOError

class opentimelineio.adapters.cmx_3600.EDLParser(edl_string, rate=24, ignore_timecode_mismatch=False)

Bases: object

add_clip(line, comments, rate=24)
add_transition(clip_handler, transition, data)
guess_kind_for_track_name(name)
parse_edl(edl_string, rate=24)
tracks_for_channel(channel_code)
class opentimelineio.adapters.cmx_3600.EDLWriter(tracks, rate, style, reelname_len=8)

Bases: object

get_content_for_track_at_index(idx, title)
class opentimelineio.adapters.cmx_3600.Event(clip, tracks, kind, rate, style, reelname_len)

Bases: object

to_edl_format()
Example output:

002 AX V C 00:00:00:00 00:00:00:05 00:00:00:05 00:00:00:10 * FROM CLIP NAME: test clip2 * FROM FILE: S:vartmptest.exr

class opentimelineio.adapters.cmx_3600.EventLine(kind, rate, reel='AX')

Bases: object

is_dissolve()
to_edl_format(edit_number)
opentimelineio.adapters.cmx_3600.read_from_string(input_str, rate=24, ignore_timecode_mismatch=False)

Reads a CMX Edit Decision List (EDL) from a string. Since EDLs don’t contain metadata specifying the rate they are meant for, you may need to specify the rate parameter (default is 24). By default, read_from_string will throw an exception if it discovers invalid timecode in the EDL. For example, if a clip’s record timecode overlaps with the previous cut. Since this is a common mistake in many EDLs, you can specify ignore_timecode_mismatch=True, which will supress these errors and attempt to guess at the correct record timecode based on the source timecode and adjacent cuts. For best results, you may wish to do something like this:

Example:
>>> try:
...     timeline = otio.adapters.read_from_string("mymovie.edl", rate=30)
... except EDLParseError:
...    print('Log a warning here')
...    try:
...        timeline = otio.adapters.read_from_string(
...            "mymovie.edl",
...            rate=30,
...            ignore_timecode_mismatch=True)
...    except EDLParseError:
...        print('Log an error here')
opentimelineio.adapters.cmx_3600.write_to_string(input_otio, rate=None, style='avid', reelname_len=8)

opentimelineio.adapters.fcp_xml module

OpenTimelineIO Final Cut Pro 7 XML Adapter.

class opentimelineio.adapters.fcp_xml.FCP7XMLParser(element_tree)

Bases: object

Implements parsing of an FCP XML file into an OTIO timeline.

Parsing FCP XML elements include two concepts that require carrying state:
  1. Inheritance

  2. The id Attribute

See also

https://developer.apple.com/library/archive/documentation/ AppleApplications/Reference/FinalCutPro_XML/Basics/Basics.html #//apple_ref/doc/uid/TP30001154-TPXREF102

Inheritance is implemented using a _Context object that is pushed down through layers of parsing. A given parsing method is passed the element to parse into an otio object along with the context that element exists under (e.x. a track element parsing method is given the track element and the sequence context for that track).

The id attribute dereferencing is handled through a lookup table stored on parser instances and using the _derefed_ methods to take an element and find dereference elements.

clip_for_element(clipitem_element, item_range, start_offset, context)

Given a clipitem xml element, returns an :class: schema.Clip.

Parameters
  • clipitem_element – The element to create a clip for.

  • item_range – The time range in the timeline the clip occupies.

  • start_offset – The amount by which the in time of the clip source should be advanced (usually due to a transition).

  • context – The parent context for the clip.

Returns

The :class: schema.Clip instance.

effect_from_filter_element(filter_element)

Given a filter element, creates an :class: schema.Effect.

Parameters

filter_element – The filter element containing the effect.

Returns

The effect instance.

item_and_timing_for_element(item_element, head_transition, tail_transition, context)

Given a track item, returns a tuple with the appropriate OpenTimelineIO schema item as the first element and an :class: opentime.TimeRange of the resolved timeline range the clip occupies.

Parameters
  • item_element – The track item XML node.

  • head_transition – The xml element for the transition immediately before or None.

  • tail_transition – The xml element for the transition immediately after or None.

  • context – The context dictionary.

Returns

An :class: core.Item subclass instance and :class: opentime.TimeRange for the item.

media_reference_for_effect_element(effect_element)

Given an effect element, returns a generator reference.

Parameters

effect_element – The effect for the generator.

Returns

An :class: schema.GeneratorReference instance.

media_reference_for_file_element(file_element, context)

Given a file XML element, returns the :class`schema.ExternalReference`.

Parameters
  • file_element – The file xml element.

  • context – The parent context dictionary.

Returns

An :class: schema.ExternalReference.

stack_for_element(element, context)

Given an element, parses out track information as a stack.

Parameters
  • element – The element under which to find the tracks (typically a media element.

  • context – The current parser context.

Returns

A :class: schema.Stack of the tracks.

timeline_for_sequence(sequence_element, context)

Returns either an :class`schema.Timeline` parsed from a sequence element.

Parameters
  • sequence_element – The sequence element.

  • context – The context dictionary.

Returns

The appropriate OTIO object for the element.

top_level_sequences()

” Returns a list of timelines for the top-level sequences in the file.

track_for_element(track_element, track_kind, context)

Given a track element, constructs the OTIO track.

Parameters
  • track_element – The track XML element.

  • track_kind – The :class: schema.TrackKind for the track.

  • context – The context dict for this track.

transition_for_element(item_element, context)

Creates an OTIO transition for the provided transition element.

Parameters
  • item_element – The element to create a transition for.

  • context – The parent context for the element.

Returns

The :class: schema.Transition instance.

opentimelineio.adapters.fcp_xml.marker_for_element(marker_element, rate)

Creates an :class: schema.Marker for the provided element.

Parameters
  • marker_element – The XML element for the marker.

  • rate – The rate for the object the marker is attached to.

Returns

The :class: schema.Marker instance.

opentimelineio.adapters.fcp_xml.markers_from_element(element, context=None)

Given an element, returns the list of markers attached to it.

Parameters
  • element – An element with one or more marker child elements.

  • context – The context for this element.

Returns

A :class: list of :class: schema.Marker instances attached to the provided element.

opentimelineio.adapters.fcp_xml.read_from_string(input_str)
opentimelineio.adapters.fcp_xml.write_to_string(input_otio)

opentimelineio.adapters.file_bundle_utils module

Common utilities used by the file bundle adapters (otiod and otioz).

class opentimelineio.adapters.file_bundle_utils.MediaReferencePolicy

Bases: object

AllMissing = 'AllMissing'
ErrorIfNotFile = 'ErrorIfNotFile'
MissingIfNotFile = 'MissingIfNotFile'
exception opentimelineio.adapters.file_bundle_utils.NotAFileOnDisk

Bases: opentimelineio._otio.OTIOError

opentimelineio.adapters.file_bundle_utils.reference_cloned_and_missing(orig_mr, reason_missing)

Replace orig_mr with a missing reference with the same metadata.

Also adds original_target_url and missing_reference_because fields.

opentimelineio.adapters.otio_json module

This adapter lets you read and write native .otio files

opentimelineio.adapters.otio_json.read_from_file(filepath)

De-serializes an OpenTimelineIO object from a file

Args:

filepath (str): The path to an otio file to read from

Returns:

OpenTimeline: An OpenTimeline object

opentimelineio.adapters.otio_json.read_from_string(input_str)

De-serializes an OpenTimelineIO object from a json string

Args:

input_str (str): A string containing json serialized otio contents

Returns:

OpenTimeline: An OpenTimeline object

opentimelineio.adapters.otio_json.write_to_file(input_otio, filepath, indent=4)

Serializes an OpenTimelineIO object into a file

Args:

input_otio (OpenTimeline): An OpenTimeline object filepath (str): The name of an otio file to write to indent (int): number of spaces for each json indentation level. Use -1 for no indentation or newlines.

Returns:

bool: Write success

Raises:

ValueError: on write error

opentimelineio.adapters.otio_json.write_to_string(input_otio, indent=4)

Serializes an OpenTimelineIO object into a string

Args:

input_otio (OpenTimeline): An OpenTimeline object indent (int): number of spaces for each json indentation level. Use -1 for no indentation or newlines.

Returns:

str: A json serialized string representation

opentimelineio.adapters.otiod module

OTIOD adapter - bundles otio files linked to local media in a directory

Takes as input an OTIO file that has media references which are all ExternalReferences with target_urls to files with unique basenames that are accessible through the file system and bundles those files and the otio file into a single directory named with a suffix of .otiod.

opentimelineio.adapters.otiod.read_from_file(filepath, absolute_media_reference_paths=False)
opentimelineio.adapters.otiod.write_to_file(input_otio, filepath, media_policy='ErrorIfNotFile', dryrun=False)

opentimelineio.adapters.otioz module

OTIOZ adapter - bundles otio files linked to local media

Takes as input an OTIO file that has media references which are all ExternalReferences with target_urls to files with unique basenames that are accessible through the file system and bundles those files and the otio file into a single zip file with the suffix .otioz. Can error out if files aren’t locally referenced or provide missing references

Can also extract the content.otio file from an otioz bundle for processing.

Note that OTIOZ files _always_ use the unix style path separator (‘/’). This ensures that regardless of which platform a bundle was created on, it can be read on unix and windows platforms.

opentimelineio.adapters.otioz.read_from_file(filepath, extract_to_directory=None)
opentimelineio.adapters.otioz.write_to_file(input_otio, filepath, media_policy='ErrorIfNotFile', dryrun=False)

opentimelineio.adapters.svg module

OTIO to SVG Adapter Points in calculations are y-up. Points in SVG are y-down.

class opentimelineio.adapters.svg.ClipData(src_start=0.0, src_end=0.0, avlbl_start=0.0, avlbl_end=0.0, avlbl_duration=0.0, trim_start=0.0, trim_duration=0.0, target_url='', clip_id=0, transition_begin=None, transition_end=None)

Bases: object

class opentimelineio.adapters.svg.Color(r=0.0, g=0.0, b=0.0, a=255.0)

Bases: object

property a
property b
property g
property r
static random_color()
svg_color()
class opentimelineio.adapters.svg.Point(x, y)

Bases: object

svg_point_string()
class opentimelineio.adapters.svg.Rect(origin=<opentimelineio.adapters.svg.Point object>, width=0.0, height=0.0)

Bases: object

contract(distance)
height = 0.0
max_x()
max_y()
mid_x()
mid_y()
min_x()
min_y()
normalized()
origin = <opentimelineio.adapters.svg.Point object>
width = 0.0
class opentimelineio.adapters.svg.SVGWriter(image_width=2406.0, image_height=1054.0, image_margin=20.0, arrow_margin=10.0, arrow_label_margin=5.0, font_size=15.0, font_family='sans-serif')

Bases: object

draw_arrow(start_point, end_point, stroke_width, stroke_color=<opentimelineio.adapters.svg.Color object>)
draw_dashed_rect(rect, stroke_width=2.0, stroke_color=<opentimelineio.adapters.svg.Color object>, fill_color=<opentimelineio.adapters.svg.Color object>)
draw_labeled_dashed_rect_with_border(rect, stroke_width=2.0, fill_color=<opentimelineio.adapters.svg.Color object>, border_color=<opentimelineio.adapters.svg.Color object>, label='', label_size=10.0)
draw_labeled_rect(rect, stroke_width=2.0, stroke_color=<opentimelineio.adapters.svg.Color object>, fill_color=<opentimelineio.adapters.svg.Color object>, label='', label_size=10.0)
draw_labeled_solid_rect_with_border(rect, stroke_width=2.0, fill_color=<opentimelineio.adapters.svg.Color object>, border_color=<opentimelineio.adapters.svg.Color object>, label='', label_size=10.0)
draw_line(start_point, end_point, stroke_width, stroke_color=<opentimelineio.adapters.svg.Color object>, is_dashed=False)
draw_rect(rect, stroke_width=2.0, stroke_color=<opentimelineio.adapters.svg.Color object>)
draw_solid_rect(rect, fill_color=<opentimelineio.adapters.svg.Color object>)
draw_solid_rect_with_border(rect, stroke_width=2.0, fill_color=<opentimelineio.adapters.svg.Color object>, border_color=<opentimelineio.adapters.svg.Color object>)
draw_text(text, location, text_size, color=<opentimelineio.adapters.svg.Color object>, stroke_width=1.0)
get_image()
opentimelineio.adapters.svg.convert_otio_to_svg(timeline, width, height)
opentimelineio.adapters.svg.convert_point_to_svg_coordinates(point, image_height)
opentimelineio.adapters.svg.convert_rect_to_svg_coordinates(rect, image_height)

Convert to SVG coordinate system (0,0 at top-left)

opentimelineio.adapters.svg.draw_item(otio_obj, svg_writer, extra_data=())
opentimelineio.adapters.svg.random() x in the interval [0, 1).
opentimelineio.adapters.svg.write_to_string(input_otio, width=2406.0, height=1054.0)