🎥 Make videos programmatically with React
Fix VS Code TypeScript errors
Jonny Burger646d54cccf06
diff --git a/packages/cli/src/config/height.ts b/packages/cli/src/config/height.tsindex 696f83fab7..60156bd526 100644--- a/packages/cli/src/config/height.ts+++ b/packages/cli/src/config/height.ts@@ -1,13 +1,9 @@-import {Internals} from 'remotion';+import {validateDimension} from '../validate';let specifiedHeight: number | null;export const overrideHeight = (newHeight: number) => {- Internals.validateDimension(- newHeight,- 'height',- 'passed to `overrideHeight()`',- );+ validateDimension(newHeight, 'height', 'passed to `overrideHeight()`');specifiedHeight = newHeight;};diff --git a/packages/cli/src/config/width.ts b/packages/cli/src/config/width.tsindex 6126660652..603b1a4c4f 100644--- a/packages/cli/src/config/width.ts+++ b/packages/cli/src/config/width.ts@@ -1,10 +1,10 @@-import {Internals} from 'remotion';+import {validateDimension} from '../validate';let passedWidth: number | null = null;export const overrideWidth = (newWidth: number) => {if (typeof newWidth !== 'number') {- Internals.validateDimension(newWidth, 'width', 'passed to `setWidth()`');+ validateDimension(newWidth, 'width', 'passed to `setWidth()`');}passedWidth = newWidth;diff --git a/packages/cli/src/validate.ts b/packages/cli/src/validate.tsnew file mode 100644index 0000000000..b5ce4193c6--- /dev/null+++ b/packages/cli/src/validate.ts@@ -0,0 +1,5 @@+/* eslint-disable prefer-destructuring */+import {Internals} from 'remotion';++export const validateDimension: typeof Internals.validateDimension =+ Internals.validateDimension;diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.tsindex 3d3ecca02d..2e0ba79b35 100644--- a/packages/lambda/src/functions/launch.ts+++ b/packages/lambda/src/functions/launch.ts@@ -2,7 +2,6 @@ import {InvokeCommand} from '@aws-sdk/client-lambda';import {RenderInternals} from '@remotion/renderer';import fs, {existsSync, mkdirSync, rmSync} from 'node:fs';import {join} from 'node:path';-import {Internals} from 'remotion';import {VERSION} from 'remotion/version';import {getLambdaClient} from '../shared/aws-clients';import {@@ -33,6 +32,11 @@ import {} from '../shared/constants';import {DOCS_URL} from '../shared/docs-url';import {invokeWebhook} from '../shared/invoke-webhook';+import {+ validateDimension,+ validateDurationInFrames,+ validateFps,+} from '../shared/validate';import {validateFramesPerLambda} from '../shared/validate-frames-per-lambda';import {validateOutname} from '../shared/validate-outname';import {validatePrivacy} from '../shared/validate-privacy';@@ -155,17 +159,13 @@ const innerLaunchHandler = async (});RenderInternals.Log.info('Composition validated, resolved props', comp.props);- Internals.validateDurationInFrames(comp.durationInFrames, {+ validateDurationInFrames(comp.durationInFrames, {component: 'passed to a Lambda render',allowFloats: false,});- Internals.validateFps(comp.fps, 'passed to a Lambda render', false);- Internals.validateDimension(- comp.height,- 'height',- 'passed to a Lambda render',- );- Internals.validateDimension(comp.width, 'width', 'passed to a Lambda render');+ validateFps(comp.fps, 'passed to a Lambda render', false);+ validateDimension(comp.height, 'height', 'passed to a Lambda render');+ validateDimension(comp.width, 'width', 'passed to a Lambda render');RenderInternals.validateBitrate(params.audioBitrate, 'audioBitrate');RenderInternals.validateBitrate(params.videoBitrate, 'videoBitrate');diff --git a/packages/lambda/src/shared/validate.ts b/packages/lambda/src/shared/validate.tsnew file mode 100644index 0000000000..9ee4ad8d94--- /dev/null+++ b/packages/lambda/src/shared/validate.ts@@ -0,0 +1,8 @@+/* eslint-disable prefer-destructuring */+import {Internals} from 'remotion';++export const validateFps: typeof Internals.validateFps = Internals.validateFps;+export const validateDimension: typeof Internals.validateDimension =+ Internals.validateDimension;+export const validateDurationInFrames: typeof Internals.validateDurationInFrames =+ Internals.validateDurationInFrames;diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsxindex ae1aa539c1..f442fd04bc 100644--- a/packages/player/src/Player.tsx+++ b/packages/player/src/Player.tsx@@ -31,6 +31,12 @@ import type {PropsIfHasProps} from './utils/props-if-has-props.js';import {validateInOutFrames} from './utils/validate-in-out-frame.js';import {validateInitialFrame} from './utils/validate-initial-frame.js';import {validatePlaybackRate} from './utils/validate-playbackrate.js';+import {+ validateDefaultAndInputProps,+ validateDimension,+ validateDurationInFrames,+ validateFps,+} from './validate.js';export type ErrorFallback = (info: {error: Error}) => React.ReactNode;@@ -180,22 +186,22 @@ const PlayerFn = <Schema extends AnyZodObject, Props>();}- Internals.validateDimension(+ validateDimension(compositionHeight,'compositionHeight','of the <Player /> component',);- Internals.validateDimension(+ validateDimension(compositionWidth,'compositionWidth','of the <Player /> component',);- Internals.validateDurationInFrames(durationInFrames, {+ validateDurationInFrames(durationInFrames, {component: 'of the <Player/> component',allowFloats: false,});- Internals.validateFps(fps, 'as a prop of the <Player/> component', false);- Internals.validateDefaultAndInputProps(inputProps, 'inputProps', null);+ validateFps(fps, 'as a prop of the <Player/> component', false);+ validateDefaultAndInputProps(inputProps, 'inputProps', null);validateInOutFrames({durationInFrames,diff --git a/packages/player/src/validate.ts b/packages/player/src/validate.tsnew file mode 100644index 0000000000..81607a734e--- /dev/null+++ b/packages/player/src/validate.ts@@ -0,0 +1,10 @@+/* eslint-disable prefer-destructuring */+import {Internals} from 'remotion';++export const validateFps: typeof Internals.validateFps = Internals.validateFps;+export const validateDimension: typeof Internals.validateDimension =+ Internals.validateDimension;+export const validateDurationInFrames: typeof Internals.validateDurationInFrames =+ Internals.validateDurationInFrames;+export const validateDefaultAndInputProps: typeof Internals.validateDefaultAndInputProps =+ Internals.validateDefaultAndInputProps;diff --git a/packages/renderer/src/prespawn-ffmpeg.ts b/packages/renderer/src/prespawn-ffmpeg.tsindex fd39203e3f..bc365e7d51 100644--- a/packages/renderer/src/prespawn-ffmpeg.ts+++ b/packages/renderer/src/prespawn-ffmpeg.ts@@ -1,4 +1,3 @@-import {Internals} from 'remotion';import {callFf} from './call-ffmpeg';import type {Codec} from './codec';import {DEFAULT_CODEC} from './codec';@@ -17,6 +16,7 @@ import {validateSelectedPixelFormatAndCodecCombination,} from './pixel-format';import type {ProResProfile} from './prores-profile';+import {validateDimension, validateFps} from './validate';import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';type RunningStatus =@@ -52,22 +52,18 @@ type PreStitcherOptions = {};export const prespawnFfmpeg = (options: PreStitcherOptions) => {- Internals.validateDimension(+ validateDimension(options.height,'height','passed to `stitchFramesToVideo()`',);- Internals.validateDimension(+ validateDimension(options.width,'width','passed to `stitchFramesToVideo()`',);const codec = options.codec ?? DEFAULT_CODEC;- Internals.validateFps(- options.fps,- 'in `stitchFramesToVideo()`',- codec === 'gif',- );+ validateFps(options.fps, 'in `stitchFramesToVideo()`', codec === 'gif');validateEvenDimensionsWithCodec({width: options.width,height: options.height,diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.tsindex 471b4e7c44..5a979608c6 100644--- a/packages/renderer/src/render-frames.ts+++ b/packages/renderer/src/render-frames.ts@@ -51,6 +51,11 @@ import type {AnySourceMapConsumer} from './symbolicate-stacktrace';import {takeFrameAndCompose} from './take-frame-and-compose';import {truthy} from './truthy';import type {OnStartData, RenderFramesOutput} from './types';+import {+ validateDimension,+ validateDurationInFrames,+ validateFps,+} from './validate';import {validateScale} from './validate-scale';const MAX_RETRIES_PER_FRAME = 1;@@ -599,22 +604,22 @@ export const internalRenderFrames = ({serializedResolvedPropsWithCustomSchema,offthreadVideoCacheSizeInBytes,}: InternalRenderFramesOptions): Promise<RenderFramesOutput> => {- Internals.validateDimension(+ validateDimension(composition.height,'height','in the `config` object passed to `renderFrames()`',);- Internals.validateDimension(+ validateDimension(composition.width,'width','in the `config` object passed to `renderFrames()`',);- Internals.validateFps(+ validateFps(composition.fps,'in the `config` object of `renderFrames()`',false,);- Internals.validateDurationInFrames(composition.durationInFrames, {+ validateDurationInFrames(composition.durationInFrames, {component: 'in the `config` object passed to `renderFrames()`',allowFloats: false,});diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex c4cd7fdf09..7ed78310cf 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -55,6 +55,7 @@ import {validateSelectedCodecAndProResCombination} from './prores-profile';import {internalRenderFrames} from './render-frames';import {internalStitchFramesToVideo} from './stitch-frames-to-video';import type {OnStartData} from './types';+import {validateFps} from './validate';import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';import {validateEveryNthFrame} from './validate-every-nth-frame';import {validateFfmpegOverride} from './validate-ffmpeg-override';@@ -401,7 +402,8 @@ export const internalRenderMedia = ({ensureFramesInOrder(realFrameRange);const fps = composition.fps / everyNthFrame;- Internals.validateFps(fps, 'in "renderMedia()"', codec === 'gif');++ validateFps(fps, 'in "renderMedia()"', codec === 'gif');const createPrestitcherIfNecessary = () => {if (preEncodedFileLocation) {diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.tsindex e4da22b68e..18d93027f3 100644--- a/packages/renderer/src/render-still.ts+++ b/packages/renderer/src/render-still.ts@@ -37,6 +37,11 @@ import {seekToFrame} from './seek-to-frame';import {setPropsAndEnv} from './set-props-and-env';import type {AnySourceMapConsumer} from './symbolicate-stacktrace';import {takeFrameAndCompose} from './take-frame-and-compose';+import {+ validateDimension,+ validateDurationInFrames,+ validateFps,+} from './validate';import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';import {validateScale} from './validate-scale';@@ -136,22 +141,23 @@ const innerRenderStill = async ({compositor: Compositor;sourceMapContext: Promise<AnySourceMapConsumer | null>;}): Promise<RenderStillReturnValue> => {- Internals.validateDimension(+ validateDimension(composition.height,'height','in the `config` object passed to `renderStill()`',);- Internals.validateDimension(++ validateDimension(composition.width,'width','in the `config` object passed to `renderStill()`',);- Internals.validateFps(+ validateFps(composition.fps,'in the `config` object of `renderStill()`',false,);- Internals.validateDurationInFrames(composition.durationInFrames, {+ validateDurationInFrames(composition.durationInFrames, {component: 'in the `config` object passed to `renderStill()`',allowFloats: false,});diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 0f935feb42..9f42a486e0 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -41,6 +41,7 @@ import {preprocessAudioTrack} from './preprocess-audio-track';import type {ProResProfile} from './prores-profile';import {validateSelectedCodecAndProResCombination} from './prores-profile';import {truthy} from './truthy';+import {validateDimension, validateFps} from './validate';import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';import {validateBitrate} from './validate-videobitrate';import type {X264Preset} from './x264-preset';@@ -224,16 +225,8 @@ const innerStitchFramesToVideo = async (}: InternalStitchFramesToVideoOptions,remotionRoot: string,): Promise<ReturnType> => {- Internals.validateDimension(- height,- 'height',- 'passed to `stitchFramesToVideo()`',- );- Internals.validateDimension(- width,- 'width',- 'passed to `stitchFramesToVideo()`',- );+ validateDimension(height, 'height', 'passed to `stitchFramesToVideo()`');+ validateDimension(width, 'width', 'passed to `stitchFramesToVideo()`');validateEvenDimensionsWithCodec({width,height,@@ -248,7 +241,7 @@ const innerStitchFramesToVideo = async (validateBitrate(audioBitrate, 'audioBitrate');validateBitrate(videoBitrate, 'videoBitrate');- Internals.validateFps(fps, 'in `stitchFramesToVideo()`', false);+ validateFps(fps, 'in `stitchFramesToVideo()`', false);const encoderName = getCodecName(codec);const proResProfileName = getProResProfileName(codec, proResProfile);diff --git a/packages/renderer/src/validate.ts b/packages/renderer/src/validate.tsnew file mode 100644index 0000000000..9ee4ad8d94--- /dev/null+++ b/packages/renderer/src/validate.ts@@ -0,0 +1,8 @@+/* eslint-disable prefer-destructuring */+import {Internals} from 'remotion';++export const validateFps: typeof Internals.validateFps = Internals.validateFps;+export const validateDimension: typeof Internals.validateDimension =+ Internals.validateDimension;+export const validateDurationInFrames: typeof Internals.validateDurationInFrames =+ Internals.validateDurationInFrames;diff --git a/packages/three/src/ThreeCanvas.tsx b/packages/three/src/ThreeCanvas.tsxindex 5736ab145b..8b692fd039 100644--- a/packages/three/src/ThreeCanvas.tsx+++ b/packages/three/src/ThreeCanvas.tsx@@ -3,6 +3,7 @@ import {Canvas, useThree} from '@react-three/fiber';import React, {useCallback, useLayoutEffect, useState} from 'react';import {continueRender, delayRender, Internals} from 'remotion';import {SuspenseLoader} from './SuspenseLoader';+import {validateDimension} from './validate';export type ThreeCanvasProps = React.ComponentProps<typeof Canvas> & {width: number;@@ -31,16 +32,8 @@ export const ThreeCanvas = (props: ThreeCanvasProps) => {delayRender('Waiting for <ThreeCanvas/> to be created'),);- Internals.validateDimension(- width,- 'width',- 'of the <ThreeCanvas /> component',- );- Internals.validateDimension(- height,- 'height',- 'of the <ThreeCanvas /> component',- );+ validateDimension(width, 'width', 'of the <ThreeCanvas /> component');+ validateDimension(height, 'height', 'of the <ThreeCanvas /> component');const contexts = Internals.useRemotionContexts();const actualStyle = {width: props.width,diff --git a/packages/three/src/validate.ts b/packages/three/src/validate.tsnew file mode 100644index 0000000000..b5ce4193c6--- /dev/null+++ b/packages/three/src/validate.ts@@ -0,0 +1,5 @@+/* eslint-disable prefer-destructuring */+import {Internals} from 'remotion';++export const validateDimension: typeof Internals.validateDimension =+ Internals.validateDimension;