Skip to content

🎥 Make videos programmatically with React

Move concurreny check after launch

Hitesha8857b22bfae
diff --git a/packages/lambda-client/src/make-lambda-payload.ts b/packages/lambda-client/src/make-lambda-payload.ts
index 8ed8688fc2..fef98f6bed 100644
--- a/packages/lambda-client/src/make-lambda-payload.ts
+++ b/packages/lambda-client/src/make-lambda-payload.ts
@@ -27,10 +27,7 @@ import {
compressInputProps,
getNeedsToUpload,
serializeOrThrow,
- shouldIgnoreConcurrency,
- validateConcurrency,
validateDownloadBehavior,
- validateFramesPerFunction,
} from '@remotion/serverless-client';
import type {AwsProvider} from './aws-provider';
import {awsImplementation} from './aws-provider';
@@ -62,7 +59,6 @@ export type InnerRenderMediaOnLambdaInput = {
maxRetries: number;
framesPerLambda: number | null;
concurrency: number | null;
- durationInFrames: number | undefined;
logLevel: LogLevel;
frameRange: FrameRange | null;
outName: OutNameInput<AwsProvider> | null;
@@ -142,37 +138,15 @@ export const makeLambdaRenderMediaPayload = async ({
apiKey,
offthreadVideoThreads,
storageClass,
- durationInFrames,
requestHandler,
}: InnerRenderMediaOnLambdaInput): Promise<
ServerlessStartPayload<AwsProvider>
> => {
const actualCodec = validateLambdaCodec(codec);
validateServeUrl(serveUrl);
- validateFramesPerFunction({
- framesPerFunction: framesPerLambda ?? null,
- durationInFrames: durationInFrames ?? 1,
- });
- validateConcurrency({
- concurrency: concurrency ?? null,
- framesPerFunction: framesPerLambda ?? null,
- durationInFrames: durationInFrames ?? 1,
- });
validateDownloadBehavior(downloadBehavior);
validateWebhook(webhook);
- // Check if concurrency should be ignored (would result in framesPerLambda < 4)
- let finalConcurrency = concurrency;
- if (
- concurrency !== null &&
- concurrency !== undefined &&
- durationInFrames !== undefined
- ) {
- if (shouldIgnoreConcurrency({concurrency, durationInFrames})) {
- finalConcurrency = null;
- }
- }
-
const stringifiedInputProps = serializeOrThrow(
inputProps ?? {},
'input-props',
@@ -199,7 +173,7 @@ export const makeLambdaRenderMediaPayload = async ({
return {
rendererFunctionName,
framesPerLambda,
- concurrency: finalConcurrency,
+ concurrency,
composition,
serveUrl,
inputProps: serialized,
diff --git a/packages/lambda-client/src/render-media-on-lambda.ts b/packages/lambda-client/src/render-media-on-lambda.ts
index a13cc3b8af..670786f0a8 100644
--- a/packages/lambda-client/src/render-media-on-lambda.ts
+++ b/packages/lambda-client/src/render-media-on-lambda.ts
@@ -52,7 +52,6 @@ export type RenderMediaOnLambdaInput = {
maxRetries?: number;
framesPerLambda?: number;
concurrency?: number;
- durationInFrames?: number;
frameRange?: FrameRange;
outName?: OutNameInput<AwsProvider>;
chromiumOptions?: Omit<ChromiumOptions, 'enableMultiProcessOnLinux'>;
@@ -167,7 +166,6 @@ export const renderMediaOnLambdaOptionalToRequired = (
forceWidth: options.forceWidth ?? null,
frameRange: options.frameRange ?? null,
framesPerLambda: options.framesPerLambda ?? null,
- durationInFrames: options.durationInFrames ?? undefined,
functionName: options.functionName,
imageFormat: options.imageFormat ?? 'jpeg',
inputProps: options.inputProps ?? {},
diff --git a/packages/lambda-client/src/test/concurrency-payload.test.ts b/packages/lambda-client/src/test/concurrency-payload.test.ts
new file mode 100644
index 0000000000..aefa65b2a4
--- /dev/null
+++ b/packages/lambda-client/src/test/concurrency-payload.test.ts
@@ -0,0 +1,119 @@
+import {ServerlessRoutines} from '@remotion/serverless-client';
+import {expect, test} from 'bun:test';
+import {makeLambdaRenderMediaPayload} from '../make-lambda-payload';
+
+test('Should include concurrency field in payload', async () => {
+ const payload = await makeLambdaRenderMediaPayload({
+ region: 'us-east-1',
+ functionName: 'test-function',
+ serveUrl: 'https://example.com',
+ composition: 'test-composition',
+ inputProps: {},
+ codec: 'h264',
+ imageFormat: 'jpeg',
+ crf: undefined,
+ envVariables: {},
+ pixelFormat: undefined,
+ proResProfile: undefined,
+ x264Preset: null,
+ privacy: 'public',
+ jpegQuality: 80,
+ maxRetries: 1,
+ framesPerLambda: null,
+ concurrency: 10,
+ logLevel: 'info',
+ frameRange: null,
+ outName: null,
+ timeoutInMilliseconds: 30000,
+ chromiumOptions: {},
+ scale: 1,
+ everyNthFrame: 1,
+ numberOfGifLoops: null,
+ concurrencyPerLambda: 1,
+ downloadBehavior: {type: 'play-in-browser'},
+ muted: false,
+ overwrite: false,
+ audioBitrate: null,
+ videoBitrate: null,
+ encodingMaxRate: null,
+ encodingBufferSize: null,
+ webhook: null,
+ forceHeight: null,
+ forceWidth: null,
+ rendererFunctionName: null,
+ forceBucketName: null,
+ audioCodec: null,
+ colorSpace: null,
+ deleteAfter: null,
+ indent: false,
+ forcePathStyle: false,
+ metadata: null,
+ apiKey: null,
+ offthreadVideoCacheSizeInBytes: null,
+ offthreadVideoThreads: null,
+ storageClass: null,
+ requestHandler: null,
+ preferLossless: false,
+ });
+
+ expect(payload.type).toBe(ServerlessRoutines.start);
+ expect(payload.concurrency).toBe(10);
+});
+
+test('Should handle null concurrency', async () => {
+ const payload = await makeLambdaRenderMediaPayload({
+ region: 'us-east-1',
+ functionName: 'test-function',
+ serveUrl: 'https://example.com',
+ composition: 'test-composition',
+ inputProps: {},
+ codec: 'h264',
+ imageFormat: 'jpeg',
+ crf: undefined,
+ envVariables: {},
+ pixelFormat: undefined,
+ proResProfile: undefined,
+ x264Preset: null,
+ privacy: 'public',
+ jpegQuality: 80,
+ maxRetries: 1,
+ framesPerLambda: null,
+ concurrency: null,
+ logLevel: 'info',
+ frameRange: null,
+ outName: null,
+ timeoutInMilliseconds: 30000,
+ chromiumOptions: {},
+ scale: 1,
+ everyNthFrame: 1,
+ numberOfGifLoops: null,
+ concurrencyPerLambda: 1,
+ downloadBehavior: {type: 'play-in-browser'},
+ muted: false,
+ overwrite: false,
+ audioBitrate: null,
+ videoBitrate: null,
+ encodingMaxRate: null,
+ encodingBufferSize: null,
+ webhook: null,
+ forceHeight: null,
+ forceWidth: null,
+ rendererFunctionName: null,
+ forceBucketName: null,
+ audioCodec: null,
+ colorSpace: null,
+ deleteAfter: null,
+ indent: false,
+ forcePathStyle: false,
+ metadata: null,
+ apiKey: null,
+ offthreadVideoCacheSizeInBytes: null,
+ offthreadVideoThreads: null,
+ storageClass: null,
+ requestHandler: null,
+ preferLossless: false,
+ });
+
+ expect(payload.type).toBe(ServerlessRoutines.start);
+ expect(payload.concurrency).toBe(null);
+});
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index ca38530004..df006dd18d 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -326,7 +326,6 @@ export const renderCommand = async ({
composition,
framesPerLambda: framesPerLambda ?? null,
concurrency: concurrency ?? null,
- durationInFrames: compositionConfig?.durationInFrames,
privacy,
logLevel,
frameRange: frameRange ?? null,
diff --git a/packages/lambda/src/test/integration/renders/old-version.test.ts b/packages/lambda/src/test/integration/renders/old-version.test.ts
index 21b088acfe..80dcf526ea 100644
--- a/packages/lambda/src/test/integration/renders/old-version.test.ts
+++ b/packages/lambda/src/test/integration/renders/old-version.test.ts
@@ -16,6 +16,7 @@ test('Should fail when using an incompatible version', async () => {
envVariables: {},
frameRange: [0, 12],
framesPerFunction: 8,
+ concurrency: null,
imageFormat: 'png',
inputProps: {
type: 'payload',
diff --git a/packages/lambda/src/test/integration/webhooks.test.ts b/packages/lambda/src/test/integration/webhooks.test.ts
index 76ba5a9802..106c0c50ed 100644
--- a/packages/lambda/src/test/integration/webhooks.test.ts
+++ b/packages/lambda/src/test/integration/webhooks.test.ts
@@ -170,6 +170,7 @@ test(
envVariables: {},
frameRange: [0, 10],
framesPerFunction: 8,
+ concurrency: null,
imageFormat: 'png',
inputProps: {
type: 'payload',
diff --git a/packages/serverless-client/src/constants.ts b/packages/serverless-client/src/constants.ts
index aca66cc7c7..4c69c86426 100644
--- a/packages/serverless-client/src/constants.ts
+++ b/packages/serverless-client/src/constants.ts
@@ -174,6 +174,7 @@ export type ServerlessPayloads<Provider extends CloudProvider> = {
serveUrl: string;
composition: string;
framesPerFunction: number | null;
+ concurrency: number | null;
bucketName: string;
inputProps: SerializedInputProps;
renderId: string;
diff --git a/packages/serverless/src/handlers/launch.ts b/packages/serverless/src/handlers/launch.ts
index a98143ada2..6195388228 100644
--- a/packages/serverless/src/handlers/launch.ts
+++ b/packages/serverless/src/handlers/launch.ts
@@ -26,6 +26,8 @@ import {
MAX_FUNCTIONS_PER_RENDER,
serializeOrThrow,
ServerlessRoutines,
+ shouldIgnoreConcurrency,
+ validateConcurrency,
validateFramesPerFunction,
validateOutname,
validatePrivacy,
@@ -145,6 +147,28 @@ 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',
@@ -162,9 +186,13 @@ const innerLaunchHandler = async <Provider extends CloudProvider>({
params.everyNthFrame,
);
- const framesPerLambda =
+ let framesPerLambda =
params.framesPerFunction ?? bestFramesPerFunctionParam(frameCount.length);
+ if (finalConcurrency) {
+ framesPerLambda = Math.ceil(frameCount.length / finalConcurrency);
+ }
+
validateFramesPerFunction({
framesPerFunction: framesPerLambda,
durationInFrames: frameCount.length,
diff --git a/packages/serverless/src/handlers/start.ts b/packages/serverless/src/handlers/start.ts
index 8057158590..5e36e02aba 100644
--- a/packages/serverless/src/handlers/start.ts
+++ b/packages/serverless/src/handlers/start.ts
@@ -82,6 +82,7 @@ export const startHandler = async <Provider extends CloudProvider>({
const payload: ServerlessPayload<Provider> = {
type: ServerlessRoutines.launch,
framesPerFunction: params.framesPerLambda,
+ concurrency: params.concurrency,
composition: params.composition,
serveUrl: realServeUrl,
inputProps: params.inputProps,