π₯ Make videos programmatically with React
better calculation for time to encode
Jonny Burgeradc6b888b871
diff --git a/packages/lambda/src/cli/commands/render/progress.ts b/packages/lambda/src/cli/commands/render/progress.tsindex 3afd171fb1..660b2e07f8 100644--- a/packages/lambda/src/cli/commands/render/progress.ts+++ b/packages/lambda/src/cli/commands/render/progress.ts@@ -96,7 +96,7 @@ const makeEncodingProgress = ({chunkProgress,totalSteps,totalFrames,- timeToEncode: doneIn,+ timeToEncode,}: {encodingProgress: EncodingProgress;chunkProgress: ChunkProgress;@@ -116,10 +116,10 @@ const makeEncodingProgress = ({'π½ ',`(4/${totalSteps})`,CliInternals.makeProgressBar(progress),- `${doneIn === null ? 'Combining' : 'Combined'} videos`,- doneIn === null+ `${timeToEncode === null ? 'Combining' : 'Combined'} videos`,+ timeToEncode === null? `${Math.round(progress * 100)}%`- : CliInternals.chalk.gray(`${doneIn}ms`),+ : CliInternals.chalk.gray(`${timeToEncode}ms`),].join(' ');};@@ -221,7 +221,7 @@ export const makeProgressString = ({downloadInfo,retriesInfo,verbose,- timeToEncodeIn,+ timeToEncode,totalFrames,}: {progress: MultiRenderProgress;@@ -229,7 +229,7 @@ export const makeProgressString = ({downloadInfo: DownloadedInfo | null;retriesInfo: ChunkRetry[];verbose: boolean;- timeToEncodeIn: number | null;+ timeToEncode: number | null;totalFrames: number | null;}) => {return [@@ -242,7 +242,7 @@ export const makeProgressString = ({encodingProgress: progress.encodingProgress,chunkProgress: progress.chunkProgress,totalSteps: steps,- timeToEncode: timeToEncodeIn,+ timeToEncode,totalFrames,}),makeCleanupProgress(progress.cleanupInfo, steps, verbose),diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.tsindex f12e8c41a2..f70a1d54d4 100644--- a/packages/lambda/src/cli/commands/render/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -175,7 +175,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {retriesInfo: status.retriesInfo,verbose,totalFrames: getTotalFrames(status),- timeToEncodeIn: status.timeToEncode,+ timeToEncode: status.timeToEncode,}));@@ -196,7 +196,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {retriesInfo: newStatus.retriesInfo,downloadInfo: null,verbose,- timeToEncodeIn: newStatus.timeToEncode,+ timeToEncode: newStatus.timeToEncode,totalFrames: getTotalFrames(newStatus),}));@@ -209,7 +209,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {downloadInfo: null,retriesInfo: newStatus.retriesInfo,verbose,- timeToEncodeIn: newStatus.timeToEncode,+ timeToEncode: newStatus.timeToEncode,totalFrames: getTotalFrames(newStatus),}));@@ -232,7 +232,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {totalSize,},verbose,- timeToEncodeIn: newStatus.timeToEncode,+ timeToEncode: newStatus.timeToEncode,totalFrames: getTotalFrames(newStatus),}));@@ -249,7 +249,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {totalSize: sizeInBytes,},verbose,- timeToEncodeIn: newStatus.timeToEncode,+ timeToEncode: newStatus.timeToEncode,totalFrames: getTotalFrames(newStatus),}));diff --git a/packages/lambda/src/functions/helpers/concat-videos.ts b/packages/lambda/src/functions/helpers/concat-videos.tsindex 5aee063357..c4b2e367e7 100644--- a/packages/lambda/src/functions/helpers/concat-videos.ts+++ b/packages/lambda/src/functions/helpers/concat-videos.ts@@ -1,18 +1,10 @@import type {Codec, FfmpegExecutable} from '@remotion/renderer';import {combineVideos, RenderInternals} from '@remotion/renderer';-import fs, {- createWriteStream,- existsSync,- mkdirSync,- promises,- rmdirSync,- rmSync,-} from 'fs';+import fs, {createWriteStream, promises} from 'fs';import path, {join} from 'path';import type {AwsRegion} from '../../pricing/aws-regions';import {chunkKey,- CONCAT_FOLDER_TOKEN,getErrorKeyPrefix,REMOTION_CONCATED_TOKEN,REMOTION_FILELIST_TOKEN,@@ -65,7 +57,7 @@ const downloadS3File = async ({});};-const getAllFilesS3 = ({+export const getAllFilesS3 = ({bucket,expectedFiles,outdir,@@ -180,52 +172,26 @@ const getAllFilesS3 = ({};export const concatVideosS3 = async ({- bucket,- expectedFiles,onProgress,numberOfFrames,- renderId,- region,codec,- expectedBucketOwner,fps,numberOfGifLoops,ffmpegExecutable,remotionRoot,- onErrors,+ files,+ outdir,}: {- bucket: string;- expectedFiles: number;onProgress: (frames: number) => void;- onErrors: (errors: EnhancedErrorInfo[]) => Promise<void>;numberOfFrames: number;- renderId: string;- region: AwsRegion;codec: LambdaCodec;- expectedBucketOwner: string;fps: number;numberOfGifLoops: number | null;ffmpegExecutable: FfmpegExecutable;remotionRoot: string;+ files: string[];+ outdir: string;}) => {- const outdir = join(RenderInternals.tmpDir(CONCAT_FOLDER_TOKEN), 'bucket');- if (existsSync(outdir)) {- (rmSync ?? rmdirSync)(outdir, {- recursive: true,- });- }-- mkdirSync(outdir);- const files = await getAllFilesS3({- bucket,- expectedFiles,- outdir,- renderId,- region,- expectedBucketOwner,- onErrors,- });-const outfile = join(RenderInternals.tmpDir(REMOTION_CONCATED_TOKEN),'concat.' + RenderInternals.getFileExtensionFromCodec(codec, 'final')diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.tsindex 62decdcc02..0386ea6472 100644--- a/packages/lambda/src/functions/launch.ts+++ b/packages/lambda/src/functions/launch.ts@@ -1,12 +1,14 @@import {InvokeCommand} from '@aws-sdk/client-lambda';import {RenderInternals} from '@remotion/renderer';-import fs from 'fs';+import fs, {existsSync, mkdirSync, rmdirSync, rmSync} from 'fs';+import {join} from 'path';import {Internals} from 'remotion';import {VERSION} from 'remotion/version';import {getLambdaClient} from '../shared/aws-clients';import {cleanupSerializedInputProps} from '../shared/cleanup-serialized-input-props';import type {LambdaPayload, RenderMetadata} from '../shared/constants';import {+ CONCAT_FOLDER_TOKEN,encodingProgressKey,initalizedMetadataKey,LambdaRoutines,@@ -23,7 +25,7 @@ import {validateOutname} from '../shared/validate-outname';import {validatePrivacy} from '../shared/validate-privacy';import {planFrameRanges} from './chunk-optimization/plan-frame-ranges';import {bestFramesPerLambdaParam} from './helpers/best-frames-per-lambda-param';-import {concatVideosS3} from './helpers/concat-videos';+import {concatVideosS3, getAllFilesS3} from './helpers/concat-videos';import {createPostRenderData} from './helpers/create-post-render-data';import {cleanupFiles} from './helpers/delete-chunks';import {getExpectedOutName} from './helpers/expected-out-name';@@ -426,21 +428,34 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {const fps = comp.fps / params.everyNthFrame;- const encodingStart = Date.now();- const {outfile, cleanupChunksProm} = await concatVideosS3({+ const outdir = join(RenderInternals.tmpDir(CONCAT_FOLDER_TOKEN), 'bucket');+ if (existsSync(outdir)) {+ (rmSync ?? rmdirSync)(outdir, {+ recursive: true,+ });+ }++ mkdirSync(outdir);+ const files = await getAllFilesS3({bucket: params.bucketName,expectedFiles: chunkCount,- onProgress,- numberOfFrames: frameCount.length,+ outdir,renderId: params.renderId,region: getCurrentRegionInFunction(),- codec: params.codec,expectedBucketOwner: options.expectedBucketOwner,+ onErrors,+ });+ const encodingStart = Date.now();+ const {outfile, cleanupChunksProm} = await concatVideosS3({+ onProgress,+ numberOfFrames: frameCount.length,+ codec: params.codec,fps,numberOfGifLoops: params.numberOfGifLoops,ffmpegExecutable: null,remotionRoot: process.cwd(),- onErrors,+ files,+ outdir,});const encodingStop = Date.now();