Skip to content

Commit

Permalink
Fix source clip start offset when writing AAFs (#506)
Browse files Browse the repository at this point in the history
* Fix missing source clip start offset

Without this, the resulting AAF always use the full available media of a clip even the start_time in source_range has different value than that of availabe_range.

Fixed private method `_target_url_fixup`.
It didn’t really use the `timeline` passed in. It just happened to pick up the`otio_timeline` when the method was called due to Python scoping.
  • Loading branch information
jchen9 authored and jminor committed Apr 24, 2019
1 parent e2eab9d commit b044e07
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
8 changes: 8 additions & 0 deletions opentimelineio_contrib/adapters/aaf_adapter/aaf_writer.py
Expand Up @@ -363,9 +363,17 @@ def aaf_sourceclip(self, otio_clip):
mastermob, mastermob_slot = self._create_mastermob(otio_clip,
filemob,
filemob_slot)

# We need both `start_time` and `duration`
# Here `start` is the offset between `first` and `in` values.

offset = otio_clip.visible_range().start_time - otio_clip.available_range().start_time
start = offset.value
length = otio_clip.visible_range().duration.value

compmob_clip = self.compositionmob.create_source_clip(
slot_id=self.timeline_mobslot.slot_id,
start=start,
length=length,
media_kind=self.media_kind)
compmob_clip.mob = mastermob
Expand Down
40 changes: 39 additions & 1 deletion opentimelineio_contrib/adapters/tests/test_aaf_adapter.py
Expand Up @@ -809,7 +809,7 @@ def test_aaf_writer_nometadata(self):
def _target_url_fixup(timeline):
# fixes up relative paths to be absolute to this test file
test_dir = os.path.dirname(os.path.abspath(__file__))
for clip in otio_timeline.each_clip():
for clip in timeline.each_clip():
target_url_str = clip.media_reference.target_url
clip.media_reference.target_url = os.path.join(test_dir, target_url_str)

Expand All @@ -834,6 +834,44 @@ def _target_url_fixup(timeline):
otio.adapters.write_to_file(otio_timeline, tmp_aaf_path, use_empty_mob_ids=True)
self._verify_aaf(tmp_aaf_path)

def test_aaf_roundtrip_first_clip(self):
def _target_url_fixup(timeline):
# fixes up relative paths to be absolute to this test file
test_dir = os.path.dirname(os.path.abspath(__file__))
for clip in timeline.each_clip():
target_url_str = clip.media_reference.target_url
clip.media_reference.target_url = os.path.join(test_dir, target_url_str)

# Exercise getting Mob IDs from AAF files
otio_timeline = otio.adapters.read_from_file(NO_METADATA_OTIO_PATH)
_target_url_fixup(otio_timeline)
fd, tmp_aaf_path = tempfile.mkstemp(suffix='.aaf')
otio.adapters.write_to_file(otio_timeline, tmp_aaf_path)
self._verify_first_clip(otio_timeline, tmp_aaf_path)

def _verify_first_clip(self, original_timeline, aaf_path):
timeline_from_aaf = otio.adapters.read_from_file(aaf_path)

original_clips = list(original_timeline.each_clip())
aaf_clips = list(timeline_from_aaf.each_clip())

self.assertTrue(len(original_clips) > 0)
self.assertEqual(len(aaf_clips), len(original_clips))

first_clip_in_original_timeline = original_clips[0]
first_clip_in_aaf_timeline = aaf_clips[0]

# Comparing stuff
for prop in ['source_range']:
self.assertEqual(getattr(first_clip_in_original_timeline, prop),
getattr(first_clip_in_aaf_timeline, prop),
"`{}` did not match".format(prop))

for method in ['visible_range', 'trimmed_range']:
self.assertEqual(getattr(first_clip_in_original_timeline, method)(),
getattr(first_clip_in_aaf_timeline, method)(),
"`{}` did not match".format(method))

def test_aaf_writer_nesting(self):
self._verify_aaf(NESTING_EXAMPLE_PATH)

Expand Down

0 comments on commit b044e07

Please sign in to comment.