Skip to content

🎥 Make videos programmatically with React

progress

Jonny Burgerb7a0f79b5c2b
diff --git a/packages/lambda/remotionlambda.zip b/packages/lambda/remotionlambda.zip
index 4c16012af2..33ceb1a8ca 100644
Binary files a/packages/lambda/remotionlambda.zip and b/packages/lambda/remotionlambda.zip differ
diff --git a/packages/lambda/src/cli/commands/render/progress.ts b/packages/lambda/src/cli/commands/render/progress.ts
index 383b9f0868..d53637598f 100644
--- a/packages/lambda/src/cli/commands/render/progress.ts
+++ b/packages/lambda/src/cli/commands/render/progress.ts
@@ -122,8 +122,7 @@ export const makeMultiProgressFromStatus = (
doneIn: status.encodingStatus?.doneIn ?? null,
},
lambdaInvokeProgress: {
- // TODO: Calculate invoke progress
- doneIn: null,
+ doneIn: status.timeToInvokeLambdas,
lambdasInvoked: status.lambdasInvoked,
totalLambdas:
status.renderMetadata?.estimatedRenderLambdaInvokations ?? null,
diff --git a/packages/lambda/src/functions/helpers/create-post-render-data.ts b/packages/lambda/src/functions/helpers/create-post-render-data.ts
index e898991894..f468dd19f9 100644
--- a/packages/lambda/src/functions/helpers/create-post-render-data.ts
+++ b/packages/lambda/src/functions/helpers/create-post-render-data.ts
@@ -10,6 +10,7 @@ import {parseLambdaTimingsKey} from '../../shared/parse-lambda-timings-key';
import {calculateChunkTimes} from './calculate-chunk-times';
import {findOutputFileInBucket} from './find-output-file-in-bucket';
import {getFilesToDelete} from './get-files-to-delete';
+import {getLambdasInvokedStats} from './get-lambdas-invoked-stats';
import {EnhancedErrorInfo} from './write-lambda-error';
const OVERHEAD_TIME_PER_LAMBDA = 100;
@@ -72,6 +73,17 @@ export const createPostRenderData = ({
.map((c) => c.Size ?? 0)
.reduce((a, b) => a + b, 0);
+ const {timeToInvokeLambdas} = getLambdasInvokedStats(
+ contents,
+ renderId,
+ renderMetadata?.estimatedRenderLambdaInvokations ?? null,
+ renderMetadata.startedDate
+ );
+
+ if (timeToInvokeLambdas === null) {
+ throw new Error('should have timing for all lambdas');
+ }
+
const data: PostRenderData = {
cost: {
currency: 'USD',
@@ -102,6 +114,7 @@ export const createPostRenderData = ({
renderId,
type: 'absolute-time',
}),
+ timeToInvokeLambdas,
};
return data;
diff --git a/packages/lambda/src/functions/helpers/get-files-to-delete.ts b/packages/lambda/src/functions/helpers/get-files-to-delete.ts
index c390d3d2d1..da571fa8c9 100644
--- a/packages/lambda/src/functions/helpers/get-files-to-delete.ts
+++ b/packages/lambda/src/functions/helpers/get-files-to-delete.ts
@@ -40,7 +40,7 @@ export const getFilesToDelete = ({
...chunks.map((i) => {
return {
name: i,
- type: 'prefix' as const,
+ type: 'exact' as const,
};
}),
...lambdaTimings.map((i) => {
diff --git a/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts b/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts
new file mode 100644
index 0000000000..a312a79d54
--- /dev/null
+++ b/packages/lambda/src/functions/helpers/get-lambdas-invoked-stats.ts
@@ -0,0 +1,29 @@
+import {_Object} from '@aws-sdk/client-s3';
+import {RenderInternals} from '@remotion/renderer';
+import {lambdaInitializedPrefix} from '../../shared/constants';
+
+export const getLambdasInvokedStats = (
+ contents: _Object[],
+ renderId: string,
+ estimatedInvokations: number | null,
+ startDate: number | null
+) => {
+ const lambdasInvoked = contents.filter((c) =>
+ c.Key?.startsWith(lambdaInitializedPrefix(renderId))
+ );
+ const allLambdasInvoked = lambdasInvoked.length === estimatedInvokations;
+
+ // TODO: Doesn't work while in cleanup, progress goes backwards
+ const timeToInvokeLambdas =
+ allLambdasInvoked && startDate
+ ? RenderInternals.max(
+ lambdasInvoked.map((l) => l.LastModified?.getTime() as number)
+ ) - startDate
+ : null;
+
+ return {
+ timeToInvokeLambdas,
+ allLambdasInvoked,
+ lambdasInvoked: lambdasInvoked.length,
+ };
+};
diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.ts
index 4b6cd97629..37c8b2bb94 100644
--- a/packages/lambda/src/functions/helpers/get-progress.ts
+++ b/packages/lambda/src/functions/helpers/get-progress.ts
@@ -2,7 +2,6 @@ import {AwsRegion} from '../..';
import {
chunkKey,
encodingProgressKey,
- lambdaInitializedPrefix,
renderMetadataKey,
RenderProgress,
rendersPrefix,
@@ -15,6 +14,7 @@ import {getCleanupProgress} from './get-cleanup-progress';
import {getCurrentRegionInFunction} from './get-current-region';
import {getEncodingMetadata} from './get-encoding-metadata';
import {getFinalEncodingStatus} from './get-final-encoding-status';
+import {getLambdasInvokedStats} from './get-lambdas-invoked-stats';
import {getPostRenderData} from './get-post-render-data';
import {getRenderMetadata} from './get-render-metadata';
import {getTimeToFinish} from './get-time-to-finish';
@@ -74,6 +74,7 @@ export const getProgress = async ({
renderMetadata: postRenderData.renderMetadata,
timeToFinish: postRenderData.timeToFinish,
timeToFinishChunks: postRenderData.timeToRenderChunks,
+ timeToInvokeLambdas: postRenderData.timeToInvokeLambdas,
};
}
@@ -148,11 +149,12 @@ export const getProgress = async ({
.map((c) => c.Size ?? 0)
.reduce((a, b) => a + b, 0);
- const lambdasInvoked = outputFile
- ? renderMetadata?.totalChunks ?? 0
- : contents.filter((c) =>
- c.Key?.startsWith(lambdaInitializedPrefix(renderId))
- ).length;
+ const lambdasInvokedStats = getLambdasInvokedStats(
+ contents,
+ renderId,
+ renderMetadata?.estimatedRenderLambdaInvokations ?? null,
+ renderMetadata?.startedDate ?? null
+ );
return {
chunks: outputFile ? renderMetadata?.totalChunks ?? 0 : chunks.length,
@@ -172,7 +174,7 @@ export const getProgress = async ({
fatalErrorEncountered: errorExplanations.some(isFatalError),
currentTime: Date.now(),
renderSize,
- lambdasInvoked,
+ lambdasInvoked: lambdasInvokedStats.lambdasInvoked,
cleanup,
timeToFinishChunks: allChunks
? calculateChunkTimes({
@@ -181,5 +183,6 @@ export const getProgress = async ({
type: 'absolute-time',
})
: null,
+ timeToInvokeLambdas: lambdasInvokedStats.timeToInvokeLambdas,
};
};
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index c53dab5c89..d6f2dd1c9d 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -255,6 +255,7 @@ export type PostRenderData = {
timeToEncode: number;
timeToCleanUp: number;
timeToRenderChunks: number;
+ timeToInvokeLambdas: number;
};
export type CostsInfo = {
@@ -287,6 +288,7 @@ export type RenderProgress = {
lambdasInvoked: number;
cleanup: CleanupInfo | null;
timeToFinishChunks: number | null;
+ timeToInvokeLambdas: number | null;
};
export type LambdaAcl = 'public-read' | 'private';