Skip to content

Commit

Permalink
Fix CDL returned dict in the clip metadata of the ale adapter (offset…
Browse files Browse the repository at this point in the history
… and power were flipped). Add unit test for cdl values.
  • Loading branch information
vvzen committed Nov 23, 2019
1 parent 99a3726 commit 8359f15
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 52 deletions.
52 changes: 17 additions & 35 deletions contrib/opentimelineio_contrib/adapters/ale.py
Expand Up @@ -21,7 +21,6 @@
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#

"""OpenTimelineIO Avid Log Exchange (ALE) Adapter"""
import re
import opentimelineio as otio
Expand Down Expand Up @@ -87,35 +86,28 @@ def _parse_data_line(line, columns, fps):
try:
duration = otio.opentime.from_timecode(value, fps)
except (ValueError, TypeError):
raise ALEParseError("Invalid Duration timecode: {}".format(
value
))
raise ALEParseError(
"Invalid Duration timecode: {}".format(value))
if metadata.get("End", "") != "":
value = metadata.pop("End")
try:
end = otio.opentime.from_timecode(value, fps)
except (ValueError, TypeError):
raise ALEParseError("Invalid End timecode: {}".format(
value
))
raise ALEParseError(
"Invalid End timecode: {}".format(value))
if duration is None:
duration = end - start
if end is None:
end = start + duration
if end != start + duration:
raise ALEParseError(
"Inconsistent Start, End, Duration: " + line
)
clip.source_range = otio.opentime.TimeRange(
start,
duration
)
raise ALEParseError("Inconsistent Start, End, Duration: " +
line)
clip.source_range = otio.opentime.TimeRange(start, duration)

if metadata.get("Source File"):
source = metadata.pop("Source File")
clip.media_reference = otio.schema.ExternalReference(
target_url=source
)
target_url=source)

# If available, collect cdl values in the same way we do for CMX EDL
cdl = {}
Expand Down Expand Up @@ -168,8 +160,8 @@ def _cdl_values_from_metadata(asc_sop_string):
cdl_data.update(
asc_sop={
'slope': [float(v) for v in asc_sop_values[:3]],
'power': [float(v) for v in asc_sop_values[3:6]],
'offset': [float(v) for v in asc_sop_values[6:9]]
'offset': [float(v) for v in asc_sop_values[3:6]],
'power': [float(v) for v in asc_sop_values[6:9]]
})

if len(asc_sop_values) == 10:
Expand Down Expand Up @@ -255,10 +247,7 @@ def nextline(lines):

collection.append(clip)

collection.metadata["ALE"] = {
"header": header,
"columns": columns
}
collection.metadata["ALE"] = {"header": header, "columns": columns}

return collection

Expand Down Expand Up @@ -328,32 +317,25 @@ def val_for_column(column, clip):
if column == "Name":
return clip.name
elif column == "Source File":
if (
clip.media_reference and
hasattr(clip.media_reference, 'target_url') and
clip.media_reference.target_url
):
if (clip.media_reference and
hasattr(clip.media_reference, 'target_url') and
clip.media_reference.target_url):
return clip.media_reference.target_url
else:
return ""
elif column == "Start":
if not clip.source_range:
return ""
return otio.opentime.to_timecode(
clip.source_range.start_time, fps
)
return otio.opentime.to_timecode(clip.source_range.start_time, fps)
elif column == "Duration":
if not clip.source_range:
return ""
return otio.opentime.to_timecode(
clip.source_range.duration, fps
)
return otio.opentime.to_timecode(clip.source_range.duration, fps)
elif column == "End":
if not clip.source_range:
return ""
return otio.opentime.to_timecode(
clip.source_range.end_time_exclusive(), fps
)
clip.source_range.end_time_exclusive(), fps)
else:
return clip.metadata.get("ALE", {}).get(column)

Expand Down

This file was deleted.

58 changes: 55 additions & 3 deletions contrib/opentimelineio_contrib/adapters/tests/test_ale_adapter.py
Expand Up @@ -33,7 +33,7 @@
SAMPLE_DATA_DIR = os.path.join(os.path.dirname(__file__), "sample_data")
EXAMPLE_PATH = os.path.join(SAMPLE_DATA_DIR, "sample.ale")
EXAMPLE2_PATH = os.path.join(SAMPLE_DATA_DIR, "sample2.ale")
EXAMPLE3_PATH = os.path.join(SAMPLE_DATA_DIR, "sample3.ale")
EXAMPLE_CDL_PATH = os.path.join(SAMPLE_DATA_DIR, "sample_cdl.ale")
EXAMPLEUHD_PATH = os.path.join(SAMPLE_DATA_DIR, "sampleUHD.ale")


Expand Down Expand Up @@ -99,8 +99,8 @@ def test_ale_read2(self):
]
)

def test_ale_read3(self):
ale_path = EXAMPLE3_PATH
def test_ale_read_cdl(self):
ale_path = EXAMPLE_CDL_PATH
collection = otio.adapters.read_from_file(ale_path)
self.assertTrue(collection is not None)
self.assertEqual(type(collection), otio.schema.SerializableCollection)
Expand Down Expand Up @@ -130,6 +130,58 @@ def test_ale_read3(self):
otio.opentime.from_timecode("00:00:03:14", fps))
])

# Slope, offset, and power values are of type _otio.AnyVector
# So we have to convert them to lists otherwise
# the comparison between those two types would fail

# FIRST CLIP
self.assertEqual(
list(collection[0].metadata['cdl']['asc_sop']['slope']),
[0.8714, 0.9334, 0.9947])
self.assertEqual(
list(collection[0].metadata['cdl']['asc_sop']['offset']),
[-0.087, -0.0922, -0.0808])
self.assertEqual(
list(collection[0].metadata['cdl']['asc_sop']['power']),
[0.9988, 1.0218, 1.0101])
self.assertEqual(collection[0].metadata['cdl']['asc_sat'], 0.9)

# SECOND CLIP
self.assertEqual(
list(collection[1].metadata['cdl']['asc_sop']['slope']),
[0.8714, 0.9334, 0.9947])
self.assertEqual(
list(collection[1].metadata['cdl']['asc_sop']['offset']),
[-0.087, -0.0922, -0.0808])
self.assertEqual(
list(collection[1].metadata['cdl']['asc_sop']['power']),
[0.9988, 1.0218, 1.0101])
self.assertEqual(collection[1].metadata['cdl']['asc_sat'], 0.9)

# THIRD CLIP
self.assertEqual(
list(collection[2].metadata['cdl']['asc_sop']['slope']),
[0.8604, 0.9252, 0.9755])
self.assertEqual(
list(collection[2].metadata['cdl']['asc_sop']['offset']),
[-0.0735, -0.0813, -0.0737])
self.assertEqual(
list(collection[2].metadata['cdl']['asc_sop']['power']),
[0.9988, 1.0218, 1.0101])
self.assertEqual(collection[2].metadata['cdl']['asc_sat'], 0.9)

# FOURTH CLIP
self.assertEqual(
list(collection[3].metadata['cdl']['asc_sop']['slope']),
[0.8714, 0.9334, 0.9947])
self.assertEqual(
list(collection[3].metadata['cdl']['asc_sop']['offset']),
[-0.087, -0.0922, -0.0808])
self.assertEqual(
list(collection[3].metadata['cdl']['asc_sop']['power']),
[0.9988, 1.0218, 1.0101])
self.assertEqual(collection[3].metadata['cdl']['asc_sat'], 0.9)

def test_ale_uhd(self):
ale_path = EXAMPLEUHD_PATH
collection = otio.adapters.read_from_file(ale_path)
Expand Down

0 comments on commit 8359f15

Please sign in to comment.