Skip to content

🎥 Make videos programmatically with React

optional width height

Jonny Burgerb4cabd7137cf
diff --git a/packages/cli/src/editor/components/CanvasOrLoading.tsx b/packages/cli/src/editor/components/CanvasOrLoading.tsx
index 88e751f5c1..26c956d304 100644
--- a/packages/cli/src/editor/components/CanvasOrLoading.tsx
+++ b/packages/cli/src/editor/components/CanvasOrLoading.tsx
@@ -1,4 +1,4 @@
-import React, {useEffect, useMemo, useState} from 'react';
+import React, {useContext, useEffect, useMemo, useState} from 'react';
import {Internals} from 'remotion';
import {ErrorLoader} from '../../preview-server/error-overlay/remotion-overlay/ErrorLoader';
import {BACKGROUND, LIGHT_TEXT} from '../helpers/colors';
@@ -6,6 +6,11 @@ import {Canvas} from './Canvas';
import {Spacing} from './layout';
import {inlineCodeSnippet} from './Menu/styles';
import {Spinner} from './Spinner';
+import {getFrameForComposition} from './FramePersistor';
+import {getZoomForComposition} from './ZoomPersistor';
+import {setCurrentFrame} from './Timeline/imperative-state';
+import {ensureFrameIsInViewport} from './Timeline/timeline-scroll-logic';
+import {TimelineZoomCtx} from '../state/timeline-zoom';
const container: React.CSSProperties = {
color: 'white',
@@ -20,6 +25,8 @@ const container: React.CSSProperties = {
export const CanvasOrLoading: React.FC = () => {
const resolved = Internals.useResolvedVideoConfig(null);
const [takesALongTime, setTakesALongTime] = useState(false);
+ const {setCurrentComposition} = useContext(Internals.CompositionManager);
+ const {setZoom} = useContext(TimelineZoomCtx);
useEffect(() => {
const timeout = setTimeout(() => {
@@ -30,6 +37,28 @@ export const CanvasOrLoading: React.FC = () => {
};
}, []);
+ useEffect(() => {
+ if (resolved?.type !== 'success') {
+ return;
+ }
+
+ const c = resolved.result;
+
+ const frame = getFrameForComposition(c.id);
+ const zoom = getZoomForComposition(c.id);
+ const frameInBounds = Math.min(c.durationInFrames - 1, frame);
+ setCurrentFrame(frameInBounds);
+ setCurrentComposition(c.id);
+ setZoom(() => zoom);
+ setTimeout(() => {
+ ensureFrameIsInViewport({
+ direction: 'center',
+ frame,
+ durationInFrames: c.durationInFrames,
+ });
+ });
+ }, [resolved, setCurrentComposition, setZoom]);
+
const style = useMemo(() => {
return {
...loaderLabel,
diff --git a/packages/cli/src/editor/components/InitialCompositionLoader.tsx b/packages/cli/src/editor/components/InitialCompositionLoader.tsx
index 1a7a66358c..fc85ec6255 100644
--- a/packages/cli/src/editor/components/InitialCompositionLoader.tsx
+++ b/packages/cli/src/editor/components/InitialCompositionLoader.tsx
@@ -5,41 +5,20 @@ import {Internals} from 'remotion';
import type {ExpandedFoldersState} from '../helpers/persist-open-folders';
import {FolderContext} from '../state/folders';
import {loadMarks} from '../state/marks';
-import {TimelineZoomCtx} from '../state/timeline-zoom';
import {getKeysToExpand} from './CompositionSelector';
-import {
- getCurrentCompositionFromUrl,
- getFrameForComposition,
-} from './FramePersistor';
-import {ensureFrameIsInViewport} from './Timeline/timeline-scroll-logic';
+import {getCurrentCompositionFromUrl} from './FramePersistor';
import {inOutHandles} from './TimelineInOutToggle';
-import {getZoomForComposition} from './ZoomPersistor';
export const useSelectComposition = () => {
- const setCurrentFrame = Internals.Timeline.useTimelineSetFrame();
- const {setCurrentComposition} = useContext(Internals.CompositionManager);
const {setFoldersExpanded} = useContext(FolderContext);
- const {setZoom} = useContext(TimelineZoomCtx);
return (c: AnyComposition, push: boolean) => {
inOutHandles.current?.setMarks(loadMarks(c.id, c.durationInFrames));
if (push) {
window.history.pushState({}, 'Studio', `/${c.id}`);
}
- const frame = getFrameForComposition(c.id);
- const zoom = getZoomForComposition(c.id);
- const frameInBounds = Math.min(c.durationInFrames - 1, frame);
- setCurrentFrame(frameInBounds);
- setCurrentComposition(c.id);
- setZoom(() => zoom);
- setTimeout(() => {
- ensureFrameIsInViewport({
- direction: 'center',
- frame,
- durationInFrames: c.durationInFrames,
- });
- });
const {folderName, parentFolderName} = c;
+
if (folderName !== null) {
setFoldersExpanded((ex) => {
const keysToExpand = getKeysToExpand(folderName, parentFolderName);
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
index 34dd010610..86b64bc199 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx
@@ -17,7 +17,7 @@ import React, {
useRef,
useState,
} from 'react';
-import type {AnyComposition, TCompMetadata} from 'remotion';
+import type {AnyComposition, VideoConfig} from 'remotion';
import {Internals} from 'remotion';
import {Button} from '../../../preview-server/error-overlay/remotion-overlay/Button';
import {ShortcutHint} from '../../../preview-server/error-overlay/remotion-overlay/ShortcutHint';
@@ -38,7 +38,6 @@ import {PicIcon} from '../../icons/frame';
import {GearIcon} from '../../icons/gear';
import {GifIcon} from '../../icons/gif';
-import type {AnyZodObject} from 'zod';
import {BLUE, BLUE_DISABLED, LIGHT_TEXT} from '../../helpers/colors';
import {ModalsContext} from '../../state/modals';
import {SidebarContext} from '../../state/sidebar';
@@ -223,7 +222,7 @@ type RenderModalProps = {
const RenderModal: React.FC<
Omit<RenderModalProps, 'compositionId'> & {
onClose: () => void;
- resolvedComposition: TCompMetadata<AnyZodObject, Record<string, unknown>>;
+ resolvedComposition: VideoConfig;
unresolvedComposition: AnyComposition;
}
> = ({
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalBasic.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalBasic.tsx
index 55d1967733..c7ce73f730 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalBasic.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalBasic.tsx
@@ -1,8 +1,6 @@
import type {Codec, ProResProfile} from '@remotion/renderer';
import {BrowserSafeApis} from '@remotion/renderer/client';
import React, {useCallback, useMemo} from 'react';
-import type {TCompMetadata} from 'remotion';
-import type {AnyZodObject} from 'zod';
import {labelProResProfile} from '../../helpers/prores-labels';
import {useFileExistence} from '../../helpers/use-file-existence';
import {Checkmark} from '../../icons/Checkmark';
@@ -20,6 +18,7 @@ import {input, label, optionRow, rightRow} from './layout';
import {OptionExplainer} from './OptionExplainer';
import type {RenderType} from './RenderModalAdvanced';
import {RenderModalInput} from './RenderModalInput';
+import type {VideoConfig} from 'remotion';
const container: React.CSSProperties = {
flex: 1,
@@ -35,7 +34,7 @@ export const RenderModalBasic: React.FC<{
setProResProfile: React.Dispatch<React.SetStateAction<ProResProfile>>;
frame: number;
setFrame: React.Dispatch<React.SetStateAction<number>>;
- resolvedComposition: TCompMetadata<AnyZodObject, Record<string, unknown>>;
+ resolvedComposition: VideoConfig;
setOutName: (value: React.SetStateAction<string>) => void;
setEndFrame: React.Dispatch<React.SetStateAction<number | null>>;
startFrame: number;
diff --git a/packages/cli/src/editor/components/SidebarRenderButton.tsx b/packages/cli/src/editor/components/SidebarRenderButton.tsx
index 78dfd00ef3..6d478a0d09 100644
--- a/packages/cli/src/editor/components/SidebarRenderButton.tsx
+++ b/packages/cli/src/editor/components/SidebarRenderButton.tsx
@@ -36,7 +36,11 @@ export const SidebarRenderButton: React.FC<{
const connectionStatus = useContext(StudioServerConnectionCtx).type;
const {props} = useContext(Internals.EditorPropsContext);
- const isVideo = composition.durationInFrames > 1;
+ const isVideo =
+ typeof composition.durationInFrames === 'undefined'
+ ? true
+ : composition.durationInFrames > 1;
+
const onClick: React.MouseEventHandler<HTMLAnchorElement> = useCallback(
(e) => {
const defaults = window.remotion_renderDefaults;
diff --git a/packages/cli/src/editor/helpers/is-composition-still.ts b/packages/cli/src/editor/helpers/is-composition-still.ts
index 92b6757b5f..c1d67530c8 100644
--- a/packages/cli/src/editor/helpers/is-composition-still.ts
+++ b/packages/cli/src/editor/helpers/is-composition-still.ts
@@ -1,4 +1,6 @@
-export const isCompositionStill = (comp: {durationInFrames: number} | null) => {
+export const isCompositionStill = (
+ comp: {durationInFrames: number | undefined} | null
+) => {
if (!comp) {
return false;
}
diff --git a/packages/cli/src/editor/helpers/is-current-selected-still.ts b/packages/cli/src/editor/helpers/is-current-selected-still.ts
index de3976dfbd..d872fc3f5f 100644
--- a/packages/cli/src/editor/helpers/is-current-selected-still.ts
+++ b/packages/cli/src/editor/helpers/is-current-selected-still.ts
@@ -1,4 +1,4 @@
-import {useContext, useMemo} from 'react';
+import {useMemo} from 'react';
import {Internals} from 'remotion';
import {isCompositionStill} from './is-composition-still';
@@ -13,23 +13,16 @@ export const useIsStill = () => {
};
export const useDimensions = () => {
- const {compositions, currentComposition} = useContext(
- Internals.CompositionManager
- );
-
- const selected = useMemo(
- () => compositions.find((c) => c.id === currentComposition),
- [compositions, currentComposition]
- );
+ const config = Internals.useUnsafeVideoConfig();
return useMemo(() => {
- if (!selected) {
+ if (!config) {
return null;
}
return {
- width: selected.width,
- height: selected.height,
+ width: config.width,
+ height: config.height,
};
- }, [selected]);
+ }, [config]);
};
diff --git a/packages/cli/src/editor/state/marks.ts b/packages/cli/src/editor/state/marks.ts
index 8252eb0712..eeacdce3d7 100644
--- a/packages/cli/src/editor/state/marks.ts
+++ b/packages/cli/src/editor/state/marks.ts
@@ -14,8 +14,12 @@ export const persistMarks = (
export const loadMarks = (
comp: string,
- durationInFrames: number
+ durationInFrames: number | undefined
): [number | null, number | null] => {
+ if (durationInFrames === undefined) {
+ return [null, null];
+ }
+
const item = localStorage.getItem(localStorageKey(comp, durationInFrames));
if (item === null) {
diff --git a/packages/cli/src/print-compositions.ts b/packages/cli/src/print-compositions.ts
index 3153a5fe8a..93637a09f3 100644
--- a/packages/cli/src/print-compositions.ts
+++ b/packages/cli/src/print-compositions.ts
@@ -1,6 +1,6 @@
-import type {AnyCompMetadata} from 'remotion';
import {Log} from './log';
import {quietFlagProvided} from './parse-command-line';
+import type {VideoConfig} from 'remotion';
const max = (arr: number[]) => {
if (arr.length === 0) {
@@ -18,7 +18,7 @@ const max = (arr: number[]) => {
return biggest;
};
-export const printCompositions = (compositions: AnyCompMetadata[]) => {
+export const printCompositions = (compositions: VideoConfig[]) => {
if (!quietFlagProvided()) {
Log.info();
Log.info('The following compositions are available:');
diff --git a/packages/compositor-darwin-arm64/compositor b/packages/compositor-darwin-arm64/compositor
index 1496de1c42..bf6f527c0a 100755
Binary files a/packages/compositor-darwin-arm64/compositor and b/packages/compositor-darwin-arm64/compositor differ
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsx
index 6da48a283c..b5951ae707 100644
--- a/packages/core/src/Composition.tsx
+++ b/packages/core/src/Composition.tsx
@@ -21,9 +21,6 @@ import {useLazyComponent} from './use-lazy-component.js';
import {useVideo} from './use-video.js';
import {validateCompositionId} from './validation/validate-composition-id.js';
import {validateDefaultAndInputProps} from './validation/validate-default-props.js';
-import {validateDimension} from './validation/validate-dimensions.js';
-import {validateDurationInFrames} from './validation/validate-duration-in-frames.js';
-import {validateFps} from './validation/validate-fps.js';
type LooseComponentType<T> = ComponentType<T> | ((props: T) => React.ReactNode);
@@ -50,25 +47,61 @@ export type CalculateMetadataFunction<T extends Record<string, unknown>> =
abortSignal: AbortSignal;
}) => Promise<CalcMetadataReturnType<T>> | CalcMetadataReturnType<T>;
-export type StillProps<
+type OptionalDimensions<
+ Schema extends AnyZodObject,
+ Props extends Record<string, unknown>
+> = {
+ width?: number;
+ height?: number;
+ calculateMetadata: CalculateMetadataFunction<InferProps<Schema, Props>>;
+};
+
+type MandatoryDimensions<
Schema extends AnyZodObject,
Props extends Record<string, unknown>
> = {
width: number;
height: number;
- id: string;
calculateMetadata?: CalculateMetadataFunction<InferProps<Schema, Props>>;
+};
+
+type StillCalculateMetadataOrExplicit<
+ Schema extends AnyZodObject,
+ Props extends Record<string, unknown>
+> = OptionalDimensions<Schema, Props> | MandatoryDimensions<Schema, Props>;
+
+type CompositionCalculateMetadataOrExplicit<
+ Schema extends AnyZodObject,
+ Props extends Record<string, unknown>
+> =
+ | (OptionalDimensions<Schema, Props> & {
+ fps?: number;
+ durationInFrames?: number;
+ })
+ | (MandatoryDimensions<Schema, Props> & {
+ fps: number;
+ durationInFrames: number;
+ });
+
+export type StillProps<
+ Schema extends AnyZodObject,
+ Props extends Record<string, unknown>
+> = {
+ id: string;
schema?: Schema;
-} & CompProps<Props> &
+} & StillCalculateMetadataOrExplicit<Schema, Props> &
+ CompProps<Props> &
PropsIfHasProps<Schema, Props>;
export type CompositionProps<
Schema extends AnyZodObject,
Props extends Record<string, unknown>
-> = StillProps<Schema, Props> & {
- fps: number;
- durationInFrames: number;
-};
+> = {
+ id: string;
+ schema?: Schema;
+} & CompositionCalculateMetadataOrExplicit<Schema, Props> &
+ CompProps<Props> &
+ PropsIfHasProps<Schema, Props>;
const Fallback: React.FC = () => {
useEffect(() => {
@@ -129,21 +162,12 @@ export const Composition = <
}
validateCompositionId(id);
- validateDimension(width, 'width', 'of the <Composition/> component');
- validateDimension(height, 'height', 'of the <Composition/> component');
- validateDurationInFrames({
- durationInFrames,
- component: 'of the <Composition/> component',
- allowFloats: false,
- });
-
- validateFps(fps, 'as a prop of the <Composition/> component', false);
validateDefaultAndInputProps(defaultProps, 'defaultProps', id);
registerComposition<Schema, Props>({
- durationInFrames,
- fps,
- height,
- width,
+ durationInFrames: durationInFrames ?? undefined,
+ fps: fps ?? undefined,
+ height: height ?? undefined,
+ width: width ?? undefined,
id,
folderName,
component: lazy,
diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsx
index 9b97082f59..3f85b4d5eb 100644
--- a/packages/core/src/CompositionManager.tsx
+++ b/packages/core/src/CompositionManager.tsx
@@ -24,10 +24,10 @@ export type TComposition<
Schema extends AnyZodObject,
Props extends Record<string, unknown>
> = {
- width: number;
- height: number;
- fps: number;
- durationInFrames: number;
+ width: number | undefined;
+ height: number | undefined;
+ fps: number | undefined;
+ durationInFrames: number | undefined;
id: string;
folderName: string | null;
parentFolderName: string | null;
diff --git a/packages/core/src/ResolveCompositionConfig.tsx b/packages/core/src/ResolveCompositionConfig.tsx
index 8f165bb32b..4a12a1faed 100644
--- a/packages/core/src/ResolveCompositionConfig.tsx
+++ b/packages/core/src/ResolveCompositionConfig.tsx
@@ -172,6 +172,7 @@ export const ResolveCompositionConfig: React.FC<
useEffect(() => {
if (selectedComposition && needsResolution(selectedComposition)) {
const controller = doResolution(selectedComposition, selectedEditorProps);
+
return () => {
controller.abort();
};
@@ -257,7 +258,11 @@ export const useResolvedVideoConfig = (
return {
type: 'success',
result: {
- ...composition,
+ width: composition.width as number,
+ height: composition.height as number,
+ fps: composition.fps as number,
+ id: composition.id,
+ durationInFrames: composition.durationInFrames as number,
defaultProps: composition.defaultProps ?? {},
props: {
...(composition.defaultProps ?? {}),
diff --git a/packages/core/src/loop/index.tsx b/packages/core/src/loop/index.tsx
index 0dc954db19..5587513a68 100644
--- a/packages/core/src/loop/index.tsx
+++ b/packages/core/src/loop/index.tsx
@@ -29,8 +29,7 @@ export const Loop: React.FC<LoopProps> = ({
const currentFrame = useCurrentFrame();
const {durationInFrames: compDuration} = useVideoConfig();
- validateDurationInFrames({
- durationInFrames,
+ validateDurationInFrames(durationInFrames, {
component: 'of the <Loop /> component',
allowFloats: true,
});
diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.ts
index 2259a3ca24..0a9b301611 100644
--- a/packages/core/src/resolve-video-config.ts
+++ b/packages/core/src/resolve-video-config.ts
@@ -6,6 +6,7 @@ import {getRemotionEnvironment} from './get-environment.js';
import {validateDimension} from './validation/validate-dimensions.js';
import {validateDurationInFrames} from './validation/validate-duration-in-frames.js';
import type {VideoConfig} from './video-config.js';
+import {validateFps} from './validation/validate-fps.js';
export const resolveVideoConfig = ({
composition,
@@ -88,52 +89,39 @@ const validateCalculated = ({
>;
calculated: CalcMetadataReturnType<Record<string, unknown>> | null;
}) => {
- const potentialErrorLocation = `calculated by calculateMetadata() for the composition "${composition.id}"`;
+ const calculateMetadataErrorLocation = `calculated by calculateMetadata() for the composition "${composition.id}"`;
+ const defaultErrorLocation = `of the "<Composition />" component with the id "${composition.id}"`;
- const width = calculated?.width ?? composition.width ?? null;
- if (!width) {
- throw new TypeError(
- 'Composition width was neither specified via the `width` prop nor the `calculateMetadata()` function.'
- );
- }
+ const width = calculated?.width ?? composition.width ?? undefined;
- validateDimension(width, 'width', potentialErrorLocation);
+ validateDimension(
+ width,
+ 'width',
+ calculated?.width ? calculateMetadataErrorLocation : defaultErrorLocation
+ );
- const height = calculated?.height ?? composition.height ?? null;
- if (!height) {
- throw new TypeError(
- 'Composition height was neither specified via the `height` prop nor the `calculateMetadata()` function.'
- );
- }
+ const height = calculated?.height ?? composition.height ?? undefined;
- validateDimension(width, 'height', potentialErrorLocation);
+ validateDimension(
+ height,
+ 'height',
+ calculated?.height ? calculateMetadataErrorLocation : defaultErrorLocation
+ );
const fps = calculated?.fps ?? composition.fps ?? null;
- if (!fps) {
- throw new TypeError(
- 'Composition fps was neither specified via the `fps` prop nor the `calculateMetadata()` function.'
- );
- }
+
+ validateFps(
+ fps,
+ calculated?.fps ? calculateMetadataErrorLocation : defaultErrorLocation,
+ false
+ );
const durationInFrames =
calculated?.durationInFrames ?? composition.durationInFrames ?? null;
- if (durationInFrames <= 0) {
- throw new TypeError(
- 'Composition durationInFrames cannot be less than or equal to 0. Got ' +
- durationInFrames
- );
- }
-
- if (!durationInFrames) {
- throw new TypeError(
- 'Composition durationInFrames was neither specified via the `durationInFrames` prop nor the `calculateMetadata()` function.'
- );
- }
- validateDurationInFrames({
- durationInFrames,
- component: potentialErrorLocation,
+ validateDurationInFrames(durationInFrames, {
allowFloats: false,
+ component: `of the "<Composition />" component with the id "${composition.id}"`,
});
return {width, height, fps, durationInFrames};
diff --git a/packages/core/src/series/index.tsx b/packages/core/src/series/index.tsx
index beb75f5957..46c8bb949b 100644
--- a/packages/core/src/series/index.tsx
+++ b/packages/core/src/series/index.tsx
@@ -82,8 +82,7 @@ const Series: FC<{
i !== flattenedChildren.length - 1 ||
durationInFramesProp !== Infinity
) {
- validateDurationInFrames({
- durationInFrames: durationInFramesProp,
+ validateDurationInFrames(durationInFramesProp, {
component: `of a <Series.Sequence /> component`,
allowFloats: true,
});
diff --git a/packages/core/src/test/composition-validation.test.tsx b/packages/core/src/test/composition-validation.test.tsx
index 9fc28d1545..97be233d4b 100644
--- a/packages/core/src/test/composition-validation.test.tsx
+++ b/packages/core/src/test/composition-validation.test.tsx
@@ -5,8 +5,8 @@ import {render} from '@testing-library/react';
import React from 'react';
import {describe, expect, test} from 'vitest';
import {Composition} from '../Composition.js';
-import {RemotionRoot} from '../RemotionRoot.js';
import {expectToThrow} from './expect-to-throw.js';
+import {resolveVideoConfig} from '../resolve-video-config.js';
const AnyComp: React.FC = () => null;
@@ -14,94 +14,99 @@ describe('Composition-validation render should throw with invalid props', () =>
test('It should throw if multiple components have the same id', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- {/**
- // @ts-expect-error */}
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={30}
- height={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "width/
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 30,
+ height: 100,
+ id: 'id',
+ width: undefined,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+
+ /The "width" prop of the "<Composition \/>" component with the id "id" must be a number, but you passed a value of type undefined/
);
});
describe('Throw with invalid height props', () => {
test('It should throw if height is a negative number', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={30}
- height={-100}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "height" prop of the <Composition\/> component must be positive, but got -100./
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 30,
+ height: -100,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+
+ /The "height" prop of the "<Composition \/>" component with the id "id" must be positive, but got -100./
);
});
test('It should throw if height=0 is boundary off-point', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={30}
- height={0}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "height" prop of the <Composition\/> component must be positive, but got 0./
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 30,
+ height: 0,
+ id: 'id',
+ width: 100,
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "height" prop of the "<Composition \/>" component with the id "id" must be positive, but got 0./
);
});
test('It should throw if height is not a number', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={30}
- // @ts-expect-error
- height={'100'}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "height" prop of the <Composition\/> component must be a number, but you passed a value of type string/
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 30,
+ // @ts-expect-error
+ height: '100',
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "height" prop of the "<Composition \/>" component with the id "id" must be a number, but you passed a value of type string/
);
});
test('It should throw if height is not an integer', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={30}
- height={100.01}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "height" prop of the <Composition\/> component must be an integer, but is 100.01/
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 30,
+ height: 100.01,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "height" prop of the "<Composition \/>" component with the id "id" must be an integer, but is 100.01./
);
});
});
@@ -109,56 +114,59 @@ describe('Composition-validation render should throw with invalid props', () =>
test('It should throw if width is a negative number', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={30}
- height={100}
- width={-100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "width" prop of the <Composition\/> component must be positive, but got -100./
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 30,
+ height: 100,
+ id: 'id',
+ width: -100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "width" prop of the "<Composition \/>" component with the id "id" must be positive, but got -100./
);
});
test('It should throw if width=0 is boundary off-point', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={30}
- height={100}
- width={0}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "width" prop of the <Composition\/> component must be positive, but got 0./
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 30,
+ height: 100,
+ id: 'id',
+ width: 0,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "width" prop of the "<Composition \/>" component with the id "id" must be positive, but got 0./
);
});
test('It should throw if width is not a number', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={30}
- height={100}
- // @ts-expect-error
- width={'100'}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "width" prop of the <Composition\/> component must be a number, but you passed a value of type string/
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 30,
+ height: 100,
+ id: 'id',
+ // @ts-expect-error
+ width: '100',
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "width" prop of the "<Composition \/>" component with the id "id" must be a number, but you passed a value of type string/
);
});
});
@@ -166,74 +174,78 @@ describe('Composition-validation render should throw with invalid props', () =>
test('It should throw if durationInFrames of a composition is a negative number', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={-100}
- fps={30}
- height={100}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "durationInFrames" prop of the <Composition\/> component must be positive, but got -100./
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: -100,
+ calculateMetadata: null,
+ fps: 30,
+ height: 100,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "durationInFrames" prop of the "<Composition \/>" component with the id "id" must be positive, but got -100./
);
});
test('It should throw if durationInFrames=0 of a composition is boundary off-point', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={0}
- fps={30}
- height={100}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "durationInFrames" prop of the <Composition\/> component must be positive, but got 0./
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 0,
+ calculateMetadata: null,
+ fps: 30,
+ height: 100,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "durationInFrames" prop of the "<Composition \/>" component with the id "id" must be positive, but got 0./
);
});
test('It should throw if durationInFrames of a composition is not an integer', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={0.11}
- fps={30}
- height={100}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "durationInFrames" prop of the <Composition\/> component must be an integer, but got 0.11./
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 0.11,
+ calculateMetadata: null,
+ fps: 30,
+ height: 100,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "durationInFrames" prop of the "<Composition \/>" component with the id "id" must be an integer, but got 0.11./
);
});
test('It should throw if durationInFrames of a composition is not a number', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- // @ts-expect-error
- durationInFrames={'100'}
- fps={30}
- height={100}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
- /The "durationInFrames" prop of the <Composition\/> component must be a number, but you passed a value of type string/
+ resolveVideoConfig({
+ composition: {
+ // @ts-expect-error
+ durationInFrames: '100',
+ calculateMetadata: null,
+ fps: 30,
+ height: 100,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
+ /The "durationInFrames" prop of the "<Composition \/>" component with the id "id" must be a number, but you passed a value of type string/
);
});
});
@@ -241,36 +253,38 @@ describe('Composition-validation render should throw with invalid props', () =>
test('It should throw if fps is of a composition is negative', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={-30}
- height={100}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: -30,
+ height: 100,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
/"fps" must be positive, but got -30./
);
});
test('It should throw if fps=0 of a composition is boundary off-point', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- fps={0}
- height={100}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ fps: 0,
+ height: 100,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
/"fps" must be positive, but got 0./
);
});
@@ -278,19 +292,20 @@ describe('Composition-validation render should throw with invalid props', () =>
test('It should throw if fps of a composition is not a number', () => {
expectToThrow(
() =>
- render(
- <RemotionRoot numberOfAudioTags={0}>
- <Composition
- lazyComponent={() => Promise.resolve({default: AnyComp})}
- durationInFrames={100}
- // @ts-expect-error
- fps={'30'}
- height={100}
- width={100}
- id="id"
- />
- </RemotionRoot>
- ),
+ resolveVideoConfig({
+ composition: {
+ durationInFrames: 100,
+ calculateMetadata: null,
+ // @ts-expect-error
+ fps: '30',
+ height: 100,
+ id: 'id',
+ width: 100,
+ defaultProps: {},
+ },
+ editorProps: {},
+ signal: new AbortController().signal,
+ }),
/"fps" must be a number, but you passed a value of type string/
);
});
diff --git a/packages/core/src/test/series.test.tsx b/packages/core/src/test/series.test.tsx
index 823104209d..b7a1ae3828 100644
--- a/packages/core/src/test/series.test.tsx
+++ b/packages/core/src/test/series.test.tsx
@@ -183,7 +183,7 @@ test('Should throw if invalid or no duration provided', () => {
</Series>
);
}).toThrow(
- /The "durationInFrames" prop of a <Series.Sequence \/> component must be a number, but you passed a value of type undefined/
+ /The "durationInFrames" prop of a <Series.Sequence \/> component is missing./
);
});
test('Should allow whitespace', () => {
diff --git a/packages/core/src/validation/validate-dimensions.ts b/packages/core/src/validation/validate-dimensions.ts
index a81ccf932d..0127074e55 100644
--- a/packages/core/src/validation/validate-dimensions.ts
+++ b/packages/core/src/validation/validate-dimensions.ts
@@ -1,8 +1,8 @@
-export const validateDimension = (
- amount: number,
+export function validateDimension(
+ amount: unknown,
nameOfProp: string,
location: string
-) => {
+): asserts amount is number {
if (typeof amount !== 'number') {
throw new Error(
`The "${nameOfProp}" prop ${location} must be a number, but you passed a value of type ${typeof amount}`
@@ -32,4 +32,4 @@ export const validateDimension = (
`The "${nameOfProp}" prop ${location} must be positive, but got ${amount}.`
);
}
-};
+}
diff --git a/packages/core/src/validation/validate-duration-in-frames.ts b/packages/core/src/validation/validate-duration-in-frames.ts
index 4681df4e66..5d753d7d22 100644
--- a/packages/core/src/validation/validate-duration-in-frames.ts
+++ b/packages/core/src/validation/validate-duration-in-frames.ts
@@ -1,12 +1,15 @@
-export const validateDurationInFrames = ({
- allowFloats,
- component,
- durationInFrames,
-}: {
- durationInFrames: number;
- component: string;
- allowFloats: boolean;
-}) => {
+export function validateDurationInFrames(
+ durationInFrames: unknown,
+ options: {
+ component: string;
+ allowFloats: boolean;
+ }
+): asserts durationInFrames is number {
+ const {allowFloats, component} = options;
+ if (typeof durationInFrames === 'undefined') {
+ throw new Error(`The "durationInFrames" prop ${component} is missing.`);
+ }
+
if (typeof durationInFrames !== 'number') {
throw new Error(
`The "durationInFrames" prop ${component} must be a number, but you passed a value of type ${typeof durationInFrames}`
@@ -30,4 +33,4 @@ export const validateDurationInFrames = ({
`The "durationInFrames" prop ${component} must be finite, but got ${durationInFrames}.`
);
}
-};
+}
diff --git a/packages/core/src/validation/validate-fps.ts b/packages/core/src/validation/validate-fps.ts
index fa42e4e373..62ff13b4ee 100644
--- a/packages/core/src/validation/validate-fps.ts
+++ b/packages/core/src/validation/validate-fps.ts
@@ -1,4 +1,8 @@
-export const validateFps = (fps: number, location: string, isGif: boolean) => {
+export function validateFps(
+ fps: unknown,
+ location: string,
+ isGif: boolean
+): asserts fps is number {
if (typeof fps !== 'number') {
throw new Error(
`"fps" must be a number, but you passed a value of type ${typeof fps} ${location}`
@@ -24,4 +28,4 @@ export const validateFps = (fps: number, location: string, isGif: boolean) => {
`The FPS for a GIF cannot be higher than 50. Use the --every-nth-frame option to lower the FPS: https://remotion.dev/docs/render-as-gif`
);
}
-};
+}
diff --git a/packages/lambda/src/api/get-compositions-on-lambda.ts b/packages/lambda/src/api/get-compositions-on-lambda.ts
index f2a2162417..ec2b237180 100644
--- a/packages/lambda/src/api/get-compositions-on-lambda.ts
+++ b/packages/lambda/src/api/get-compositions-on-lambda.ts
@@ -1,5 +1,5 @@
import type {ChromiumOptions, LogLevel} from '@remotion/renderer';
-import type {AnyCompMetadata} from 'remotion';
+import type {VideoConfig} from 'remotion';
import {VERSION} from 'remotion/version';
import type {AwsRegion} from '../client';
import {LambdaRoutines} from '../defaults';
@@ -26,7 +26,7 @@ export type GetCompositionsOnLambdaInput = {
dumpBrowserLogs?: boolean;
};
-export type GetCompositionsOnLambdaOutput = AnyCompMetadata[];
+export type GetCompositionsOnLambdaOutput = VideoConfig[];
/**
* @description Returns the compositions from a serveUrl
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index f864562e96..79221e18af 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -188,8 +188,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
logLevel: params.logLevel,
server: undefined,
});
- Internals.validateDurationInFrames({
- durationInFrames: comp.durationInFrames,
+ Internals.validateDurationInFrames(comp.durationInFrames, {
component: 'passed to a Lambda render',
allowFloats: false,
});
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index be7f7136da..81fa4969b5 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -9,7 +9,7 @@ import type {
StillImageFormat,
VideoImageFormat,
} from '@remotion/renderer';
-import type {AnyCompMetadata} from 'remotion';
+import type {VideoConfig} from 'remotion';
import type {ChunkRetry} from '../functions/helpers/get-retry-stats';
import type {EnhancedErrorInfo} from '../functions/helpers/write-lambda-error';
import type {AwsRegion} from '../pricing/aws-regions';
@@ -402,7 +402,7 @@ type Discriminated =
export type RenderMetadata = Discriminated & {
siteId: string;
- videoConfig: AnyCompMetadata;
+ videoConfig: VideoConfig;
startedDate: number;
totalChunks: number;
estimatedTotalLambdaInvokations: number;
diff --git a/packages/lambda/src/test/unit/expected-out-name.test.ts b/packages/lambda/src/test/unit/expected-out-name.test.ts
index b1f220124f..f13ea54e45 100644
--- a/packages/lambda/src/test/unit/expected-out-name.test.ts
+++ b/packages/lambda/src/test/unit/expected-out-name.test.ts
@@ -31,6 +31,7 @@ const testRenderMetadata: RenderMetadata = {
height: 1080,
id: 'react-svg',
width: 1080,
+ props: {},
},
privacy: 'public',
everyNthFrame: 1,
diff --git a/packages/lambda/src/test/unit/price-calculation.test.ts b/packages/lambda/src/test/unit/price-calculation.test.ts
index 963643a162..527d29032e 100644
--- a/packages/lambda/src/test/unit/price-calculation.test.ts
+++ b/packages/lambda/src/test/unit/price-calculation.test.ts
@@ -41,6 +41,7 @@ test('Should not throw while calculating prices when time shifts occur', () => {
id: 'react-svg',
width: 1080,
defaultProps: {},
+ props: {},
},
outName: 'out.mp4',
privacy: 'public',
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index d1be66a4e8..198a3de8e7 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -188,8 +188,7 @@ const PlayerFn = <Schema extends AnyZodObject, Props>(
'compositionWidth',
'of the <Player /> component'
);
- Internals.validateDurationInFrames({
- durationInFrames,
+ Internals.validateDurationInFrames(durationInFrames, {
component: 'of the <Player/> component',
allowFloats: false,
});
diff --git a/packages/renderer/rust/frame_cache.rs b/packages/renderer/rust/frame_cache.rs
index b34aefed51..3122fe6f73 100644
--- a/packages/renderer/rust/frame_cache.rs
+++ b/packages/renderer/rust/frame_cache.rs
@@ -2,10 +2,7 @@ extern crate ffmpeg_next as remotionffmpeg;
use std::sync::atomic::{AtomicUsize, Ordering};
-use crate::{
- errors::ErrorWithBacktrace, global_printer::_print_debug, opened_stream::get_time,
- scalable_frame::ScalableFrame,
-};
+use crate::{errors::ErrorWithBacktrace, opened_stream::get_time, scalable_frame::ScalableFrame};
pub fn get_frame_cache_id() -> usize {
static COUNTER: AtomicUsize = AtomicUsize::new(1);
diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.ts
index e6182fb986..fd00778153 100644
--- a/packages/renderer/src/render-frames.ts
+++ b/packages/renderer/src/render-frames.ts
@@ -586,8 +586,7 @@ export const internalRenderFrames = ({
'in the `config` object of `renderFrames()`',
false
);
- Internals.validateDurationInFrames({
- durationInFrames: composition.durationInFrames,
+ Internals.validateDurationInFrames(composition.durationInFrames, {
component: 'in the `config` object passed to `renderFrames()`',
allowFloats: false,
});
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index 83bf81e3e7..30cffd0c83 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -145,8 +145,7 @@ const innerRenderStill = async ({
'in the `config` object of `renderStill()`',
false
);
- Internals.validateDurationInFrames({
- durationInFrames: composition.durationInFrames,
+ Internals.validateDurationInFrames(composition.durationInFrames, {
component: 'in the `config` object passed to `renderStill()`',
allowFloats: false,
});