Skip to content

🎥 Make videos programmatically with React

simplify

Jonny Burger8429d0bbe778
diff --git a/packages/lambda/src/functions/helpers/calculate-price-from-bucket.ts b/packages/lambda/src/functions/helpers/calculate-price-from-bucket.ts
index e3b94bf8c3..11143c9ff1 100644
--- a/packages/lambda/src/functions/helpers/calculate-price-from-bucket.ts
+++ b/packages/lambda/src/functions/helpers/calculate-price-from-bucket.ts
@@ -2,21 +2,17 @@ import {estimatePrice} from '../../api/estimate-price';
import type {RenderMetadata} from '../../shared/constants';
import type {ParsedTiming} from '../../shared/parse-lambda-timings-key';
import {calculateChunkTimes} from './calculate-chunk-times';
-import type {OutputFileMetadata} from './find-output-file-in-bucket';
import {getCurrentRegionInFunction} from './get-current-region';
-import {getTimeToFinish} from './get-time-to-finish';
export const estimatePriceFromBucket = ({
renderMetadata,
memorySizeInMb,
- outputFileMetadata,
diskSizeInMb,
lambdasInvoked,
timings,
}: {
renderMetadata: RenderMetadata | null;
memorySizeInMb: number;
- outputFileMetadata: OutputFileMetadata | null;
diskSizeInMb: number;
lambdasInvoked: number;
timings: ParsedTiming[];
@@ -25,16 +21,10 @@ export const estimatePriceFromBucket = ({
return null;
}
- const timeToFinish = getTimeToFinish({
- lastModified: outputFileMetadata?.lastModified ?? null,
- renderMetadata,
- });
-
- const elapsedTime =
- timeToFinish === null
- ? Math.max(0, Date.now() - (renderMetadata?.startedDate ?? 0))
- : timeToFinish;
-
+ const elapsedTime = Math.max(
+ 0,
+ Date.now() - (renderMetadata?.startedDate ?? 0),
+ );
const unfinished = Math.max(
0,
(renderMetadata?.totalChunks ?? 0) - timings.length,
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 891752c180..9f3e6486b4 100644
--- a/packages/lambda/src/functions/helpers/create-post-render-data.ts
+++ b/packages/lambda/src/functions/helpers/create-post-render-data.ts
@@ -9,7 +9,6 @@ import {
} from '../../shared/get-most-expensive-chunks';
import {calculateChunkTimes} from './calculate-chunk-times';
import type {OutputFileMetadata} from './find-output-file-in-bucket';
-import {getTimeToFinish} from './get-time-to-finish';
import type {OverallRenderProgress} from './overall-render-progress';
import type {EnhancedErrorInfo} from './write-lambda-error';
@@ -24,6 +23,7 @@ export const createPostRenderData = ({
outputFile,
timeToCombine,
overallProgress,
+ timeToFinish,
}: {
region: AwsRegion;
memorySizeInMb: number;
@@ -35,6 +35,7 @@ export const createPostRenderData = ({
outputFile: OutputFileMetadata;
timeToCombine: number | null;
overallProgress: OverallRenderProgress;
+ timeToFinish: number;
}): PostRenderData => {
const parsedTimings = overallProgress.timings;
@@ -58,15 +59,6 @@ export const createPostRenderData = ({
const endTime = Date.now();
- const timeToFinish = getTimeToFinish({
- renderMetadata,
- lastModified: endTime,
- });
-
- if (!timeToFinish) {
- throw new TypeError(`Cannot calculate timeToFinish value`);
- }
-
const renderSize = contents
.map((c) => c.Size ?? 0)
.reduce((a, b) => a + b, 0);
diff --git a/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts b/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts
index dc58accfd1..b77927b1fe 100644
--- a/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts
+++ b/packages/lambda/src/functions/helpers/find-output-file-in-bucket.ts
@@ -9,7 +9,6 @@ import {lambdaHeadCommand} from './io';
export type OutputFileMetadata = {
url: string;
size: number;
- lastModified: number;
};
export const findOutputFileInBucket = async ({
@@ -41,7 +40,6 @@ export const findOutputFileInBucket = async ({
customCredentials,
});
return {
- lastModified: head.LastModified?.getTime() as number,
size: head.ContentLength as number,
url: getOutputUrlFromMetadata(
renderMetadata,
diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.ts
index 5f9b6135bd..d93375d4b6 100644
--- a/packages/lambda/src/functions/helpers/get-progress.ts
+++ b/packages/lambda/src/functions/helpers/get-progress.ts
@@ -16,7 +16,6 @@ import {formatCostsInfo} from './format-costs-info';
import {getCurrentRegionInFunction} from './get-current-region';
import {getOverallProgress} from './get-overall-progress';
import {getOverallProgressS3} from './get-overall-progress-s3';
-import {getTimeToFinish} from './get-time-to-finish';
import {inspectErrors} from './inspect-errors';
import {lambdaLs} from './io';
import {makeTimeoutError} from './make-timeout-error';
@@ -150,7 +149,6 @@ export const getProgress = async ({
const priceFromBucket = estimatePriceFromBucket({
renderMetadata,
memorySizeInMb,
- outputFileMetadata: outputFile,
lambdasInvoked: renderMetadata?.estimatedRenderLambdaInvokations ?? 0,
// We cannot determine the ephemeral storage size, so we
// overestimate the price, but will only have a miniscule effect (~0.2%)
@@ -168,11 +166,6 @@ export const getProgress = async ({
filesDeleted: 0,
};
- const timeToFinish = getTimeToFinish({
- lastModified: outputFile?.lastModified ?? null,
- renderMetadata,
- });
-
const chunkMultiplier = [hasAudio, hasVideo].filter(truthy).length;
const allChunks =
@@ -242,7 +235,7 @@ export const getProgress = async ({
renderMetadata,
bucket: bucketName,
outputFile: outputFile?.url ?? null,
- timeToFinish,
+ timeToFinish: null,
errors: allErrors,
fatalErrorEncountered: allErrors.some((f) => f.isFatal && !f.willRetry),
currentTime: Date.now(),
diff --git a/packages/lambda/src/functions/helpers/get-time-to-finish.ts b/packages/lambda/src/functions/helpers/get-time-to-finish.ts
deleted file mode 100644
index 1eadf77680..0000000000
--- a/packages/lambda/src/functions/helpers/get-time-to-finish.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import type {RenderMetadata} from '../../defaults';
-
-export const getTimeToFinish = ({
- renderMetadata,
- lastModified,
-}: {
- renderMetadata: RenderMetadata | null;
- lastModified: number | null;
-}) => {
- if (!lastModified) {
- return null;
- }
-
- if (!renderMetadata) {
- return null;
- }
-
- return Math.max(0, lastModified - renderMetadata.startedDate);
-};
diff --git a/packages/lambda/src/functions/helpers/merge-chunks.ts b/packages/lambda/src/functions/helpers/merge-chunks.ts
index f33b1c6f11..57682abbd4 100644
--- a/packages/lambda/src/functions/helpers/merge-chunks.ts
+++ b/packages/lambda/src/functions/helpers/merge-chunks.ts
@@ -50,6 +50,7 @@ export const mergeChunksAndFinishRender = async (options: {
outdir: string;
files: string[];
overallProgress: OverallProgressHelper;
+ startTime: number;
}): Promise<PostRenderData> => {
const onProgress = (framesEncoded: number) => {
options.overallProgress.setCombinedFrames(framesEncoded);
@@ -146,12 +147,12 @@ export const mergeChunksAndFinishRender = async (options: {
])
).reduce((a, b) => a + b, 0),
outputFile: {
- lastModified: Date.now(),
size: outputSize.size,
url: outputUrl,
},
timeToCombine: encodingStop - encodingStart,
overallProgress: options.overallProgress.get(),
+ timeToFinish: Date.now() - options.startTime,
});
options.overallProgress.setPostRenderData(postRenderData);
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index ee8234d1aa..64853d7571 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -100,6 +100,7 @@ const innerLaunchHandler = async ({
'Validating composition, input props:',
serializedInputPropsWithCustomSchema,
);
+ const startTime = Date.now();
const comp = await validateComposition({
serveUrl: params.serveUrl,
composition: params.composition,
@@ -389,6 +390,7 @@ const innerLaunchHandler = async ({
outdir,
files: files.sort(),
overallProgress,
+ startTime,
});
return postRenderData;
diff --git a/packages/lambda/src/test/unit/price-calculation.test.ts b/packages/lambda/src/test/unit/price-calculation.test.ts
index 0badf09dcd..eb05e086fe 100644
--- a/packages/lambda/src/test/unit/price-calculation.test.ts
+++ b/packages/lambda/src/test/unit/price-calculation.test.ts
@@ -48,11 +48,6 @@ test('Should not throw while calculating prices when time shifts occur', () => {
numberOfGifLoops: null,
muted: false,
},
- outputFileMetadata: {
- url: 'out.mp4',
- lastModified: Date.now() - 2000,
- size: 1000000,
- },
diskSizeInMb: 512,
lambdasInvoked: 1,
timings: [