Skip to content

🎥 Make videos programmatically with React

studio: Preserve source duration while trimming nested sequences

JonnyBurger9818eeb12f4d
diff --git a/packages/example/e2e/sequence-playback-rate.test.mts b/packages/example/e2e/sequence-playback-rate.test.mts
index 57b4f1fd0e..06414d029a 100644
--- a/packages/example/e2e/sequence-playback-rate.test.mts
+++ b/packages/example/e2e/sequence-playback-rate.test.mts
@@ -48,7 +48,7 @@ test('retimed nested sequences preserve local frames when trimming, moving, and
.poll(() => fs.readFileSync(fixture, 'utf-8'))
.toMatch(/interpolate\(\s*frame,\s*\[20,\s*40,\s*80\]/);
- // Child duration 100 parent frames occupies 50 composition frames.
+ // The parent ends at frame 65, so the child is visible for 45 frames.
await row.click();
const trim = page
.getByRole('separator', {name: 'Drag to trim start', exact: true})
@@ -60,7 +60,7 @@ test('retimed nested sequences preserve local frames when trimming, moving, and
const durationBox = await duration.last().boundingBox();
if (!trimBox || !durationBox)
throw new Error('Expected sequence edge handles');
- const pixelsPerFrame = (durationBox.x - trimBox.x) / 50;
+ const pixelsPerFrame = (durationBox.x - trimBox.x) / 45;
const trimX = trimBox.x + trimBox.width / 2;
const trimY = trimBox.y + trimBox.height / 2;
await page.mouse.move(trimX, trimY);
@@ -70,7 +70,7 @@ test('retimed nested sequences preserve local frames when trimming, moving, and
await expect
.poll(() => fs.readFileSync(fixture, 'utf-8'))
.toMatch(
- /from=\{30\}[\s\S]*durationInFrames=\{90\}[\s\S]*trimBefore=\{9\}/,
+ /from=\{30\}[\s\S]*durationInFrames=\{95\}[\s\S]*trimBefore=\{9\}/,
);
await expect(
page.getByText('Local frame: 14', {exact: true}),
@@ -107,7 +107,7 @@ test('retimed nested sequences preserve local frames when trimming, moving, and
await page.mouse.up();
await expect
.poll(() => fs.readFileSync(fixture, 'utf-8'))
- .toMatch(/durationInFrames=\{80\}/);
+ .toMatch(/durationInFrames=\{30\}/);
} finally {
await stopStudio();
fs.writeFileSync(fixture, original);
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
index b323a37eb0..6412667b3e 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
@@ -992,13 +992,22 @@ export const getTimelineSequenceLeftEdgeDragTargets = ({
const key = stringifySequenceSubscriptionKey(nodePath);
if (!targets.has(key)) {
const runtimeValues = controls.runtimeValues.getSnapshot();
+ const playbackRate = getTrimPlaybackRate({
+ sequence: originalSequence,
+ runtimeValues,
+ });
+ const runtimeDuration = runtimeValues.durationInFrames;
targets.set(key, {
parentPlaybackRate: getParentSequencePlaybackRate(
originalSequence,
sequences,
),
fileName: nodePath.absolutePath,
- initialDuration: originalSequence.duration,
+ initialDuration:
+ typeof runtimeDuration === 'number' &&
+ Number.isFinite(runtimeDuration)
+ ? runtimeDuration / playbackRate
+ : originalSequence.duration,
initialFrom: positionField === 'from' ? originalSequence.from : 0,
initialTrimBefore: trimsMedia
? (originalSequence.trimBefore ??
@@ -1009,10 +1018,7 @@ export const getTimelineSequenceLeftEdgeDragTargets = ({
sequences,
}),
nodePath,
- playbackRate: getTrimPlaybackRate({
- sequence: originalSequence,
- runtimeValues,
- }),
+ playbackRate,
positionField,
schema: controls.schema,
});