🎥 Make videos programmatically with React
alright
Jonny Burger10d1e4360602
diff --git a/packages/lambda/src/api/get-compositions-on-lambda.ts b/packages/lambda/src/api/get-compositions-on-lambda.tsindex 56de2b353b..5063e27347 100644--- a/packages/lambda/src/api/get-compositions-on-lambda.ts+++ b/packages/lambda/src/api/get-compositions-on-lambda.ts@@ -55,10 +55,14 @@ export const getCompositionsOnLambda = async ({region,userSpecifiedBucketName: bucketName ?? null,propsType: 'input-props',- needsToUpload: getNeedsToUpload('video-or-audio', [- stringifiedInputProps.length,- JSON.stringify(envVariables).length,- ]),+ needsToUpload: getNeedsToUpload({+ type: 'video-or-audio',+ sizes: [+ stringifiedInputProps.length,+ JSON.stringify(envVariables).length,+ ],+ providerSpecifics: awsImplementation,+ }),providerSpecifics: awsImplementation,forcePathStyle: forcePathStyle ?? false,skipPutAcl: false,diff --git a/packages/lambda/src/api/make-lambda-payload.ts b/packages/lambda/src/api/make-lambda-payload.tsindex 8afd2aae11..f6e93234a5 100644--- a/packages/lambda/src/api/make-lambda-payload.ts+++ b/packages/lambda/src/api/make-lambda-payload.ts@@ -152,10 +152,14 @@ export const makeLambdaRenderMediaPayload = async ({const serialized = await compressInputProps({stringifiedInputProps,region,- needsToUpload: getNeedsToUpload('video-or-audio', [- stringifiedInputProps.length,- JSON.stringify(envVariables).length,- ]),+ needsToUpload: getNeedsToUpload({+ type: 'video-or-audio',+ sizes: [+ stringifiedInputProps.length,+ JSON.stringify(envVariables).length,+ ],+ providerSpecifics: awsImplementation,+ }),userSpecifiedBucketName: bucketName ?? null,propsType: 'input-props',providerSpecifics: awsImplementation,@@ -266,10 +270,14 @@ export const makeLambdaRenderStillPayload = async ({const serializedInputProps = await compressInputProps({stringifiedInputProps,region,- needsToUpload: getNeedsToUpload('still', [- stringifiedInputProps.length,- JSON.stringify(envVariables).length,- ]),+ needsToUpload: getNeedsToUpload({+ type: 'still',+ sizes: [+ stringifiedInputProps.length,+ JSON.stringify(envVariables).length,+ ],+ providerSpecifics: awsImplementation,+ }),userSpecifiedBucketName: forceBucketName ?? null,propsType: 'input-props',providerSpecifics: awsImplementation,diff --git a/packages/lambda/src/functions/aws-implementation.ts b/packages/lambda/src/functions/aws-implementation.tsindex e919f97e53..0b0eb4909d 100644--- a/packages/lambda/src/functions/aws-implementation.ts+++ b/packages/lambda/src/functions/aws-implementation.ts@@ -122,4 +122,7 @@ export const awsImplementation: ProviderSpecifics<AwsProvider> = {getLoggingUrlForRendererFunction: getCloudwatchRendererUrl,isFlakyError,getOutputUrl: getOutputUrlFromMetadata,+ serverStorageProductName: () => 'S3',+ getMaxStillInlinePayloadSize: () => 5_000_000,+ getMaxNonInlinePayloadSizePerFunction: () => 200_000,};diff --git a/packages/lambda/src/test/mock-implementation.ts b/packages/lambda/src/test/mock-implementation.tsindex 0834384e03..1239609332 100644--- a/packages/lambda/src/test/mock-implementation.ts+++ b/packages/lambda/src/test/mock-implementation.ts@@ -40,6 +40,11 @@ export const getBrowserInstance: GetBrowserInstance = async () => {};export const mockImplementation: ProviderSpecifics<AwsProvider> = {+ getMaxNonInlinePayloadSizePerFunction: () => 200_000,+ getMaxStillInlinePayloadSize() {+ return 5_000_000;+ },+ serverStorageProductName: () => 'file system',applyLifeCycle: () => Promise.resolve(),getChromiumPath() {return null;diff --git a/packages/serverless/src/best-frames-per-function-param.ts b/packages/serverless/src/best-frames-per-function-param.tsindex 412c985030..93982fecea 100644--- a/packages/serverless/src/best-frames-per-function-param.ts+++ b/packages/serverless/src/best-frames-per-function-param.ts@@ -8,11 +8,11 @@ export const bestFramesPerFunctionParam = (frameCount: number) => {extrapolateRight: 'clamp',});- // At least have 20 as a `framesPerLambda` value- const framesPerLambda = Math.max(frameCount / concurrency, 20);+ // At least have 20 as a `framesPerFunction` value+ const framesPerFunction = Math.max(frameCount / concurrency, 20);- // Evenly distribute: For 21 frames over 2 lambda functions, distribute as 11 + 10 ==> framesPerLambda = 11- const lambdasNeeded = Math.ceil(frameCount / framesPerLambda);+ // Evenly distribute: For 21 frames over 2 functions, distribute as 11 + 10 ==> framesPerLambda = 11+ const functionsNeeded = Math.ceil(frameCount / framesPerFunction);- return Math.ceil(frameCount / lambdasNeeded);+ return Math.ceil(frameCount / functionsNeeded);};diff --git a/packages/serverless/src/compress-props.ts b/packages/serverless/src/compress-props.tsindex 0e70def168..fe665d6190 100644--- a/packages/serverless/src/compress-props.ts+++ b/packages/serverless/src/compress-props.ts@@ -35,13 +35,20 @@ export const serializeOrThrow = (}};-export const getNeedsToUpload = (- type: 'still' | 'video-or-audio',- sizes: number[],-) => {+export const getNeedsToUpload = <Provider extends CloudProvider>({+ type,+ sizes,+ providerSpecifics,+}: {+ type: 'still' | 'video-or-audio';+ sizes: number[];+ providerSpecifics: ProviderSpecifics<Provider>;+}) => {const MARGIN = 5_000 + MAX_WEBHOOK_CUSTOM_DATA_SIZE;const MAX_INLINE_PAYLOAD_SIZE =- (type === 'still' ? 5_000_000 : 200_000) - MARGIN;+ (type === 'still'+ ? providerSpecifics.getMaxStillInlinePayloadSize()+ : providerSpecifics.getMaxNonInlinePayloadSizePerFunction()) - MARGIN;const sizesAlreadyUsed = sizes.reduce((a, b) => a + b);@@ -52,7 +59,7 @@ export const getNeedsToUpload = (MAX_INLINE_PAYLOAD_SIZE / 1000,)}KB (${Math.ceil(sizesAlreadyUsed / 1024,- )}KB) in size. Uploading them to S3 to circumvent AWS Lambda payload size, which may lead to slowdown.`,+ )}KB) in size. Uploading them to ${providerSpecifics.serverStorageProductName()} to circumvent AWS Lambda payload size, which may lead to slowdown.`,);return true;}diff --git a/packages/serverless/src/handlers/launch.ts b/packages/serverless/src/handlers/launch.tsindex 7ae4c86e83..41c696294b 100644--- a/packages/serverless/src/handlers/launch.ts+++ b/packages/serverless/src/handlers/launch.ts@@ -205,13 +205,17 @@ const innerLaunchHandler = async <Provider extends CloudProvider>({const serializedResolved = serializeOrThrow(comp.props, 'resolved-props');- const needsToUpload = getNeedsToUpload('video-or-audio', [- serializedResolved.length,- params.inputProps.type === 'bucket-url'- ? params.inputProps.hash.length- : params.inputProps.payload.length,- JSON.stringify(params.envVariables).length,- ]);+ const needsToUpload = getNeedsToUpload({+ type: 'video-or-audio',+ sizes: [+ serializedResolved.length,+ params.inputProps.type === 'bucket-url'+ ? params.inputProps.hash.length+ : params.inputProps.payload.length,+ JSON.stringify(params.envVariables).length,+ ],+ providerSpecifics,+ });const serializedResolvedProps = await compressInputProps({propsType: 'resolved-props',diff --git a/packages/serverless/src/provider-implementation.ts b/packages/serverless/src/provider-implementation.tsindex e2323b7c39..bba9b5d561 100644--- a/packages/serverless/src/provider-implementation.ts+++ b/packages/serverless/src/provider-implementation.ts@@ -269,4 +269,7 @@ export type ProviderSpecifics<Provider extends CloudProvider> = {getEphemeralStorageForPriceCalculation: () => number;getOutputUrl: GetOutputUrl<Provider>;isFlakyError: (err: Error) => boolean;+ serverStorageProductName: () => string;+ getMaxStillInlinePayloadSize: () => number;+ getMaxNonInlinePayloadSizePerFunction: () => number;};