opentimelineio.algorithms package

Algorithms for OTIO objects.

Submodules

opentimelineio.algorithms.filter module

Algorithms for filtering OTIO files.

opentimelineio.algorithms.filter.filtered_composition(root, unary_filter_fn, types_to_prune=None)

Filter a deep copy of root (and children) with unary_filter_fn.

types_to_prune:: tuple of types, example: (otio.schema.Gap,…)

  1. Make a deep copy of root

  2. Starting with root, perform a depth first traversal

  3. For each item (including root):
    1. if types_to_prune is not None and item is an instance of a type

      in types_to_prune, prune it from the copy, continue.

    2. Otherwise, pass the copy to unary_filter_fn. If unary_filter_fn:
      1. returns an object: add it to the copy, replacing original

      2. returns a tuple: insert it into the list, replacing original

      3. returns None: prune it

  4. If an item is pruned, do not traverse its children

  5. Return the new deep copy.

EXAMPLE 1 (filter):
If your unary function is:
def fn(thing):
if thing.name == B:

return thing’ # some transformation of B

else:

return thing

If you have a track: [A,B,C]

filtered_composition(track, fn) => [A,B’,C]

EXAMPLE 2 (prune):
If your unary function is:
def fn(thing):
if thing.name == B:

return None

else:

return thing

filtered_composition(track, fn) => [A,C]

EXAMPLE 3 (expand):
If your unary function is:
def fn(thing):
if thing.name == B:

return tuple(B_1,B_2,B_3)

else:

return thing

filtered_composition(track, fn) => [A,B_1,B_2,B_3,C]

EXAMPLE 4 (prune gaps):
track :: [Gap, A, Gap]
filtered_composition(

track, lambda _:_, types_to_prune=(otio.schema.Gap,)) => [A]

opentimelineio.algorithms.filter.filtered_with_sequence_context(root, reduce_fn, types_to_prune=None)

Filter a deep copy of root (and children) with reduce_fn.

reduce_fn::function(previous_item, current, next_item) (see below) types_to_prune:: tuple of types, example: (otio.schema.Gap,…)

  1. Make a deep copy of root

  2. Starting with root, perform a depth first traversal

  3. For each item (including root):
    1. if types_to_prune is not None and item is an instance of a type

      in types_to_prune, prune it from the copy, continue.

    2. Otherwise, pass (prev, copy, and next) to reduce_fn. If reduce_fn:
      1. returns an object: add it to the copy, replacing original

      2. returns a tuple: insert it into the list, replacing original

      3. returns None: prune it

      ** note that reduce_fn is always passed objects from the original

      deep copy, not what prior calls return. See below for examples

  4. If an item is pruned, do not traverse its children

  5. Return the new deep copy.

EXAMPLE 1 (filter):
>>> track = [A,B,C]
>>> def fn(prev_item, thing, next_item):
...     if prev_item.name == A:
...         return D # some new clip
...     else:
...         return thing
>>> filtered_with_sequence_context(track, fn) => [A,D,C]
order of calls to fn:

fn(None, A, B) => A fn(A, B, C) => D fn(B, C, D) => C # !! note that it was passed B instead of D.

EXAMPLE 2 (prune):
>>> track = [A,B,C]
>>> def fn(prev_item, thing, next_item):
...    if prev_item.name == A:
...        return None # prune the clip
...   else:
...        return thing
>>> filtered_with_sequence_context(track, fn) => [A,C]
order of calls to fn:

fn(None, A, B) => A fn(A, B, C) => None fn(B, C, D) => C # !! note that it was passed B instead of D.

EXAMPLE 3 (expand):
>>> def fn(prev_item, thing, next_item):
...     if prev_item.name == A:
...         return (D, E) # tuple of new clips
...     else:
...         return thing
>>> filtered_with_sequence_context(track, fn) => [A, D, E, C]
the order of calls to fn will be:

fn(None, A, B) => A fn(A, B, C) => (D, E) fn(B, C, D) => C # !! note that it was passed B instead of D.

opentimelineio.algorithms.stack_algo module

Algorithms for stack objects.

opentimelineio.algorithms.stack_algo.top_clip_at_time(in_stack, t)

Return the topmost visible child that overlaps with time t.

Example: tr1: G1, A, G2 tr2: [B——] G1, and G2 are gaps, A and B are clips.

If t is within A, a will be returned. If t is within G1 or G2, B will be returned.

opentimelineio.algorithms.timeline_algo module

Algorithms for timeline objects.

opentimelineio.algorithms.timeline_algo.timeline_trimmed_to_range(in_timeline, trim_range)

Returns a new timeline that is a copy of the in_timeline, but with items outside the trim_range removed and items on the ends trimmed to the trim_range. Note that the timeline is never expanded, only shortened. Please note that you could do nearly the same thing non-destructively by just setting the Track’s source_range but sometimes you want to really cut away the stuff outside and that’s what this function is meant for.

opentimelineio.algorithms.track_algo module

Algorithms for track objects.

opentimelineio.algorithms.track_algo.track_trimmed_to_range(in_track, trim_range)

Returns a new track that is a copy of the in_track, but with items outside the trim_range removed and items on the ends trimmed to the trim_range. Note that the track is never expanded, only shortened. Please note that you could do nearly the same thing non-destructively by just setting the Track’s source_range but sometimes you want to really cut away the stuff outside and that’s what this function is meant for.

opentimelineio.algorithms.track_algo.track_with_expanded_transitions(in_track)

Expands transitions such that neighboring clips are trimmed into regions of overlap.

For example, if your track is:

Clip1, T, Clip2

will return:

Clip1’, Clip1_t, T, Clip2_t, Clip2’

Where Clip1’ is the part of Clip1 not in the transition, Clip1_t is the part inside the transition and so on.