Skip to content

Commit

Permalink
Refactor OTIO frame range collection
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
jakubjezek001 committed Dec 13, 2024
1 parent 704b011 commit 63ed2f2
Showing 1 changed file with 70 additions and 17 deletions.
87 changes: 70 additions & 17 deletions client/ayon_core/plugins/publish/collect_otio_frame_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,65 @@ 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

# 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
Expand All @@ -42,15 +96,13 @@ def process(self, instance):
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
Expand All @@ -59,16 +111,19 @@ def process(self, instance):
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
Expand All @@ -87,7 +142,5 @@ def process(self, instance):
"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)))

0 comments on commit 63ed2f2

Please sign in to comment.