From 63ed2f21d00a188301a844a932227d22d6fa5104 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 13 Dec 2024 18:40:40 +0100 Subject: [PATCH] Refactor OTIO frame range collection - Removed unused function import. - Added detailed logging for data updates. - Streamlined frame range calculations and handling. - Introduced a new class for collecting source frame ranges. - Improved readability by cleaning up code structure. --- .../publish/collect_otio_frame_ranges.py | 87 +++++++++++++++---- 1 file changed, 70 insertions(+), 17 deletions(-) diff --git a/client/ayon_core/plugins/publish/collect_otio_frame_ranges.py b/client/ayon_core/plugins/publish/collect_otio_frame_ranges.py index 62b4cefec6..0d1f76f338 100644 --- a/client/ayon_core/plugins/publish/collect_otio_frame_ranges.py +++ b/client/ayon_core/plugins/publish/collect_otio_frame_ranges.py @@ -24,11 +24,65 @@ class CollectOtioFrameRanges(pyblish.api.InstancePlugin): # Not all hosts can import these modules. import opentimelineio as otio from ayon_core.pipeline.editorial import ( - get_media_range_with_retimes, otio_range_to_frame_range, otio_range_with_handles ) + if not instance.data.get("otioClip"): + self.log.debug("Skipping collect OTIO frame range.") + return + + # get basic variables + otio_clip = instance.data["otioClip"] + workfile_start = instance.data["workfileFrameStart"] + + # get ranges + otio_tl_range = otio_clip.range_in_parent() + otio_tl_range_handles = otio_range_with_handles( + otio_tl_range, instance) + + # convert to frames + range_convert = otio_range_to_frame_range + tl_start, tl_end = range_convert(otio_tl_range) + tl_start_h, tl_end_h = range_convert(otio_tl_range_handles) + frame_start = workfile_start + frame_end = frame_start + otio.opentime.to_frames( + otio_tl_range.duration, otio_tl_range.duration.rate) - 1 + + data = { + "frameStart": frame_start, + "frameEnd": frame_end, + "clipIn": tl_start, + "clipOut": tl_end - 1, + "clipInH": tl_start_h, + "clipOutH": tl_end_h - 1, + } + instance.data.update(data) + self.log.debug( + "_ data: {}".format(pformat(data))) + self.log.debug( + "_ instance.data: {}".format(pformat(instance.data))) + + +class CollectOtioSourceFrameRanges(pyblish.api.InstancePlugin): + """Getting otio ranges from otio_clip + + Adding timeline and source ranges to instance data""" + + label = "Collect OTIO Frame Ranges (with media range)" + order = pyblish.api.CollectorOrder - 0.07 + families = ["shot", "clip"] + hosts = ["hiero", "flame"] + + def process(self, instance): + # Not all hosts can import these modules. + import opentimelineio as otio + from ayon_core.pipeline.editorial import ( + get_media_range_with_retimes, + otio_range_to_frame_range, + otio_range_with_handles, + ) + if not instance.data.get("otioClip"): self.log.debug("Skipping collect OTIO frame range.") return @@ -42,15 +96,13 @@ class CollectOtioFrameRanges(pyblish.api.InstancePlugin): otio_tl_range = otio_clip.range_in_parent() otio_src_range = otio_clip.source_range otio_avalable_range = otio_clip.available_range() - otio_tl_range_handles = otio_range_with_handles( - otio_tl_range, instance) - otio_src_range_handles = otio_range_with_handles( - otio_src_range, instance) + otio_tl_range_handles = otio_range_with_handles(otio_tl_range, instance) + otio_src_range_handles = otio_range_with_handles(otio_src_range, instance) # get source avalable start frame src_starting_from = otio.opentime.to_frames( - otio_avalable_range.start_time, - otio_avalable_range.start_time.rate) + otio_avalable_range.start_time, otio_avalable_range.start_time.rate + ) # convert to frames range_convert = otio_range_to_frame_range @@ -59,16 +111,19 @@ class CollectOtioFrameRanges(pyblish.api.InstancePlugin): src_start, src_end = range_convert(otio_src_range) src_start_h, src_end_h = range_convert(otio_src_range_handles) frame_start = workfile_start - frame_end = frame_start + otio.opentime.to_frames( - otio_tl_range.duration, otio_tl_range.duration.rate) - 1 + frame_end = ( + frame_start + + otio.opentime.to_frames( + otio_tl_range.duration, otio_tl_range.duration.rate + ) + - 1 + ) # in case of retimed clip and frame range should not be retimed if workfile_source_duration: # get available range trimmed with processed retimes - retimed_attributes = get_media_range_with_retimes( - otio_clip, 0, 0) - self.log.debug( - ">> retimed_attributes: {}".format(retimed_attributes)) + retimed_attributes = get_media_range_with_retimes(otio_clip, 0, 0) + self.log.debug(">> retimed_attributes: {}".format(retimed_attributes)) media_in = int(retimed_attributes["mediaIn"]) media_out = int(retimed_attributes["mediaOut"]) frame_end = frame_start + (media_out - media_in) + 1 @@ -87,7 +142,5 @@ class CollectOtioFrameRanges(pyblish.api.InstancePlugin): "sourceEndH": src_starting_from + src_end_h - 1, } instance.data.update(data) - self.log.debug( - "_ data: {}".format(pformat(data))) - self.log.debug( - "_ instance.data: {}".format(pformat(instance.data))) + self.log.debug("_ data: {}".format(pformat(data))) + self.log.debug("_ instance.data: {}".format(pformat(instance.data)))