Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5863 from ynput/bugfix/OP-6951_resolve_db_duratio…
Browse files Browse the repository at this point in the history
…n_calculation

resolve: fixing loader handles calculation
  • Loading branch information
jakubjezek001 authored Nov 28, 2023
2 parents 5068b65 + 2511006 commit 845a071
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion openpype/hosts/resolve/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def create_timeline_item(
if source_end:
clip_data["endFrame"] = source_end
if timecode_in:
clip_data["recordFrame"] = timecode_in
clip_data["recordFrame"] = timeline_in

# add to timeline
media_pool.AppendToTimeline([clip_data])
Expand Down
74 changes: 36 additions & 38 deletions openpype/hosts/resolve/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,26 +406,42 @@ def load(self, files):
self.active_bin
)
_clip_property = media_pool_item.GetClipProperty
source_in = int(_clip_property("Start"))
source_out = int(_clip_property("End"))
source_duration = int(_clip_property("Frames"))

# get handles
handle_start = self.data["versionData"].get("handleStart")
handle_end = self.data["versionData"].get("handleEnd")
if handle_start is None:
handle_start = int(self.data["assetData"]["handleStart"])
if handle_end is None:
handle_end = int(self.data["assetData"]["handleEnd"])

# check frame duration from versionData or assetData
frame_start = self.data["versionData"].get("frameStart")
if frame_start is None:
frame_start = self.data["assetData"]["frameStart"]

# check frame duration from versionData or assetData
frame_end = self.data["versionData"].get("frameEnd")
if frame_end is None:
frame_end = self.data["assetData"]["frameEnd"]

db_frame_duration = int(frame_end) - int(frame_start) + 1
if not self.with_handles:
# Load file without the handles of the source media
# We remove the handles from the source in and source out
# so that the handles are excluded in the timeline
handle_start = 0
handle_end = 0

# get version data frame data from db
version_data = self.data["versionData"]
frame_start = version_data.get("frameStart")
frame_end = version_data.get("frameEnd")

# The version data usually stored the frame range + handles of the
# media however certain representations may be shorter because they
# exclude those handles intentionally. Unfortunately the
# representation does not store that in the database currently;
# so we should compensate for those cases. If the media is shorter
# than the frame range specified in the database we assume it is
# without handles and thus we do not need to remove the handles
# from source and out
if frame_start is not None and frame_end is not None:
# Version has frame range data, so we can compare media length
handle_start = version_data.get("handleStart", 0)
handle_end = version_data.get("handleEnd", 0)
frame_start_handle = frame_start - handle_start
frame_end_handle = frame_start + handle_end
database_frame_duration = int(
frame_end_handle - frame_start_handle + 1
)
if source_duration >= database_frame_duration:
source_in += handle_start
source_out -= handle_end

# get timeline in
timeline_start = self.active_timeline.GetStartFrame()
Expand All @@ -437,24 +453,6 @@ def load(self, files):
timeline_in = int(
timeline_start + self.data["assetData"]["clipIn"])

source_in = int(_clip_property("Start"))
source_out = int(_clip_property("End"))
source_duration = int(_clip_property("Frames"))

# check if source duration is shorter than db frame duration
source_with_handles = True
if source_duration < db_frame_duration:
source_with_handles = False

# only exclude handles if source has no handles or
# if user wants to load without handles
if (
not self.with_handles
or not source_with_handles
):
source_in += handle_start
source_out -= handle_end

# make track item from source in bin as item
timeline_item = lib.create_timeline_item(
media_pool_item,
Expand Down Expand Up @@ -868,7 +866,7 @@ def _solve_tag_hierarchy_data(self, hierarchy_formatting_data):
def _convert_to_entity(self, key):
""" Converting input key to key with type. """
# convert to entity type
entity_type = self.types.get(key, None)
entity_type = self.types.get(key)

assert entity_type, "Missing entity type for `{}`".format(
key
Expand Down

0 comments on commit 845a071

Please sign in to comment.