Skip to content

🎥 Make videos programmatically with React

Remove half-frame offset from timeline layer positioning (#6716)

Jonny Burger7b606a319ec0
diff --git a/packages/studio/src/helpers/get-timeline-sequence-layout.ts b/packages/studio/src/helpers/get-timeline-sequence-layout.ts
index 24b1e91386..19676165a5 100644
--- a/packages/studio/src/helpers/get-timeline-sequence-layout.ts
+++ b/packages/studio/src/helpers/get-timeline-sequence-layout.ts
@@ -48,39 +48,22 @@ export const getTimelineSequenceLayout = ({
(maxMediaDuration ?? Infinity) - startFromMedia;
const lastFrame = (video.durationInFrames ?? 1) - 1;
- let spatialDuration = Math.min(
+ const spatialDuration = Math.min(
maxMediaSequenceDuration,
durationInFrames - 1,
lastFrame - startFrom,
);
// Unclipped spatial duration: without the lastFrame - startFrom constraint
- let naturalSpatialDuration = Math.min(
+ const naturalSpatialDuration = Math.min(
maxMediaSequenceDuration,
durationInFrames - 1,
);
- const shouldAddHalfAFrameAtEnd = startFrom + durationInFrames < lastFrame;
- const shouldAddHalfAFrameAtStart = startFrom > 0;
- if (shouldAddHalfAFrameAtEnd) {
- spatialDuration += 0.5;
- naturalSpatialDuration += 0.5;
- }
-
- if (shouldAddHalfAFrameAtStart) {
- spatialDuration += 0.5;
- naturalSpatialDuration += 0.5;
- }
-
- const startFromWithOffset = shouldAddHalfAFrameAtStart
- ? startFrom - 0.5
- : startFrom;
-
const marginLeft =
lastFrame === 0
? 0
- : (startFromWithOffset / lastFrame) *
- (windowWidth - TIMELINE_PADDING * 2);
+ : (startFrom / lastFrame) * (windowWidth - TIMELINE_PADDING * 2);
const nonNegativeMarginLeft = Math.min(marginLeft, 0);
diff --git a/packages/studio/src/test/timeline-sequence-layout.test.ts b/packages/studio/src/test/timeline-sequence-layout.test.ts
index 3b61c5e2b6..60328107ab 100644
--- a/packages/studio/src/test/timeline-sequence-layout.test.ts
+++ b/packages/studio/src/test/timeline-sequence-layout.test.ts
@@ -41,11 +41,11 @@ test('Should test timeline sequence layout without max media duration', () => {
windowWidth: 1414.203125,
}),
).toEqual({
- marginLeft: 1154.2137986426505,
+ marginLeft: 1154.4991419797689,
premountWidth: null,
postmountWidth: null,
- width: 226.9893263573493,
- naturalWidth: 226.9893263573493,
+ width: 226.70398302023122,
+ naturalWidth: 226.70398302023122,
});
});
test('Should test timeline sequence layout with max media duration', () => {
@@ -75,11 +75,11 @@ test('Should test timeline sequence layout with max media duration', () => {
windowWidth: 1414.203125,
}),
).toEqual({
- marginLeft: 1154.2137986426505,
+ marginLeft: 1154.4991419797689,
premountWidth: null,
postmountWidth: null,
- width: 221.8531462892238,
- naturalWidth: 221.8531462892238,
+ width: 221.5678029521057,
+ naturalWidth: 221.5678029521057,
});
});
@@ -165,7 +165,7 @@ test('naturalWidth is constrained by maxMediaDuration but not by timeline end',
expect(clippedByBoth.naturalWidth).toBeGreaterThan(clippedByBoth.width);
// Same segment but not clipped by timeline end (starts earlier)
- // Both should have the same half-frame behavior (shouldAddHalfAFrameAtEnd = true)
+ // Both should have the same behavior
const clippedByMediaOnly = getTimelineSequenceLayout({
durationInFrames: 200,
startFrom: 100,