Skip to content

πŸŽ₯ Make videos programmatically with React

does not work well anymore...

Jonny Burger04ca853c59a4
diff --git a/packages/lambda/src/cli/commands/render/progress.ts b/packages/lambda/src/cli/commands/render/progress.ts
index 1fc4dd5f48..3e644e6cf3 100644
--- a/packages/lambda/src/cli/commands/render/progress.ts
+++ b/packages/lambda/src/cli/commands/render/progress.ts
@@ -15,11 +15,11 @@ type LambdaInvokeProgress = {
};
type ChunkProgress = {
- totalChunks: number | null;
- chunksInvoked: number;
doneIn: number | null;
framesRendered: number;
totalFrames: number | null;
+ totalChunks: number | null;
+ chunksInvoked: number;
};
type MultiRenderProgress = {
@@ -61,25 +61,38 @@ const makeRenderProgress = ({
invokeProgress: LambdaInvokeProgress;
totalSteps: number;
}) => {
- const lambdaIsDone = invokeProgress.doneIn !== null;
const {chunksInvoked, totalChunks, doneIn} = chunkProgress;
- const progress = totalChunks === null ? 0 : chunksInvoked / totalChunks;
- const shouldShow = lambdaIsDone || progress > 0;
- if (!shouldShow) {
- return '';
- }
+ const renderProgress =
+ chunkProgress.totalFrames === null
+ ? 0
+ : chunkProgress.framesRendered / chunkProgress.totalFrames;
+ const encodingProgress =
+ totalChunks === null ? 0 : chunksInvoked / totalChunks;
- return [
+ const frames =
+ chunkProgress.totalFrames === null
+ ? `${chunkProgress.framesRendered}`
+ : `(${chunkProgress.framesRendered}/${chunkProgress.totalFrames})`;
+
+ const first = [
'🧩',
`(2/${totalSteps})`,
- CliInternals.makeProgressBar(progress),
- chunkProgress.totalFrames === null
- ? `${chunkProgress.framesRendered} frames`
- : `${chunkProgress.framesRendered}/${chunkProgress.totalFrames} frames`,
+ CliInternals.makeProgressBar(renderProgress),
+ doneIn === null ? 'Rendering frames' : 'Rendered frames',
+ doneIn === null ? frames : CliInternals.chalk.gray(`${doneIn}ms`),
+ ].join(' ');
+
+ const second = [
+ 'πŸ—οΈ',
+ `(3/${totalSteps})`,
+ CliInternals.makeProgressBar(encodingProgress),
+ `${doneIn === null ? 'Encoding' : 'Encoded'} chunks`,
doneIn === null
- ? `${Math.round(progress * 100)}%`
+ ? `${Math.round(encodingProgress * 100)}%`
: CliInternals.chalk.gray(`${doneIn}ms`),
].join(' ');
+
+ return [first, second];
};
const makeEncodingProgress = ({
@@ -101,7 +114,7 @@ const makeEncodingProgress = ({
return [
'πŸ“½ ',
- `(3/${totalSteps})`,
+ `(4/${totalSteps})`,
CliInternals.makeProgressBar(progress),
`${doneIn === null ? 'Combining' : 'Combined'} videos`,
doneIn === null
@@ -122,7 +135,7 @@ const makeCleanupProgress = (
if (skipped) {
return [
'πŸͺ£ ',
- `(4/${totalSteps})`,
+ `(5/${totalSteps})`,
CliInternals.chalk.blueBright(
`Not cleaning up because --log=verbose was set`
),
@@ -133,7 +146,7 @@ const makeCleanupProgress = (
const progress = filesDeleted / minFilesToDelete;
return [
'πŸͺ£ ',
- `(4/${totalSteps})`,
+ `(5/${totalSteps})`,
CliInternals.makeProgressBar(progress),
`${doneIn === null ? 'Cleaning up' : 'Cleaned up'} artifacts`,
doneIn === null
@@ -148,7 +161,7 @@ const makeDownloadProgress = (
) => {
return [
'πŸ’Ύ',
- `(5/${totalSteps})`,
+ `(6/${totalSteps})`,
downloadInfo.totalSize === null
? CliInternals.getFileSizeDownloadBar(downloadInfo.downloaded)
: CliInternals.makeProgressBar(
@@ -221,7 +234,7 @@ export const makeProgressString = ({
}) => {
return [
makeInvokeProgress(progress.lambdaInvokeProgress, steps, retriesInfo),
- makeRenderProgress({
+ ...makeRenderProgress({
chunkProgress: progress.chunkProgress,
invokeProgress: progress.lambdaInvokeProgress,
totalSteps: steps,
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index ef02851828..1c485e0f54 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -136,7 +136,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
: undefined,
});
- const totalSteps = downloadName ? 5 : 4;
+ const totalSteps = downloadName ? 6 : 5;
const progressBar = CliInternals.createOverwriteableCliOutput(
CliInternals.quietFlagProvided()
diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.ts
index c7eec4b89a..168105a8fc 100644
--- a/packages/lambda/src/functions/helpers/get-progress.ts
+++ b/packages/lambda/src/functions/helpers/get-progress.ts
@@ -28,6 +28,7 @@ import {getLambdasInvokedStats} from './get-lambdas-invoked-stats';
import {getOverallProgress} from './get-overall-progress';
import {getPostRenderData} from './get-post-render-data';
import {getRenderMetadata} from './get-render-metadata';
+import {getRenderedFramesProgress} from './get-rendered-frames-progress';
import {getRetryStats} from './get-retry-stats';
import {getTimeToFinish} from './get-time-to-finish';
import {inspectErrors} from './inspect-errors';
@@ -200,13 +201,15 @@ export const getProgress = async ({
});
const chunks = contents.filter((c) => c.Key?.startsWith(chunkKey(renderId)));
- const framesRendered = contents
- // TODO: Deduplicate attempts
- .filter((c) => c.Key?.startsWith(lambdaChunkInitializedPrefix(renderId)))
- .map((c) => {
- return getProgressOfChunk(c.ETag as string);
- })
- .reduce((a, b) => a + b, 0);
+ const framesRendered = renderMetadata
+ ? getRenderedFramesProgress({
+ contents,
+ everyNthFrame: renderMetadata.everyNthFrame,
+ frameRange: renderMetadata.frameRange,
+ framesPerLambda: renderMetadata.framesPerLambda,
+ renderId,
+ })
+ : 0;
console.log(
'etags',
contents
diff --git a/packages/lambda/src/functions/helpers/get-rendered-frames-progress.ts b/packages/lambda/src/functions/helpers/get-rendered-frames-progress.ts
index 4fbafd6307..194ab801fe 100644
--- a/packages/lambda/src/functions/helpers/get-rendered-frames-progress.ts
+++ b/packages/lambda/src/functions/helpers/get-rendered-frames-progress.ts
@@ -1,25 +1,42 @@
import type {_Object} from '@aws-sdk/client-s3';
import {getProgressOfChunk} from '../../shared/chunk-progress';
-import {chunkKey} from '../../shared/constants';
+import {chunkKey, lambdaChunkInitializedPrefix} from '../../shared/constants';
import {parseLambdaChunkKey} from '../../shared/parse-chunk-key';
import {parseLambdaInitializedKey} from '../../shared/parse-lambda-initialized-key';
+import {planFrameRanges} from '../chunk-optimization/plan-frame-ranges';
export const getRenderedFramesProgress = ({
contents,
renderId,
framesPerLambda,
+ everyNthFrame,
+ frameRange,
}: {
contents: _Object[];
renderId: string;
framesPerLambda: number;
+ frameRange: [number, number];
+ everyNthFrame: number;
}) => {
const chunkProgress: Record<number, number> = {};
- // Sort, so only the latest attempt is used
- const sortedChunks = contents.sort((a, b) => {
- return (a.Key as string).localeCompare(b.Key as string);
+ const {chunks} = planFrameRanges({
+ everyNthFrame,
+ frameRange,
+ framesPerLambda,
});
+ // Sort, so only the latest attempt is used
+ const sortedChunks = contents
+ .filter((c) => {
+ return (c.Key as string).startsWith(
+ lambdaChunkInitializedPrefix(renderId)
+ );
+ })
+ .sort((a, b) => {
+ return (a.Key as string).localeCompare(b.Key as string);
+ });
+
for (const chunk of sortedChunks) {
const key = parseLambdaInitializedKey(chunk.Key as string);
chunkProgress[key.chunk] = getProgressOfChunk(chunk.ETag as string);
@@ -29,8 +46,9 @@ export const getRenderedFramesProgress = ({
c.Key?.startsWith(chunkKey(renderId))
)) {
const parsed = parseLambdaChunkKey(chunk.Key as string);
- // TODO: What if it was the last chunk?
- chunkProgress[parsed.chunk] = framesPerLambda;
+ const frameRangeInChunk = chunks[parsed.chunk];
+ chunkProgress[parsed.chunk] =
+ frameRangeInChunk[1] - frameRangeInChunk[0] + 1;
}
const framesRendered = Object.values(chunkProgress).reduce(