🎥 Make videos programmatically with React
inline post render data
Jonny Burger176249c288af
diff --git a/packages/lambda/src/functions/helpers/get-post-render-data.ts b/packages/lambda/src/functions/helpers/get-post-render-data.tsdeleted file mode 100644index 9d24eff965..0000000000--- a/packages/lambda/src/functions/helpers/get-post-render-data.ts+++ /dev/null@@ -1,30 +0,0 @@-import type {AwsRegion} from '../../pricing/aws-regions';-import type {PostRenderData} from '../../shared/constants';-import {postRenderDataKey} from '../../shared/constants';-import {streamToString} from '../../shared/stream-to-string';-import {lambdaReadFile} from './io';--export const getPostRenderData = async ({- bucketName,- renderId,- region,- expectedBucketOwner,-}: {- bucketName: string;- renderId: string;- region: AwsRegion;- expectedBucketOwner: string;-}): Promise<PostRenderData | null> => {- try {- const data = await lambdaReadFile({- bucketName,- key: postRenderDataKey(renderId),- region,- expectedBucketOwner,- });- return JSON.parse(await streamToString(data)) as PostRenderData;- } catch (err) {- // Does not exist- return null;- }-};diff --git a/packages/lambda/src/functions/helpers/get-progress.ts b/packages/lambda/src/functions/helpers/get-progress.tsindex c5ac772b7a..4ffa8cd0fe 100644--- a/packages/lambda/src/functions/helpers/get-progress.ts+++ b/packages/lambda/src/functions/helpers/get-progress.ts@@ -19,7 +19,6 @@ import {getCleanupProgress} from './get-cleanup-progress';import {getCurrentRegionInFunction} from './get-current-region';import {getOverallProgress} from './get-overall-progress';import {getOverallProgressS3} from './get-overall-progress-s3';-import {getPostRenderData} from './get-post-render-data';import {getRenderMetadata} from './get-render-metadata';import {getTimeToFinish} from './get-time-to-finish';import {inspectErrors} from './inspect-errors';@@ -45,70 +44,70 @@ export const getProgress = async ({timeoutInMilliseconds: number;customCredentials: CustomCredentials | null;}): Promise<RenderProgress> => {- const postRenderData = await getPostRenderData({- bucketName,- region,+ const overallProgress = await getOverallProgressS3({renderId,+ bucketName,expectedBucketOwner,});- if (postRenderData) {+ if (overallProgress?.postRenderData) {const outData = getExpectedOutName(- postRenderData.renderMetadata,+ overallProgress.postRenderData.renderMetadata,bucketName,customCredentials,);const totalFrameCount =- postRenderData.renderMetadata.type === 'still'+ overallProgress.postRenderData.renderMetadata.type === 'still'? 1: RenderInternals.getFramesToRender(- postRenderData.renderMetadata.frameRange,- postRenderData.renderMetadata.everyNthFrame,+ overallProgress.postRenderData.renderMetadata.frameRange,+ overallProgress.postRenderData.renderMetadata.everyNthFrame,).length;return {framesRendered: totalFrameCount,bucket: bucketName,- renderSize: postRenderData.renderSize,- chunks: postRenderData.renderMetadata.totalChunks,+ renderSize: overallProgress.postRenderData.renderSize,+ chunks: overallProgress.postRenderData.renderMetadata.totalChunks,cleanup: {- doneIn: postRenderData.timeToCleanUp,- filesDeleted: postRenderData.filesCleanedUp,- minFilesToDelete: postRenderData.filesCleanedUp,+ doneIn: overallProgress.postRenderData.timeToCleanUp,+ filesDeleted: overallProgress.postRenderData.filesCleanedUp,+ minFilesToDelete: overallProgress.postRenderData.filesCleanedUp,},costs: {- accruedSoFar: postRenderData.cost.estimatedCost,- displayCost: postRenderData.cost.estimatedDisplayCost,- currency: postRenderData.cost.currency,- disclaimer: postRenderData.cost.disclaimer,+ accruedSoFar: overallProgress.postRenderData.cost.estimatedCost,+ displayCost: overallProgress.postRenderData.cost.estimatedDisplayCost,+ currency: overallProgress.postRenderData.cost.currency,+ disclaimer: overallProgress.postRenderData.cost.disclaimer,},currentTime: Date.now(),done: true,encodingStatus: {framesEncoded: totalFrameCount,combinedFrames: totalFrameCount,- timeToCombine: postRenderData.timeToCombine,+ timeToCombine: overallProgress.postRenderData.timeToCombine,},- errors: postRenderData.errors,+ errors: overallProgress.postRenderData.errors,fatalErrorEncountered: false,- lambdasInvoked: postRenderData.renderMetadata.totalChunks,- outputFile: postRenderData.outputFile,+ lambdasInvoked: overallProgress.postRenderData.renderMetadata.totalChunks,+ outputFile: overallProgress.postRenderData.outputFile,renderId,- renderMetadata: postRenderData.renderMetadata,- timeToFinish: postRenderData.timeToFinish,- timeToFinishChunks: postRenderData.timeToRenderChunks,+ renderMetadata: overallProgress.postRenderData.renderMetadata,+ timeToFinish: overallProgress.postRenderData.timeToFinish,+ timeToFinishChunks: overallProgress.postRenderData.timeToRenderChunks,overallProgress: 1,- retriesInfo: postRenderData.retriesInfo,+ retriesInfo: overallProgress.postRenderData.retriesInfo,outKey: outData.key,outBucket: outData.renderBucketName,- mostExpensiveFrameRanges: postRenderData.mostExpensiveFrameRanges ?? null,- timeToEncode: postRenderData.timeToEncode,- outputSizeInBytes: postRenderData.outputSize,+ mostExpensiveFrameRanges:+ overallProgress.postRenderData.mostExpensiveFrameRanges ?? null,+ timeToEncode: overallProgress.postRenderData.timeToEncode,+ outputSizeInBytes: overallProgress.postRenderData.outputSize,type: 'success',estimatedBillingDurationInMilliseconds:- postRenderData.estimatedBillingDurationInMilliseconds,- timeToCombine: postRenderData.timeToCombine,+ overallProgress.postRenderData.estimatedBillingDurationInMilliseconds,+ timeToCombine: overallProgress.postRenderData.timeToCombine,combinedFrames: totalFrameCount,};}@@ -193,12 +192,6 @@ export const getProgress = async ({const chunkMultiplier = [hasAudio, hasVideo].filter(truthy).length;- const overallProgress = await getOverallProgressS3({- renderId,- bucketName,- expectedBucketOwner,- });-const allChunks =(overallProgress?.chunks ?? []).length / chunkMultiplier ===(renderMetadata?.totalChunks ?? Infinity);diff --git a/packages/lambda/src/functions/helpers/merge-chunks.ts b/packages/lambda/src/functions/helpers/merge-chunks.tsindex 7206ed3455..1c4bd78417 100644--- a/packages/lambda/src/functions/helpers/merge-chunks.ts+++ b/packages/lambda/src/functions/helpers/merge-chunks.ts@@ -24,7 +24,6 @@ import {inspectErrors} from './inspect-errors';import {lambdaDeleteFile, lambdaLs, lambdaWriteFile} from './io';import type {OverallProgressHelper} from './overall-render-progress';import {timer} from './timer';-import {writePostRenderData} from './write-post-render-data';export const mergeChunksAndFinishRender = async (options: {bucketName: string;@@ -174,13 +173,7 @@ export const mergeChunksAndFinishRender = async (options: {overallProgress: options.overallProgress.get(),});- await writePostRenderData({- bucketName: options.bucketName,- expectedBucketOwner: options.expectedBucketOwner,- postRenderData,- region: getCurrentRegionInFunction(),- renderId: options.renderId,- });+ options.overallProgress.setPostRenderData(postRenderData);await lambdaDeleteFile({bucketName: options.bucketName,key: initalizedMetadataKey(options.renderId),diff --git a/packages/lambda/src/functions/helpers/overall-render-progress.ts b/packages/lambda/src/functions/helpers/overall-render-progress.tsindex 850926c157..f3a3149490 100644--- a/packages/lambda/src/functions/helpers/overall-render-progress.ts+++ b/packages/lambda/src/functions/helpers/overall-render-progress.ts@@ -1,4 +1,5 @@import type {AwsRegion} from '../../client';+import type {PostRenderData} from '../../shared/constants';import {overallProgressKey} from '../../shared/constants';import type {ChunkRetry} from './get-retry-stats';import {lambdaWriteFile} from './io';@@ -11,6 +12,7 @@ export type OverallRenderProgress = {timeToCombine: number | null;lambdasInvoked: number;retries: ChunkRetry[];+ postRenderData: PostRenderData | null;};export type OverallProgressHelper = {@@ -29,6 +31,7 @@ export type OverallProgressHelper = {setCombinedFrames: (framesEncoded: number) => void;setTimeToCombine: (timeToCombine: number) => void;addRetry: (retry: ChunkRetry) => void;+ setPostRenderData: (postRenderData: PostRenderData) => void;get: () => OverallRenderProgress;};@@ -57,6 +60,7 @@ export const makeOverallRenderProgress = ({timeToCombine: null,lambdasInvoked: 0,retries: [],+ postRenderData: null,};let currentUploadPromise: Promise<void> | null = null;@@ -128,6 +132,10 @@ export const makeOverallRenderProgress = ({renderProgress.lambdasInvoked = lambdasInvoked.reduce((a, b) => a + b, 0);upload();},+ setPostRenderData(postRenderData) {+ renderProgress.postRenderData = postRenderData;+ upload();+ },addRetry(retry) {renderProgress.retries.push(retry);upload();diff --git a/packages/lambda/src/functions/helpers/write-post-render-data.ts b/packages/lambda/src/functions/helpers/write-post-render-data.tsdeleted file mode 100644index 001a304f28..0000000000--- a/packages/lambda/src/functions/helpers/write-post-render-data.ts+++ /dev/null@@ -1,29 +0,0 @@-import type {AwsRegion} from '../../pricing/aws-regions';-import type {PostRenderData} from '../../shared/constants';-import {postRenderDataKey} from '../../shared/constants';-import {lambdaWriteFile} from './io';--export const writePostRenderData = async ({- bucketName,- renderId,- postRenderData,- expectedBucketOwner,- region,-}: {- bucketName: string;- renderId: string;- postRenderData: PostRenderData;- expectedBucketOwner: string;- region: AwsRegion;-}) => {- await lambdaWriteFile({- bucketName,- key: postRenderDataKey(renderId),- privacy: 'private',- body: JSON.stringify(postRenderData),- expectedBucketOwner,- region,- downloadBehavior: null,- customCredentials: null,- });-};diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.tsindex 0b516ae81b..961a840900 100644--- a/packages/lambda/src/shared/constants.ts+++ b/packages/lambda/src/shared/constants.ts@@ -156,10 +156,6 @@ export const customOutName = (};};-export const postRenderDataKey = (renderId: string) => {- return `${rendersPrefix(renderId)}/post-render-metadata.json`;-};-export const defaultPropsKey = (hash: string) => {return `default-props/${hash}.json`;};