Skip to content

🎥 Make videos programmatically with React

yeah

Jonny Burgerc1f1d0f8fadf
diff --git a/packages/docs/docs/lambda/cli/render.mdx b/packages/docs/docs/lambda/cli/render.mdx
index 71c859ca10..880f1ebe5b 100644
--- a/packages/docs/docs/lambda/cli/render.mdx
+++ b/packages/docs/docs/lambda/cli/render.mdx
@@ -115,7 +115,7 @@ Minimum value: <MinimumFramesPerLambda />
The `framesPerLambda` parameter cannot result in more than 200 functions being spawned. See: [Concurrency](/docs/lambda/concurrency)
:::
-### `--concurrency`
+### `--concurrency`<AvailableFrom v="4.0.322" />
Specify the number of Lambda functions to use for rendering. This is an alternative to `--frames-per-lambda` that allows you to set the concurrency directly without needing to know the video duration.
diff --git a/packages/docs/docs/lambda/rendermediaonlambda.mdx b/packages/docs/docs/lambda/rendermediaonlambda.mdx
index 48cf679bd4..26fbc72e7f 100644
--- a/packages/docs/docs/lambda/rendermediaonlambda.mdx
+++ b/packages/docs/docs/lambda/rendermediaonlambda.mdx
@@ -67,7 +67,7 @@ Minimum value: <MinimumFramesPerLambda />
The `framesPerLambda` parameter cannot result in more than 200 functions being spawned. See: [Concurrency](/docs/lambda/concurrency)
:::
-### `concurrency?`
+### `concurrency?`<AvailableFrom v="4.0.322" />
_optional_
diff --git a/packages/example/runlambda.sh b/packages/example/runlambda.sh
index 815fbb2b99..5a7ddc5825 100644
--- a/packages/example/runlambda.sh
+++ b/packages/example/runlambda.sh
@@ -8,4 +8,4 @@ cd example
bunx remotion lambda functions rmall -f
bunx remotion lambda functions deploy --memory=3000 --disk=10000
bunx remotion lambda sites create --site-name=testbed-v6 --log=verbose --enable-folder-expiry
-bunx remotion lambda render testbed-v6 OffthreadRemoteVideo --log=verbose --delete-after="1-day" --api-key=rm_pub_9a996d341238eaa34e696b099968d8510420b9f6ba4aa0ee
+bunx remotion lambda render testbed-v6 OffthreadRemoteVideo --log=verbose --delete-after="1-day" --api-key=rm_pub_9a996d341238eaa34e696b099968d8510420b9f6ba4aa0ee --frames-per-lambda=20
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index df006dd18d..4adeb06fc0 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -4,7 +4,6 @@ import type {ChromiumOptions, LogLevel} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
import {BrowserSafeApis} from '@remotion/renderer/client';
import path from 'path';
-import type {VideoConfig} from 'remotion';
import {NoReactInternals} from 'remotion/no-react';
import {internalDownloadMedia} from '../../../api/download-media';
@@ -19,12 +18,7 @@ import {
DEFAULT_OUTPUT_PRIVACY,
} from '@remotion/lambda-client/constants';
import type {EnhancedErrorInfo, ProviderSpecifics} from '@remotion/serverless';
-import {
- validateConcurrency,
- validateFramesPerFunction,
- validatePrivacy,
- type ServerlessCodec,
-} from '@remotion/serverless';
+import {validatePrivacy, type ServerlessCodec} from '@remotion/serverless';
import {sleep} from '../../../shared/sleep';
import {validateMaxRetries} from '../../../shared/validate-retries';
import {parsedLambdaCli} from '../../args';
@@ -192,7 +186,6 @@ export const renderCommand = async ({
};
let composition: string = args[1];
- let compositionConfig: VideoConfig | null = null;
if (!composition) {
Log.info(
@@ -222,7 +215,7 @@ export const renderCommand = async ({
const indent = false;
- const {compositionId, config} =
+ const {compositionId} =
await CliInternals.getCompositionWithDimensionOverride({
args: args.slice(1),
compositionIdFromUi: null,
@@ -255,12 +248,6 @@ export const renderCommand = async ({
chromeMode: 'headless-shell',
});
composition = compositionId;
- compositionConfig = config;
- } else {
- // If composition is provided, we still need to get the config for validation
- // This is a simplified approach - in a real implementation, you might want to
- // fetch the composition config here as well
- compositionConfig = null;
}
const outName = parsedLambdaCli['out-name'];
@@ -294,19 +281,7 @@ export const renderCommand = async ({
validatePrivacy(privacy, true);
const framesPerLambda = parsedLambdaCli['frames-per-lambda'] ?? undefined;
const concurrency = parsedLambdaCli['concurrency'] ?? undefined;
-
- // Use actual durationInFrames if available, otherwise fallback to 1
- const durationInFrames = compositionConfig?.durationInFrames ?? 1;
-
- validateFramesPerFunction({
- framesPerFunction: framesPerLambda,
- durationInFrames,
- });
- validateConcurrency({
- concurrency: concurrency,
- framesPerFunction: framesPerLambda,
- durationInFrames,
- });
+ const concurrencyPerLambda = parsedLambdaCli['concurrency-per-lambda'] ?? 1;
const webhookCustomData = getWebhookCustomData(logLevel);
@@ -335,7 +310,7 @@ export const renderCommand = async ({
scale,
numberOfGifLoops,
everyNthFrame,
- concurrencyPerLambda: parsedLambdaCli['concurrency-per-lambda'] ?? 1,
+ concurrencyPerLambda,
muted,
overwrite,
audioBitrate,
diff --git a/packages/serverless/src/best-frames-per-function-param.ts b/packages/serverless-client/src/best-frames-per-function-param.ts
similarity index 92%
rename from packages/serverless/src/best-frames-per-function-param.ts
rename to packages/serverless-client/src/best-frames-per-function-param.ts
index f50c6479f9..8f1924ed7d 100644
--- a/packages/serverless/src/best-frames-per-function-param.ts
+++ b/packages/serverless-client/src/best-frames-per-function-param.ts
@@ -1,7 +1,7 @@
-import {interpolate} from '@remotion/serverless-client';
-
// Always update the code in docs/lambda/concurrency.md too
+import {interpolate} from 'remotion/no-react';
+
export const bestFramesPerFunctionParam = (frameCount: number) => {
// Between 0 and 10 minutes (at 30fps), interpolate the concurrency from 75 to 150
const concurrency = interpolate(frameCount, [0, 18000], [75, 150], {
diff --git a/packages/serverless-client/src/index.ts b/packages/serverless-client/src/index.ts
index ffdb84b494..b3804448f5 100644
--- a/packages/serverless-client/src/index.ts
+++ b/packages/serverless-client/src/index.ts
@@ -33,10 +33,6 @@ export {
SerializedArtifact,
} from './serialize-artifact';
-export {
- shouldIgnoreConcurrency,
- validateConcurrency,
-} from './validate-concurrency';
export {validateDownloadBehavior} from './validate-download-behavior';
export {validateFramesPerFunction} from './validate-frames-per-function';
diff --git a/packages/serverless/src/test/best-frames-per-function.test.ts b/packages/serverless-client/src/test/best-frames.test.ts
similarity index 100%
rename from packages/serverless/src/test/best-frames-per-function.test.ts
rename to packages/serverless-client/src/test/best-frames.test.ts
diff --git a/packages/serverless-client/src/test/concurrency-integration.test.ts b/packages/serverless-client/src/test/concurrency-integration.test.ts
deleted file mode 100644
index 87ab7b6c66..0000000000
--- a/packages/serverless-client/src/test/concurrency-integration.test.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-import {expect, test} from 'bun:test';
-import {shouldIgnoreConcurrency} from '../validate-concurrency';
-
-test('concurrency should be ignored when it would result in framesPerLambda < 4', () => {
- // Test cases where concurrency should be ignored
- const testCases = [
- {concurrency: 50, durationInFrames: 10, expected: true}, // 10/50 = 0.2, ceil = 1 < 4
- {concurrency: 100, durationInFrames: 10, expected: true}, // 10/100 = 0.1, ceil = 1 < 4
- {concurrency: 10, durationInFrames: 10, expected: true}, // 10/10 = 1, ceil = 1 < 4
- {concurrency: 5, durationInFrames: 10, expected: true}, // 10/5 = 2, ceil = 2 < 4
- {concurrency: 4, durationInFrames: 10, expected: true}, // 10/4 = 2.5, ceil = 3 < 4
- ];
-
- testCases.forEach(({concurrency, durationInFrames, expected}) => {
- const result = shouldIgnoreConcurrency({concurrency, durationInFrames});
- expect(result).toBe(expected);
- });
-});
-
-test('concurrency should not be ignored when it would result in framesPerLambda >= 4', () => {
- // Test cases where concurrency should NOT be ignored
- const testCases = [
- {concurrency: 10, durationInFrames: 100, expected: false}, // 100/10 = 10 >= 4
- {concurrency: 25, durationInFrames: 100, expected: false}, // 100/25 = 4 >= 4
- {concurrency: 50, durationInFrames: 200, expected: false}, // 200/50 = 4 >= 4
- {concurrency: 1, durationInFrames: 4, expected: false}, // 4/1 = 4 >= 4
- ];
-
- testCases.forEach(({concurrency, durationInFrames, expected}) => {
- const result = shouldIgnoreConcurrency({concurrency, durationInFrames});
- expect(result).toBe(expected);
- });
-});
-
-test('edge cases for concurrency ignoring', () => {
- // When durationInFrames is less than 4, the effective minimum is durationInFrames
- expect(shouldIgnoreConcurrency({concurrency: 1, durationInFrames: 3})).toBe(
- false,
- ); // 3/1 = 3 >= 3
- expect(shouldIgnoreConcurrency({concurrency: 2, durationInFrames: 3})).toBe(
- true,
- ); // 3/2 = 1.5, ceil = 2 < 3
-
- // When durationInFrames is exactly 4
- expect(shouldIgnoreConcurrency({concurrency: 1, durationInFrames: 4})).toBe(
- false,
- ); // 4/1 = 4 >= 4
- expect(shouldIgnoreConcurrency({concurrency: 2, durationInFrames: 4})).toBe(
- true,
- ); // 4/2 = 2 < 4
-});
diff --git a/packages/serverless-client/src/test/validate-concurrency.test.ts b/packages/serverless-client/src/test/validate-concurrency.test.ts
deleted file mode 100644
index 81f8663651..0000000000
--- a/packages/serverless-client/src/test/validate-concurrency.test.ts
+++ /dev/null
@@ -1,157 +0,0 @@
-import {expect, test} from 'bun:test';
-import {
- shouldIgnoreConcurrency,
- validateConcurrency,
-} from '../validate-concurrency';
-
-test('should pass validation for valid concurrency values', () => {
- expect(() => {
- validateConcurrency({
- concurrency: 100,
- framesPerFunction: null,
- durationInFrames: 1000,
- });
- }).not.toThrow();
-});
-
-test('should pass validation when concurrency is not provided', () => {
- expect(() => {
- validateConcurrency({
- concurrency: null,
- framesPerFunction: 20,
- durationInFrames: 1000,
- });
- }).not.toThrow();
-});
-
-test('should throw error when both concurrency and framesPerFunction are provided', () => {
- expect(() => {
- validateConcurrency({
- concurrency: 100,
- framesPerFunction: 20,
- durationInFrames: 1000,
- });
- }).toThrow("Cannot specify both 'concurrency' and 'framesPerLambda'");
-});
-
-test('should throw error when concurrency is not a number', () => {
- expect(() => {
- validateConcurrency({
- concurrency: '100' as any,
- framesPerFunction: null,
- durationInFrames: 1000,
- });
- }).toThrow("'concurrency' needs to be a number");
-});
-
-test('should throw error when concurrency is not finite', () => {
- expect(() => {
- validateConcurrency({
- concurrency: Infinity,
- framesPerFunction: null,
- durationInFrames: 1000,
- });
- }).toThrow("'concurrency' needs to be finite");
-});
-
-test('should throw error when concurrency is NaN', () => {
- expect(() => {
- validateConcurrency({
- concurrency: NaN,
- framesPerFunction: null,
- durationInFrames: 1000,
- });
- }).toThrow("'concurrency' needs to be finite");
-});
-
-test('should throw error when concurrency is not an integer', () => {
- expect(() => {
- validateConcurrency({
- concurrency: 100.5,
- framesPerFunction: null,
- durationInFrames: 1000,
- });
- }).toThrow("'concurrency' needs to be an integer");
-});
-
-test('should throw error when concurrency is zero', () => {
- expect(() => {
- validateConcurrency({
- concurrency: 0,
- framesPerFunction: null,
- durationInFrames: 1000,
- });
- }).toThrow("'concurrency' needs to be positive");
-});
-
-test('should throw error when concurrency is negative', () => {
- expect(() => {
- validateConcurrency({
- concurrency: -10,
- framesPerFunction: null,
- durationInFrames: 1000,
- });
- }).toThrow("'concurrency' needs to be positive");
-});
-
-test('should throw error when concurrency exceeds maximum', () => {
- expect(() => {
- validateConcurrency({
- concurrency: 201,
- framesPerFunction: null,
- durationInFrames: 1000,
- });
- }).toThrow("'concurrency' cannot exceed 200");
-});
-
-test('should ignore concurrency when calculated framesPerLambda would be too low', () => {
- expect(() => {
- validateConcurrency({
- concurrency: 50,
- framesPerFunction: null,
- durationInFrames: 10,
- });
- }).not.toThrow();
-});
-
-test('shouldIgnoreConcurrency should return true when framesPerLambda would be < 4', () => {
- expect(shouldIgnoreConcurrency({concurrency: 50, durationInFrames: 10})).toBe(
- true,
- );
- expect(
- shouldIgnoreConcurrency({concurrency: 100, durationInFrames: 10}),
- ).toBe(true);
- expect(shouldIgnoreConcurrency({concurrency: 10, durationInFrames: 10})).toBe(
- true,
- );
-});
-
-test('shouldIgnoreConcurrency should return false when framesPerLambda would be >= 4', () => {
- expect(
- shouldIgnoreConcurrency({concurrency: 10, durationInFrames: 100}),
- ).toBe(false);
- expect(
- shouldIgnoreConcurrency({concurrency: 25, durationInFrames: 100}),
- ).toBe(false);
- expect(
- shouldIgnoreConcurrency({concurrency: 50, durationInFrames: 200}),
- ).toBe(false);
-});
-
-test('shouldIgnoreConcurrency should handle edge cases', () => {
- // When durationInFrames is less than 4, the effective minimum is durationInFrames
- expect(shouldIgnoreConcurrency({concurrency: 1, durationInFrames: 3})).toBe(
- false,
- );
- expect(shouldIgnoreConcurrency({concurrency: 2, durationInFrames: 3})).toBe(
- true,
- );
-
- // When durationInFrames is exactly 4
- expect(shouldIgnoreConcurrency({concurrency: 1, durationInFrames: 4})).toBe(
- false,
- );
- expect(shouldIgnoreConcurrency({concurrency: 2, durationInFrames: 4})).toBe(
- true,
- );
-});
diff --git a/packages/serverless-client/src/validate-concurrency.ts b/packages/serverless-client/src/validate-concurrency.ts
deleted file mode 100644
index 9b2cd0b1d4..0000000000
--- a/packages/serverless-client/src/validate-concurrency.ts
+++ /dev/null
@@ -1,96 +0,0 @@
-import {
- MAX_FUNCTIONS_PER_RENDER,
- MINIMUM_FRAMES_PER_FUNCTIONS,
-} from './constants';
-
-export const shouldIgnoreConcurrency = ({
- concurrency,
- durationInFrames,
-}: {
- concurrency: number;
- durationInFrames: number;
-}): boolean => {
- // Calculate framesPerLambda from concurrency
- const calculatedFramesPerLambda = Math.ceil(durationInFrames / concurrency);
-
- // Check if the calculated framesPerLambda meets minimum requirements
- const effectiveMinimum = Math.min(
- MINIMUM_FRAMES_PER_FUNCTIONS,
- durationInFrames,
- );
-
- // If the calculated framesPerLambda would be less than the minimum, ignore the concurrency setting
- return calculatedFramesPerLambda < effectiveMinimum;
-};
-
-export const validateConcurrency = ({
- concurrency,
- framesPerFunction,
- durationInFrames,
-}: {
- concurrency: unknown;
- framesPerFunction: unknown;
- durationInFrames: number;
-}) => {
- // If concurrency is not provided, skip validation
- if (concurrency === null || concurrency === undefined) {
- return;
- }
-
- // Validate concurrency is a number
- if (typeof concurrency !== 'number') {
- throw new TypeError(
- `'concurrency' needs to be a number, passed ${JSON.stringify(
- concurrency,
- )}`,
- );
- }
-
- // Validate concurrency is finite
- if (!Number.isFinite(concurrency)) {
- throw new TypeError(
- `'concurrency' needs to be finite, passed ${concurrency}`,
- );
- }
-
- // Validate concurrency is not NaN
- if (Number.isNaN(concurrency)) {
- throw new TypeError(
- `'concurrency' needs to be a valid number, passed ${concurrency}`,
- );
- }
-
- // Validate concurrency is an integer
- if (concurrency % 1 !== 0) {
- throw new TypeError(
- `'concurrency' needs to be an integer, passed ${concurrency}`,
- );
- }
-
- // Validate concurrency is positive
- if (concurrency <= 0) {
- throw new TypeError(
- `'concurrency' needs to be positive, passed ${concurrency}`,
- );
- }
-
- // Validate concurrency doesn't exceed maximum
- if (concurrency > MAX_FUNCTIONS_PER_RENDER) {
- throw new TypeError(
- `'concurrency' cannot exceed ${MAX_FUNCTIONS_PER_RENDER}, passed ${concurrency}`,
- );
- }
-
- // If the calculated framesPerLambda would be less than the minimum, ignore the concurrency setting
- if (shouldIgnoreConcurrency({concurrency, durationInFrames})) {
- // Return without throwing an error - this effectively ignores the concurrency setting
- return;
- }
-
- // Validate mutual exclusivity with framesPerFunction
- if (framesPerFunction !== null && framesPerFunction !== undefined) {
- throw new TypeError(
- `Cannot specify both 'concurrency' and 'framesPerLambda'. Please use only one of them.`,
- );
- }
-};
diff --git a/packages/serverless-client/src/validate-frames-per-function.ts b/packages/serverless-client/src/validate-frames-per-function.ts
index ca582a6df5..26cd52a6ec 100644
--- a/packages/serverless-client/src/validate-frames-per-function.ts
+++ b/packages/serverless-client/src/validate-frames-per-function.ts
@@ -1,18 +1,92 @@
-import {MINIMUM_FRAMES_PER_FUNCTIONS} from './constants';
+import {bestFramesPerFunctionParam} from './best-frames-per-function-param';
+import {
+ MAX_FUNCTIONS_PER_RENDER,
+ MINIMUM_FRAMES_PER_FUNCTIONS,
+} from './constants';
export const validateFramesPerFunction = ({
framesPerFunction,
durationInFrames,
+ concurrency,
}: {
- framesPerFunction: unknown;
+ framesPerFunction: number | null;
durationInFrames: number;
-}) => {
+ concurrency: number | null;
+}): number => {
+ if (concurrency !== null && framesPerFunction !== null) {
+ throw new TypeError(
+ `Both 'framesPerLambda' and 'concurrency' were set. Please use only one of them.`,
+ );
+ }
+
+ const effectiveMinimum = Math.min(
+ MINIMUM_FRAMES_PER_FUNCTIONS,
+ durationInFrames,
+ );
+
+ if (concurrency !== null) {
+ // Validate concurrency is a number
+ if (typeof concurrency !== 'number') {
+ throw new TypeError(
+ `'concurrency' needs to be a number, passed ${JSON.stringify(
+ concurrency,
+ )}`,
+ );
+ }
+
+ // Validate concurrency is finite
+ if (!Number.isFinite(concurrency)) {
+ throw new TypeError(
+ `'concurrency' needs to be finite, passed ${concurrency}`,
+ );
+ }
+
+ // Validate concurrency is not NaN
+ if (Number.isNaN(concurrency)) {
+ throw new TypeError(
+ `'concurrency' needs to be a valid number, passed ${concurrency}`,
+ );
+ }
+
+ // Validate concurrency is an integer
+ if (concurrency % 1 !== 0) {
+ throw new TypeError(
+ `'concurrency' needs to be an integer, passed ${concurrency}`,
+ );
+ }
+
+ // Validate concurrency is positive
+ if (concurrency <= 0) {
+ throw new TypeError(
+ `'concurrency' needs to be positive, passed ${concurrency}`,
+ );
+ }
+
+ // Validate concurrency doesn't exceed maximum
+ if (concurrency > MAX_FUNCTIONS_PER_RENDER) {
+ throw new TypeError(
+ `'concurrency' cannot exceed ${MAX_FUNCTIONS_PER_RENDER}, passed ${concurrency}`,
+ );
+ }
+
+ return Math.max(
+ Math.ceil(durationInFrames / concurrency),
+ effectiveMinimum,
+ );
+ }
+
if (framesPerFunction === null) {
- return;
+ return Math.max(
+ bestFramesPerFunctionParam(durationInFrames),
+ effectiveMinimum,
+ );
}
if (framesPerFunction === undefined) {
- return;
+ return Math.max(
+ bestFramesPerFunctionParam(durationInFrames),
+ effectiveMinimum,
+ );
}
if (typeof framesPerFunction !== 'number') {
@@ -41,14 +115,11 @@ export const validateFramesPerFunction = ({
);
}
- const effectiveMinimum = Math.min(
- MINIMUM_FRAMES_PER_FUNCTIONS,
- durationInFrames,
- );
-
if (framesPerFunction < effectiveMinimum) {
throw new TypeError(
`The framesPerLambda needs to be at least ${effectiveMinimum}, but is ${framesPerFunction}`,
);
}
+
+ return framesPerFunction;
};
diff --git a/packages/serverless/src/handlers/launch.ts b/packages/serverless/src/handlers/launch.ts
index 6195388228..d36ad00697 100644
--- a/packages/serverless/src/handlers/launch.ts
+++ b/packages/serverless/src/handlers/launch.ts
@@ -26,13 +26,10 @@ import {
MAX_FUNCTIONS_PER_RENDER,
serializeOrThrow,
ServerlessRoutines,
- shouldIgnoreConcurrency,
- validateConcurrency,
validateFramesPerFunction,
validateOutname,
validatePrivacy,
} from '@remotion/serverless-client';
-import {bestFramesPerFunctionParam} from '../best-frames-per-function-param';
import {cleanupProps} from '../cleanup-props';
import {findOutputFileInBucket} from '../find-output-file-in-bucket';
import type {LaunchedBrowser} from '../get-browser-instance';
@@ -147,28 +144,6 @@ const innerLaunchHandler = async <Provider extends CloudProvider>({
RenderInternals.validateBitrate(params.audioBitrate, 'audioBitrate');
RenderInternals.validateBitrate(params.videoBitrate, 'videoBitrate');
- // Now that we have the real duration, validate concurrency
- if (params.concurrency !== null && params.concurrency !== undefined) {
- validateConcurrency({
- concurrency: params.concurrency,
- framesPerFunction: params.framesPerFunction,
- durationInFrames: comp.durationInFrames,
- });
- }
-
- // Check if concurrency should be ignored
- let finalConcurrency = params.concurrency;
- if (finalConcurrency !== null && finalConcurrency !== undefined) {
- if (
- shouldIgnoreConcurrency({
- concurrency: finalConcurrency,
- durationInFrames: comp.durationInFrames,
- })
- ) {
- finalConcurrency = null;
- }
- }
-
RenderInternals.validateConcurrency({
value: params.concurrencyPerFunction,
setting: 'concurrencyPerLambda',
@@ -186,16 +161,10 @@ const innerLaunchHandler = async <Provider extends CloudProvider>({
params.everyNthFrame,
);
- let framesPerLambda =
- params.framesPerFunction ?? bestFramesPerFunctionParam(frameCount.length);
-
- if (finalConcurrency) {
- framesPerLambda = Math.ceil(frameCount.length / finalConcurrency);
- }
-
- validateFramesPerFunction({
- framesPerFunction: framesPerLambda,
+ const framesPerLambda = validateFramesPerFunction({
+ framesPerFunction: params.framesPerFunction,
durationInFrames: frameCount.length,
+ concurrency: params.concurrency,
});
validateOutname({