Skip to content

🎥 Make videos programmatically with React

extend length of timeline by one frame so layers are adjacent

Jonny Burger73e328cc75d4
diff --git a/packages/cli/src/editor/helpers/get-timeline-sequence-layout.ts b/packages/cli/src/editor/helpers/get-timeline-sequence-layout.ts
index 5516173d07..91b4d05e61 100644
--- a/packages/cli/src/editor/helpers/get-timeline-sequence-layout.ts
+++ b/packages/cli/src/editor/helpers/get-timeline-sequence-layout.ts
@@ -3,6 +3,27 @@ import {TIMELINE_PADDING} from './timeline-layout';
export const SEQUENCE_BORDER_WIDTH = 1;
+const getWidthOfTrack = ({
+ durationInFrames,
+ lastFrame,
+ windowWidth,
+ spatialDuration,
+ nonNegativeMarginLeft,
+}: {
+ durationInFrames: number;
+ lastFrame: number;
+ windowWidth: number;
+ spatialDuration: number;
+ nonNegativeMarginLeft: number;
+}) => {
+ const fullWidth = windowWidth - TIMELINE_PADDING * 2;
+ const base =
+ durationInFrames === Infinity || lastFrame === 0
+ ? fullWidth
+ : (spatialDuration / lastFrame) * fullWidth;
+ return base - SEQUENCE_BORDER_WIDTH + nonNegativeMarginLeft;
+};
+
export const getTimelineSequenceLayout = ({
durationInFrames,
startFrom,
@@ -20,28 +41,44 @@ export const getTimelineSequenceLayout = ({
}) => {
const maxMediaSequenceDuration =
(maxMediaDuration ?? Infinity) - startFromMedia;
- const spatialDuration = Math.min(
+ let spatialDuration = Math.min(
maxMediaSequenceDuration,
durationInFrames - 1
);
const lastFrame = (video.durationInFrames ?? 1) - 1;
+ const shouldAddHalfAFrameAtEnd = startFrom + durationInFrames < lastFrame;
+ const shouldAddHalfAFrameAtStart = startFrom > 0;
+ if (shouldAddHalfAFrameAtEnd) {
+ spatialDuration += 0.5;
+ }
+
+ if (shouldAddHalfAFrameAtStart) {
+ spatialDuration += 0.5;
+ }
+
+ const startFromWithOffset = shouldAddHalfAFrameAtStart
+ ? startFrom - 0.5
+ : startFrom;
const marginLeft =
lastFrame === 0
? 0
- : (startFrom / lastFrame) * (windowWidth - TIMELINE_PADDING * 2);
+ : (startFromWithOffset / lastFrame) *
+ (windowWidth - TIMELINE_PADDING * 2);
- const negativeMarginLeft = Math.min(marginLeft, 0);
+ const nonNegativeMarginLeft = Math.min(marginLeft, 0);
- const width =
- (durationInFrames === Infinity || lastFrame === 0
- ? windowWidth - TIMELINE_PADDING * 2
- : (spatialDuration / lastFrame) * (windowWidth - TIMELINE_PADDING * 2)) -
- SEQUENCE_BORDER_WIDTH +
- negativeMarginLeft;
return {
marginLeft: Math.round(Math.max(marginLeft, 0)),
- width: Math.floor(width),
+ width: Math.floor(
+ getWidthOfTrack({
+ durationInFrames,
+ lastFrame,
+ nonNegativeMarginLeft,
+ spatialDuration,
+ windowWidth,
+ })
+ ),
};
};