Skip to content

🎥 Make videos programmatically with React

use Sequence here and there

JonnyBurgeraa16025672a2
diff --git a/packages/core/src/HtmlInCanvas.tsx b/packages/core/src/HtmlInCanvas.tsx
index f5dfb9d412..2663f5f21d 100644
--- a/packages/core/src/HtmlInCanvas.tsx
+++ b/packages/core/src/HtmlInCanvas.tsx
@@ -14,7 +14,7 @@ import type {EffectsProp} from './effects/effect-types.js';
import {runEffectChain} from './effects/run-effect-chain.js';
import {useEffectChainState} from './effects/use-effect-chain-state.js';
import {addSequenceStackTraces} from './enable-sequence-stack-traces.js';
-import type {SequenceSchema} from './sequence-field-schema.js';
+import {sequenceSchema} from './sequence-field-schema.js';
import type {
AbsoluteFillLayout,
LayoutAndStyle,
@@ -265,37 +265,6 @@ export type HtmlInCanvasProps = Omit<
const HtmlInCanvasAncestorContext = createContext(false);
-const htmlInCanvasSchema = {
- 'style.translate': {
- type: 'translate',
- step: 1,
- default: '0px 0px',
- description: 'Position',
- },
- 'style.scale': {
- type: 'number',
- min: 0.05,
- max: 100,
- step: 0.01,
- default: 1,
- description: 'Scale',
- },
- 'style.rotate': {
- type: 'rotation',
- step: 1,
- default: '0deg',
- description: 'Rotation',
- },
- 'style.opacity': {
- type: 'number',
- min: 0,
- max: 1,
- step: 0.01,
- default: 1,
- description: 'Opacity',
- },
-} as const satisfies SequenceSchema;
-
const HtmlInCanvasInner = forwardRef<
HTMLCanvasElement,
HtmlInCanvasProps & {
@@ -549,7 +518,7 @@ const HtmlInCanvasInner = forwardRef<
HtmlInCanvasInner.displayName = 'HtmlInCanvas';
-const HtmlInCanvasWrapped = wrapInSchema(HtmlInCanvasInner, htmlInCanvasSchema);
+const HtmlInCanvasWrapped = wrapInSchema(HtmlInCanvasInner, sequenceSchema);
export const HtmlInCanvas = Object.assign(HtmlInCanvasWrapped, {
isHtmlInCanvasSupported,
diff --git a/packages/core/src/Img.tsx b/packages/core/src/Img.tsx
index b1a688ca7f..80486b0d0b 100644
--- a/packages/core/src/Img.tsx
+++ b/packages/core/src/Img.tsx
@@ -11,7 +11,7 @@ import type {SequenceControls} from './CompositionManager.js';
import {addSequenceStackTraces} from './enable-sequence-stack-traces.js';
import {getCrossOriginValue} from './get-cross-origin-value.js';
import {usePreload} from './prefetch.js';
-import type {SequenceSchema} from './sequence-field-schema.js';
+import {sequenceSchema} from './sequence-field-schema.js';
import {SequenceContext} from './SequenceContext.js';
import {useBufferState} from './use-buffer-state.js';
import {useDelayRender} from './use-delay-render.js';
@@ -58,37 +58,6 @@ export type ImgProps = NativeImgProps & {
type Expected = Omit<NativeImgProps, 'onError' | 'src' | 'crossOrigin' | 'ref'>;
-const imgSchema = {
- 'style.translate': {
- type: 'translate',
- step: 1,
- default: '0px 0px',
- description: 'Position',
- },
- 'style.scale': {
- type: 'number',
- min: 0.05,
- max: 100,
- step: 0.01,
- default: 1,
- description: 'Scale',
- },
- 'style.rotate': {
- type: 'rotation',
- step: 1,
- default: '0deg',
- description: 'Rotation',
- },
- 'style.opacity': {
- type: 'number',
- min: 0,
- max: 1,
- step: 0.01,
- default: 1,
- description: 'Opacity',
- },
-} as const satisfies SequenceSchema;
-
const ImgInner: React.FC<
ImgProps & {
readonly _experimentalControls: SequenceControls | undefined;
@@ -344,5 +313,5 @@ const ImgInner: React.FC<
* @description Works just like a regular HTML img tag. When you use the <Img> tag, Remotion will ensure that the image is loaded before rendering the frame.
* @see [Documentation](https://remotion.dev/docs/img)
*/
-export const Img = wrapInSchema(ImgInner, imgSchema);
+export const Img = wrapInSchema(ImgInner, sequenceSchema);
addSequenceStackTraces(Img);
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index 4faf00e1a1..bdbfc64f72 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -14,6 +14,7 @@ import {useMemoizedEffects} from './effects/use-memoized-effects.js';
import {Freeze} from './freeze.js';
import {useNonce} from './nonce.js';
import {PremountContext} from './PremountContext.js';
+import {sequenceSchema} from './sequence-field-schema.js';
import type {SequenceContextType} from './SequenceContext.js';
import {SequenceContext} from './SequenceContext.js';
import {
@@ -29,6 +30,7 @@ import type {BasicMediaInTimelineReturnType} from './use-media-in-timeline.js';
import {useRemotionEnvironment} from './use-remotion-environment.js';
import {useVideoConfig} from './use-video-config.js';
import {ENABLE_V5_BREAKING_CHANGES} from './v5-flag.js';
+import {wrapInSchema} from './wrap-in-schema.js';
export type AbsoluteFillLayout = {
layout?: 'absolute-fill';
@@ -131,9 +133,20 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
);
}
- // @ts-expect-error
- if (layout === 'none' && typeof other.style !== 'undefined') {
- throw new TypeError('If layout="none", you may not pass a style.');
+ if (
+ layout === 'none' &&
+ // @ts-expect-error
+ typeof other.style !== 'undefined' &&
+ // TODO: In visual mode, we inject a schema, but that adds an undefined style.
+ // @ts-expect-error
+ Object.values(other.style).filter((f) => f !== undefined && f !== null)
+ .length > 0
+ ) {
+ throw new TypeError(
+ 'If layout="none", you may not pass a style. Passed: ' +
+ // @ts-expect-error
+ JSON.stringify(other.style),
+ );
}
if (typeof durationInFrames !== 'number') {
@@ -417,7 +430,7 @@ const PremountedPostmountedSequenceRefForwardingFunction: React.ForwardRefRender
return (
<Freeze frame={freezeFrame} active={isFreezingActive}>
- <Sequence
+ <SequenceInner
ref={ref}
from={from}
durationInFrames={durationInFrames}
@@ -460,8 +473,10 @@ const SequenceRefForwardingFunction: React.ForwardRefRenderFunction<
return <RegularSequence {...props} ref={ref} />;
};
+const SequenceInner = forwardRef(SequenceRefForwardingFunction);
+
/*
* @description A component that time-shifts its children and wraps them in an absolutely positioned <div>.
* @see [Documentation](https://www.remotion.dev/docs/sequence)
*/
-export const Sequence = forwardRef(SequenceRefForwardingFunction);
+export const Sequence = wrapInSchema(SequenceInner, sequenceSchema);
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index e29ea05bc5..59abc2d748 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -97,6 +97,7 @@ import type {
SequenceFieldSchema,
SequenceSchema,
} from './sequence-field-schema.js';
+import {sequenceSchema} from './sequence-field-schema.js';
import type {ResolvedStackLocation} from './sequence-stack-traces.js';
import {SequenceStackTracesUpdateContext} from './sequence-stack-traces.js';
import {SequenceContext} from './SequenceContext.js';
@@ -202,6 +203,7 @@ export const Internals = {
SequenceVisibilityToggleContext,
useSchema,
wrapInSchema,
+ sequenceSchema,
useSequenceControlOverride,
RemotionRootContexts,
CompositionManagerProvider,
diff --git a/packages/core/src/sequence-field-schema.ts b/packages/core/src/sequence-field-schema.ts
index 57f2b7f626..f0b00e203a 100644
--- a/packages/core/src/sequence-field-schema.ts
+++ b/packages/core/src/sequence-field-schema.ts
@@ -39,3 +39,34 @@ export type SchemaKeysRecord<S extends SequenceSchema> = Record<
keyof S,
unknown
>;
+
+export const sequenceSchema = {
+ 'style.translate': {
+ type: 'translate',
+ step: 1,
+ default: '0px 0px',
+ description: 'Position',
+ },
+ 'style.scale': {
+ type: 'number',
+ min: 0.05,
+ max: 100,
+ step: 0.01,
+ default: 1,
+ description: 'Scale',
+ },
+ 'style.rotate': {
+ type: 'rotation',
+ step: 1,
+ default: '0deg',
+ description: 'Rotation',
+ },
+ 'style.opacity': {
+ type: 'number',
+ min: 0,
+ max: 1,
+ step: 0.01,
+ default: 1,
+ description: 'Opacity',
+ },
+} as const satisfies SequenceSchema;
diff --git a/packages/core/src/wrap-in-schema.ts b/packages/core/src/wrap-in-schema.ts
index 2745c7370b..94b8f8b881 100644
--- a/packages/core/src/wrap-in-schema.ts
+++ b/packages/core/src/wrap-in-schema.ts
@@ -66,15 +66,13 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>(
schema: S,
): React.ComponentType<Props> => {
const schemaKeys = Object.keys(schema);
+ if (!process.env.EXPERIMENTAL_VISUAL_MODE_ENABLED) {
+ return Component as unknown as React.ComponentType<Props>;
+ }
const Wrapped = forwardRef<unknown, Props>((props, ref) => {
const env = useRemotionEnvironment();
- if (
- !env.isStudio ||
- env.isReadOnlyStudio ||
- env.isRendering ||
- !process.env.EXPERIMENTAL_VISUAL_MODE_ENABLED
- ) {
+ if (!env.isStudio || env.isReadOnlyStudio || env.isRendering) {
return React.createElement(Component, {
...props,
_experimentalControls: null,
@@ -114,6 +112,18 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>(
schemaKeys,
);
+ // If the parent has passed `_experimentalControls`, we should not override it.
+ // @ts-expect-error
+ if (props._experimentalControls) {
+ return React.createElement(Component, {
+ ...props,
+ ref,
+ } as unknown as Props & {
+ _experimentalControls: SequenceControls | undefined;
+ ref: typeof ref;
+ });
+ }
+
return React.createElement(Component, {
...mergedProps,
_experimentalControls: controls,
diff --git a/packages/example/src/ExperimentalControls/index.tsx b/packages/example/src/ExperimentalControls/index.tsx
index fdee9a7c5d..8d5c2c9ba5 100644
--- a/packages/example/src/ExperimentalControls/index.tsx
+++ b/packages/example/src/ExperimentalControls/index.tsx
@@ -61,12 +61,19 @@ export const ExperimentalControlsShowcase: React.FC = () => {
maxWidth: '100%',
maxHeight: '100%',
translate: '0px 93px',
- scale: 1.65,
+ scale: 1.98,
}}
/>
</Tile>
<Tile title="Sequence">
- <Sequence durationInFrames={120} name="inner-sequence">
+ <Sequence
+ durationInFrames={120}
+ name="inner-sequence"
+ style={{
+ translate: '0px 66px',
+ scale: 2.05,
+ }}
+ >
<AbsoluteFill
style={{
backgroundColor: '#3344ff',
@@ -86,8 +93,8 @@ export const ExperimentalControlsShowcase: React.FC = () => {
width={400}
height={300}
style={{
- translate: '0px -110px',
- scale: 0.78,
+ translate: '0px -124px',
+ scale: 2.06,
rotate: '48deg',
}}
>
@@ -166,6 +173,11 @@ export const ExperimentalControlsShowcase: React.FC = () => {
<Audio src={staticFile('music.mp3')} volume={1.29} />
</div>
</Tile>
+ <Tile title="Sequence layout='none'">
+ <Sequence name="layout='none'" layout="none">
+ hi
+ </Sequence>
+ </Tile>
</div>
</AbsoluteFill>
);
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index c8e52bfda8..254cf2d27d 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -2087,7 +2087,7 @@ export const Index: React.FC = () => {
<Composition
id="experimental-controls-showcase"
component={ExperimentalControlsShowcase}
- width={1920}
+ width={2300}
height={1080}
fps={30}
durationInFrames={120}
diff --git a/packages/gif/src/Gif.tsx b/packages/gif/src/Gif.tsx
index e7952ae292..52c6d7f0cf 100644
--- a/packages/gif/src/Gif.tsx
+++ b/packages/gif/src/Gif.tsx
@@ -33,34 +33,7 @@ const gifSchema = {
default: 1,
description: 'Playback Rate',
},
- 'style.translate': {
- type: 'translate',
- step: 1,
- default: '0px 0px',
- description: 'Position',
- },
- 'style.scale': {
- type: 'number',
- min: 0.05,
- max: 100,
- step: 0.01,
- default: 1,
- description: 'Scale',
- },
- 'style.rotate': {
- type: 'rotation',
- step: 1,
- default: '0deg',
- description: 'Rotation',
- },
- 'style.opacity': {
- type: 'number',
- min: 0,
- max: 1,
- step: 0.01,
- default: 1,
- description: 'Opacity',
- },
+ ...Internals.sequenceSchema,
} as const satisfies SequenceSchema;
const GifInner = ({
diff --git a/packages/light-leaks/src/LightLeak.tsx b/packages/light-leaks/src/LightLeak.tsx
index 3d4b9d6ba1..db88604d9c 100644
--- a/packages/light-leaks/src/LightLeak.tsx
+++ b/packages/light-leaks/src/LightLeak.tsx
@@ -243,34 +243,7 @@ const lightLeakSchema = {
default: 0,
description: 'Hue Shift',
},
- 'style.translate': {
- type: 'translate',
- step: 1,
- default: '0px 0px',
- description: 'Position',
- },
- 'style.scale': {
- type: 'number',
- min: 0.05,
- max: 100,
- step: 0.01,
- default: 1,
- description: 'Scale',
- },
- 'style.rotate': {
- type: 'rotation',
- step: 1,
- default: '0deg',
- description: 'Rotation',
- },
- 'style.opacity': {
- type: 'number',
- min: 0,
- max: 1,
- step: 0.01,
- default: 1,
- description: 'Opacity',
- },
+ ...Internals.sequenceSchema,
} as const satisfies SequenceSchema;
const LightLeakInner: React.FC<
diff --git a/packages/media/src/video/video.tsx b/packages/media/src/video/video.tsx
index 8e960fee30..8aa88d21ca 100644
--- a/packages/media/src/video/video.tsx
+++ b/packages/media/src/video/video.tsx
@@ -31,34 +31,7 @@ const videoSchema = {
description: 'Playback Rate',
},
loop: {type: 'boolean', default: false, description: 'Loop'},
- 'style.translate': {
- type: 'translate',
- step: 1,
- default: '0px 0px',
- description: 'Position',
- },
- 'style.scale': {
- type: 'number',
- min: 0.05,
- max: 100,
- step: 0.01,
- default: 1,
- description: 'Scale',
- },
- 'style.rotate': {
- type: 'rotation',
- step: 1,
- default: '0deg',
- description: 'Rotation',
- },
- 'style.opacity': {
- type: 'number',
- min: 0,
- max: 1,
- step: 0.01,
- default: 1,
- description: 'Opacity',
- },
+ ...Internals.sequenceSchema,
} as const satisfies SequenceSchema;
const InnerVideo: React.FC<
@@ -290,6 +263,7 @@ const VideoInner: React.FC<
return null;
}
+ console.log('controls', controls);
return (
<Sequence
layout="none"
diff --git a/packages/starburst/src/Starburst.tsx b/packages/starburst/src/Starburst.tsx
index c354615636..27c1655f10 100644
--- a/packages/starburst/src/Starburst.tsx
+++ b/packages/starburst/src/Starburst.tsx
@@ -334,34 +334,7 @@ const starburstSchema = {
default: 0,
description: 'Origin Offset Y',
},
- 'style.translate': {
- type: 'translate',
- step: 1,
- default: '0px 0px',
- description: 'Position',
- },
- 'style.scale': {
- type: 'number',
- min: 0.05,
- max: 100,
- step: 0.01,
- default: 1,
- description: 'Scale',
- },
- 'style.rotate': {
- type: 'rotation',
- step: 1,
- default: '0deg',
- description: 'Rotation',
- },
- 'style.opacity': {
- type: 'number',
- min: 0,
- max: 1,
- step: 0.01,
- default: 1,
- description: 'Opacity',
- },
+ ...Internals.sequenceSchema,
} as const satisfies SequenceSchema;
const StarburstInner: React.FC<