Skip to content

🎥 Make videos programmatically with React

fix(lambda): consolidate default output keys and preserve separate audio filenames

JonnyBurger8fe48289fd48
diff --git a/packages/docs/docs/lambda/custom-destination.mdx b/packages/docs/docs/lambda/custom-destination.mdx
index 5ca0e11dcd..48af9e8663 100644
--- a/packages/docs/docs/lambda/custom-destination.mdx
+++ b/packages/docs/docs/lambda/custom-destination.mdx
@@ -20,7 +20,11 @@ The output name must match `/^([0-9a-zA-Z-!_.*'()/]+)$/g`.
## Customizing the output bucket
-To render into a different bucket, specify the `outName` option to [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) or [`renderStillOnLambda()`](/docs/lambda/renderstillonlambda) and pass an object with the `bucketName` value and an optional `key` (which defaults to `renders/{renderId}/out.{extension}` or `renders/{renderId}/out.{imageFormat}` for stills):
+To render into a different bucket, specify the `outName` option to [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) or [`renderStillOnLambda()`](/docs/lambda/renderstillonlambda) and pass an object with `bucketName` and an optional `key`.
+
+From <AvailableFrom v="4.0.538" inline />, you can omit `key` to use `renders/${renderId}/out.{extension}` in the destination bucket, including when using `s3OutputProvider`. The extension is chosen from the codec and audio options, or the image format for stills.
+
+If you specify `key`, include the extension.
```tsx twoslash {13-16}
import {renderMediaOnLambda} from '@remotion/lambda';
@@ -37,7 +41,7 @@ const {bucketName, renderId} = await renderMediaOnLambda({
maxRetries: 1,
privacy: 'no-acl',
outName: {
- key: 'my-output',
+ key: 'my-output.mp4',
bucketName: 'output-bucket',
},
});
@@ -49,7 +53,7 @@ If you like to use this feature:
- If you set `privacy` to `"public"` or `"private"`, also grant `s3:PutObjectAcl` on the destination bucket's objects.
- The bucket must be in the same region.
- When calling APIs such as [`downloadMedia()`](/docs/lambda/downloadmedia) or [`getRenderProgress()`](/docs/lambda/getrenderprogress), you must pass the `bucketName` where the site resides in, not the bucket where the video gets saved.
-- The `key` is optional and defaults to `renders/{renderId}/out.{extension}` (or `renders/{renderId}/out.{imageFormat}` for stills). If provided, it must match `/^([0-9a-zA-Z-!_.*'()/]+)$/g`.
+- If provided, the `key` must match `/^([0-9a-zA-Z-!_.*'()/]+)$/g`.
- The bucketName must match `/^(?=^.{3,63}$)(?!^(\d+\.)+\d+$)(^(([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])$)/`.
This feature is not supported from the CLI.
@@ -100,7 +104,7 @@ const {bucketName, renderId} = await renderMediaOnLambda({
maxRetries: 1,
privacy: 'no-acl',
outName: {
- key: 'my-output',
+ key: 'my-output.mp4',
bucketName: 'output-bucket',
s3OutputProvider: {
endpoint: 'https://fra1.digitaloceanspaces.com',
diff --git a/packages/docs/docs/lambda/rendermediaonlambda.mdx b/packages/docs/docs/lambda/rendermediaonlambda.mdx
index 1b4f931c0a..ebdf1e7818 100644
--- a/packages/docs/docs/lambda/rendermediaonlambda.mdx
+++ b/packages/docs/docs/lambda/rendermediaonlambda.mdx
@@ -260,7 +260,7 @@ It can either be:
Save the mixed audio as a separate file and omit the audio track from the video. By default, audio is included in the video.
-A string such as `"audio.wav"` saves to `renders/{renderId}/audio.wav` in the render bucket. An object with `bucketName`, `key` and an optional `s3OutputProvider` supports a [custom destination](/docs/lambda/custom-destination), using the same rules as [`outName`](/docs/lambda/rendermediaonlambda#outname).
+A string such as `"audio.wav"` saves to `renders/{renderId}/audio.wav` in the render bucket. An object with `bucketName`, `key` and an optional `s3OutputProvider` supports a [custom destination](/docs/lambda/custom-destination). The `key` is required for `separateAudioTo` and must include an audio file extension.
```ts twoslash title="Render video and audio separately"
import {renderMediaOnLambda} from '@remotion/lambda/client';
diff --git a/packages/lambda-client/src/make-lambda-payload.ts b/packages/lambda-client/src/make-lambda-payload.ts
index 42a700d4ff..3c685b2807 100644
--- a/packages/lambda-client/src/make-lambda-payload.ts
+++ b/packages/lambda-client/src/make-lambda-payload.ts
@@ -9,6 +9,7 @@ import type {
DownloadBehavior,
LogLevel,
OutNameInput,
+ OutNameInputWithKey,
PixelFormat,
Privacy,
ServerlessCodec,
@@ -66,7 +67,7 @@ export type InnerRenderMediaOnLambdaInput = {
logLevel: LogLevel;
frameRange: SingleFrameRange | null;
outName: OutNameInput<AwsProvider> | null;
- separateAudioTo: OutNameInput<AwsProvider> | null;
+ separateAudioTo: OutNameInputWithKey<AwsProvider> | null;
timeoutInMilliseconds: number;
chromiumOptions: ChromiumOptions;
scale: number;
diff --git a/packages/lambda-client/src/render-media-on-lambda.ts b/packages/lambda-client/src/render-media-on-lambda.ts
index a7f2d41b61..9283704a8a 100644
--- a/packages/lambda-client/src/render-media-on-lambda.ts
+++ b/packages/lambda-client/src/render-media-on-lambda.ts
@@ -6,6 +6,7 @@ import type {
ChromiumOptions,
DownloadBehavior,
OutNameInput,
+ OutNameInputWithKey,
PixelFormat,
Privacy,
ServerlessCodec,
@@ -55,7 +56,7 @@ export type RenderMediaOnLambdaInput = {
concurrency?: number;
frameRange?: SingleFrameRange;
outName?: OutNameInput<AwsProvider>;
- separateAudioTo?: OutNameInput<AwsProvider>;
+ separateAudioTo?: OutNameInputWithKey<AwsProvider>;
chromiumOptions?: Omit<ChromiumOptions, 'enableMultiProcessOnLinux'>;
scale?: number;
everyNthFrame?: number;
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 0e4e2537c0..9a7af4b5ec 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -416,7 +416,7 @@ export const renderCommand = async ({
typeof resolvedOutName === 'object' && resolvedOutName !== null
? {
bucketName: resolvedOutName.bucketName,
- keyPrefix: resolvedOutName.key ?? '',
+ keyPrefix: resolvedOutName.key,
s3OutputProvider: resolvedOutName.s3OutputProvider,
}
: resolvedOutName,
diff --git a/packages/lambda/src/cli/helpers/get-s3-output-provider-from-cli.ts b/packages/lambda/src/cli/helpers/get-s3-output-provider-from-cli.ts
index e225e9acea..54e95d3b8a 100644
--- a/packages/lambda/src/cli/helpers/get-s3-output-provider-from-cli.ts
+++ b/packages/lambda/src/cli/helpers/get-s3-output-provider-from-cli.ts
@@ -1,5 +1,8 @@
import {LambdaClientInternals} from '@remotion/lambda-client';
-import type {CustomCredentials, OutNameInput} from '@remotion/serverless';
+import type {
+ CustomCredentials,
+ OutNameInputWithKey,
+} from '@remotion/serverless';
import type {AwsProvider} from '../../client';
export const S3_OUTPUT_PROVIDER_ACCESS_KEY_ID_ENV_NAME =
@@ -54,7 +57,7 @@ export const makeOutNameWithCustomCredentials = ({
bucketName: string | undefined;
key: string | undefined;
s3OutputProvider: CustomCredentials<AwsProvider> | null;
-}): OutNameInput<AwsProvider> | null => {
+}): OutNameInputWithKey<AwsProvider> | null => {
if (!s3OutputProvider) {
return key ?? null;
}
diff --git a/packages/lambda/src/test/unit/output-access-error-identity.test.ts b/packages/lambda/src/test/unit/output-access-error-identity.test.ts
index 382d2a05e3..8476ecf032 100644
--- a/packages/lambda/src/test/unit/output-access-error-identity.test.ts
+++ b/packages/lambda/src/test/unit/output-access-error-identity.test.ts
@@ -54,7 +54,7 @@ const params: ServerlessPayloads<AwsProvider>['launch'] = {
audioCodec: null,
imageFormat: 'png',
inputProps: {type: 'payload', payload: '{}'},
- outName: {bucketName: destination, key: 'output.mp4'},
+ outName: {bucketName: destination},
separateAudioTo: null,
concurrency: 1,
framesPerFunction: null,
@@ -398,7 +398,12 @@ test.each(['bundled', 'same package'] as const)(
);
try {
await invokeLaunch(fixture);
- expect(fixture.writeFileIfNotExists).toHaveBeenCalledTimes(1);
+ expect(fixture.writeFileIfNotExists).toHaveBeenCalledWith(
+ expect.objectContaining({
+ bucketName: destination,
+ key: `renders/${renderId}/out.mp4`,
+ }),
+ );
expect(fixture.getOutput()!.toString()).toBe('rendered output');
expect(fixture.getProgress().postRenderData).not.toBeNull();
expect(
diff --git a/packages/serverless-client/src/constants.ts b/packages/serverless-client/src/constants.ts
index 3eee0632a8..36a20fd0f2 100644
--- a/packages/serverless-client/src/constants.ts
+++ b/packages/serverless-client/src/constants.ts
@@ -63,6 +63,10 @@ export type OutNameInput<Provider extends CloudProvider> =
s3OutputProvider?: CustomCredentials<Provider>;
};
+export type OutNameInputWithKey<Provider extends CloudProvider> =
+ | string
+ | (OutNameInput<Provider> & {key: string});
+
export type RenderOutput = 'main' | 'separate-audio';
export type SeparateAudioOutput = {
@@ -150,7 +154,7 @@ export type ServerlessStartPayload<Provider extends CloudProvider> = {
logLevel: LogLevel;
frameRange: SingleFrameRange | null;
outName: OutNameInput<Provider> | null;
- separateAudioTo: OutNameInput<Provider> | null;
+ separateAudioTo: OutNameInputWithKey<Provider> | null;
timeoutInMilliseconds: number;
chromiumOptions: ChromiumOptions;
scale: number;
@@ -219,7 +223,7 @@ export type ServerlessPayloads<Provider extends CloudProvider> = {
logLevel: LogLevel;
frameRange: SingleFrameRange | null;
outName: OutNameInput<Provider> | null;
- separateAudioTo: OutNameInput<Provider> | null;
+ separateAudioTo: OutNameInputWithKey<Provider> | null;
timeoutInMilliseconds: number;
// Non-JS SDKs may not set chromiumOptions, may be undefined
chromiumOptions: ChromiumOptions | undefined;
@@ -388,8 +392,7 @@ export const outName = (renderId: string, extension: string) =>
export const customOutName = <Provider extends CloudProvider>(
renderId: string,
bucketName: string,
- name: OutNameInput<Provider>,
- defaultKey?: string,
+ name: OutNameInputWithKey<Provider>,
): OutNameOutput<Provider> => {
if (typeof name === 'string') {
return {
@@ -399,15 +402,8 @@ export const customOutName = <Provider extends CloudProvider>(
};
}
- const resolvedKey = name.key ?? defaultKey;
- if (typeof resolvedKey !== 'string') {
- throw new TypeError(
- 'The S3 key must be specified or a default key must be available.',
- );
- }
-
return {
- key: resolvedKey,
+ key: name.key,
renderBucketName: name.bucketName,
customCredentials: name.s3OutputProvider ?? null,
};
diff --git a/packages/serverless-client/src/expected-out-name.ts b/packages/serverless-client/src/expected-out-name.ts
index 85985a6260..c793cbd239 100644
--- a/packages/serverless-client/src/expected-out-name.ts
+++ b/packages/serverless-client/src/expected-out-name.ts
@@ -32,30 +32,6 @@ export const getCredentialsFromOutName = <Provider extends CloudProvider>(
return name.s3OutputProvider ?? null;
};
-const getDefaultKey = <Provider extends CloudProvider>({
- renderMetadata,
- separateAudioFilename,
-}: {
- renderMetadata: RenderMetadata<Provider>;
- separateAudioFilename: string | null;
-}): string => {
- if (renderMetadata.type === 'still') {
- return outStillName(renderMetadata.renderId, renderMetadata.imageFormat);
- }
-
- if (renderMetadata.type === 'video') {
- return outName(
- renderMetadata.renderId,
- NoReactAPIs.getFileExtensionFromCodec(
- renderMetadata.codec as Codec,
- separateAudioFilename === null ? renderMetadata.audioCodec : null,
- ),
- );
- }
-
- throw new TypeError('no type passed');
-};
-
export const getExpectedOutName = <Provider extends CloudProvider>({
renderMetadata,
bucketName,
@@ -101,35 +77,48 @@ export const getExpectedOutName = <Provider extends CloudProvider>({
separateAudioTo: separateAudioFilename?.toLowerCase() ?? null,
bucketNamePrefix,
});
+ if (typeof outNameValue === 'string') {
+ return customOutName(renderMetadata.renderId, bucketName, outNameValue);
+ }
- const defaultKey =
- output === 'separate-audio' ||
- typeof outNameValue === 'string' ||
- outNameValue.key !== undefined
- ? undefined
- : getDefaultKey({
- renderMetadata,
- separateAudioFilename,
- });
-
- return customOutName(
- renderMetadata.renderId,
- bucketName,
- outNameValue,
- defaultKey,
- );
+ if (outNameValue.key !== undefined) {
+ return customOutName(renderMetadata.renderId, bucketName, {
+ ...outNameValue,
+ key: outNameValue.key,
+ });
+ }
}
if (output === 'separate-audio') {
throw new Error('This render does not have a separate audio output.');
}
- return {
- renderBucketName: bucketName,
- key: getDefaultKey({
- renderMetadata,
- separateAudioFilename,
- }),
- customCredentials: null,
- };
+ const destination =
+ typeof outNameValue === 'object' && outNameValue !== null
+ ? outNameValue
+ : null;
+
+ if (renderMetadata.type === 'still') {
+ return {
+ renderBucketName: destination?.bucketName ?? bucketName,
+ key: outStillName(renderMetadata.renderId, renderMetadata.imageFormat),
+ customCredentials: destination?.s3OutputProvider ?? null,
+ };
+ }
+
+ if (renderMetadata.type === 'video') {
+ return {
+ renderBucketName: destination?.bucketName ?? bucketName,
+ key: outName(
+ renderMetadata.renderId,
+ NoReactAPIs.getFileExtensionFromCodec(
+ renderMetadata.codec as Codec,
+ separateAudioFilename === null ? renderMetadata.audioCodec : null,
+ ),
+ ),
+ customCredentials: destination?.s3OutputProvider ?? null,
+ };
+ }
+
+ throw new TypeError('no type passed');
};
diff --git a/packages/serverless-client/src/test/expected-out-name.test.ts b/packages/serverless-client/src/test/expected-out-name.test.ts
index 0c95b5bfca..5298d549d2 100644
--- a/packages/serverless-client/src/test/expected-out-name.test.ts
+++ b/packages/serverless-client/src/test/expected-out-name.test.ts
@@ -140,6 +140,7 @@ test('Should preserve custom provider regions outside the built-in AWS list', ()
test('Should default key when outName specifies custom s3OutputProvider without key for video', () => {
const newRenderMetadata: RenderMetadata<MockProvider> = {
...testRenderMetadata,
+ audioCodec: 'pcm-16',
outName: {
bucketName: 'renders-dev.mykaraoke.video',
s3OutputProvider: {
@@ -172,7 +173,7 @@ test('Should default key when outName specifies custom s3OutputProvider without
forcePathStyle: false,
},
renderBucketName: 'renders-dev.mykaraoke.video',
- key: 'renders/9n8dsfafs/out.mp4',
+ key: 'renders/9n8dsfafs/out.mkv',
});
});
diff --git a/packages/serverless-client/src/validate-outname.ts b/packages/serverless-client/src/validate-outname.ts
index 289d7bca67..4a86495f64 100644
--- a/packages/serverless-client/src/validate-outname.ts
+++ b/packages/serverless-client/src/validate-outname.ts
@@ -38,7 +38,7 @@ export const validateOutname = ({
}
if (typeof outName !== 'string') {
- if (typeof outName.key !== 'undefined') {
+ if (outName.key !== undefined) {
validateS3Key(outName.key);
}