Skip to content

🎥 Make videos programmatically with React

`remotion`: Change `durationInFrames` to use the child clock

JonnyBurgerd342f9555490
diff --git a/packages/codemods/src/split-jsx-sequence.ts b/packages/codemods/src/split-jsx-sequence.ts
index 02f20dbc98..f0acd8d9f2 100644
--- a/packages/codemods/src/split-jsx-sequence.ts
+++ b/packages/codemods/src/split-jsx-sequence.ts
@@ -442,10 +442,10 @@ export const splitJsxSequences = ({
}
const timing = readSequenceTiming(jsxElement);
+ const contentDuration = timing.durationInFrames;
+ const timelineDuration = contentDuration / timing.playbackRate;
const finiteEnd =
- timing.durationInFrames === Infinity
- ? Infinity
- : timing.from + timing.durationInFrames;
+ timelineDuration === Infinity ? Infinity : timing.from + timelineDuration;
if (splitFrame <= timing.from) {
throw new Error('Cannot split at or before the sequence start');
@@ -455,21 +455,32 @@ export const splitJsxSequences = ({
throw new Error('Cannot split at or after the sequence end');
}
- return {finiteEnd, jsxElement, jsxPath, splitFrame, timing};
+ return {
+ contentDuration,
+ jsxElement,
+ jsxPath,
+ splitFrame,
+ timing,
+ };
});
const nodeLabels: string[] = [];
const logLines: number[] = [];
const sourceEdits = targets.map(
- ({finiteEnd, jsxElement, jsxPath, splitFrame, timing}) => {
+ ({contentDuration, jsxElement, jsxPath, splitFrame, timing}) => {
const right = cloneJsxElement(jsxElement);
// Match Studio's numeric dragger precision while retaining fractional frames.
- const leftDuration = normalizeComputedTiming(splitFrame - timing.from);
+ const leftTimelineDuration = normalizeComputedTiming(
+ splitFrame - timing.from,
+ );
+ const leftDuration = normalizeComputedTiming(
+ leftTimelineDuration * timing.playbackRate,
+ );
const rightDuration =
- timing.durationInFrames === Infinity
+ contentDuration === Infinity
? Infinity
- : normalizeComputedTiming(finiteEnd - splitFrame);
+ : normalizeComputedTiming(contentDuration - leftDuration);
const rightTrimBefore = normalizeComputedTiming(
- timing.trimBefore + leftDuration * timing.playbackRate,
+ timing.trimBefore + leftDuration,
);
setNumericAttribute({
@@ -488,7 +499,7 @@ export const splitJsxSequences = ({
element: right,
name: 'durationInFrames',
value: rightDuration === Infinity ? null : rightDuration,
- omitIfMissing: !timing.hasDurationInFrames,
+ omitIfMissing: false,
});
setNumericAttribute({
element: right,
diff --git a/packages/codemods/src/test/split-jsx-sequence.test.ts b/packages/codemods/src/test/split-jsx-sequence.test.ts
index 65c262030f..a6c900af5e 100644
--- a/packages/codemods/src/test/split-jsx-sequence.test.ts
+++ b/packages/codemods/src/test/split-jsx-sequence.test.ts
@@ -99,10 +99,10 @@ test('splitting a sped-up sequence preserves its child clock across a fractional
splitFrame: 22.5,
});
expect(output.replace(/\s+/g, ' ')).toContain(
- 'from={10} durationInFrames={12.5} trimBefore={5} playbackRate={2}',
+ 'from={10} durationInFrames={25} trimBefore={5} playbackRate={2}',
);
expect(output.replace(/\s+/g, ' ')).toContain(
- 'from={22.5} durationInFrames={37.5} trimBefore={30} playbackRate={2}',
+ 'from={22.5} durationInFrames={25} trimBefore={30} playbackRate={2}',
);
});
diff --git a/packages/core/src/AbsoluteFill.tsx b/packages/core/src/AbsoluteFill.tsx
index 37b832971c..2d17e7fb5a 100644
--- a/packages/core/src/AbsoluteFill.tsx
+++ b/packages/core/src/AbsoluteFill.tsx
@@ -73,7 +73,6 @@ const AbsoluteFillWithTiming: React.FC<
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -98,8 +97,6 @@ const AbsoluteFillWithTiming: React.FC<
from: from ?? 0,
durationInFrames: resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -116,11 +113,10 @@ const AbsoluteFillWithTiming: React.FC<
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
- durationInFrames={durationInFrames ?? Infinity}
+ durationInFrames={durationInFrames}
hidden={hidden}
name={name ?? '<AbsoluteFill>'}
showInTimeline={showInTimeline ?? true}
@@ -154,7 +150,6 @@ const AbsoluteFillInner: React.FC<
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -193,7 +188,6 @@ const AbsoluteFillInner: React.FC<
styleWhilePremounted={styleWhilePremounted}
styleWhilePostmounted={styleWhilePostmounted}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/core/src/HtmlInCanvas.tsx b/packages/core/src/HtmlInCanvas.tsx
index 2ce2ccf8d6..5eb355dc4a 100644
--- a/packages/core/src/HtmlInCanvas.tsx
+++ b/packages/core/src/HtmlInCanvas.tsx
@@ -788,8 +788,6 @@ const HtmlInCanvasInner = forwardRef<
from: sequenceProps.from ?? 0,
durationInFrames: resolveSequenceDuration({
durationInFrames,
- trimBefore: sequenceProps.trimBefore,
- trimAfter: sequenceProps.trimAfter,
playbackRate: sequenceProps.playbackRate,
loop: sequenceProps.loop,
}),
diff --git a/packages/core/src/Img.tsx b/packages/core/src/Img.tsx
index 325c7c9b83..4771c4cf40 100644
--- a/packages/core/src/Img.tsx
+++ b/packages/core/src/Img.tsx
@@ -85,7 +85,6 @@ type ImgContentProps = Omit<
| 'showInTimeline'
| 'from'
| 'trimBefore'
- | 'trimAfter'
| 'loop'
| 'durationInFrames'
| 'freeze'
@@ -364,7 +363,6 @@ const NativeImgInner: React.FC<NativeImgInnerProps> = ({
src,
from,
trimBefore,
- trimAfter,
loop,
durationInFrames,
freeze,
@@ -404,8 +402,6 @@ const NativeImgInner: React.FC<NativeImgInnerProps> = ({
from: from ?? 0,
durationInFrames: resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate: undefined,
loop,
}),
@@ -431,9 +427,8 @@ const NativeImgInner: React.FC<NativeImgInnerProps> = ({
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
loop={loop}
- durationInFrames={durationInFrames ?? Infinity}
+ durationInFrames={durationInFrames}
freeze={freeze}
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/img"
_remotionInternalIsMedia={isMedia}
@@ -562,7 +557,6 @@ const ImgInner: React.FC<
src,
from,
trimBefore,
- trimAfter,
durationInFrames,
freeze,
premountFor,
@@ -599,7 +593,6 @@ const ImgInner: React.FC<
src={src}
from={from}
trimBefore={trimBefore}
- trimAfter={trimAfter}
durationInFrames={durationInFrames}
freeze={freeze}
premountFor={premountFor}
@@ -662,7 +655,6 @@ const ImgInner: React.FC<
delayRenderTimeoutInMilliseconds={delayRenderTimeoutInMilliseconds}
from={from}
trimBefore={trimBefore}
- trimAfter={trimAfter}
durationInFrames={durationInFrames}
freeze={freeze}
premountFor={premountFor}
diff --git a/packages/core/src/Interactive.tsx b/packages/core/src/Interactive.tsx
index 5025ec04a2..94543b2cb2 100644
--- a/packages/core/src/Interactive.tsx
+++ b/packages/core/src/Interactive.tsx
@@ -84,7 +84,6 @@ export type InteractiveBaseProps = Pick<
| 'durationInFrames'
| 'from'
| 'trimBefore'
- | 'trimAfter'
| 'playbackRate'
| 'loop'
| 'freeze'
@@ -250,7 +249,6 @@ const makeInteractiveElement = <Tag extends InteractiveTag>(
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -280,8 +278,6 @@ const makeInteractiveElement = <Tag extends InteractiveTag>(
from: from ?? 0,
durationInFrames: resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -313,10 +309,9 @@ const makeInteractiveElement = <Tag extends InteractiveTag>(
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
- durationInFrames={durationInFrames ?? Infinity}
+ durationInFrames={durationInFrames}
freeze={freeze}
hidden={hidden}
name={name ?? displayName}
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index cff600347c..bde9711756 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -23,7 +23,10 @@ import {
sequenceSchemaWithoutFrom,
} from './interactivity-schema.js';
import {LoopContext, type LoopContextType} from './loop/loop-context.js';
-import {resolveSequenceDuration} from './resolve-sequence-duration.js';
+import {
+ resolveSequenceContentDuration,
+ resolveSequenceDuration,
+} from './resolve-sequence-duration.js';
import type {RuntimeValueStore} from './runtime-value-store.js';
import {
getSequenceCropClipPath,
@@ -80,7 +83,6 @@ export type SequencePropsWithoutDuration = {
readonly cropBottom?: number;
readonly from?: number;
readonly trimBefore?: number;
- readonly trimAfter?: number;
readonly playbackRate?: number;
readonly loop?: boolean;
readonly freeze?: number | null;
@@ -151,11 +153,10 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
{
from = 0,
trimBefore = 0,
- trimAfter,
playbackRate = 1,
loop = false,
freeze,
- durationInFrames = Infinity,
+ durationInFrames,
children,
name,
height,
@@ -222,15 +223,19 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
);
}
- if (typeof durationInFrames !== 'number') {
+ const contentDurationInFrames = resolveSequenceContentDuration({
+ durationInFrames,
+ });
+
+ if (typeof contentDurationInFrames !== 'number') {
throw new TypeError(
- `You passed to durationInFrames an argument of type ${typeof durationInFrames}, but it must be a number.`,
+ `You passed to durationInFrames an argument of type ${typeof contentDurationInFrames}, but it must be a number.`,
);
}
- if (durationInFrames <= 0) {
+ if (contentDurationInFrames <= 0) {
throw new TypeError(
- `durationInFrames must be positive, but got ${durationInFrames}`,
+ `durationInFrames must be positive, but got ${contentDurationInFrames}`,
);
}
@@ -270,38 +275,15 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
);
}
- if (typeof trimAfter !== 'undefined') {
- if (typeof trimAfter !== 'number') {
- throw new TypeError(
- `The "trimAfter" prop of <Sequence /> must be a number, but is of type ${typeof trimAfter}.`,
- );
- }
-
- if (Number.isNaN(trimAfter)) {
- throw new TypeError(
- 'The "trimAfter" prop of <Sequence /> must be a real number, but it is NaN.',
- );
- }
-
- if (trimAfter <= trimBefore) {
- throw new TypeError(
- `The "trimAfter" prop of <Sequence /> must be greater than "trimBefore" (${trimBefore}), but got ${trimAfter}.`,
- );
- }
- }
-
if (typeof loop !== 'boolean') {
throw new TypeError(
`The "loop" prop of <Sequence /> must be a boolean, but is of type ${typeof loop}.`,
);
}
- if (
- loop &&
- (typeof trimAfter === 'undefined' || !Number.isFinite(trimAfter))
- ) {
+ if (loop && !Number.isFinite(contentDurationInFrames)) {
throw new Error(
- 'The "loop" prop of <Sequence /> requires a finite "trimAfter" prop, because a <Sequence /> has no intrinsic duration. Set "trimAfter" to the frame at which the children should start over, or use <Loop /> to repeat a duration measured in the parent timeline.',
+ 'The "loop" prop of <Sequence /> requires a finite "durationInFrames" prop, because a <Sequence /> has no intrinsic duration.',
);
}
@@ -350,8 +332,6 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
const videoConfig = useVideoConfig();
const effectiveDurationInFrames = resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
});
@@ -368,13 +348,13 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
Math.min(videoConfig.durationInFrames - from, parentSequenceDuration),
);
- // A looped sequence repeats the child range [trimBefore, trimAfter). Each
+ // A looped sequence repeats the child range selected by `durationInFrames`. Each
// iteration lasts `loopPeriod` parent frames and moves the clock origin,
// while the visible window stays at [from, from + effectiveDurationInFrames).
const frameInParent = (absoluteFrame - cumulatedFrom) * parentPlaybackRate;
const loopPeriod =
- loop && typeof trimAfter === 'number'
- ? (trimAfter - trimBefore) / playbackRate
+ loop && Number.isFinite(contentDurationInFrames)
+ ? contentDurationInFrames / playbackRate
: null;
let loopIteration = 0;
if (loopPeriod !== null) {
@@ -400,8 +380,8 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
const effectiveRelativeFrom = clockFrom - trimBefore / playbackRate;
const relativeFrom = effectiveRelativeFrom / parentPlaybackRate;
const absoluteFrom = (parentSequence?.absoluteFrom ?? 0) + relativeFrom;
- // Inside a loop, the local clock ends at `trimAfter`, except in a final
- // iteration that `durationInFrames` or the parent cuts short.
+ // Inside a loop, the local clock ends after `durationInFrames`, except in a final
+ // iteration that the parent cuts short.
const localClockEnd =
loopPeriod === null
? actualDurationInFrames * playbackRate + trimBefore
@@ -509,8 +489,11 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
return null;
}
- return {iteration: loopIteration, durationInFrames: loopPeriod};
- }, [loopIteration, loopPeriod]);
+ return {
+ iteration: loopIteration,
+ durationInFrames: contentDurationInFrames,
+ };
+ }, [contentDurationInFrames, loopIteration, loopPeriod]);
const resolvedLoopDisplay = useMemo((): LoopDisplay | undefined => {
if (loopDisplay || loopPeriod === null) {
@@ -859,7 +842,7 @@ const PremountedPostmountedSequenceRefForwardingFunction: React.ForwardRefRender
const {
style: passedStyle,
from = 0,
- durationInFrames = Infinity,
+ durationInFrames,
premountFor = 0,
postmountFor = 0,
styleWhilePremounted,
@@ -877,8 +860,6 @@ const PremountedPostmountedSequenceRefForwardingFunction: React.ForwardRefRender
from,
durationInFrames: resolveSequenceDuration({
durationInFrames,
- trimBefore: otherProps.trimBefore,
- trimAfter: otherProps.trimAfter,
playbackRate: otherProps.playbackRate,
loop: otherProps.loop,
}),
diff --git a/packages/core/src/animated-image/AnimatedImage.tsx b/packages/core/src/animated-image/AnimatedImage.tsx
index f4fa2fd47f..01d90e9b2b 100644
--- a/packages/core/src/animated-image/AnimatedImage.tsx
+++ b/packages/core/src/animated-image/AnimatedImage.tsx
@@ -336,8 +336,6 @@ const AnimatedImageInner = ({
from: from ?? 0,
durationInFrames: resolveSequenceDuration({
durationInFrames,
- trimBefore: sequenceProps.trimBefore,
- trimAfter: sequenceProps.trimAfter,
playbackRate,
loop: sequenceProps.loop,
}),
@@ -379,7 +377,7 @@ const AnimatedImageInner = ({
layout="none"
from={from ?? 0}
playbackRate={playbackRate}
- durationInFrames={durationInFrames ?? Infinity}
+ durationInFrames={durationInFrames}
name="<AnimatedImage>"
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/animatedimage"
controls={controls}
diff --git a/packages/core/src/canvas-image/CanvasImage.tsx b/packages/core/src/canvas-image/CanvasImage.tsx
index a1963f7367..75c43e8371 100644
--- a/packages/core/src/canvas-image/CanvasImage.tsx
+++ b/packages/core/src/canvas-image/CanvasImage.tsx
@@ -538,7 +538,6 @@ const CanvasImageInner = forwardRef<
durationInFrames,
from,
trimBefore,
- trimAfter,
loop,
freeze,
premountFor,
@@ -588,8 +587,6 @@ const CanvasImageInner = forwardRef<
from: from ?? 0,
durationInFrames: resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate: undefined,
loop,
}),
@@ -615,9 +612,8 @@ const CanvasImageInner = forwardRef<
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
loop={loop}
- durationInFrames={durationInFrames ?? Infinity}
+ durationInFrames={durationInFrames}
freeze={freeze}
hidden={hidden}
showInTimeline={showInTimeline ?? true}
diff --git a/packages/core/src/effects/Solid.tsx b/packages/core/src/effects/Solid.tsx
index 89d7663348..3e4bfb32e2 100644
--- a/packages/core/src/effects/Solid.tsx
+++ b/packages/core/src/effects/Solid.tsx
@@ -280,7 +280,6 @@ const SolidOuter = forwardRef<
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -315,8 +314,6 @@ const SolidOuter = forwardRef<
from: from ?? 0,
durationInFrames: resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -342,7 +339,6 @@ const SolidOuter = forwardRef<
layout="none"
from={from}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/core/src/interactivity-schema.ts b/packages/core/src/interactivity-schema.ts
index ecb5d38f4e..cee220148b 100644
--- a/packages/core/src/interactivity-schema.ts
+++ b/packages/core/src/interactivity-schema.ts
@@ -647,7 +647,6 @@ export const baseSchema = {
durationInFrames: durationInFramesField,
from: fromField,
trimBefore: trimBeforeField,
- trimAfter: trimAfterField,
playbackRate: playbackRateField,
loop: loopField,
freeze: freezeField,
@@ -661,7 +660,6 @@ export const baseSchemaWithoutPlaybackRate = {
durationInFrames: durationInFramesField,
from: fromField,
trimBefore: trimBeforeField,
- trimAfter: trimAfterField,
loop: loopField,
freeze: freezeField,
hidden: hiddenField,
@@ -685,7 +683,6 @@ export const sequenceSchema = {
export const baseSchemaWithoutFrom = {
durationInFrames: durationInFramesField,
trimBefore: trimBeforeField,
- trimAfter: trimAfterField,
playbackRate: playbackRateField,
loop: loopField,
freeze: freezeField,
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 450881bf05..c7bd4d2184 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -108,6 +108,7 @@ import {
sequenceStyleSchema,
sequenceVisualStyleSchema,
textSchema,
+ trimAfterField,
transformSchema,
type AssetFieldSchema,
type ArrayFieldSchema,
@@ -494,6 +495,7 @@ export const Internals = {
durationInFramesField,
freezeField,
fromField,
+ trimAfterField,
resolveSequenceCrop,
useCropStyle,
} as const;
diff --git a/packages/core/src/loop/index.tsx b/packages/core/src/loop/index.tsx
index af976cc9d7..24df980a94 100644
--- a/packages/core/src/loop/index.tsx
+++ b/packages/core/src/loop/index.tsx
@@ -48,6 +48,8 @@ export const Loop: React.FC<LoopProps> & {
const {durationInFrames: compDuration} = useVideoConfig();
const parentSequence = useContext(SequenceContext);
const parentPlaybackRate = parentSequence?.playbackRate ?? 1;
+ const playbackRateValue = playbackRate ?? 1;
+ const iterationDurationInFrames = durationInFrames / playbackRateValue;
const loopStartFrame = parentSequence
? parentSequence.cumulatedFrom + parentSequence.relativeFrom
: 0;
@@ -56,7 +58,8 @@ export const Loop: React.FC<LoopProps> & {
(parentSequence?.cumulatedNegativeFrom ?? 0) / parentPlaybackRate;
const endFrame =
loopStartFrame +
- Math.min(compDuration, durationInFrames * times) / parentPlaybackRate;
+ Math.min(compDuration, iterationDurationInFrames * times) /
+ parentPlaybackRate;
validateDurationInFrames(durationInFrames, {
component: 'of the <Loop /> component',
@@ -81,10 +84,10 @@ export const Loop: React.FC<LoopProps> & {
);
}
- const maxTimes = Math.ceil(compDuration / durationInFrames);
+ const maxTimes = Math.ceil(compDuration / iterationDurationInFrames);
const actualTimes = Math.min(maxTimes, times);
- const maxFrame = durationInFrames * (actualTimes - 1);
- const loopsElapsed = currentFrame / durationInFrames;
+ const maxFrame = iterationDurationInFrames * (actualTimes - 1);
+ const loopsElapsed = currentFrame / iterationDurationInFrames;
const nearestIteration = Math.round(loopsElapsed);
// Fractional durations and nested playback rates can put an exact loop
// boundary a few floating-point units before the next iteration.
@@ -98,16 +101,18 @@ export const Loop: React.FC<LoopProps> & {
isAtBoundary ? nearestIteration : Math.floor(loopsElapsed),
),
);
- const start = isAtBoundary ? currentFrame : iteration * durationInFrames;
+ const start = isAtBoundary
+ ? currentFrame
+ : iteration * iterationDurationInFrames;
const from = Math.max(0, Math.min(start, maxFrame));
const loopDisplay: LoopDisplay = useMemo(() => {
return {
- numberOfTimes: Math.min(compDuration / durationInFrames, times),
+ numberOfTimes: Math.min(compDuration / iterationDurationInFrames, times),
startOffset: -from,
- durationInFrames,
+ durationInFrames: iterationDurationInFrames,
};
- }, [compDuration, durationInFrames, from, times]);
+ }, [compDuration, from, iterationDurationInFrames, times]);
const loopContext: LoopContextType = useMemo(() => {
return {
diff --git a/packages/core/src/resolve-sequence-duration.ts b/packages/core/src/resolve-sequence-duration.ts
index 9f7b22d3c1..24994de753 100644
--- a/packages/core/src/resolve-sequence-duration.ts
+++ b/packages/core/src/resolve-sequence-duration.ts
@@ -1,26 +1,29 @@
-// Length of an item in its parent timeline. `trimAfter` is measured in the
-// child clock, so it only bounds the duration once converted by `playbackRate`.
-// A looped item repeats the trimmed range, so only `durationInFrames` caps it.
+export const resolveSequenceContentDuration = ({
+ durationInFrames,
+}: {
+ durationInFrames: number | undefined;
+}): number => {
+ return durationInFrames ?? Infinity;
+};
+
+// Length of an item in its parent timeline. `durationInFrames` is measured in
+// the child clock.
export const resolveSequenceDuration = ({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}: {
durationInFrames: number | undefined;
- trimBefore: number | undefined;
- trimAfter: number | undefined;
playbackRate: number | undefined;
loop: boolean | undefined;
}): number => {
- const duration = durationInFrames ?? Infinity;
- if (loop || trimAfter === undefined) {
- return duration;
+ if (loop) {
+ return Infinity;
}
- return Math.min(
- duration,
- (trimAfter - (trimBefore ?? 0)) / (playbackRate ?? 1),
+ return (
+ resolveSequenceContentDuration({
+ durationInFrames,
+ }) / (playbackRate ?? 1)
);
};
diff --git a/packages/core/src/series/index.tsx b/packages/core/src/series/index.tsx
index 672c8d8610..e5f24d2647 100644
--- a/packages/core/src/series/index.tsx
+++ b/packages/core/src/series/index.tsx
@@ -39,9 +39,7 @@ type SeriesSequenceProps = PropsWithChildren<
| 'showInTimeline'
| 'freeze'
| 'trimBefore'
- | 'trimAfter'
| 'playbackRate'
- | 'loop'
> &
LayoutAndStyle
>;
@@ -67,9 +65,8 @@ const seriesSequenceSchema = {
showInTimeline: Interactive.sequenceSchema.showInTimeline,
freeze: Interactive.baseSchema.freeze,
trimBefore: Interactive.sequenceSchema.trimBefore,
- trimAfter: Interactive.sequenceSchema.trimAfter,
playbackRate: Interactive.sequenceSchema.playbackRate,
- loop: Interactive.sequenceSchema.loop,
+ loop: {type: 'hidden'},
layout: Interactive.sequenceSchema.layout,
} as const satisfies InteractivitySchema;
@@ -202,6 +199,14 @@ const SeriesInner: FC<SeriesProps> = (props) => {
return React.cloneElement(castedElement, {
_remotionInternalRender: (resolvedProps, ref) => {
const durationInFramesProp = resolvedProps.durationInFrames;
+ const timelineDurationInFrames =
+ durationInFramesProp / (resolvedProps.playbackRate ?? 1);
+ if ((resolvedProps as {readonly loop?: boolean}).loop) {
+ throw new Error(
+ '<Series.Sequence> does not accept `loop`. Put a looping <Sequence> inside the <Series.Sequence> instead.',
+ );
+ }
+
const {
durationInFrames: _durationInFrames,
children: sequenceChildren,
@@ -220,7 +225,7 @@ const SeriesInner: FC<SeriesProps> = (props) => {
});
const currentStartFrame = startFrame + offset;
- const nextStartFrame = startFrame + durationInFramesProp + offset;
+ const nextStartFrame = startFrame + timelineDurationInFrames + offset;
return (
<>
diff --git a/packages/core/src/test/audio-for-rendering.test.tsx b/packages/core/src/test/audio-for-rendering.test.tsx
index ed3843c4a0..01a87f08b1 100644
--- a/packages/core/src/test/audio-for-rendering.test.tsx
+++ b/packages/core/src/test/audio-for-rendering.test.tsx
@@ -175,7 +175,7 @@ test('nested Sequence rates preserve source trims when collecting media for rend
);
const {rerender} = render(composition(10));
- for (const frame of [10, 25, 26, 49, 50]) {
+ for (const frame of [10, 25, 26, 29, 30]) {
if (frame !== 10) {
rerender(composition(frame));
}
@@ -184,7 +184,7 @@ test('nested Sequence rates preserve source trims when collecting media for rend
act(() => {
assets = collectAssets.current!.collectAssets();
});
- expect(assets, `frame ${frame}`).toHaveLength(frame === 50 ? 0 : 3);
+ expect(assets, `frame ${frame}`).toHaveLength(frame === 30 ? 0 : 3);
for (const asset of assets) {
if (asset.type !== 'audio' && asset.type !== 'video') {
throw new Error(`Unexpected asset type: ${asset.type}`);
diff --git a/packages/core/src/test/sequence-playback-rate.test.tsx b/packages/core/src/test/sequence-playback-rate.test.tsx
index bfb831a052..edb336685d 100644
--- a/packages/core/src/test/sequence-playback-rate.test.tsx
+++ b/packages/core/src/test/sequence-playback-rate.test.tsx
@@ -38,10 +38,10 @@ test('nested rates scale child clocks, trims and durations within parent-frame w
const view = render(content(34));
expect(view.container.textContent).toBe('');
view.rerender(content(35));
- expect(view.getByText('Frame 3, duration 13')).toBeTruthy();
+ expect(view.getByText('Frame 3, duration 18')).toBeTruthy();
view.rerender(content(44));
- expect(view.getByText('Frame 12, duration 13')).toBeTruthy();
- view.rerender(content(45));
+ expect(view.getByText('Frame 12, duration 18')).toBeTruthy();
+ view.rerender(content(50));
expect(view.container.textContent).toBe('');
});
@@ -65,12 +65,12 @@ test('slow sequences retain fractional child frames and freeze in the child cloc
</WrapSequenceContext>
);
const view = render(content(11, false));
- expect(view.getByText('Frame 4.5, duration 14')).toBeTruthy();
+ expect(view.getByText('Frame 4.5, duration 24')).toBeTruthy();
view.rerender(content(20, true));
- expect(view.getByText('Frame 6, duration 14')).toBeTruthy();
- view.rerender(content(29, true));
- expect(view.getByText('Frame 6, duration 14')).toBeTruthy();
- view.rerender(content(30, true));
+ expect(view.getByText('Frame 6, duration 24')).toBeTruthy();
+ view.rerender(content(49, true));
+ expect(view.getByText('Frame 6, duration 24')).toBeTruthy();
+ view.rerender(content(50, true));
expect(view.container.textContent).toBe('');
});
@@ -91,7 +91,7 @@ test('parent-evaluated animation keeps the parent clock', () => {
</WrapSequenceContext>,
);
expect(view.getByText('Parent 5')).toBeTruthy();
- expect(view.getByText('Frame 10, duration 40')).toBeTruthy();
+ expect(view.getByText('Frame 10, duration 20')).toBeTruthy();
});
test('premount and postmount freeze accelerated descendants at the window boundaries', () => {
@@ -127,11 +127,11 @@ test('premount and postmount freeze accelerated descendants at the window bounda
</WrapSequenceContext>
);
const view = render(content(8));
- expect(view.getByText('Frame 6, duration 36')).toBeTruthy();
+ expect(view.getByText('Frame 6, duration 16')).toBeTruthy();
view.rerender(content(12));
- expect(view.getByText('Frame 18, duration 36')).toBeTruthy();
+ expect(view.getByText('Frame 12.999999999999996, duration 16')).toBeTruthy();
view.rerender(content(15));
- expect(view.getByText('Frame 33, duration 36')).toBeTruthy();
+ expect(view.container.textContent).toBe('');
});
test('playbackRate rejects invalid values and animation while allowing a paused static edit', () => {
@@ -154,8 +154,8 @@ test('playbackRate rejects invalid values and animation while allowing a paused
);
const view = render(content(5, 1));
view.rerender(content(5, 2));
- expect(view.getByText('Frame 10, duration 40')).toBeTruthy();
+ expect(view.getByText('Frame 10, duration 20')).toBeTruthy();
view.rerender(content(6, 2));
- expect(view.getByText('Frame 12, duration 40')).toBeTruthy();
+ expect(view.getByText('Frame 12, duration 20')).toBeTruthy();
expect(() => view.rerender(content(7, 3))).toThrow(/must be constant/);
});
diff --git a/packages/core/src/test/sequence-trim-after-loop.test.tsx b/packages/core/src/test/sequence-trim-after-loop.test.tsx
index e217c86ac3..73715a77d4 100644
--- a/packages/core/src/test/sequence-trim-after-loop.test.tsx
+++ b/packages/core/src/test/sequence-trim-after-loop.test.tsx
@@ -45,64 +45,63 @@ const renderFrame = ({
);
};
-test('trimAfter uses the child clock and the earliest end wins', () => {
+test('durationInFrames uses the child clock', () => {
const content = (durationInFrames: number) => (
<Sequence
layout="none"
from={5}
trimBefore={10}
- trimAfter={18}
playbackRate={2}
durationInFrames={durationInFrames}
>
<Clock label="clock" />
</Sequence>
);
- const view = render(renderFrame({frame: 4, children: content(10)}));
+ const view = render(renderFrame({frame: 4, children: content(8)}));
expect(view.container.textContent).toBe('');
- view.rerender(renderFrame({frame: 5, children: content(10)}));
+ view.rerender(renderFrame({frame: 5, children: content(8)}));
expect(view.container.textContent).toBe(
'clock: frame 10, duration 18, iteration none, period none',
);
- view.rerender(renderFrame({frame: 8, children: content(10)}));
+ view.rerender(renderFrame({frame: 8, children: content(8)}));
expect(view.container.textContent).toBe(
'clock: frame 16, duration 18, iteration none, period none',
);
- view.rerender(renderFrame({frame: 9, children: content(10)}));
+ view.rerender(renderFrame({frame: 9, children: content(8)}));
expect(view.container.textContent).toBe('');
- view.rerender(renderFrame({frame: 6, children: content(2)}));
+ view.rerender(renderFrame({frame: 5, children: content(2)}));
expect(view.container.textContent).toBe(
- 'clock: frame 12, duration 14, iteration none, period none',
+ 'clock: frame 10, duration 12, iteration none, period none',
);
- view.rerender(renderFrame({frame: 7, children: content(2)}));
+ view.rerender(renderFrame({frame: 6, children: content(2)}));
expect(view.container.textContent).toBe('');
});
-test('loop repeats the trimmed range and exposes a partial final iteration', () => {
+test('loop repeats durationInFrames and exposes a partial final iteration', () => {
const content = (
- <Sequence
- layout="none"
- from={3}
- trimBefore={10}
- trimAfter={16}
- playbackRate={2}
- durationInFrames={8}
- loop
- >
- <Clock label="clock" />
+ <Sequence layout="none" from={3} durationInFrames={8}>
+ <Sequence
+ layout="none"
+ trimBefore={10}
+ playbackRate={2}
+ durationInFrames={6}
+ loop
+ >
+ <Clock label="clock" />
+ </Sequence>
</Sequence>
);
const view = render(renderFrame({frame: 2, children: content}));
expect(view.container.textContent).toBe('');
for (const [frame, expected] of [
- [3, 'clock: frame 10, duration 16, iteration 0, period 3'],
- [5, 'clock: frame 14, duration 16, iteration 0, period 3'],
- [6, 'clock: frame 10, duration 16, iteration 1, period 3'],
- [9, 'clock: frame 10, duration 14, iteration 2, period 3'],
- [10, 'clock: frame 12, duration 14, iteration 2, period 3'],
+ [3, 'clock: frame 10, duration 16, iteration 0, period 6'],
+ [5, 'clock: frame 14, duration 16, iteration 0, period 6'],
+ [6, 'clock: frame 10, duration 16, iteration 1, period 6'],
+ [9, 'clock: frame 10, duration 14, iteration 2, period 6'],
+ [10, 'clock: frame 12, duration 14, iteration 2, period 6'],
] as const) {
view.rerender(renderFrame({frame, children: content}));
expect(view.container.textContent).toBe(expected);
@@ -110,7 +109,7 @@ test('loop repeats the trimmed range and exposes a partial final iteration', ()
view.rerender(renderFrame({frame: 5, children: content}));
expect(view.container.textContent).toBe(
- 'clock: frame 14, duration 16, iteration 0, period 3',
+ 'clock: frame 14, duration 16, iteration 0, period 6',
);
view.rerender(renderFrame({frame: 11, children: content}));
expect(view.container.textContent).toBe('');
@@ -119,7 +118,7 @@ test('loop repeats the trimmed range and exposes a partial final iteration', ()
test('loop respects nested playback rates and a parent cutting an iteration short', () => {
const fractionalBoundary = (
<Sequence layout="none" playbackRate={0.3} durationInFrames={20}>
- <Sequence layout="none" trimAfter={1} loop>
+ <Sequence layout="none" durationInFrames={1} loop>
<Clock label="fractional" />
</Sequence>
</Sequence>
@@ -131,7 +130,7 @@ test('loop respects nested playback rates and a parent cutting an iteration shor
const parentCutoff = (
<Sequence layout="none" durationInFrames={7}>
- <Sequence layout="none" trimAfter={4} loop>
+ <Sequence layout="none" durationInFrames={4} loop>
<Clock label="cutoff" />
</Sequence>
</Sequence>
@@ -149,7 +148,7 @@ test('a frame read outside a looping Sequence keeps the parent clock', () => {
const ParentClock = () => {
const frame = useCurrentFrame();
return (
- <Sequence layout="none" trimAfter={20} loop>
+ <Sequence layout="none" durationInFrames={20} loop>
<div>parent frame {frame}</div>
</Sequence>
);
@@ -169,18 +168,16 @@ test('Sequence loop matches Loop and timed wrappers forward the props', () => {
<Loop durationInFrames={5} times={3} layout="none">
<Clock label="Loop" />
</Loop>
- <Sequence layout="none" trimAfter={5} durationInFrames={15} loop>
- <Clock label="Sequence" />
+ <Sequence layout="none" durationInFrames={15}>
+ <Sequence layout="none" durationInFrames={5} loop>
+ <Clock label="Sequence" />
+ </Sequence>
+ </Sequence>
+ <Sequence from={2} durationInFrames={5}>
+ <AbsoluteFill trimBefore={4} durationInFrames={2} loop>
+ <Clock label="AbsoluteFill" />
+ </AbsoluteFill>
</Sequence>
- <AbsoluteFill
- from={2}
- trimBefore={4}
- trimAfter={6}
- durationInFrames={5}
- loop
- >
- <Clock label="AbsoluteFill" />
- </AbsoluteFill>
</>
);
const view = render(renderFrame({frame: 5, children: content}));
@@ -196,8 +193,10 @@ test('Sequence loop matches Loop and timed wrappers forward the props', () => {
const series = (
<Series>
- <Series.Sequence layout="none" durationInFrames={5} trimAfter={2} loop>
- <Clock label="first" />
+ <Series.Sequence layout="none" durationInFrames={5}>
+ <Sequence layout="none" durationInFrames={2} loop>
+ <Clock label="first" />
+ </Sequence>
</Series.Sequence>
<Series.Sequence layout="none" durationInFrames={3}>
<Clock label="second" />
diff --git a/packages/core/src/test/sequence-validation.test.tsx b/packages/core/src/test/sequence-validation.test.tsx
index b7f1642728..d5f93b2c01 100644
--- a/packages/core/src/test/sequence-validation.test.tsx
+++ b/packages/core/src/test/sequence-validation.test.tsx
@@ -103,65 +103,30 @@ describe('Composition-validation render should throw with invalid props', () =>
);
});
});
- describe('Throw with invalid trimAfter and loop props', () => {
- test('trimAfter must be a number greater than trimBefore', () => {
- for (const [trimBefore, trimAfter, expected] of [
- [
- 0,
- '30',
- /The "trimAfter" prop of <Sequence \/> must be a number, but is of type string./,
- ],
- [
- 0,
- NaN,
- /The "trimAfter" prop of <Sequence \/> must be a real number, but it is NaN./,
- ],
- [
- 10,
- 10,
- /The "trimAfter" prop of <Sequence \/> must be greater than "trimBefore" \(10\), but got 10./,
- ],
- [
- 10,
- 9,
- /The "trimAfter" prop of <Sequence \/> must be greater than "trimBefore" \(10\), but got 9./,
- ],
- ] as const) {
- expectToThrow(
- () =>
- render(
- <WrapSequenceContext>
- <Sequence
- trimBefore={trimBefore}
- trimAfter={trimAfter as number}
- />
- </WrapSequenceContext>,
- ),
- expected,
- );
- }
- });
-
- test('loop must be boolean and requires a finite trimAfter', () => {
+ describe('Throw with invalid loop props', () => {
+ test('loop must be boolean and requires a finite durationInFrames', () => {
expectToThrow(
() =>
render(
<WrapSequenceContext>
- <Sequence loop={'true' as unknown as boolean} trimAfter={30} />
+ <Sequence
+ loop={'true' as unknown as boolean}
+ durationInFrames={30}
+ />
</WrapSequenceContext>,
),
/The "loop" prop of <Sequence \/> must be a boolean, but is of type string./,
);
- for (const trimAfter of [undefined, Infinity]) {
+ for (const durationInFrames of [undefined, Infinity]) {
expectToThrow(
() =>
render(
<WrapSequenceContext>
- <Sequence loop trimAfter={trimAfter} durationInFrames={30} />
+ <Sequence loop durationInFrames={durationInFrames} />
</WrapSequenceContext>,
),
- /requires a finite "trimAfter" prop/,
+ /requires a finite "durationInFrames" prop/,
);
}
});
diff --git a/packages/core/src/test/sequence-wrapper-playback-rate.test.tsx b/packages/core/src/test/sequence-wrapper-playback-rate.test.tsx
index 828771b229..9ab7da23a0 100644
--- a/packages/core/src/test/sequence-wrapper-playback-rate.test.tsx
+++ b/packages/core/src/test/sequence-wrapper-playback-rate.test.tsx
@@ -40,11 +40,11 @@ test('sequence wrappers cascade playback rates while preserving sequence and loo
);
expect(render(12)).toContain('<span>6</span>');
- expect(render(19)).toContain('<span>27</span>');
- expect(render(20)).toBe('<span>0</span>');
- expect(render(24)).toBe('<span>8</span>');
- expect(render(25)).toBe('<span>0</span>');
- expect(render(29)).toBe('<span>8</span>');
+ expect(render(19)).toContain('<span>3</span>');
+ expect(render(20)).toBe('');
+ expect(render(24)).toBe('');
+ expect(render(25)).toBe('');
+ expect(render(29)).toBe('');
expect(render(30)).toBe('');
});
diff --git a/packages/core/src/test/with-interactivity-schema-helpers.test.ts b/packages/core/src/test/with-interactivity-schema-helpers.test.ts
index 66e92e185d..bd1a0a4dcb 100644
--- a/packages/core/src/test/with-interactivity-schema-helpers.test.ts
+++ b/packages/core/src/test/with-interactivity-schema-helpers.test.ts
@@ -149,7 +149,6 @@ test('baseSchema exposes common timeline fields', () => {
'name',
'showInTimeline',
'trimBefore',
- 'trimAfter',
'playbackRate',
'loop',
].sort(),
@@ -251,7 +250,6 @@ test('getFlatSchema(sequenceSchema) exposes every variant key', () => {
'from',
'freeze',
'trimBefore',
- 'trimAfter',
'playbackRate',
'loop',
].sort(),
@@ -574,7 +572,6 @@ test('selectActiveKeys returns only the hidden + layout keys when layout=none',
'durationInFrames',
'from',
'trimBefore',
- 'trimAfter',
'playbackRate',
'loop',
'freeze',
@@ -598,7 +595,6 @@ test('selectActiveKeys exposes style.* keys when layout=absolute-fill', () => {
'durationInFrames',
'from',
'trimBefore',
- 'trimAfter',
'playbackRate',
'loop',
'freeze',
@@ -632,7 +628,6 @@ test('selectActiveKeys exposes style.* keys when layout=absolute-fill', () => {
'durationInFrames',
'from',
'trimBefore',
- 'trimAfter',
'playbackRate',
'loop',
'freeze',
@@ -686,7 +681,6 @@ test('end-to-end: layout=none drops style.scale from active props', () => {
'durationInFrames',
'from',
'trimBefore',
- 'trimAfter',
'playbackRate',
'loop',
'freeze',
diff --git a/packages/docs/components/TimingTimeline.tsx b/packages/docs/components/TimingTimeline.tsx
index 1367258dc4..1cf7acc297 100644
--- a/packages/docs/components/TimingTimeline.tsx
+++ b/packages/docs/components/TimingTimeline.tsx
@@ -4,21 +4,19 @@ export const TimingTimeline: React.FC<{
readonly from: number;
readonly durationInFrames?: number;
readonly trimBefore: number;
- readonly trimAfter: number | null;
readonly playbackRate: number;
readonly loop: boolean;
-}> = ({from, durationInFrames, trimBefore, trimAfter, playbackRate, loop}) => {
+}> = ({from, durationInFrames, trimBefore, playbackRate, loop}) => {
const [frame, setFrame] = useState(from);
const scrubbingPointer = useRef<number | null>(null);
const totalFrames = loop ? 120 : 90;
const fps = 30;
- const sourceRange = trimAfter === null ? null : trimAfter - trimBefore;
+ const sourceRange = durationInFrames ?? null;
const cycleDuration =
sourceRange === null ? null : sourceRange / playbackRate;
- const displayedDuration = Math.min(
- durationInFrames ?? totalFrames - from,
- loop || cycleDuration === null ? Infinity : cycleDuration,
- );
+ const displayedDuration = loop
+ ? totalFrames - from
+ : Math.min(cycleDuration ?? Infinity, totalFrames - from);
const localFrame =
frame >= from && frame < from + displayedDuration
? (loop && sourceRange !== null
diff --git a/packages/docs/docs/interactive.mdx b/packages/docs/docs/interactive.mdx
index 694050e5ec..4ced9dca0c 100644
--- a/packages/docs/docs/interactive.mdx
+++ b/packages/docs/docs/interactive.mdx
@@ -72,7 +72,7 @@ Use them with [`Interactive.withSchema()`](/docs/interactive-with-schema).
Controls inherited from [`<Sequence>`](/docs/sequence):
-`durationInFrames`, `from`, `trimBefore`, `trimAfter`, `playbackRate`, `loop`, `freeze`, `hidden`, `name` and `showInTimeline`.
+`durationInFrames`, `from`, `trimBefore`, `playbackRate`, `loop`, `freeze`, `hidden`, `name` and `showInTimeline`.
Use it for components that render a `<Sequence>` internally and forward these props to it.
diff --git a/packages/docs/docs/interactivity-schema.mdx b/packages/docs/docs/interactivity-schema.mdx
index f1216a9945..e28e07b534 100644
--- a/packages/docs/docs/interactivity-schema.mdx
+++ b/packages/docs/docs/interactivity-schema.mdx
@@ -37,7 +37,7 @@ Keys may use dot notation. For example, a key named `style.opacity` reads from a
### `Interactive.baseSchema`
-Timeline props inherited from [`<Sequence>`](/docs/sequence): [`durationInFrames`](/docs/sequence#durationinframes), [`from`](/docs/sequence#from), [`trimBefore`](/docs/sequence#trimbefore), [`trimAfter`](/docs/sequence#trimafter), [`playbackRate`](/docs/sequence#playbackrate), [`loop`](/docs/sequence#loop), [`freeze`](/docs/sequence#freeze), [`hidden`](/docs/sequence#hidden), [`name`](/docs/sequence#name) and [`showInTimeline`](/docs/sequence#showintimeline).
+Timeline props inherited from [`<Sequence>`](/docs/sequence): [`durationInFrames`](/docs/sequence#durationinframes), [`from`](/docs/sequence#from), [`trimBefore`](/docs/sequence#trimbefore), [`playbackRate`](/docs/sequence#playbackrate), [`loop`](/docs/sequence#loop), [`freeze`](/docs/sequence#freeze), [`hidden`](/docs/sequence#hidden), [`name`](/docs/sequence#name) and [`showInTimeline`](/docs/sequence#showintimeline).
### `Interactive.captionsSchema`<AvailableFrom v="4.0.500" />
diff --git a/packages/docs/docs/loop.mdx b/packages/docs/docs/loop.mdx
index f2a7c15edf..0a0ad828bb 100644
--- a/packages/docs/docs/loop.mdx
+++ b/packages/docs/docs/loop.mdx
@@ -35,15 +35,17 @@ You can nest loops within each other and they will cascade.
[Many components](/docs/timing) accept a [`loop`](/docs/timing#loop-repeat-an-item) nowadays.
-It is useful if you want to mix it with other props such as `trimAfter` or `playbackRate`.
+It is useful if you want to mix it with other props such as `trimBefore` or `playbackRate`.
```tsx twoslash
// @include: example-BlueSquare
import {Sequence} from 'remotion';
// ---cut---
const WithSequence = () => (
- <Sequence trimAfter={50} durationInFrames={150} loop>
- <BlueSquare />
+ <Sequence durationInFrames={150}>
+ <Sequence durationInFrames={50} loop>
+ <BlueSquare />
+ </Sequence>
</Sequence>
);
```
@@ -54,11 +56,11 @@ The Loop component is a high order component and accepts, besides it's children,
### `durationInFrames`
-How many frames one iteration of the loop should be long.
+How many frames of the child timeline one iteration of the loop should contain. An iteration occupies `durationInFrames / playbackRate` frames in the parent timeline.
### `playbackRate?`<AvailableFrom v="4.0.528" />
-Changes the speed of the children within each iteration. Defaults to `1` and must remain constant across frames. Each iteration still lasts `durationInFrames` frames in the parent timeline. See [`playbackRate`](/docs/sequence#playbackrate) on [`<Sequence>`](/docs/sequence).
+Changes the speed of the children within each iteration. Defaults to `1` and must remain constant across frames. Each iteration lasts `durationInFrames / playbackRate` frames in the parent timeline. See [`playbackRate`](/docs/sequence#playbackrate) on [`<Sequence>`](/docs/sequence).
### `times?`
diff --git a/packages/docs/docs/media/audio.mdx b/packages/docs/docs/media/audio.mdx
index 8b05964b4f..bfcc5ea8fd 100644
--- a/packages/docs/docs/media/audio.mdx
+++ b/packages/docs/docs/media/audio.mdx
@@ -44,13 +44,13 @@ export const MyComposition = () => {
The URL of the audio to be rendered. Can be a remote URL or a local file referenced with [`staticFile()`](/docs/staticfile).
-### `from?`<AvailableFrom v="4.0.445" />
+### `from?`<AvailableFrom v="4.0.446" />
At which frame this clip should start relative to the parent timeline. Default is `0`. Same meaning as [`from`](/docs/sequence#from) on [`<Sequence>`](/docs/sequence).
-### `durationInFrames?`<AvailableFrom v="4.0.445" />
+### `durationInFrames?`<AvailableFrom v="4.0.446" />
-For how many frames the clip stays mounted. Default is `Infinity`. Same meaning as [`durationInFrames`](/docs/sequence#durationinframes) on [`<Sequence>`](/docs/sequence).
+Selects this many source frames starting at `trimBefore`, unless `trimAfter` ends the range earlier. The clip occupies `durationInFrames / playbackRate` frames on the parent timeline, or uses this range as its loop when `loop` is enabled. Same meaning as [`durationInFrames`](/docs/sequence#durationinframes) on [`<Sequence>`](/docs/sequence).
:::note
You can still wrap `<Audio>` in an outer [`<Sequence>`](/docs/sequence). Timing [cascades](/docs/sequence#cascading) like nested sequences.
@@ -106,7 +106,7 @@ export const MyComposition = () => {
### `trimAfter?`
-Removes a portion of the audio at the end (right side). See [`trimBefore`](#trimbefore) for an explanation.
+Removes a portion of the audio at the end (right side). If `durationInFrames` ends the range earlier, the shorter range is used. See [`trimBefore`](#trimbefore) for an explanation.
### `volume?`
diff --git a/packages/docs/docs/media/video.mdx b/packages/docs/docs/media/video.mdx
index c9d9d6a555..295876b547 100644
--- a/packages/docs/docs/media/video.mdx
+++ b/packages/docs/docs/media/video.mdx
@@ -83,13 +83,13 @@ Crops the video from the top by a ratio between `0` and `1`. See [`cropTop`](/do
Crops the video from the bottom by a ratio between `0` and `1`. See [`cropBottom`](/docs/sequence#cropbottom).
-### `from?`<AvailableFrom v="4.0.445" />
+### `from?`<AvailableFrom v="4.0.446" />
At which frame this clip should start relative to the parent timeline. Default is `0`. Same meaning as [`from`](/docs/sequence#from) on [`<Sequence>`](/docs/sequence).
-### `durationInFrames?`<AvailableFrom v="4.0.445" />
+### `durationInFrames?`<AvailableFrom v="4.0.446" />
-For how many frames the clip stays mounted. Default is `Infinity`. Same meaning as [`durationInFrames`](/docs/sequence#durationinframes) on [`<Sequence>`](/docs/sequence).
+Selects this many source frames starting at `trimBefore`, unless `trimAfter` ends the range earlier. The clip occupies `durationInFrames / playbackRate` frames on the parent timeline, or uses this range as its loop when `loop` is enabled. Same meaning as [`durationInFrames`](/docs/sequence#durationinframes) on [`<Sequence>`](/docs/sequence).
:::note
You can still wrap `<Video>` in an outer [`<Sequence>`](/docs/sequence). Timing [cascades](/docs/sequence#cascading) like nested sequences.
@@ -155,7 +155,7 @@ export const MyComposition = () => {
### `trimAfter?`
-Removes a portion of the video at the end (right side). See [`trimBefore`](#trimbefore) for an explanation.
+Removes a portion of the video at the end (right side). If `durationInFrames` ends the range earlier, the shorter range is used. See [`trimBefore`](#trimbefore) for an explanation.
### `volume?`
diff --git a/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx b/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx
index d4b7db0d78..fd8ff35f21 100644
--- a/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx
+++ b/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx
@@ -74,23 +74,19 @@ Moves the blurred content on its parent timeline. Default: `0`.
### `durationInFrames?`
-Limits how long the blurred content appears on its parent timeline, starting at `from`. By default, it lasts until the composition ends.
+Selects how many child frames are shown, starting at `trimBefore`. The blurred content occupies `durationInFrames / playbackRate` frames in its parent timeline. By default, it lasts until the composition ends.
### `trimBefore?`
Skips the beginning of the content without moving its `from` position. Default: `0`.
-### `trimAfter?`
-
-Ends the content at this child frame, unless `durationInFrames` ends it earlier. The frame is measured in the same clock as `trimBefore`.
-
### `playbackRate?`
Changes how quickly the child frames advance. Default: `1`. The motion blur samples follow this speed.
### `loop?`
-Repeats the range from `trimBefore` up to `trimAfter`. Set a finite `trimAfter` when enabling `loop`. `durationInFrames` can limit the total time the loop appears. Default: `false`.
+Repeats the range selected by `trimBefore` and `durationInFrames`. Set a finite `durationInFrames` when enabling `loop`. Default: `false`.
See [Timing and trimming](/docs/timing) for how these props combine.
diff --git a/packages/docs/docs/sequence.mdx b/packages/docs/docs/sequence.mdx
index fb642be52b..e82dde27a3 100644
--- a/packages/docs/docs/sequence.mdx
+++ b/packages/docs/docs/sequence.mdx
@@ -190,7 +190,9 @@ From v3.2.36 onwards, this prop will be optional; by default, it will be 0.
### `durationInFrames?`
-For how many frames the sequence should be displayed. Children are unmounted if they are not within the time range of display. By default it will be `Infinity` to avoid limit the duration of the sequence.
+For how many frames of the child timeline the sequence should be displayed, starting at [`trimBefore`](#trimbefore). By default it will be `Infinity` to avoid limiting the duration of the sequence.
+
+The sequence occupies `durationInFrames / playbackRate` frames in its parent. When `loop` is enabled, `durationInFrames` is the loop length and the sequence repeats until its parent ends.
### `trimBefore?`<AvailableFrom v="4.0.482" />
@@ -216,38 +218,13 @@ export const MyVideo = () => {
In the example above, `Child` mounts at composition frame `30` and receives frame `15`.
-### `trimAfter?`
-
-Ends the child timeline at the specified frame, measured in the same clock as [`trimBefore`](#trimbefore).
-Children receive frames from `trimBefore` up to, but not including, `trimAfter`.
-
-The sequence unmounts after `(trimAfter - trimBefore) / playbackRate` frames in the parent timeline, unless [`durationInFrames`](#durationinframes) or the parent ends it earlier.
-Must be greater than `trimBefore`.
-
-```tsx twoslash title="MyVideo.tsx"
-import {Sequence, useCurrentFrame} from 'remotion';
-
-const Child = () => <div>{useCurrentFrame()}</div>;
-
-// ---cut---
-export const MyVideo = () => {
- return (
- <Sequence from={30} trimBefore={15} trimAfter={45}>
- <Child />
- </Sequence>
- );
-};
-```
-
-In the example above, `Child` receives frames `15` through `44` and the sequence is visible from composition frame `30` through `59`.
-
### `loop?`
-Repeats the child range selected by [`trimBefore`](#trimbefore) and [`trimAfter`](#trimafter). Default: `false`.
+Repeats the child range selected by [`trimBefore`](#trimbefore) and [`durationInFrames`](#durationinframes) until the parent ends. Default: `false`.
-Requires a finite `trimAfter`, because a sequence has no intrinsic duration.
-Each cycle lasts `(trimAfter - trimBefore) / playbackRate` frames in the parent timeline.
-[`durationInFrames`](#durationinframes) limits the total length; without it, the sequence loops until its parent ends.
+Requires a finite `durationInFrames`, because a sequence has no intrinsic duration.
+Each cycle lasts `durationInFrames / playbackRate` frames in the parent timeline.
+Wrap it in an outer `<Sequence>` to set a finite total duration.
```tsx twoslash title="MyVideo.tsx"
import {Sequence, useCurrentFrame} from 'remotion';
@@ -257,8 +234,10 @@ const Child = () => <div>{useCurrentFrame()}</div>;
// ---cut---
export const MyVideo = () => {
return (
- <Sequence trimBefore={30} trimAfter={60} playbackRate={2} durationInFrames={90} loop>
- <Child />
+ <Sequence durationInFrames={90}>
+ <Sequence trimBefore={30} playbackRate={2} durationInFrames={30} loop>
+ <Child />
+ </Sequence>
</Sequence>
);
};
@@ -274,8 +253,7 @@ To repeat a duration measured in the parent timeline, use [`<Loop>`](/docs/loop)
Changes the speed of the children, including their animations and media. Default: `1`.
Use `2` for double speed or `0.5` for half speed. The value must be positive and finite, and must remain constant across frames.
-`from` and `durationInFrames` are measured in the parent timeline. Changing `playbackRate` does not change when the sequence mounts or unmounts.
-`trimBefore` and `trimAfter` are measured in the children's frames and are applied after the speed change:
+`durationInFrames` and `trimBefore` are measured in the child timeline, so changing `playbackRate` changes the mounted duration.
```tsx twoslash title="MyVideo.tsx"
import {Sequence, useCurrentFrame} from 'remotion';
@@ -290,7 +268,7 @@ export const MyVideo = () => (
```
At composition frame `30`, `Child` receives frame `10`. At frame `40`, it receives frame `30`: `(40 - 30) * 2 + 10`.
-The sequence remains visible through composition frame `89`.
+The sequence remains visible through composition frame `59`.
Nested playback rates multiply. A sequence with `playbackRate={2}` inside one with `playbackRate={0.5}` plays at the original speed.
A media component's own `playbackRate` also multiplies with its parent sequences' rates.
diff --git a/packages/docs/docs/series.mdx b/packages/docs/docs/series.mdx
index 4f8a9f674e..95e266ab95 100644
--- a/packages/docs/docs/series.mdx
+++ b/packages/docs/docs/series.mdx
@@ -62,7 +62,9 @@ A `<Series.Sequence />` component accepts the following props:
### `durationInFrames?`
-For how many frames the sequence should be displayed. Children are unmounted if they are not within the time range of display.
+For how many frames of the child timeline the sequence should be displayed. Children are unmounted if they are not within the time range of display. The next sequence starts after `durationInFrames / playbackRate` frames.
+
+To loop within a series scene, put a looping `<Sequence>` inside `<Series.Sequence>`.
Only the last `<Series.Sequence />` instance is allowed to have `Infinity` as a duration, all previous one must have a positive integer.
@@ -81,8 +83,9 @@ Trims frames from the beginning without changing where the sequence starts. See
### `playbackRate?`<AvailableFrom v="4.0.528" />
-Changes the speed of the children. Defaults to `1` and must remain constant across frames. See [`playbackRate`](/docs/sequence#playbackrate) on [`<Sequence>`](/docs/sequence).
-The sequence's duration and the next sequence's start remain unchanged. Setting `playbackRate` on `<Series>` speeds up the whole series, including transitions between its sequences.
+Changes the speed of the children. Defaults to `1` and must remain constant across frames. The next sequence starts after `durationInFrames / playbackRate` frames. See [`playbackRate`](/docs/sequence#playbackrate) on [`<Sequence>`](/docs/sequence).
+
+Setting `playbackRate` on `<Series>` speeds up the whole series, including transitions between its sequences.
### `freeze?`<AvailableFrom v="4.0.476" />
diff --git a/packages/docs/docs/studio/make-component-interactive.mdx b/packages/docs/docs/studio/make-component-interactive.mdx
index 2759f18b9d..63a9b090cc 100644
--- a/packages/docs/docs/studio/make-component-interactive.mdx
+++ b/packages/docs/docs/studio/make-component-interactive.mdx
@@ -15,7 +15,7 @@ For code that remains editable after visual changes, follow [Interactivity best
An [`InteractivitySchema`](/docs/interactivity-schema) describes which props the Studio may edit.
-Use [`Interactive.baseSchema`](/docs/interactive#interactivebaseschema) for props inherited from [`<Sequence>`](/docs/sequence), such as [`from`](/docs/sequence#from), [`trimBefore`](/docs/sequence#trimbefore), [`trimAfter`](/docs/sequence#trimafter), [`playbackRate`](/docs/sequence#playbackrate), [`loop`](/docs/sequence#loop), [`durationInFrames`](/docs/sequence#durationinframes), [`freeze`](/docs/sequence#freeze), [`hidden`](/docs/sequence#hidden), [`name`](/docs/sequence#name) and [`showInTimeline`](/docs/sequence#showintimeline).
+Use [`Interactive.baseSchema`](/docs/interactive#interactivebaseschema) for props inherited from [`<Sequence>`](/docs/sequence), such as [`from`](/docs/sequence#from), [`trimBefore`](/docs/sequence#trimbefore), [`playbackRate`](/docs/sequence#playbackrate), [`loop`](/docs/sequence#loop), [`durationInFrames`](/docs/sequence#durationinframes), [`freeze`](/docs/sequence#freeze), [`hidden`](/docs/sequence#hidden), [`name`](/docs/sequence#name) and [`showInTimeline`](/docs/sequence#showintimeline).
As a rule, include `Interactive.baseSchema` in every schema passed to `Interactive.withSchema()` so trimming, looping and visibility controls remain available. Forward all of these props to the `<Sequence>` your component renders.
diff --git a/packages/docs/docs/timing.mdx b/packages/docs/docs/timing.mdx
index 5dfcf80d23..ff16c0e280 100644
--- a/packages/docs/docs/timing.mdx
+++ b/packages/docs/docs/timing.mdx
@@ -22,7 +22,7 @@ The way timing works is standardized across these components:
`from` moves an item on the timeline.
By default, its children start at frame `0` when it appears:
-<TimingTimeline from={30} trimBefore={0} trimAfter={null} playbackRate={1} loop={false} />
+<TimingTimeline from={30} trimBefore={0} playbackRate={1} loop={false} />
```tsx twoslash title="MyComposition.tsx"
import {Interactive, useCurrentFrame} from 'remotion';
@@ -40,7 +40,7 @@ export const MyComposition = () => (
`trimBefore` trims the beginning of an item.
-<TimingTimeline from={30} trimBefore={15} trimAfter={null} playbackRate={1} loop={false} />
+<TimingTimeline from={30} trimBefore={15} playbackRate={1} loop={false} />
```tsx twoslash title="MyComposition.tsx"
import {Interactive, useCurrentFrame} from 'remotion';
@@ -54,11 +54,12 @@ export const MyComposition = () => (
);
```
-## `trimAfter`: Trim the end
+## `durationInFrames`: Set the duration
-`trimAfter` trims an item to end early.
+`durationInFrames` selects how many frames of the child timeline are shown, starting at `trimBefore`.
+The item occupies `durationInFrames / playbackRate` frames in its parent timeline.
-<TimingTimeline from={30} trimBefore={45} trimAfter={105} playbackRate={2} loop={false} />
+<TimingTimeline from={30} durationInFrames={60} trimBefore={45} playbackRate={2} loop={false} />
```tsx twoslash title="MyComposition.tsx"
import {Interactive, useCurrentFrame} from 'remotion';
@@ -69,7 +70,7 @@ export const MyComposition = () => (
<Interactive.Div
from={30}
trimBefore={45}
- trimAfter={105}
+ durationInFrames={60}
playbackRate={2}
>
<Counter />
@@ -81,7 +82,7 @@ export const MyComposition = () => (
`playbackRate` changes the speed of its children.
-<TimingTimeline from={30} trimBefore={15} trimAfter={null} playbackRate={2} loop={false} />
+<TimingTimeline from={30} durationInFrames={60} trimBefore={15} playbackRate={2} loop={false} />
```tsx twoslash title="MyComposition.tsx"
import {Interactive, useCurrentFrame} from 'remotion';
@@ -92,6 +93,7 @@ export const MyComposition = () => (
<Interactive.Div
from={30}
trimBefore={15}
+ durationInFrames={60}
playbackRate={2}
>
<Counter />
@@ -101,9 +103,9 @@ export const MyComposition = () => (
## `loop`: Repeat an item
-`loop` repeats the range selected by `trimBefore` and `trimAfter`.
+`loop` repeats the range selected by `trimBefore` and `durationInFrames` until the parent ends.
-<TimingTimeline from={30} durationInFrames={90} trimBefore={45} trimAfter={105} playbackRate={2} loop />
+<TimingTimeline from={30} durationInFrames={60} trimBefore={45} playbackRate={2} loop />
```tsx twoslash title="MyComposition.tsx"
import {Interactive, useCurrentFrame} from 'remotion';
@@ -114,46 +116,27 @@ export const MyComposition = () => (
<Interactive.Div
from={30}
trimBefore={45}
- trimAfter={105}
+ durationInFrames={60}
playbackRate={2}
loop
- durationInFrames={90}
>
<Counter />
</Interactive.Div>
);
```
-[`<Video>`](/docs/media/video) and [`<Audio>`](/docs/media/audio) have an intrinsic duration, so they may omit `trimAfter` when passing `loop`.
-All other items require `trimAfter` to loop.
-
-## `durationInFrames`: Limit an item
-
-`durationInFrames` sets how long an item stays on the timeline, starting at `from`.
-It is not affected by `playbackRate` and `loop`.
-
-<TimingTimeline from={30} durationInFrames={45} trimBefore={0} trimAfter={null} playbackRate={1} loop={false} />
-
-```tsx twoslash title="MyComposition.tsx"
-import {Interactive, useCurrentFrame} from 'remotion';
-
-const Counter = () => <div>{useCurrentFrame()}</div>;
-
-export const MyComposition = () => (
- <Interactive.Div from={30} durationInFrames={45}>
- <Counter />
- </Interactive.Div>
-);
-```
+To set a finite total duration for a loop, wrap it in an outer item with `durationInFrames`.
+[`<Video>`](/docs/media/video) and [`<Audio>`](/docs/media/audio) may omit `durationInFrames` because they have an intrinsic duration. They also support `trimAfter` for trimming the source.
## Order of operations
Think of the timing props as applying to the content in this order:
-1. `from`, `trimBefore` and `trimAfter` define the selected range
-2. `playbackRate` stretches or compresses the selected range
-3. `loop` repeats the stretched range
-4. `durationInFrames` is applied last and defines the duration of the item in the timeline.
+1. `from` positions the item in its parent timeline.
+2. `trimBefore` sets the first frame in the child timeline.
+3. `durationInFrames` selects the child range.
+4. `playbackRate` stretches or compresses the selected range.
+5. `loop` repeats the selected range until the parent ends.
## Formula
@@ -166,7 +149,7 @@ trimBefore + (frame - from) * playbackRate
If the item loops:
```md
-trimBefore + ((frame - from) * playbackRate) % (trimAfter - trimBefore)
+trimBefore + ((frame - from) * playbackRate) % durationInFrames
```
## See also
diff --git a/packages/gif/src/Gif.tsx b/packages/gif/src/Gif.tsx
index d1da858fbb..40fce1615a 100644
--- a/packages/gif/src/Gif.tsx
+++ b/packages/gif/src/Gif.tsx
@@ -85,8 +85,6 @@ const GifInner = ({
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore: sequenceProps.trimBefore,
- trimAfter: sequenceProps.trimAfter,
playbackRate,
loop: sequenceProps.loop,
}),
@@ -141,7 +139,7 @@ const GifInner = ({
layout="none"
from={from ?? 0}
playbackRate={playbackRate}
- durationInFrames={durationInFrames ?? Infinity}
+ durationInFrames={durationInFrames}
name="<Gif>"
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/gif/gif"
controls={controls}
diff --git a/packages/lottie/src/Lottie.tsx b/packages/lottie/src/Lottie.tsx
index 18c05172ca..4068465fc6 100644
--- a/packages/lottie/src/Lottie.tsx
+++ b/packages/lottie/src/Lottie.tsx
@@ -182,7 +182,6 @@ export const Lottie = ({
from,
durationInFrames,
trimBefore,
- trimAfter,
loop,
freeze,
hidden,
@@ -195,7 +194,6 @@ export const Lottie = ({
style,
...props
}: LottieProps) => {
- const sequenceLoop = loop === true && trimAfter !== undefined;
const {
effectivePremountFor,
effectivePostmountFor,
@@ -208,10 +206,8 @@ export const Lottie = ({
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate: undefined,
- loop: sequenceLoop,
+ loop,
}),
premountFor: premountFor ?? null,
postmountFor: postmountFor ?? null,
@@ -227,8 +223,7 @@ export const Lottie = ({
from={from}
durationInFrames={durationInFrames}
trimBefore={trimBefore}
- trimAfter={trimAfter}
- loop={sequenceLoop}
+ loop={loop}
freeze={freeze}
hidden={hidden}
name={name ?? '<Lottie>'}
diff --git a/packages/mac-cursors/src/MacOSCursor.tsx b/packages/mac-cursors/src/MacOSCursor.tsx
index 16a8f4ff5b..3923f7ee2e 100644
--- a/packages/mac-cursors/src/MacOSCursor.tsx
+++ b/packages/mac-cursors/src/MacOSCursor.tsx
@@ -64,7 +64,6 @@ const MacOSCursorInner: React.FC<
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -95,8 +94,6 @@ const MacOSCursorInner: React.FC<
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -113,7 +110,6 @@ const MacOSCursorInner: React.FC<
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/maptiler/src/MapHeatmap.tsx b/packages/maptiler/src/MapHeatmap.tsx
index 184a5a48e9..009fdbde02 100644
--- a/packages/maptiler/src/MapHeatmap.tsx
+++ b/packages/maptiler/src/MapHeatmap.tsx
@@ -212,7 +212,6 @@ export const MapHeatmap = (props: MapHeatmapProps) => {
name,
showInTimeline,
trimBefore,
- trimAfter,
playbackRate,
loop,
} = props;
@@ -228,8 +227,6 @@ export const MapHeatmap = (props: MapHeatmapProps) => {
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -246,7 +243,6 @@ export const MapHeatmap = (props: MapHeatmapProps) => {
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/maptiler/src/MapLayer.tsx b/packages/maptiler/src/MapLayer.tsx
index ef81b77188..2e7e647c31 100644
--- a/packages/maptiler/src/MapLayer.tsx
+++ b/packages/maptiler/src/MapLayer.tsx
@@ -147,7 +147,6 @@ export const MapLayer = ({
from,
durationInFrames,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -169,8 +168,6 @@ export const MapLayer = ({
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -189,7 +186,6 @@ export const MapLayer = ({
from={from}
durationInFrames={durationInFrames}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/maptiler/src/MapOverlay.tsx b/packages/maptiler/src/MapOverlay.tsx
index 175a2687c4..be38d8aa09 100644
--- a/packages/maptiler/src/MapOverlay.tsx
+++ b/packages/maptiler/src/MapOverlay.tsx
@@ -131,7 +131,6 @@ const MapOverlayRefForwardingFunction: ForwardRefRenderFunction<
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -170,8 +169,6 @@ const MapOverlayRefForwardingFunction: ForwardRefRenderFunction<
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -188,7 +185,6 @@ const MapOverlayRefForwardingFunction: ForwardRefRenderFunction<
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/maptiler/src/MapPoint.tsx b/packages/maptiler/src/MapPoint.tsx
index e51841569e..e4511a44cb 100644
--- a/packages/maptiler/src/MapPoint.tsx
+++ b/packages/maptiler/src/MapPoint.tsx
@@ -286,7 +286,6 @@ export const MapPoint = (props: MapPointProps) => {
name,
showInTimeline,
trimBefore,
- trimAfter,
playbackRate,
loop,
} = props;
@@ -302,8 +301,6 @@ export const MapPoint = (props: MapPointProps) => {
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -320,7 +317,6 @@ export const MapPoint = (props: MapPointProps) => {
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/maptiler/src/MapPolygon.tsx b/packages/maptiler/src/MapPolygon.tsx
index 197aa86b0c..3dfa9a2926 100644
--- a/packages/maptiler/src/MapPolygon.tsx
+++ b/packages/maptiler/src/MapPolygon.tsx
@@ -376,7 +376,6 @@ export const MapPolygon = (props: MapPolygonProps) => {
name,
showInTimeline,
trimBefore,
- trimAfter,
playbackRate,
loop,
} = props;
@@ -392,8 +391,6 @@ export const MapPolygon = (props: MapPolygonProps) => {
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -410,7 +407,6 @@ export const MapPolygon = (props: MapPolygonProps) => {
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/maptiler/src/MapPolyline.tsx b/packages/maptiler/src/MapPolyline.tsx
index 1dc0b641d2..751ab4ed01 100644
--- a/packages/maptiler/src/MapPolyline.tsx
+++ b/packages/maptiler/src/MapPolyline.tsx
@@ -446,7 +446,6 @@ export const MapPolyline = (props: MapPolylineProps) => {
name,
showInTimeline,
trimBefore,
- trimAfter,
playbackRate,
loop,
} = props;
@@ -462,8 +461,6 @@ export const MapPolyline = (props: MapPolylineProps) => {
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -480,7 +477,6 @@ export const MapPolyline = (props: MapPolylineProps) => {
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/maptiler/src/MapRegion.tsx b/packages/maptiler/src/MapRegion.tsx
index 2df244e5d6..f30f7618e3 100644
--- a/packages/maptiler/src/MapRegion.tsx
+++ b/packages/maptiler/src/MapRegion.tsx
@@ -364,7 +364,6 @@ const MapRegionRefForwardingFunction: ForwardRefRenderFunction<
premountFor,
postmountFor,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -390,8 +389,6 @@ const MapRegionRefForwardingFunction: ForwardRefRenderFunction<
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -408,7 +405,6 @@ const MapRegionRefForwardingFunction: ForwardRefRenderFunction<
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/maptiler/src/MapRoute.tsx b/packages/maptiler/src/MapRoute.tsx
index e81d8b3ec1..d4db5cab7b 100644
--- a/packages/maptiler/src/MapRoute.tsx
+++ b/packages/maptiler/src/MapRoute.tsx
@@ -293,7 +293,6 @@ const MapRouteRefForwardingFunction: ForwardRefRenderFunction<
premountFor,
postmountFor,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -319,8 +318,6 @@ const MapRouteRefForwardingFunction: ForwardRefRenderFunction<
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -337,7 +334,6 @@ const MapRouteRefForwardingFunction: ForwardRefRenderFunction<
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/maptiler/src/MapSource.tsx b/packages/maptiler/src/MapSource.tsx
index a6771e5076..a25ab9a2d4 100644
--- a/packages/maptiler/src/MapSource.tsx
+++ b/packages/maptiler/src/MapSource.tsx
@@ -99,7 +99,6 @@ export const MapSource = ({
from,
durationInFrames,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -121,8 +120,6 @@ export const MapSource = ({
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -141,7 +138,6 @@ export const MapSource = ({
from={from}
durationInFrames={durationInFrames}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/maptiler/src/MapViewport.tsx b/packages/maptiler/src/MapViewport.tsx
index 0860e1c3ff..be9a870ea8 100644
--- a/packages/maptiler/src/MapViewport.tsx
+++ b/packages/maptiler/src/MapViewport.tsx
@@ -552,7 +552,6 @@ const MapViewportRefForwardingFunction: ForwardRefRenderFunction<
durationInFrames,
from,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -580,8 +579,6 @@ const MapViewportRefForwardingFunction: ForwardRefRenderFunction<
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -600,7 +597,6 @@ const MapViewportRefForwardingFunction: ForwardRefRenderFunction<
durationInFrames={durationInFrames}
from={from}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/media/src/audio/audio.tsx b/packages/media/src/audio/audio.tsx
index eaf388f03c..56a3db0949 100644
--- a/packages/media/src/audio/audio.tsx
+++ b/packages/media/src/audio/audio.tsx
@@ -12,6 +12,10 @@ import {
import {useLoopedVolume} from '../looped-frame';
import {getLoopDisplay} from '../show-in-timeline';
import {validateToneFrequency} from '../validate-tone-frequency';
+import {
+ getMediaTrimAfter,
+ getVideoSequenceDuration,
+} from '../video/get-video-sequence-duration';
import {AudioForPreview} from './audio-for-preview';
import {AudioForRendering} from './audio-for-rendering';
import type {AudioProps} from './props';
@@ -27,6 +31,7 @@ export const audioSchema: InteractivitySchema = {
keyframable: false,
},
...Internals.baseSchema,
+ trimAfter: Internals.trimAfterField,
...Internals.premountSchema,
volume: {
type: 'number',
@@ -86,8 +91,20 @@ const AudioInner: React.FC<
const [mediaVolume] = Internals.useMediaVolumeState();
const mediaStartsAt = Internals.useMediaStartsAt();
const videoConfig = useVideoConfig();
+ const effectiveTrimAfter = getMediaTrimAfter({
+ durationInFrames,
+ trimAfter: props.trimAfter,
+ trimBefore: props.trimBefore,
+ });
+ const audioSequenceDuration = getVideoSequenceDuration({
+ durationInFrames,
+ loop: props.loop ?? false,
+ playbackRate: props.playbackRate ?? 1,
+ trimAfter: effectiveTrimAfter,
+ trimBefore: props.trimBefore,
+ });
const sequenceDurationInFrames = Math.min(
- durationInFrames ?? Infinity,
+ audioSequenceDuration ?? Infinity,
Math.max(0, videoConfig.durationInFrames - (from ?? 0)),
);
const [mediaDurationInSeconds, setMediaDurationInSeconds] = useState<
@@ -102,7 +119,7 @@ const AudioInner: React.FC<
startsAt: Math.min(0, mediaStartsAt + (from ?? 0)),
playbackRate: props.playbackRate ?? 1,
trimBefore: props.trimBefore,
- trimAfter: props.trimAfter,
+ trimAfter: effectiveTrimAfter,
});
const basicInfo = Internals.useBasicMediaInTimeline({
@@ -110,7 +127,7 @@ const AudioInner: React.FC<
volume,
playbackRate: props.playbackRate ?? 1,
trimBefore: props.trimBefore,
- trimAfter: props.trimAfter,
+ trimAfter: effectiveTrimAfter,
sequenceDurationInFrames,
mediaType: 'audio',
displayName: name ?? '<Audio>',
@@ -127,7 +144,7 @@ const AudioInner: React.FC<
loop: props.loop ?? false,
mediaDurationInSeconds,
playbackRate: props.playbackRate ?? 1,
- trimAfter: props.trimAfter,
+ trimAfter: effectiveTrimAfter,
trimBefore: props.trimBefore,
sequenceDurationInFrames,
compFps: videoConfig.fps,
@@ -136,7 +153,7 @@ const AudioInner: React.FC<
props.loop,
mediaDurationInSeconds,
props.playbackRate,
- props.trimAfter,
+ effectiveTrimAfter,
props.trimBefore,
sequenceDurationInFrames,
videoConfig.fps,
@@ -216,12 +233,14 @@ const AudioInner: React.FC<
{environment.isRendering ? (
<AudioForRendering
{...otherProps}
+ trimAfter={effectiveTrimAfter}
style={premountingStyle ?? undefined}
/>
) : (
<AudioForPreview
name={name}
{...otherProps}
+ trimAfter={effectiveTrimAfter}
style={premountingStyle}
_remotionInternalStack={sourceStack}
setMediaDurationInSeconds={setMediaDurationInSeconds}
diff --git a/packages/media/src/test/get-video-sequence-duration.test.ts b/packages/media/src/test/get-video-sequence-duration.test.ts
index afafa497c5..e35c512b0d 100644
--- a/packages/media/src/test/get-video-sequence-duration.test.ts
+++ b/packages/media/src/test/get-video-sequence-duration.test.ts
@@ -59,7 +59,7 @@ test('uses the shorter of trimAfter and an explicit duration', () => {
).toBe(120);
});
-test('loop keeps the sequence unbounded despite trimAfter', () => {
+test('loop keeps the sequence unbounded', () => {
expect(
getDuration({loop: true, trimBefore: 30, trimAfter: 150}),
).toBeUndefined();
@@ -70,5 +70,5 @@ test('loop keeps the sequence unbounded despite trimAfter', () => {
trimBefore: 30,
trimAfter: 150,
}),
- ).toBe(180);
+ ).toBeUndefined();
});
diff --git a/packages/media/src/test/html5-playback-rate.test.tsx b/packages/media/src/test/html5-playback-rate.test.tsx
index 2d8da2eda7..835f588189 100644
--- a/packages/media/src/test/html5-playback-rate.test.tsx
+++ b/packages/media/src/test/html5-playback-rate.test.tsx
@@ -131,7 +131,7 @@ test('preserves the Player media playback rate across source changes and reloads
shortSequence && 'volume' in shortSequence
? shortSequence.volume
: null,
- ).toBe('0.25,0.5');
+ ).toBe('0.25,0.5,1.25,2.5');
playerRef.current!.seekTo(11);
await expect.poll(() => shortVideoRef.current?.volume).toBe(0.5);
playerRef.current!.seekTo(30);
@@ -259,7 +259,7 @@ test('seeks trimmed HTML5 loops across fractional boundaries under nested sequen
.toBe(4);
const frames = useThreeLevels
- ? [50, 49, 50, 80, 81, 110, 111, 141, 142, 154, 20, 50]
+ ? [50, 49, 50, 20, 21, 48, 49, 50, 51, 65, 66, 20, 50]
: [7, 26, 27, 28, 51, 52, 53, 126, 127, 128, 377, 376, 27, 7];
for (const frame of frames) {
playerRef.current!.seekTo(frame);
@@ -291,7 +291,7 @@ test('seeks trimmed HTML5 loops across fractional boundaries under nested sequen
const samples = String(layer && 'volume' in layer ? layer.volume : '')
.split(',')
.map(Number);
- expect(samples).toHaveLength(useThreeLevels ? 135 : 493);
+ expect(samples).toHaveLength(useThreeLevels ? 47 : 493);
expect(
samples[frame - (useThreeLevels ? 20 : 7)],
`${type} timeline volume at frame ${frame}, media rate ${mediaRate}`,
@@ -305,7 +305,7 @@ test('seeks trimmed HTML5 loops across fractional boundaries under nested sequen
}
if (useThreeLevels) {
- playerRef.current!.seekTo(155);
+ playerRef.current!.seekTo(67);
await expect.poll(() => videoRef.current).toBeNull();
await expect.poll(() => audioRef.current).toBeNull();
}
diff --git a/packages/media/src/test/sequence-playback-rate.test.tsx b/packages/media/src/test/sequence-playback-rate.test.tsx
index 99e4014a99..f8fb373696 100644
--- a/packages/media/src/test/sequence-playback-rate.test.tsx
+++ b/packages/media/src/test/sequence-playback-rate.test.tsx
@@ -88,7 +88,7 @@ test('nested Sequence rates keep decoded video, looping, and scheduled audio in
onVideoFrame={() => trimmedDraws++}
/>
</Sequence>
- {frame >= 30 && frame < 120 ? (
+ {frame >= 30 && frame < 75 ? (
<Freeze frame={197 + ((((frame - 30) * 2 + 75) * 0.7) % 27)}>
<Video
src={trimmedSrc}
@@ -144,12 +144,15 @@ test('nested Sequence rates keep decoded video, looping, and scheduled audio in
const previousTrimmedReferenceDraws = trimmedReferenceDraws;
playerRef.current!.seekTo(frame);
await expect
- .poll(() => nestedDraws, {timeout: 10_000})
+ .poll(() => nestedDraws, {
+ timeout: 10_000,
+ message: `nested video at frame ${frame}`,
+ })
.toBeGreaterThan(previousNestedDraws);
await expect
.poll(() => referenceDraws, {timeout: 10_000})
.toBeGreaterThan(previousReferenceDraws);
- if (frame >= 30 && frame < 120) {
+ if (frame >= 30 && frame < 75) {
await expect
.poll(() => trimmedDraws, {timeout: 10_000})
.toBeGreaterThan(previousTrimmedDraws);
@@ -171,7 +174,7 @@ test('nested Sequence rates keep decoded video, looping, and scheduled audio in
nested.toDataURL() === reference.toDataURL(),
`nested video must match source frame at composition frame ${frame}`,
).toBe(true);
- if (frame >= 30 && frame < 120) {
+ if (frame >= 30 && frame < 75) {
const trimmed = container.querySelector<HTMLCanvasElement>(
'[data-testid="trimmed-video"]',
)!;
diff --git a/packages/media/src/video/get-video-sequence-duration.ts b/packages/media/src/video/get-video-sequence-duration.ts
index e9106061cc..a565a842be 100644
--- a/packages/media/src/video/get-video-sequence-duration.ts
+++ b/packages/media/src/video/get-video-sequence-duration.ts
@@ -1,4 +1,24 @@
-import {Internals} from 'remotion';
+export const getMediaTrimAfter = ({
+ durationInFrames,
+ trimAfter,
+ trimBefore,
+}: {
+ readonly durationInFrames: number | undefined;
+ readonly trimAfter: number | undefined;
+ readonly trimBefore: number | undefined;
+}) => {
+ const durationAsTrimAfter =
+ durationInFrames === undefined
+ ? undefined
+ : (trimBefore ?? 0) + durationInFrames;
+ if (durationAsTrimAfter === undefined) {
+ return trimAfter;
+ }
+
+ return trimAfter === undefined
+ ? durationAsTrimAfter
+ : Math.min(trimAfter, durationAsTrimAfter);
+};
export const getVideoSequenceDuration = ({
durationInFrames,
@@ -13,16 +33,14 @@ export const getVideoSequenceDuration = ({
readonly trimAfter: number | undefined;
readonly trimBefore: number | undefined;
}) => {
- if (loop || trimAfter === undefined) {
- return durationInFrames;
+ if (loop) {
+ return undefined;
}
- const trimmedDuration = Internals.calculateMediaDuration({
- trimAfter,
- trimBefore,
- playbackRate,
- mediaDurationInFrames: Infinity,
- });
-
- return Math.min(durationInFrames ?? Infinity, trimmedDuration);
+ const trimDuration =
+ trimAfter === undefined ? Infinity : trimAfter - (trimBefore ?? 0);
+ const contentDuration = Math.min(durationInFrames ?? Infinity, trimDuration);
+ return contentDuration === Infinity
+ ? undefined
+ : contentDuration / playbackRate;
};
diff --git a/packages/media/src/video/video.tsx b/packages/media/src/video/video.tsx
index 183360a1ec..55c997141d 100644
--- a/packages/media/src/video/video.tsx
+++ b/packages/media/src/video/video.tsx
@@ -12,7 +12,10 @@ import {
import {useLoopedVolume} from '../looped-frame';
import {getLoopDisplay} from '../show-in-timeline';
import {validateToneFrequency} from '../validate-tone-frequency';
-import {getVideoSequenceDuration} from './get-video-sequence-duration';
+import {
+ getMediaTrimAfter,
+ getVideoSequenceDuration,
+} from './get-video-sequence-duration';
import type {InnerVideoProps, VideoProps} from './props';
import {VideoForPreview} from './video-for-preview';
import {VideoForRendering} from './video-for-rendering';
@@ -33,6 +36,7 @@ export const videoSchema: InteractivitySchema = {
keyframable: false,
},
...Internals.baseSchema,
+ trimAfter: Internals.trimAfterField,
...Internals.premountSchema,
volume: {
type: 'number',
@@ -265,17 +269,22 @@ const VideoInner: React.FC<
const [mediaVolume] = Internals.useMediaVolumeState();
const mediaStartsAt = Internals.useMediaStartsAt();
const videoConfig = useVideoConfig();
- const sequenceDurationInFrames = Math.min(
- durationInFrames ?? Infinity,
- Math.max(0, videoConfig.durationInFrames - (from ?? 0)),
- );
+ const effectiveTrimAfter = getMediaTrimAfter({
+ durationInFrames,
+ trimAfter,
+ trimBefore,
+ });
const videoSequenceDuration = getVideoSequenceDuration({
durationInFrames,
loop: loop ?? false,
playbackRate: playbackRate ?? 1,
- trimAfter,
+ trimAfter: effectiveTrimAfter,
trimBefore,
});
+ const sequenceDurationInFrames = Math.min(
+ videoSequenceDuration ?? Infinity,
+ Math.max(0, videoConfig.durationInFrames - (from ?? 0)),
+ );
const [mediaDurationInSeconds, setMediaDurationInSeconds] = useState<
number | null
>(null);
@@ -288,7 +297,7 @@ const VideoInner: React.FC<
startsAt: Math.min(0, mediaStartsAt + (from ?? 0)),
playbackRate: playbackRate ?? 1,
trimBefore,
- trimAfter,
+ trimAfter: effectiveTrimAfter,
});
const basicInfo = Internals.useBasicMediaInTimeline({
@@ -296,7 +305,7 @@ const VideoInner: React.FC<
volume: loopedVolume,
playbackRate: playbackRate ?? 1,
trimBefore,
- trimAfter,
+ trimAfter: effectiveTrimAfter,
sequenceDurationInFrames,
mediaType: 'video',
displayName: name ?? '<Video>',
@@ -313,7 +322,7 @@ const VideoInner: React.FC<
loop: loop ?? false,
mediaDurationInSeconds,
playbackRate: playbackRate ?? 1,
- trimAfter,
+ trimAfter: effectiveTrimAfter,
trimBefore,
sequenceDurationInFrames,
compFps: videoConfig.fps,
@@ -322,7 +331,7 @@ const VideoInner: React.FC<
loop,
mediaDurationInSeconds,
playbackRate,
- trimAfter,
+ effectiveTrimAfter,
trimBefore,
sequenceDurationInFrames,
videoConfig.fps,
@@ -420,7 +429,7 @@ const VideoInner: React.FC<
showInTimeline={showInTimeline ?? true}
src={src}
style={croppedStyle ?? {}}
- trimAfter={trimAfter}
+ trimAfter={effectiveTrimAfter}
trimBefore={trimBefore}
volume={volume ?? 1}
toneFrequency={toneFrequency ?? 1}
diff --git a/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx b/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx
index 92db986376..6b8deb976e 100644
--- a/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx
+++ b/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx
@@ -106,7 +106,6 @@ const HtmlInCanvasMotionBlurInner: React.FC<
from,
durationInFrames,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -142,8 +141,6 @@ const HtmlInCanvasMotionBlurInner: React.FC<
Math.min(
Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -224,7 +221,6 @@ const HtmlInCanvasMotionBlurInner: React.FC<
from={from}
durationInFrames={durationInFrames}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/rive/src/RemotionRiveCanvas.tsx b/packages/rive/src/RemotionRiveCanvas.tsx
index 52df363f9f..684ba200e9 100644
--- a/packages/rive/src/RemotionRiveCanvas.tsx
+++ b/packages/rive/src/RemotionRiveCanvas.tsx
@@ -450,7 +450,6 @@ const RemotionRiveCanvasInnerForwardRefFunction: React.ForwardRefRenderFunction<
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -480,8 +479,6 @@ const RemotionRiveCanvasInnerForwardRefFunction: React.ForwardRefRenderFunction<
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -507,7 +504,6 @@ const RemotionRiveCanvasInnerForwardRefFunction: React.ForwardRefRenderFunction<
layout="none"
from={from}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/rough-notation/src/Annotation.tsx b/packages/rough-notation/src/Annotation.tsx
index 8c13427e4f..19027a9b1b 100644
--- a/packages/rough-notation/src/Annotation.tsx
+++ b/packages/rough-notation/src/Annotation.tsx
@@ -369,7 +369,6 @@ const makeAnnotationComponent = ({
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -425,8 +424,6 @@ const makeAnnotationComponent = ({
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -443,7 +440,6 @@ const makeAnnotationComponent = ({
layout="none"
from={from ?? 0}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
durationInFrames={durationInFrames ?? Infinity}
diff --git a/packages/shapes/src/components/render-svg.tsx b/packages/shapes/src/components/render-svg.tsx
index f7678ec2fa..812b7158fa 100644
--- a/packages/shapes/src/components/render-svg.tsx
+++ b/packages/shapes/src/components/render-svg.tsx
@@ -45,7 +45,6 @@ const RenderSvgWithTiming = ({
styleWhilePostmounted,
from,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -80,8 +79,6 @@ const RenderSvgWithTiming = ({
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -98,7 +95,6 @@ const RenderSvgWithTiming = ({
layout="none"
from={from}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
@@ -142,7 +138,6 @@ export const RenderSvg = ({
styleWhilePremounted,
styleWhilePostmounted,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -299,7 +294,6 @@ export const RenderSvg = ({
styleWhilePostmounted={styleWhilePostmounted}
from={from}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/shapes/src/test/effects.test.tsx b/packages/shapes/src/test/effects.test.tsx
index 55b5d96112..58cbdaa42d 100644
--- a/packages/shapes/src/test/effects.test.tsx
+++ b/packages/shapes/src/test/effects.test.tsx
@@ -88,7 +88,6 @@ mock.module('remotion', () => {
durationInFrames: {},
from: {},
trimBefore: {},
- trimAfter: {},
loop: {},
freeze: {},
hidden: {},
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsx
index 3eeb24c01a..a65c9ae506 100644
--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx
@@ -1005,7 +1005,7 @@ const TimelineSequenceInner: React.FC<{
explicitDurationInFrames:
explicitDurationInFrames === null
? null
- : explicitDurationInFrames / s.sequencePlaybackRate,
+ : explicitDurationInFrames / s.playbackRate,
hasImplicitDuration: hasImplicitMediaDuration,
naturalMediaDuration,
timelineDurationInFrames: video.durationInFrames,
diff --git a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
index d47dd6e686..3cf9de02ae 100644
--- a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
@@ -101,50 +101,13 @@ const isResettableStatus = ({
return JSON.stringify(effectiveCodeValue) !== JSON.stringify(defaultValue);
};
-const getPlaybackRateAdjustedDuration = ({
- durationInFrames,
- previousPlaybackRate,
- playbackRate,
-}: {
- readonly durationInFrames: number;
- readonly previousPlaybackRate: number;
- readonly playbackRate: number;
-}): number | null => {
- const adjustedDuration =
- (durationInFrames * previousPlaybackRate) / playbackRate;
- if (!Number.isFinite(adjustedDuration) || adjustedDuration <= 0) {
- return null;
- }
-
- const nearestInteger = Math.round(adjustedDuration);
- return nearestInteger > 0 &&
- Math.abs(adjustedDuration - nearestInteger) <=
- Number.EPSILON * Math.max(1, Math.abs(adjustedDuration)) * 2
- ? nearestInteger
- : adjustedDuration;
-};
-
const Value: React.FC<{
readonly field: SchemaFieldInfo;
readonly nodePath: SequencePropsSubscriptionKey;
readonly validatedLocation: CodePosition;
readonly schema: InteractivitySchema;
readonly propStatus: CanUpdateSequencePropStatusStatic;
- readonly durationPropStatus: CanUpdateSequencePropStatus | null;
-}> = ({
- field,
- nodePath,
- validatedLocation,
- schema,
- propStatus,
- durationPropStatus,
-}) => {
- const playbackRateBaseline = useRef<{
- durationInFrames: number;
- playbackRate: number;
- lastSavedDurationInFrames: number;
- lastSavedPlaybackRate: number;
- } | null>(null);
+}> = ({field, nodePath, validatedLocation, schema, propStatus}) => {
const previewedKeyframes = useRef<
ReturnType<typeof getPlaybackRateKeyframeChanges>['previews']
>([]);
@@ -196,21 +159,21 @@ const Value: React.FC<{
sequencesRef,
],
);
- // Items without an intrinsic duration need `trimAfter` to loop. Filling it
+ // Items without an intrinsic duration need a finite loop range. Filling it
// with the current end keeps the output unchanged until the clip is extended.
- const getLoopTrimAfter = useCallback(
+ const getLoopDurationChange = useCallback(
(value: unknown): number | null => {
- if (field.key !== 'loop' || value !== true || !schema.trimAfter) {
+ if (field.key !== 'loop' || value !== true || !schema.durationInFrames) {
return null;
}
- const trimAfterStatus = Internals.getPropStatusesCtx(
+ const durationStatus = Internals.getPropStatusesCtx(
propStatusesRef.current,
nodePath,
- )?.trimAfter;
+ )?.durationInFrames;
if (
- trimAfterStatus?.status !== 'static' ||
- trimAfterStatus.codeValue !== undefined
+ durationStatus?.status !== 'static' ||
+ durationStatus.codeValue !== undefined
) {
return null;
}
@@ -233,85 +196,17 @@ const Value: React.FC<{
return null;
}
- const runtimeTrimBefore =
- sequence.controls?.runtimeValues.getSnapshot().trimBefore;
- const trimBefore =
- typeof runtimeTrimBefore === 'number' ? runtimeTrimBefore : 0;
-
- return trimBefore + sequence.duration * sequence.sequencePlaybackRate;
+ return sequence.duration * sequence.sequencePlaybackRate;
},
[
field.key,
nodePath,
overrideIdToNodePathMappings,
propStatusesRef,
- schema.trimAfter,
+ schema,
sequencesRef,
],
);
- const getAdjustedDuration = useCallback(
- (playbackRate: unknown): number | null => {
- if (
- field.key !== 'playbackRate' ||
- !schema.durationInFrames ||
- durationPropStatus?.status !== 'static' ||
- typeof durationPropStatus.codeValue !== 'number' ||
- !Number.isFinite(durationPropStatus.codeValue) ||
- typeof playbackRate !== 'number' ||
- !Number.isFinite(playbackRate) ||
- playbackRate <= 0
- ) {
- return null;
- }
-
- const currentPlaybackRate =
- typeof propStatus.codeValue === 'number'
- ? propStatus.codeValue
- : field.fieldSchema.default;
- if (
- typeof currentPlaybackRate !== 'number' ||
- !Number.isFinite(currentPlaybackRate) ||
- currentPlaybackRate <= 0
- ) {
- return null;
- }
-
- const currentDuration = durationPropStatus.codeValue;
- let baseline = playbackRateBaseline.current;
- // Keep the first duration and rate across successive rate edits. A change
- // to either prop outside this control starts a new baseline.
- if (
- baseline === null ||
- !(
- (currentDuration === baseline.durationInFrames &&
- currentPlaybackRate === baseline.playbackRate) ||
- (currentDuration === baseline.lastSavedDurationInFrames &&
- currentPlaybackRate === baseline.lastSavedPlaybackRate)
- )
- ) {
- baseline = {
- durationInFrames: currentDuration,
- playbackRate: currentPlaybackRate,
- lastSavedDurationInFrames: currentDuration,
- lastSavedPlaybackRate: currentPlaybackRate,
- };
- playbackRateBaseline.current = baseline;
- }
-
- return getPlaybackRateAdjustedDuration({
- durationInFrames: baseline.durationInFrames,
- previousPlaybackRate: baseline.playbackRate,
- playbackRate,
- });
- },
- [
- durationPropStatus,
- field.fieldSchema.default,
- field.key,
- propStatus.codeValue,
- schema.durationInFrames,
- ],
- );
const {getDragOverrides} = useContext(
Internals.VisualModeDragOverridesContext,
);
@@ -356,8 +251,7 @@ const Value: React.FC<{
const stringifiedValue = JSON.stringify(value);
const fieldLabel = field.description ?? field.key;
- const adjustedDuration = getAdjustedDuration(value);
- const loopTrimAfter = getLoopTrimAfter(value);
+ const loopDurationChange = getLoopDurationChange(value);
if (value === propStatus.codeValue) {
return Promise.resolve();
@@ -370,12 +264,6 @@ const Value: React.FC<{
return Promise.resolve();
}
- if (adjustedDuration !== null && playbackRateBaseline.current) {
- playbackRateBaseline.current.lastSavedDurationInFrames =
- adjustedDuration;
- playbackRateBaseline.current.lastSavedPlaybackRate = value as number;
- }
-
return unstable_batchedUpdates(() =>
saveSequenceProps({
addedKeyframes: null,
@@ -393,26 +281,14 @@ const Value: React.FC<{
? {type: 'playback-rate'}
: options?.sourceEdit,
},
- ...(adjustedDuration === null
+ ...(loopDurationChange === null
? []
: [
{
fileName: validatedLocation.source,
nodePath,
fieldKey: 'durationInFrames',
- value: adjustedDuration,
- defaultValue: null,
- schema,
- },
- ]),
- ...(loopTrimAfter === null
- ? []
- : [
- {
- fileName: validatedLocation.source,
- nodePath,
- fieldKey: 'trimAfter',
- value: loopTrimAfter,
+ value: loopDurationChange,
defaultValue: null,
schema,
},
@@ -432,8 +308,7 @@ const Value: React.FC<{
field.fieldSchema.default,
field.fieldSchema.type,
field.key,
- getAdjustedDuration,
- getLoopTrimAfter,
+ getLoopDurationChange,
nodePath,
schema,
setPropStatuses,
@@ -447,7 +322,6 @@ const Value: React.FC<{
throw new Error('Cannot drag value');
}
- const adjustedDuration = getAdjustedDuration(value);
const keyframeChanges = getPlaybackRateChanges(value);
unstable_batchedUpdates(() => {
for (const preview of previewedKeyframes.current) {
@@ -464,14 +338,6 @@ const Value: React.FC<{
field.key,
Internals.makeStaticDragOverride(value),
);
- if (adjustedDuration !== null) {
- setDragOverrides(
- nodePath,
- 'durationInFrames',
- Internals.makeStaticDragOverride(adjustedDuration),
- );
- }
-
for (const preview of previewedKeyframes.current) {
if (preview.effectIndex === null) {
setDragOverrides(preview.nodePath, preview.fieldKey, {
@@ -496,7 +362,6 @@ const Value: React.FC<{
setEffectDragOverrides,
nodePath,
field.key,
- getAdjustedDuration,
getPlaybackRateChanges,
],
);
@@ -841,34 +706,6 @@ export const TimelineSequencePropItem: React.FC<{
? JSON.stringify(field.fieldSchema.default)
: null;
const fieldLabel = field.description ?? field.key;
- const previousPlaybackRate =
- field.key === 'playbackRate' &&
- propStatus.status === 'static' &&
- typeof propStatus.codeValue === 'number'
- ? propStatus.codeValue
- : null;
- const nextPlaybackRate = field.fieldSchema.default;
- const canRetime =
- previousPlaybackRate !== null &&
- Number.isFinite(previousPlaybackRate) &&
- previousPlaybackRate > 0 &&
- typeof nextPlaybackRate === 'number' &&
- Number.isFinite(nextPlaybackRate) &&
- nextPlaybackRate > 0;
-
- const durationStatus = propStatusesForOverride?.durationInFrames;
- const adjustedDuration =
- canRetime &&
- schema.durationInFrames &&
- durationStatus?.status === 'static' &&
- typeof durationStatus.codeValue === 'number' &&
- Number.isFinite(durationStatus.codeValue)
- ? getPlaybackRateAdjustedDuration({
- durationInFrames: durationStatus.codeValue,
- previousPlaybackRate,
- playbackRate: nextPlaybackRate,
- })
- : null;
saveSequenceProps({
addedKeyframes: null,
@@ -886,18 +723,6 @@ export const TimelineSequencePropItem: React.FC<{
? {...change, sourceEdit: {type: 'playback-rate' as const}}
: change,
),
- ...(adjustedDuration !== null
- ? [
- {
- fileName: validatedLocation.source,
- nodePath,
- fieldKey: 'durationInFrames',
- value: adjustedDuration,
- defaultValue: null,
- schema,
- },
- ]
- : []),
],
setPropStatuses,
clientId: previewServerState.clientId,
@@ -912,7 +737,6 @@ export const TimelineSequencePropItem: React.FC<{
field.key,
nodePath,
previewServerState,
- propStatusesForOverride?.durationInFrames,
schema,
setPropStatuses,
validatedLocation.source,
@@ -986,7 +810,6 @@ export const TimelineSequencePropItem: React.FC<{
) : propStatus.status === 'static' ? (
<Value
field={field}
- durationPropStatus={propStatusesForOverride?.durationInFrames ?? null}
nodePath={nodePath}
validatedLocation={validatedLocation}
schema={schema}
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
index bbee8d69d2..b323a37eb0 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
@@ -184,11 +184,10 @@ const baseStyle: React.CSSProperties = {
touchAction: 'none',
};
-// The right edge edits whichever prop currently defines the end of the item.
-// `trimAfter` is measured in the child clock, so parent-frame drags are
-// converted through `trimBefore` and `playbackRate`.
+// `durationInFrames` is measured in the child clock, so parent-frame drags are
+// converted through `playbackRate`.
export type TimelineSequenceEndField = {
- readonly fieldKey: 'durationInFrames' | 'trimAfter';
+ readonly fieldKey: 'durationInFrames';
readonly trimBefore: number;
readonly playbackRate: number;
};
@@ -215,9 +214,6 @@ export type TimelineSequenceLeftEdgeDragTarget = {
readonly playbackRate: number;
readonly positionField: 'from' | null;
readonly schema: InteractivitySchema;
- // When `trimAfter` defines the end, moving `trimBefore` keeps the end in
- // place by itself and `durationInFrames` stays untouched.
- readonly writesDuration: boolean;
};
export type TimelineSequenceFromDragTarget = {
@@ -359,10 +355,11 @@ const getMinimumSequenceDuration = ({
);
};
-// Only `<Loop>` registers a loop display without controls. Items with controls
-// own their `loop` prop, so their edges stay editable while looping.
export const isTimelineSequenceDurationDraggable = (sequence: TSequence) => {
const isInteractiveCascadingSequence = isCascadingSequence(sequence);
+ if (sequence.loopDisplay) {
+ return false;
+ }
return (
(sequence.type === 'sequence' ||
@@ -430,20 +427,7 @@ export const getTimelineSequenceEndField = ({
const playbackRate = getTrimPlaybackRate({sequence, runtimeValues});
const trimBefore =
typeof runtimeValues.trimBefore === 'number' ? runtimeValues.trimBefore : 0;
- const {trimAfter, durationInFrames} = runtimeValues;
- // A looped item repeats its trim range, so its end is always the duration.
- const endsAtTrimAfter =
- runtimeValues.loop !== true &&
- typeof trimAfter === 'number' &&
- Number.isFinite(trimAfter) &&
- (typeof durationInFrames !== 'number' ||
- (trimAfter - trimBefore) / playbackRate < durationInFrames);
-
- return {
- fieldKey: endsAtTrimAfter ? 'trimAfter' : 'durationInFrames',
- trimBefore,
- playbackRate,
- };
+ return {fieldKey: 'durationInFrames', trimBefore, playbackRate};
};
export const getTimelineSequenceEndFieldValue = ({
@@ -453,11 +437,7 @@ export const getTimelineSequenceEndFieldValue = ({
readonly endField: TimelineSequenceEndField;
readonly durationInFrames: number;
}) => {
- if (endField.fieldKey === 'durationInFrames') {
- return durationInFrames;
- }
-
- return endField.trimBefore + durationInFrames * endField.playbackRate;
+ return durationInFrames * endField.playbackRate;
};
const isFromDraggableSequence = (sequence: TSequence) => {
@@ -565,15 +545,12 @@ export const getTimelineSequenceLeftEdgeDragChanges = ({
});
}
- if (
- target.writesDuration &&
- nextValues.durationInFrames !== target.initialDuration
- ) {
+ if (nextValues.durationInFrames !== target.initialDuration) {
changes.push({
fileName: target.fileName,
nodePath: target.nodePath,
fieldKey: 'durationInFrames',
- value: nextValues.durationInFrames,
+ value: nextValues.durationInFrames * target.playbackRate,
defaultValue: null,
schema: target.schema,
});
@@ -1038,11 +1015,6 @@ export const getTimelineSequenceLeftEdgeDragTargets = ({
}),
positionField,
schema: controls.schema,
- writesDuration:
- getTimelineSequenceEndField({
- sequence: originalSequence,
- runtimeValues,
- }).fieldKey === 'durationInFrames',
});
}
}
@@ -1512,13 +1484,13 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
);
}
- if (target.writesDuration) {
- latestRef.current.setDragOverrides(
- target.nodePath,
- 'durationInFrames',
- Internals.makeStaticDragOverride(nextValues.durationInFrames),
- );
- }
+ latestRef.current.setDragOverrides(
+ target.nodePath,
+ 'durationInFrames',
+ Internals.makeStaticDragOverride(
+ nextValues.durationInFrames * target.playbackRate,
+ ),
+ );
latestRef.current.setDragOverrides(
target.nodePath,
diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.ts
index 139b666df6..25728a3cbf 100644
--- a/packages/studio/src/test/timeline-selection.test.ts
+++ b/packages/studio/src/test/timeline-selection.test.ts
@@ -2010,98 +2010,58 @@ test('Timeline duration drag supports interactive video clips', () => {
]);
});
-test('Timeline edge drags edit the prop that defines the visible end', () => {
+test('Timeline edge drags edit durationInFrames in the child clock', () => {
const nodePathInfo = makeNodePathInfo(['body', 0], []);
const nodePath = nodePathInfo.sequenceSubscriptionKey;
- const makePropStatuses = (
- fieldKey: 'durationInFrames' | 'trimAfter',
- ): PropStatuses => ({
+ const propStatuses: PropStatuses = {
[Internals.makeSequencePropsSubscriptionKey(nodePath)]: {
canUpdate: true,
props: {
- [fieldKey]: {
+ durationInFrames: {
status: 'static',
keyframeDisplayOffsetAdjustment: null,
- codeValue: fieldKey === 'trimAfter' ? 24 : 10,
+ codeValue: 20,
},
},
effects: [],
},
+ };
+ const targets = getTimelineSequenceDurationDragTargets({
+ draggedNodePathInfo: nodePathInfo,
+ draggedSequenceMediaDurationDragLimits: null,
+ selectedSequenceMediaDurationDragLimits: null,
+ selectedItems: [{type: 'sequence', nodePathInfo}],
+ sequences: [
+ makeTimelineSequence({
+ schema: Internals.baseSchema,
+ duration: 10,
+ sequencePlaybackRate: 2,
+ currentRuntimeValueDotNotation: {
+ durationInFrames: 20,
+ playbackRate: 2,
+ trimBefore: 4,
+ },
+ }),
+ ],
+ overrideIdsToNodePaths: {override: nodePath},
+ propStatuses,
+ timelineDurationInFrames: 1000,
});
- const makeTargets = ({
- durationInFrames,
- loop,
- endField,
- }: {
- readonly durationInFrames: number;
- readonly loop: boolean;
- readonly endField: 'durationInFrames' | 'trimAfter';
- }) =>
- getTimelineSequenceDurationDragTargets({
- draggedNodePathInfo: nodePathInfo,
- draggedSequenceMediaDurationDragLimits: null,
- selectedSequenceMediaDurationDragLimits: null,
- selectedItems: [{type: 'sequence', nodePathInfo}],
- sequences: [
- makeTimelineSequence({
- schema: Internals.baseSchema,
- duration: loop ? durationInFrames : Math.min(10, durationInFrames),
- sequencePlaybackRate: 2,
- currentRuntimeValueDotNotation: {
- durationInFrames,
- loop,
- playbackRate: 2,
- trimAfter: 24,
- trimBefore: 4,
- },
- }),
- ],
- overrideIdsToNodePaths: {override: nodePath},
- propStatuses: makePropStatuses(endField),
- timelineDurationInFrames: 1000,
- });
- const trimAfterTargets = makeTargets({
- durationInFrames: 11,
- loop: false,
- endField: 'trimAfter',
- });
- expect(trimAfterTargets?.[0].endField).toEqual({
- fieldKey: 'trimAfter',
+ expect(targets?.[0].endField).toEqual({
+ fieldKey: 'durationInFrames',
trimBefore: 4,
playbackRate: 2,
});
expect(
getTimelineSequenceDurationDragChanges({
- targets: trimAfterTargets ?? [],
- deltaFrames: 2,
- })[0],
- ).toMatchObject({fieldKey: 'trimAfter', value: 28});
-
- // If both props end at the same frame, extending trimAfter alone would not
- // move the edge because durationInFrames would still cap the item.
- const equalEndTargets = makeTargets({
- durationInFrames: 10,
- loop: false,
- endField: 'durationInFrames',
- });
- expect(equalEndTargets?.[0].endField.fieldKey).toBe('durationInFrames');
- expect(
- getTimelineSequenceDurationDragChanges({
- targets: equalEndTargets ?? [],
+ targets: targets ?? [],
deltaFrames: 2,
})[0],
- ).toMatchObject({fieldKey: 'durationInFrames', value: 12});
-
- const loopTargets = makeTargets({
- durationInFrames: 20,
- loop: true,
- endField: 'durationInFrames',
- });
- expect(loopTargets?.[0].endField.fieldKey).toBe('durationInFrames');
+ ).toMatchObject({fieldKey: 'durationInFrames', value: 24});
});
-test('Left edge trim leaves duration untouched when trimAfter defines the end', () => {
+test('Left edge trim updates durationInFrames in the child clock', () => {
const nodePathInfo = makeNodePathInfo(['body', 0], []);
const nodePath = nodePathInfo.sequenceSubscriptionKey;
const sequence = makeTimelineSequence({
@@ -2110,9 +2070,8 @@ test('Left edge trim leaves duration untouched when trimAfter defines the end',
sequencePlaybackRate: 2,
trimBefore: 4,
currentRuntimeValueDotNotation: {
- durationInFrames: 11,
+ durationInFrames: 20,
playbackRate: 2,
- trimAfter: 24,
trimBefore: 4,
},
});
@@ -2124,7 +2083,6 @@ test('Left edge trim leaves duration untouched when trimAfter defines the end',
propStatuses: makeLeftEdgePropStatuses([nodePath], true),
});
- expect(targets?.[0].writesDuration).toBe(false);
expect(
getTimelineSequenceLeftEdgeDragChanges({
targets: targets ?? [],
@@ -2132,11 +2090,12 @@ test('Left edge trim leaves duration untouched when trimAfter defines the end',
}).map((change) => [change.fieldKey, change.value]),
).toEqual([
['from', 2],
+ ['durationInFrames', 16],
['trimBefore', 8],
]);
});
-test('Looping timeline items stay resizable but cannot be split', () => {
+test('Looping timeline items cannot be resized or split', () => {
const nodePathInfo = makeNodePathInfo(['body', 0], []);
const loopedSequence = {
...makeTimelineSequence({
@@ -2154,7 +2113,7 @@ test('Looping timeline items stay resizable but cannot be split', () => {
nodePathInfo,
};
- expect(isTimelineSequenceDurationDraggable(loopedSequence)).toBe(true);
+ expect(isTimelineSequenceDurationDraggable(loopedSequence)).toBe(false);
const loopedVideo = {
...loopedSequence,
type: 'video',
@@ -2181,10 +2140,7 @@ test('Looping timeline items stay resizable but cannot be split', () => {
]),
timelineDurationInFrames: 1000,
});
- expect(resizeTargets?.[0]).toMatchObject({
- initialDuration: 20,
- maximumDuration: 1000,
- });
+ expect(resizeTargets).toBeNull();
expect(
getTimelineSequenceSplitEligibility({
selection,
diff --git a/packages/three/src/ThreeCanvas.tsx b/packages/three/src/ThreeCanvas.tsx
index 0e74cc6fdb..e1828464f5 100644
--- a/packages/three/src/ThreeCanvas.tsx
+++ b/packages/three/src/ThreeCanvas.tsx
@@ -159,7 +159,6 @@ export const ThreeCanvasInternals = ({
from,
durationInFrames,
trimBefore,
- trimAfter,
playbackRate,
loop,
freeze,
@@ -185,8 +184,6 @@ export const ThreeCanvasInternals = ({
from: from ?? 0,
durationInFrames: Internals.resolveSequenceDuration({
durationInFrames,
- trimBefore,
- trimAfter,
playbackRate,
loop,
}),
@@ -204,7 +201,6 @@ export const ThreeCanvasInternals = ({
from={from}
durationInFrames={durationInFrames}
trimBefore={trimBefore}
- trimAfter={trimAfter}
playbackRate={playbackRate}
loop={loop}
freeze={freeze}
diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsx
index 350a11afb1..77811758ff 100644
--- a/packages/transitions/src/TransitionSeries.tsx
+++ b/packages/transitions/src/TransitionSeries.tsx
@@ -132,9 +132,7 @@ type SeriesSequenceProps = PropsWithChildren<
| 'freeze'
| 'hidden'
| 'trimBefore'
- | 'trimAfter'
| 'playbackRate'
- | 'loop'
>
>;
@@ -155,9 +153,8 @@ const transitionSeriesSequenceSchema = {
showInTimeline: Internals.sequenceSchema.showInTimeline,
freeze: Internals.freezeField,
trimBefore: Internals.sequenceSchema.trimBefore,
- trimAfter: Internals.sequenceSchema.trimAfter,
playbackRate: Internals.sequenceSchema.playbackRate,
- loop: Internals.sequenceSchema.loop,
+ loop: {type: 'hidden'},
layout: Internals.sequenceSchema.layout,
} as const satisfies InteractivitySchema;
@@ -567,6 +564,14 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
return React.cloneElement(castedChildAgain, {
_remotionInternalRender: (resolvedProps) => {
const durationInFramesProp = resolvedProps.durationInFrames;
+ const timelineDurationInFrames =
+ durationInFramesProp / (resolvedProps.playbackRate ?? 1);
+ if ((resolvedProps as {readonly loop?: boolean}).loop) {
+ throw new Error(
+ '<TransitionSeries.Sequence> does not accept `loop`. Put a looping <Sequence> inside the <TransitionSeries.Sequence> instead.',
+ );
+ }
+
const debugInfo = `index = ${i}, duration = ${durationInFramesProp}`;
const {
durationInFrames,
@@ -620,7 +625,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
let actualStartFrame = currentStartFrame + resolvedTransitionOffsets;
- resolvedStartFrame += durationInFramesProp + offset;
+ resolvedStartFrame += timelineDurationInFrames + offset;
// Handle the case where the first item is a transition
if (actualStartFrame < 0) {
@@ -632,7 +637,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
// the live Studio override instead of the original JSX value.
const nextSequenceDurations = [
...sequenceDurations,
- durationInFramesProp,
+ timelineDurationInFrames,
];
// Validate: check if a preceding overlay extends beyond this sequence
@@ -645,9 +650,9 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
const framesAfterCut =
lastOverlay.halfDuration + lastOverlay.overlayOffset;
- if (framesAfterCut > durationInFramesProp) {
+ if (framesAfterCut > timelineDurationInFrames) {
throw new TypeError(
- `A <TransitionSeries.Overlay /> extends beyond the next sequence. The overlay needs ${framesAfterCut} frames after the cut, but the next sequence is only ${durationInFramesProp} frames long.`,
+ `A <TransitionSeries.Overlay /> extends beyond the next sequence. The overlay needs ${framesAfterCut} frames after the cut, but the next sequence is only ${timelineDurationInFrames} frames long.`,
);
}
}
@@ -671,7 +676,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
frame:
frame -
actualStartFrame -
- durationInFrames +
+ timelineDurationInFrames +
next.props.timing.getDurationInFrames({fps}),
fps,
})
@@ -686,23 +691,25 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
if (
next &&
- durationInFramesProp < next.props.timing.getDurationInFrames({fps})
+ timelineDurationInFrames <
+ next.props.timing.getDurationInFrames({fps})
) {
throw new Error(
`The duration of a <TransitionSeries.Sequence /> must not be shorter than the duration of the next <TransitionSeries.Transition />. The transition is ${next.props.timing.getDurationInFrames(
{fps},
- )} frames long, but the sequence is only ${durationInFramesProp} frames long (${debugInfo})`,
+ )} frames long, but the sequence is only ${timelineDurationInFrames} frames long (${debugInfo})`,
);
}
if (
prev &&
- durationInFramesProp < prev.props.timing.getDurationInFrames({fps})
+ timelineDurationInFrames <
+ prev.props.timing.getDurationInFrames({fps})
) {
throw new Error(
`The duration of a <TransitionSeries.Sequence /> must not be shorter than the duration of the previous <TransitionSeries.Transition />. The transition is ${prev.props.timing.getDurationInFrames(
{fps},
- )} frames long, but the sequence is only ${durationInFramesProp} frames long (${debugInfo})`,
+ )} frames long, but the sequence is only ${timelineDurationInFrames} frames long (${debugInfo})`,
);
}
diff --git a/packages/transitions/src/test/transitions.test.tsx b/packages/transitions/src/test/transitions.test.tsx
index 90aade3984..ba7b01cbd8 100644
--- a/packages/transitions/src/test/transitions.test.tsx
+++ b/packages/transitions/src/test/transitions.test.tsx
@@ -10,7 +10,7 @@ const ABS_FILL =
const Frame = () => <span>{useCurrentFrame()}</span>;
-test('TransitionSeries playback rates cascade without moving sequence boundaries', () => {
+test('TransitionSeries playback rates cascade and determine sequence boundaries', () => {
const markup = (
<TransitionSeries playbackRate={2}>
<TransitionSeries.Sequence durationInFrames={20} playbackRate={0.5}>
@@ -23,9 +23,10 @@ test('TransitionSeries playback rates cascade without moving sequence boundaries
);
expect(renderForFrame(9, markup)).toContain('<span>9</span>');
- expect(renderForFrame(10, markup)).toContain('<span>0</span>');
- expect(renderForFrame(12, markup)).toContain('<span>12</span>');
- expect(renderForFrame(20, markup)).not.toContain('<span>');
+ expect(renderForFrame(10, markup)).toContain('<span>10</span>');
+ expect(renderForFrame(20, markup)).toContain('<span>0</span>');
+ expect(renderForFrame(23, markup)).toContain('<span>18</span>');
+ expect(renderForFrame(24, markup)).not.toContain('<span>');
});
const Letter: React.FC<{