Skip to content

Commit d2164c0

Browse files
Add fallback for transform calculation with older otio versions
Signed-off-by: Éloïse Brosseau <[email protected]>
1 parent 582da10 commit d2164c0

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/plugins/rv-packages/otio_reader/annotation_hook.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,27 @@ def _get_transform_properties():
2929
global_translate_vec = otio.schema.V2d(0.0, 0.0)
3030
global_scale_vec = otio.schema.V2d(1.0, 1.0)
3131

32-
global_translate = commands.getFloatProperty(f"{transform_node}.otio.global_translate")
33-
global_scale = commands.getFloatProperty(f"{transform_node}.otio.global_scale")
34-
global_translate_vec = otio.schema.V2d(global_translate[0], global_translate[1])
35-
global_scale_vec = otio.schema.V2d(global_scale[0], global_scale[1])
32+
if commands.propertyExists(f"{transform_node}.otio.global_translate") and commands.propertyExists(
33+
f"{transform_node}.otio.global_scale"
34+
):
35+
global_translate = commands.getFloatProperty(f"{transform_node}.otio.global_translate")
36+
global_scale = commands.getFloatProperty(f"{transform_node}.otio.global_scale")
37+
global_translate_vec = otio.schema.V2d(global_translate[0], global_translate[1])
38+
global_scale_vec = otio.schema.V2d(global_scale[0], global_scale[1])
39+
else:
40+
logging.warning(
41+
"OTIO global scale and translate properties not found, using aspect ratio from the source"
42+
)
43+
try:
44+
media_info = commands.sourceMediaInfo(first_source_node)
45+
height = media_info["height"]
46+
aspect_ratio = media_info["width"] / height if height != 0 else 1920 / 1080
47+
except Exception:
48+
logging.warning("Unable to determine aspect ratio, using default value of 16:9")
49+
aspect_ratio = 1920 / 1080
50+
51+
scale = aspect_ratio / 16
52+
global_scale_vec = otio.schema.V2d(scale, scale)
3653

3754
translate = commands.getFloatProperty(f"{transform_node}.transform.translate")
3855
scale = commands.getFloatProperty(f"{transform_node}.transform.scale")
@@ -67,7 +84,6 @@ def _transform_otio_to_world_coordinate(point):
6784

6885
def hook_function(in_timeline: otio.schemadef.Annotation.Annotation, argument_map: dict | None = None) -> None:
6986
"""A hook for the annotation schema"""
70-
7187
try:
7288
if argument_map["effect_metadata"]:
7389
effect_metadata = argument_map["effect_metadata"]

0 commit comments

Comments
 (0)