🎥 Make videos programmatically with React
some progress
Jonny Burgerbc6856582747
diff --git a/packages/cli/src/lambda-command.ts b/packages/cli/src/lambda-command.tsindex 0b2df1689a..5e9d55d57c 100644--- a/packages/cli/src/lambda-command.ts+++ b/packages/cli/src/lambda-command.ts@@ -13,7 +13,7 @@ export const lambdaCommand = async (});const {LambdaInternals} = require(path);- await LambdaInternals.executeCommand(args, remotionRoot, logLevel);+ await LambdaInternals.executeCommand(args, remotionRoot, logLevel, null);process.exit(0);} catch (err) {const manager = StudioServerInternals.getPackageManager(diff --git a/packages/lambda/src/api/render-media-on-lambda.ts b/packages/lambda/src/api/render-media-on-lambda.tsindex 0beee2f62a..cd90773b97 100644--- a/packages/lambda/src/api/render-media-on-lambda.ts+++ b/packages/lambda/src/api/render-media-on-lambda.ts@@ -9,6 +9,7 @@ import type {} from '@remotion/renderer';import type {BrowserSafeApis} from '@remotion/renderer/client';import {NoReactAPIs} from '@remotion/renderer/pure';+import type {ProviderSpecifics} from '@remotion/serverless';import type {DownloadBehavior,OutNameInput,@@ -17,6 +18,7 @@ import type {WebhookOption,} from '@remotion/serverless/client';import {ServerlessRoutines} from '@remotion/serverless/client';+import {awsImplementation} from '../functions/aws-implementation';import type {AwsRegion} from '../regions';import {callLambda} from '../shared/call-lambda';import {@@ -81,6 +83,7 @@ export type RenderMediaOnLambdaOutput = {export const internalRenderMediaOnLambdaRaw = async (input: InnerRenderMediaOnLambdaInput,+ providerSpecifics: ProviderSpecifics<AwsRegion>,): Promise<RenderMediaOnLambdaOutput> => {const {functionName, region, rendererFunctionName} = input;@@ -219,7 +222,10 @@ export const renderMediaOnLambda = ();}- return wrapped(renderMediaOnLambdaOptionalToRequired(options));+ return wrapped(+ renderMediaOnLambdaOptionalToRequired(options),+ awsImplementation,+ );};/**diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.tsindex d1bea0c728..03b0f40e9e 100644--- a/packages/lambda/src/cli/commands/render/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -10,7 +10,9 @@ import {getRenderProgress} from '../../../api/get-render-progress';import {internalRenderMediaOnLambdaRaw} from '../../../api/render-media-on-lambda';import type {EnhancedErrorInfo} from '../../../functions/helpers/write-lambda-error';+import type {ProviderSpecifics} from '@remotion/serverless';import type {ServerlessCodec} from '@remotion/serverless/client';+import type {AwsRegion} from '../../../regions';import {BINARY_NAME,DEFAULT_MAX_RETRIES,@@ -58,6 +60,7 @@ export const renderCommand = async (args: string[],remotionRoot: string,logLevel: LogLevel,+ providerSpecifics: ProviderSpecifics<AwsRegion>,) => {const serveUrl = args[0];if (!serveUrl) {@@ -267,58 +270,63 @@ export const renderCommand = async (const webhookCustomData = getWebhookCustomData(logLevel);- const res = await internalRenderMediaOnLambdaRaw({- functionName,- serveUrl,- inputProps,- codec: codec as ServerlessCodec,- imageFormat,- crf: crf ?? undefined,- envVariables,- pixelFormat,- proResProfile,- jpegQuality,- region,- maxRetries,- composition,- framesPerLambda: framesPerLambda ?? null,- privacy,- logLevel,- frameRange: frameRange ?? null,- outName: parsedLambdaCli['out-name'] ?? null,- timeoutInMilliseconds,- chromiumOptions,- scale,- numberOfGifLoops,- everyNthFrame,- concurrencyPerLambda: parsedLambdaCli['concurrency-per-lambda'] ?? 1,- muted,- overwrite,- audioBitrate,- videoBitrate,- encodingBufferSize,- encodingMaxRate,- forceHeight: height,- forceWidth: width,- webhook: parsedLambdaCli.webhook- ? {- url: parsedLambdaCli.webhook,- secret: parsedLambdaCli['webhook-secret'] ?? null,- customData: webhookCustomData,- }- : null,- rendererFunctionName: parsedLambdaCli['renderer-function-name'] ?? null,- forceBucketName: parsedLambdaCli['force-bucket-name'] ?? null,- audioCodec:- CliInternals.parsedCli[BrowserSafeApis.options.audioCodecOption.cliFlag],- deleteAfter: deleteAfter ?? null,- colorSpace,- downloadBehavior: {type: 'play-in-browser'},- offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,- x264Preset: x264Preset ?? null,- preferLossless,- indent: false,- });+ const res = await internalRenderMediaOnLambdaRaw(+ {+ functionName,+ serveUrl,+ inputProps,+ codec: codec as ServerlessCodec,+ imageFormat,+ crf: crf ?? undefined,+ envVariables,+ pixelFormat,+ proResProfile,+ jpegQuality,+ region,+ maxRetries,+ composition,+ framesPerLambda: framesPerLambda ?? null,+ privacy,+ logLevel,+ frameRange: frameRange ?? null,+ outName: parsedLambdaCli['out-name'] ?? null,+ timeoutInMilliseconds,+ chromiumOptions,+ scale,+ numberOfGifLoops,+ everyNthFrame,+ concurrencyPerLambda: parsedLambdaCli['concurrency-per-lambda'] ?? 1,+ muted,+ overwrite,+ audioBitrate,+ videoBitrate,+ encodingBufferSize,+ encodingMaxRate,+ forceHeight: height,+ forceWidth: width,+ webhook: parsedLambdaCli.webhook+ ? {+ url: parsedLambdaCli.webhook,+ secret: parsedLambdaCli['webhook-secret'] ?? null,+ customData: webhookCustomData,+ }+ : null,+ rendererFunctionName: parsedLambdaCli['renderer-function-name'] ?? null,+ forceBucketName: parsedLambdaCli['force-bucket-name'] ?? null,+ audioCodec:+ CliInternals.parsedCli[+ BrowserSafeApis.options.audioCodecOption.cliFlag+ ],+ deleteAfter: deleteAfter ?? null,+ colorSpace,+ downloadBehavior: {type: 'play-in-browser'},+ offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,+ x264Preset: x264Preset ?? null,+ preferLossless,+ indent: false,+ },+ providerSpecifics,+ );const progressBar = CliInternals.createOverwriteableCliOutput({quiet: CliInternals.quietFlagProvided(),diff --git a/packages/lambda/src/cli/commands/sites/create.ts b/packages/lambda/src/cli/commands/sites/create.tsindex 75463c2703..33335abbe7 100644--- a/packages/lambda/src/cli/commands/sites/create.ts+++ b/packages/lambda/src/cli/commands/sites/create.ts@@ -3,11 +3,12 @@ import {ConfigInternals} from '@remotion/cli/config';import type {LogLevel} from '@remotion/renderer';import {BrowserSafeApis} from '@remotion/renderer/client';+import type {ProviderSpecifics} from '@remotion/serverless';import type {Privacy} from '@remotion/serverless/client';import {NoReactInternals} from 'remotion/no-react';import {internalGetOrCreateBucket} from '../../../api/get-or-create-bucket';-import {awsImplementation} from '../../../functions/aws-implementation';import {LambdaInternals} from '../../../internals';+import type {AwsRegion} from '../../../regions';import {BINARY_NAME} from '../../../shared/constants';import {randomHash} from '../../../shared/random-hash';import {validateSiteName} from '../../../shared/validate-site-name';@@ -39,6 +40,7 @@ export const sitesCreateSubcommand = async (args: string[],remotionRoot: string,logLevel: LogLevel,+ implementation: ProviderSpecifics<AwsRegion>,) => {const {file, reason} = CliInternals.findEntryPoint({args,@@ -126,7 +128,7 @@ export const sitesCreateSubcommand = async (region: getAwsRegion(),enableFolderExpiry,customCredentials: null,- providerSpecifics: awsImplementation,+ providerSpecifics: implementation,})).bucketName;diff --git a/packages/lambda/src/cli/commands/sites/index.ts b/packages/lambda/src/cli/commands/sites/index.tsindex da5520d68a..935487c3cf 100644--- a/packages/lambda/src/cli/commands/sites/index.ts+++ b/packages/lambda/src/cli/commands/sites/index.ts@@ -1,5 +1,7 @@import {CliInternals} from '@remotion/cli';import type {LogLevel} from '@remotion/renderer';+import type {ProviderSpecifics} from '@remotion/serverless';+import type {AwsRegion} from '../../../regions';import {BINARY_NAME} from '../../../shared/constants';import {quit} from '../../helpers/quit';import {SITES_CREATE_SUBCOMMAND, sitesCreateSubcommand} from './create';@@ -58,21 +60,27 @@ export const sitesCommand = (args: string[],remotionRoot: string,logLevel: LogLevel,+ implementation: ProviderSpecifics<AwsRegion>,) => {if (args[0] === SITES_LS_SUBCOMMAND) {return sitesLsSubcommand(logLevel);}if (args[0] === SITES_RM_COMMAND) {- return sitesRmSubcommand(args.slice(1), logLevel);+ return sitesRmSubcommand(args.slice(1), logLevel, implementation);}if (args[0] === SITES_RMALL_COMMAND) {- return sitesRmallSubcommand(logLevel);+ return sitesRmallSubcommand(logLevel, implementation);}if (args[0] === SITES_CREATE_SUBCOMMAND) {- return sitesCreateSubcommand(args.slice(1), remotionRoot, logLevel);+ return sitesCreateSubcommand(+ args.slice(1),+ remotionRoot,+ logLevel,+ implementation,+ );}if (args[0]) {diff --git a/packages/lambda/src/cli/commands/sites/rm.ts b/packages/lambda/src/cli/commands/sites/rm.tsindex 044db11d09..fd7f08b26a 100644--- a/packages/lambda/src/cli/commands/sites/rm.ts+++ b/packages/lambda/src/cli/commands/sites/rm.ts@@ -1,9 +1,10 @@import {CliInternals} from '@remotion/cli';import type {LogLevel} from '@remotion/renderer';+import type {ProviderSpecifics} from '@remotion/serverless';import {deleteSite} from '../../../api/delete-site';import {internalGetOrCreateBucket} from '../../../api/get-or-create-bucket';import {getSites} from '../../../api/get-sites';-import {awsImplementation} from '../../../functions/aws-implementation';+import type {AwsRegion} from '../../../regions';import {parsedLambdaCli} from '../../args';import {getAwsRegion} from '../../get-aws-region';import {confirmCli} from '../../helpers/confirm';@@ -11,7 +12,11 @@ import {quit} from '../../helpers/quit';import {Log} from '../../log';export const SITES_RM_COMMAND = 'rm';-export const sitesRmSubcommand = async (args: string[], logLevel: LogLevel) => {+export const sitesRmSubcommand = async (+ args: string[],+ logLevel: LogLevel,+ implementation: ProviderSpecifics<AwsRegion>,+) => {if (args.length === 0) {Log.error({indent: false, logLevel},@@ -38,7 +43,7 @@ export const sitesRmSubcommand = async (args: string[], logLevel: LogLevel) => {region,enableFolderExpiry: false,customCredentials: null,- providerSpecifics: awsImplementation,+ providerSpecifics: implementation,})).bucketName;diff --git a/packages/lambda/src/cli/commands/sites/rmall.ts b/packages/lambda/src/cli/commands/sites/rmall.tsindex cabb07f8dc..def41cccee 100644--- a/packages/lambda/src/cli/commands/sites/rmall.ts+++ b/packages/lambda/src/cli/commands/sites/rmall.ts@@ -1,9 +1,10 @@import {CliInternals} from '@remotion/cli';import type {LogLevel} from '@remotion/renderer';+import type {ProviderSpecifics} from '@remotion/serverless';import {deleteSite} from '../../../api/delete-site';import {internalGetOrCreateBucket} from '../../../api/get-or-create-bucket';import {getSites} from '../../../api/get-sites';-import {awsImplementation} from '../../../functions/aws-implementation';+import type {AwsRegion} from '../../../regions';import {parsedLambdaCli} from '../../args';import {getAwsRegion} from '../../get-aws-region';import {confirmCli} from '../../helpers/confirm';@@ -11,7 +12,10 @@ import {Log} from '../../log';export const SITES_RMALL_COMMAND = 'rmall';-export const sitesRmallSubcommand = async (logLevel: LogLevel) => {+export const sitesRmallSubcommand = async (+ logLevel: LogLevel,+ implementation: ProviderSpecifics<AwsRegion>,+) => {const region = getAwsRegion();const deployedSites = await getSites({region,@@ -24,7 +28,7 @@ export const sitesRmallSubcommand = async (logLevel: LogLevel) => {region,enableFolderExpiry: false,customCredentials: null,- providerSpecifics: awsImplementation,+ providerSpecifics: implementation,})).bucketName;diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.tsindex bbfd6df434..f772df8a1a 100644--- a/packages/lambda/src/cli/index.ts+++ b/packages/lambda/src/cli/index.ts@@ -1,8 +1,11 @@import {CliInternals} from '@remotion/cli';import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';+import type {ProviderSpecifics} from '@remotion/serverless';import {ROLE_NAME} from '../api/iam-validation/suggested-policy';import {BINARY_NAME} from '../defaults';+import {awsImplementation} from '../functions/aws-implementation';+import type {AwsRegion} from '../regions';import {checkCredentials} from '../shared/check-credentials';import {DOCS_URL} from '../shared/docs-url';import {parsedLambdaCli} from './args';@@ -46,6 +49,7 @@ const matchCommand = (args: string[],remotionRoot: string,logLevel: LogLevel,+ implementation: ProviderSpecifics<AwsRegion>,) => {if (parsedLambdaCli.help || args.length === 0) {printHelp(logLevel);@@ -57,7 +61,7 @@ const matchCommand = (}if (args[0] === RENDER_COMMAND) {- return renderCommand(args.slice(1), remotionRoot, logLevel);+ return renderCommand(args.slice(1), remotionRoot, logLevel, implementation);}if (args[0] === STILL_COMMAND) {@@ -85,7 +89,7 @@ const matchCommand = (}if (args[0] === SITES_COMMAND) {- return sitesCommand(args.slice(1), remotionRoot, logLevel);+ return sitesCommand(args.slice(1), remotionRoot, logLevel, implementation);}if (args[0] === 'upload') {@@ -141,10 +145,16 @@ export const executeCommand = async (args: string[],remotionRoot: string,logLevel: LogLevel,+ implementation: ProviderSpecifics<AwsRegion> | null,) => {try {setIsCli(true);- await matchCommand(args, remotionRoot, logLevel);+ await matchCommand(+ args,+ remotionRoot,+ logLevel,+ implementation ?? awsImplementation,+ );} catch (err) {const error = err as Error;if (@@ -246,5 +256,10 @@ export const cli = async (logLevel: LogLevel) => {const remotionRoot = RenderInternals.findRemotionRoot();await CliInternals.initializeCli(remotionRoot);- await executeCommand(parsedLambdaCli._, remotionRoot, logLevel);+ await executeCommand(+ parsedLambdaCli._,+ remotionRoot,+ logLevel,+ awsImplementation,+ );};diff --git a/packages/lambda/src/shared/__mocks__/aws-clients.ts b/packages/lambda/src/shared/__mocks__/aws-clients.tsindex 6e941d4d65..21149a0360 100644--- a/packages/lambda/src/shared/__mocks__/aws-clients.ts+++ b/packages/lambda/src/shared/__mocks__/aws-clients.ts@@ -1,8 +1,9 @@import type {LambdaClient} from '@aws-sdk/client-lambda';-import {awsImplementation} from '../../functions/aws-implementation';import {ResponseStream} from '../../functions/helpers/streamify-response';import type {getLambdaClient as original} from '../../shared/aws-clients';+import {mockImplementation} from '../../test/mock-implementation';+export const getLambdaClient: typeof original = (region, timeoutInTest) => {return {config: {@@ -31,7 +32,7 @@ export const getLambdaClient: typeof original = (region, timeoutInTest) => {getRemainingTimeInMillis: () => timeoutInTest ?? 120000,awsRequestId: 'fake',},- awsImplementation,+ mockImplementation,);if (params.input.InvocationType === 'RequestResponse' ||diff --git a/packages/lambda/src/test/integration/cli.test.ts b/packages/lambda/src/test/integration/cli.test.tsindex 26b459532b..3c726bbebd 100644--- a/packages/lambda/src/test/integration/cli.test.ts+++ b/packages/lambda/src/test/integration/cli.test.ts@@ -8,6 +8,7 @@ import {} from '../../defaults';import {LambdaInternals} from '../../internals';import {LAMBDA_VERSION_STRING} from '../../shared/lambda-version-string';+import {mockImplementation} from '../mock-implementation';import {getProcessWriteOutput} from './console-hooks';const remotionRoot = process.cwd();@@ -16,7 +17,8 @@ test('Deploy function', async () => {await LambdaInternals.executeCommand(['functions', 'deploy'],remotionRoot,- 'info',+ 'verbose',+ mockImplementation,);expect(getProcessWriteOutput()).toContain(`Deployed as remotion-render-${LAMBDA_VERSION_STRING}-mem${DEFAULT_MEMORY_SIZE}mb-disk${DEFAULT_EPHEMERAL_STORAGE_IN_MB}mb-${DEFAULT_TIMEOUT}sec\n`,@@ -28,11 +30,13 @@ test('Deploy function and list it', async () => {['functions', 'deploy'],remotionRoot,'info',+ mockImplementation,);await LambdaInternals.executeCommand(['functions', 'ls'],remotionRoot,'info',+ mockImplementation,);expect(getProcessWriteOutput()).toContain('Getting functions...');expect(getProcessWriteOutput()).toContain('Memory (MB)');@@ -44,11 +48,13 @@ test('Deploy function and it already exists should fail', async () => {['functions', 'deploy'],remotionRoot,'info',+ mockImplementation,);await LambdaInternals.executeCommand(['functions', 'deploy'],remotionRoot,'info',+ mockImplementation,);expect(getProcessWriteOutput()).toMatch(/Already exists as remotion-render/);@@ -60,6 +66,7 @@ test('If no functions are there and is quiet, should return "()"', async () => {['functions', 'ls'],remotionRoot,'info',+ mockImplementation,);expect(getProcessWriteOutput()).toBe('()');});@@ -69,6 +76,7 @@ test('Should handle functions rm called with no functions', async () => {['functions', 'rm', '()'],remotionRoot,'info',+ mockImplementation,);expect(getProcessWriteOutput()).toBe('No functions to remove.');});diff --git a/packages/lambda/src/test/setup.ts b/packages/lambda/src/test/setup.tsindex 5d12b0c6a8..2d7bba56c5 100644--- a/packages/lambda/src/test/setup.ts+++ b/packages/lambda/src/test/setup.ts@@ -12,9 +12,6 @@ vi.mock('../functions/helpers/timer', () =>vi.mock('../functions/helpers/print-cloudwatch-helper', () =>vi.importActual('../functions/helpers/__mocks__/print-cloudwatch-helper'),);-vi.mock('../functions/helpers/get-current-region', () =>- vi.importActual('../functions/helpers/__mocks__/get-current-region'),-);vi.mock('../functions/helpers/get-browser-instance', () =>vi.importActual('../functions/helpers/__mocks__/get-browser-instance'),);