Skip to content

Commit

Permalink
Apply frame offset to timewarp to handle source frame offset.
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-ynput committed Jan 28, 2025
1 parent 43700c7 commit f5bd7a9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 44 deletions.
32 changes: 32 additions & 0 deletions client/ayon_core/pipeline/editorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ def get_media_range_with_retimes(otio_clip, handle_start, handle_end):
in_frame += time_scalar
frame_range.append(in_frame)

# Different editorial DCC might have different TimeWarp logic.
# The following logic assumes that the "lookup" list values are
# frame offsets relative to the current source frame number.
#
# media_source_range |______1_____|______2______|______3______|
#
# media_retimed_range |______2_____|______2______|______3______|
#
# TimeWarp lookup +1 0 0
for tw_idx, tw in enumerate(time_warp_nodes):
for idx, frame_number in enumerate(frame_range):
# First timewarp, apply on media range
Expand All @@ -467,9 +476,32 @@ def get_media_range_with_retimes(otio_clip, handle_start, handle_end):
)

# adjust range if needed
media_in_trimmed_before_tw = media_in_trimmed
media_in_trimmed = max(min(frame_range), media_in)
media_out_trimmed = min(max(frame_range), media_out)

# If TimeWarp changes the first frame of the soure range,
# we need to offset the first TimeWarp values accordingly.
#
# expected_range |______2_____|______2______|______3______|
#
# EDITORIAL
# media_source_range |______1_____|______2______|______3______|
#
# TimeWarp lookup +1 0 0
#
# EXTRACTED PLATE
# plate_range |______2_____|______3______|_ _ _ _ _ _ _|
#
# expected TimeWarp 0 -1 -1
if media_in_trimmed != media_in_trimmed_before_tw:
offset = media_in_trimmed_before_tw - media_in_trimmed
offset *= 1.0 / time_scalar
time_warp_nodes[0]["lookup"] = [
value + offset
for value in time_warp_nodes[0]["lookup"]
]

# adjust available handles if needed
if (media_in_trimmed - media_in) < handle_start:
handle_start = max(0, media_in_trimmed - media_in)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ def test_movie_timewarp():
'Class': 'TimeWarp',
'length': 4.0,
'lookup': [
2.0,
1.8959999809265136,
1.767999971389771,
1.59199997138977,
1.3439999809265135,
1.0,
0.5440000181198119,
-0.007999974250793684,
-0.6319999756813051,
-1.3039999847412114,
-2.0
0.0,
-0.10400001907348644,
-0.23200002861022906,
-0.4080000286102301,
-0.6560000190734865,
-1.0,
-1.455999981880188,
-2.0079999742507937,
-2.631999975681305,
-3.3039999847412114,
-4.0
],
'name': 'TimeWarp2'
}
Expand Down Expand Up @@ -581,17 +581,17 @@ def test_img_sequence_timewarp_beyond_range():
'Class': 'TimeWarp',
'length': 1.0,
'lookup': [
-5.0,
-3.9440000305175777,
-2.852000034332275,
-1.6880000228881844,
-0.4160000076293944,
1.0,
2.5839999923706056,
4.311999977111817,
6.147999965667726,
8.055999969482421,
10.0
0.0,
1.0559999694824223,
2.147999965667725,
3.3119999771118156,
4.583999992370606,
6.0,
7.583999992370606,
9.311999977111817,
11.147999965667726,
13.055999969482421,
15.0
],
'name': 'TimeWarp3'
}
Expand Down Expand Up @@ -632,17 +632,17 @@ def test_img_sequence_2X_speed_timewarp():
'Class': 'TimeWarp',
'length': 4.0,
'lookup': [
2.0,
1.7039999923706055,
1.431999991416931,
1.2079999942779531,
1.055999998092652,
1.0,
1.056000007629395,
1.208000022888184,
1.432000034332276,
1.7040000305175766,
2.0
0.0,
-0.2960000076293945,
-0.568000008583069,
-0.7920000057220469,
-0.944000001907348,
-1.0,
-0.9439999923706051,
-0.791999977111816,
-0.5679999656677239,
-0.29599996948242335,
0.0
],
'name': 'TimeWarp6'
}
Expand Down Expand Up @@ -682,17 +682,17 @@ def test_img_sequence_multiple_timewarps():
'Class': 'TimeWarp',
'length': 1.0,
'lookup': [
-5.0,
-3.9440000305175777,
-2.852000034332275,
-1.6880000228881844,
-0.4160000076293944,
1.0,
2.5839999923706056,
4.311999977111817,
6.147999965667726,
8.055999969482421,
10.0
0.0,
1.0559999694824223,
2.147999965667725,
3.3119999771118156,
4.583999992370606,
6.0,
7.583999992370606,
9.311999977111817,
11.147999965667726,
13.055999969482421,
15.0
],
'name': 'TimeWarp3'
},
Expand Down

0 comments on commit f5bd7a9

Please sign in to comment.