π₯ Make videos programmatically with React
lfg
Jonny Burger75e6627c5a2b
diff --git a/packages/lambda/src/api/create-function.ts b/packages/lambda/src/api/create-function.tsindex 550bdfcb9f..7352aeca66 100644--- a/packages/lambda/src/api/create-function.ts+++ b/packages/lambda/src/api/create-function.ts@@ -28,7 +28,7 @@ export const createFunction = async ({FunctionName: functionName,Handler: 'index.handler',// TODO: Give helpful suggestion if user did not create role- Role: `arn:aws:iam::${accountId[1]}:role/remotion-lambda-role`,+ Role: `arn:aws:iam::${accountId}:role/remotion-lambda-role`,Runtime: 'nodejs14.x',Description: 'Renders a Remotion video.',MemorySize: memorySizeInMb,diff --git a/packages/lambda/src/cli/commands/render/progress.ts b/packages/lambda/src/cli/commands/render/progress.tsnew file mode 100644index 0000000000..88074735c2--- /dev/null+++ b/packages/lambda/src/cli/commands/render/progress.ts@@ -0,0 +1,96 @@+import {CliInternals} from '@remotion/cli';+import {EncodingProgress, RenderProgress} from '../../../defaults';++type LambdaInvokeProgress = {+ totalLambdas: number | null;+ lambdasInvoked: number;+ doneIn: number | null;+};++type ChunkProgress = {+ totalChunks: number | null;+ chunksInvoked: number;+ doneIn: number | null;+};++export type MultiRenderProgress = {+ lambdaInvokeProgress: LambdaInvokeProgress;+ chunkProgress: ChunkProgress;+ encodingProgress: EncodingProgress;+};++export const makeInvokeProgress = (chunkProgress: LambdaInvokeProgress) => {+ const {lambdasInvoked, totalLambdas, doneIn} = chunkProgress;+ return [+ 'π©',+ `(1/3)`,+ CliInternals.makeProgressBar(+ totalLambdas === null ? 0 : lambdasInvoked / totalLambdas+ ),+ `${doneIn === null ? 'Invoking' : 'Invoked'} lambdas`,+ doneIn === null+ ? `${Math.round(+ totalLambdas === null ? 0 : (lambdasInvoked / totalLambdas) * 100+ )}%`+ : CliInternals.chalk.gray(`${doneIn}ms`),+ ].join(' ');+};++export const makeChunkProgress = (chunkProgress: ChunkProgress) => {+ const {chunksInvoked, totalChunks, doneIn} = chunkProgress;+ return [+ 'π½',+ `(2/3)`,+ CliInternals.makeProgressBar(+ totalChunks === null ? 0 : chunksInvoked / totalChunks+ ),+ `${doneIn === null ? 'Rendering' : 'Rendered'} chunks`,+ doneIn === null+ ? `${Math.round(+ totalChunks === null ? 0 : (chunksInvoked / totalChunks) * 100+ )}%`+ : CliInternals.chalk.gray(`${doneIn}ms`),+ ].join(' ');+};++export const makeEncodingProgress = (encodingProgress: EncodingProgress) => {+ const {framesEncoded, totalFrames, doneIn} = encodingProgress;+ return [+ 'π½',+ `(3/3)`,+ CliInternals.makeProgressBar(+ totalFrames === null ? 0 : framesEncoded / totalFrames+ ),+ `${doneIn === null ? 'Encoding' : 'Encoded'} frames`,+ doneIn === null+ ? `${Math.round(+ totalFrames === null ? 0 : (framesEncoded / totalFrames) * 100+ )}%`+ : CliInternals.chalk.gray(`${doneIn}ms`),+ ].join(' ');+};++export const makeMultiProgressFromStatus = (+ status: RenderProgress+): MultiRenderProgress => {+ return {+ chunkProgress: {+ chunksInvoked: status.chunks,+ totalChunks: status.renderMetadata?.totalChunks ?? null,+ // TODO: Define done in+ doneIn: null,+ },+ encodingProgress: {+ framesEncoded: status.encodingStatus?.framesEncoded ?? 0,+ totalFrames: status.encodingStatus?.totalFrames ?? null,+ // TODO: Define done in+ doneIn: null,+ },+ lambdaInvokeProgress: {+ doneIn: null,+ lambdasInvoked: status.lambdasInvoked,+ totalLambdas:+ status.renderMetadata?.estimatedRenderLambdaInvokations ?? null,+ },+ };+};diff --git a/packages/lambda/src/cli/commands/render.ts b/packages/lambda/src/cli/commands/render/render.tssimilarity index 52%rename from packages/lambda/src/cli/commands/render.tsrename to packages/lambda/src/cli/commands/render/render.tsindex b29e19f560..66cb8c1bff 100644--- a/packages/lambda/src/cli/commands/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -1,11 +1,20 @@import {CliInternals} from '@remotion/cli';-import {getRenderProgress} from '../../api/get-render-progress';-import {renderVideoOnLambda} from '../../api/render-video-on-lambda';-import {BINARY_NAME, DEFAULT_FRAMES_PER_LAMBDA} from '../../shared/constants';-import {sleep} from '../../shared/sleep';-import {getAwsRegion} from '../get-aws-region';-import {findFunctionName} from '../helpers/find-function-name';-import {Log} from '../log';+import {getRenderProgress} from '../../../api/get-render-progress';+import {renderVideoOnLambda} from '../../../api/render-video-on-lambda';+import {+ BINARY_NAME,+ DEFAULT_FRAMES_PER_LAMBDA,+} from '../../../shared/constants';+import {sleep} from '../../../shared/sleep';+import {getAwsRegion} from '../../get-aws-region';+import {findFunctionName} from '../../helpers/find-function-name';+import {Log} from '../../log';+import {+ makeChunkProgress,+ makeEncodingProgress,+ makeInvokeProgress,+ makeMultiProgressFromStatus,+} from './progress';export const RENDER_COMMAND = 'render';@@ -57,21 +66,51 @@ export const renderCommand = async (args: string[]) => {composition,framesPerLambda: cliOptions.framesPerLambda ?? DEFAULT_FRAMES_PER_LAMBDA,});++ const progressBar = CliInternals.createOverwriteableCliOutput();++ const status = await getRenderProgress({+ functionName,+ bucketName: res.bucketName,+ renderId: res.renderId,+ region: getAwsRegion(),+ });+ const multiProgress = makeMultiProgressFromStatus(status);+ progressBar.update(+ [+ makeInvokeProgress(multiProgress.lambdaInvokeProgress),+ makeChunkProgress(multiProgress.chunkProgress),+ makeEncodingProgress(multiProgress.encodingProgress),+ ].join('\n')+ );+for (let i = 0; i < 3000; i++) {await sleep(1000);- const status = await getRenderProgress({+ const newStatus = await getRenderProgress({functionName,bucketName: res.bucketName,renderId: res.renderId,region: getAwsRegion(),});- Log.info(status);- if (status.done) {- Log.info('Done! ' + res.bucketName);+ CliInternals.Log.verbose(JSON.stringify(newStatus, null, 2));+ const newProgress = makeMultiProgressFromStatus(newStatus);+ progressBar.update(+ [+ makeInvokeProgress(newProgress.lambdaInvokeProgress),+ makeChunkProgress(newProgress.chunkProgress),+ makeEncodingProgress(newProgress.encodingProgress),+ ].join('\n')+ );++ // Log.info(newStatus);+ if (newStatus.done) {+ Log.info();+ Log.info('Done! ' + newStatus.outputFile);process.exit(0);}- if (status.fatalErrorEncountered) {+ if (newStatus.fatalErrorEncountered) {+ Log.error(newStatus);Log.error('Fatal error encountered. Exiting.');process.exit(1);}diff --git a/packages/lambda/src/cli/help.ts b/packages/lambda/src/cli/help.tsindex db97ff588c..525296ca00 100644--- a/packages/lambda/src/cli/help.ts+++ b/packages/lambda/src/cli/help.ts@@ -2,7 +2,7 @@ import {CliInternals} from '@remotion/cli';import {BINARY_NAME} from '../shared/constants';import {CLEANUP_COMMAND} from './cleanup';import {FUNCTIONS_COMMAND} from './commands/functions';-import {RENDER_COMMAND} from './commands/render';+import {RENDER_COMMAND} from './commands/render/render';import {STILL_COMMAND} from './commands/still';import {Log} from './log';diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.tsindex 925e0ff519..a331f03eaf 100644--- a/packages/lambda/src/cli/index.ts+++ b/packages/lambda/src/cli/index.ts@@ -6,7 +6,7 @@ import {functionsCommand, FUNCTIONS_COMMAND} from './commands/functions';import {policiesCommand, POLICIES_COMMAND} from './commands/policies/policies';import {ROLE_SUBCOMMAND} from './commands/policies/role';import {USER_SUBCOMMAND} from './commands/policies/user';-import {renderCommand, RENDER_COMMAND} from './commands/render';+import {renderCommand, RENDER_COMMAND} from './commands/render/render';import {sitesCommand, SITES_COMMAND} from './commands/sites';import {stillCommand, STILL_COMMAND} from './commands/still';import {printHelp} from './help';diff --git a/packages/lambda/src/functions/helpers/get-final-encoding-status.ts b/packages/lambda/src/functions/helpers/get-final-encoding-status.tsindex bf21e8f4b0..f8eaeb79d5 100644--- a/packages/lambda/src/functions/helpers/get-final-encoding-status.ts+++ b/packages/lambda/src/functions/helpers/get-final-encoding-status.ts@@ -16,6 +16,9 @@ export const getFinalEncodingStatus = ({if (outputFileExists) {return {framesEncoded: renderMetadata.videoConfig.durationInFrames,+ totalFrames: renderMetadata.videoConfig.durationInFrames,+ // TODO: Define doneIn+ doneIn: null,};}diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.tsindex f1206868ec..25d039658a 100644--- a/packages/lambda/src/functions/helpers/get-progress.ts+++ b/packages/lambda/src/functions/helpers/get-progress.ts@@ -62,6 +62,9 @@ export const getProgress = async ({encodingStatus: {framesEncoded:postRenderData.renderMetadata.videoConfig.durationInFrames,+ totalFrames: postRenderData.renderMetadata.videoConfig.durationInFrames,+ // TODO: Define doneIn proeprty+ doneIn: null,},errors: postRenderData.errors,fatalErrorEncountered: false,diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.tsindex 1488e83ede..605f90569b 100644--- a/packages/lambda/src/functions/launch.ts+++ b/packages/lambda/src/functions/launch.ts@@ -227,6 +227,9 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {const onProgress = (framesEncoded: number) => {const encodingProgress: EncodingProgress = {framesEncoded,+ totalFrames: comp.durationInFrames,+ // TODO: Define doneIn property+ doneIn: null,};lambdaWriteFile({bucketName: params.bucketName,diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.tsindex 0228145c6f..3e3587289d 100644--- a/packages/lambda/src/shared/constants.ts+++ b/packages/lambda/src/shared/constants.ts@@ -198,6 +198,8 @@ export type LambdaPayload = LambdaPayloads[LambdaRoutines];export type EncodingProgress = {framesEncoded: number;+ totalFrames: number | null;+ doneIn: number | null;};export type RenderMetadata = {