Skip to content

Commit c19aa58

Browse files
committed
AAF adapter: added clip_timecode_offset argument
Added `clip_timecode_offset` as new optional argument. By default, the behaviour is the same as before. However, if the parameter is set to `False`, the global timecode offset will not be added to the clip source range. This allows for easy access to the actual source range used in the clip.
1 parent 5957ddc commit c19aa58

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

contrib/opentimelineio_contrib/adapters/advanced_authoring_format.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
# If enabled, output recursive traversal info of _transcribe() method.
5858
_TRANSCRIBE_DEBUG = False
5959

60+
# If enabled, the track timecode offset will be included in the clip source_range
61+
_CLIP_TIMECODE_OFFSET = True
62+
6063

6164
def _transcribe_log(s, indent=0, always_print=False):
6265
if always_print or _TRANSCRIBE_DEBUG:
@@ -300,7 +303,7 @@ def _transcribe(item, parents, edit_rate, indent=0):
300303
media_start = source_start
301304
media_length = item.length
302305

303-
if timecode_info:
306+
if _CLIP_TIMECODE_OFFSET and timecode_info:
304307
media_start, media_length = timecode_info
305308
source_start += media_start
306309

@@ -1153,15 +1156,32 @@ def _contains_something_valuable(thing):
11531156
return True
11541157

11551158

1156-
def read_from_file(filepath, simplify=True, transcribe_log=False):
1159+
def read_from_file(filepath, simplify=True,
1160+
transcribe_log=False, clip_timecode_offset=True
1161+
):
1162+
"""Reads AAF content from `filepath` and outputs a OTIO timeline object.
1163+
1164+
Args:
1165+
filepath (str): AAF filepath
1166+
simplify (bool, optional): simplify timeline structure by stripping empty items
1167+
transcribe_log (bool, optional): log activity as items are getting transcribed
1168+
clip_timecode_offset (bool, optional): offset clip ranges by track timecode
1169+
1170+
Returns:
1171+
otio.schema.Timeline
11571172
1173+
"""
11581174
# 'activate' transcribe logging if adapter argument is provided.
11591175
# Note that a global 'switch' is used in order to avoid
11601176
# passing another argument around in the _transcribe() method.
11611177
#
11621178
global _TRANSCRIBE_DEBUG
11631179
_TRANSCRIBE_DEBUG = transcribe_log
11641180

1181+
# enable / disable clip timecode offset for clip source_range times
1182+
global _CLIP_TIMECODE_OFFSET
1183+
_CLIP_TIMECODE_OFFSET = clip_timecode_offset
1184+
11651185
with aaf2.open(filepath) as aaf_file:
11661186

11671187
storage = aaf_file.content

contrib/opentimelineio_contrib/adapters/tests/test_aaf_adapter.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,34 @@ def test_timecode(self):
589589
otio.opentime.RationalTime(86424, 24),
590590
)
591591

592+
def test_aaf_clip_with_timecode_offset(self):
593+
timeline = otio.adapters.read_from_file(TIMCODE_EXAMPLE_PATH,
594+
clip_timecode_offset=True)
595+
expected_start_times = {
596+
'Frame Debugger 0h.mov': 24.0,
597+
'Frame Debugger 1h.mov': 86424.0
598+
}
599+
600+
start_times = {}
601+
for clip in timeline.each_clip():
602+
start_times[clip.name] = clip.source_range.start_time.value
603+
604+
self.assertEqual(start_times, expected_start_times)
605+
606+
def test_aaf_clip_without_timecode_offset(self):
607+
timeline = otio.adapters.read_from_file(TIMCODE_EXAMPLE_PATH,
608+
clip_timecode_offset=False)
609+
expected_start_times = {
610+
'Frame Debugger 0h.mov': 24.0,
611+
'Frame Debugger 1h.mov': 24.0
612+
}
613+
614+
start_times = {}
615+
for clip in timeline.each_clip():
616+
start_times[clip.name] = clip.source_range.start_time.value
617+
618+
self.assertEqual(start_times, expected_start_times)
619+
592620
def test_aaf_user_comments(self):
593621
aaf_path = TRIMS_EXAMPLE_PATH
594622
timeline = otio.adapters.read_from_file(aaf_path)

0 commit comments

Comments
 (0)