🎥 Make videos programmatically with React
docs(lambda): document optional outName.key and deduplicate defaultKey derivation
smartcalsystems-sketch7c4dfa2656e4
diff --git a/packages/docs/docs/lambda/custom-destination.mdx b/packages/docs/docs/lambda/custom-destination.mdxindex ea79b37131..5ca0e11dcd 100644--- a/packages/docs/docs/lambda/custom-destination.mdx+++ b/packages/docs/docs/lambda/custom-destination.mdx@@ -20,7 +20,7 @@ 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 `key` and `bucketName` values:+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):```tsx twoslash {13-16}import {renderMediaOnLambda} from '@remotion/lambda';@@ -49,7 +49,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` must match `/^([0-9a-zA-Z-!_.*'()/]+)$/g`+- 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`.- 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.diff --git a/packages/docs/docs/lambda/rendermediaonlambda.mdx b/packages/docs/docs/lambda/rendermediaonlambda.mdxindex 55a515cb26..1b4f931c0a 100644--- a/packages/docs/docs/lambda/rendermediaonlambda.mdx+++ b/packages/docs/docs/lambda/rendermediaonlambda.mdx@@ -254,7 +254,7 @@ It can either be:- `undefined` - it will default to `out` plus the appropriate file extension, for example: `renders/${renderId}/out.mp4`.- A `string` - it will get saved to the same S3 bucket as your site under the key `renders/{renderId}/{outName}`. Make sure to include the file extension at the end of the string.-- An object if you want to render to a different bucket or cloud provider - [see here for detailed instructions](/docs/lambda/custom-destination).+- An object if you want to render to a different bucket or cloud provider (where `key` is optional and falls back to the default render key if omitted) - [see here for detailed instructions](/docs/lambda/custom-destination).### `separateAudioTo?`<AvailableFrom v="4.0.535" />diff --git a/packages/docs/docs/lambda/renderstillonlambda.mdx b/packages/docs/docs/lambda/renderstillonlambda.mdxindex de1ca05412..09097eb6e8 100644--- a/packages/docs/docs/lambda/renderstillonlambda.mdx+++ b/packages/docs/docs/lambda/renderstillonlambda.mdx@@ -173,7 +173,7 @@ It can either be:- `undefined` - it will default to `out` plus the appropriate file extension, for example: `renders/${renderId}/out.mp4`.- A `string` - it will get saved to the same S3 bucket as your site under the key `renders/{renderId}/{outName}`. Make sure to include the file extension at the end of the string.-- An object if you want to render to a different bucket or cloud provider - [see here for detailed instructions](/docs/lambda/custom-destination).+- An object if you want to render to a different bucket or cloud provider (where `key` is optional and falls back to the default still key if omitted) - [see here for detailed instructions](/docs/lambda/custom-destination).### `timeoutInMilliseconds?`diff --git a/packages/serverless-client/src/expected-out-name.ts b/packages/serverless-client/src/expected-out-name.tsindex f55ee794b7..4826af05a9 100644--- a/packages/serverless-client/src/expected-out-name.ts+++ b/packages/serverless-client/src/expected-out-name.ts@@ -32,6 +32,30 @@ 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,@@ -78,36 +102,19 @@ export const getExpectedOutName = <Provider extends CloudProvider>({bucketNamePrefix,});- const defaultKey = (() => {- if (output === 'separate-audio') {- return null;- }-- 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,- ),- );- }-- return null;- })();+ const defaultKey =+ output === 'separate-audio'+ ? undefined+ : getDefaultKey({+ renderMetadata,+ separateAudioFilename,+ });return customOutName(renderMetadata.renderId,bucketName,outNameValue,- defaultKey ?? undefined,+ defaultKey,);}@@ -115,27 +122,12 @@ export const getExpectedOutName = <Provider extends CloudProvider>({throw new Error('This render does not have a separate audio output.');}- if (renderMetadata.type === 'still') {- return {- renderBucketName: bucketName,- key: outStillName(renderMetadata.renderId, renderMetadata.imageFormat),- customCredentials: null,- };- }-- if (renderMetadata.type === 'video') {- return {- renderBucketName: bucketName,- key: outName(- renderMetadata.renderId,- NoReactAPIs.getFileExtensionFromCodec(- renderMetadata.codec as Codec,- separateAudioFilename === null ? renderMetadata.audioCodec : null,- ),- ),- customCredentials: null,- };- }-- throw new TypeError('no type passed');+ return {+ renderBucketName: bucketName,+ key: getDefaultKey({+ renderMetadata,+ separateAudioFilename,+ }),+ customCredentials: null,+ };};