π₯ Make videos programmatically with React
new logger
Jonny Burger5b53e112cacb
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex a2988ef942..8ef7da63b5 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -267,8 +267,6 @@ export const benchmarkCommand = async (onProgress: () => undefined,indentOutput: false,logLevel,- bundlingStep: 0,- steps: 1,onDirectoryCreated: (dir) => {registerCleanupJob(() => RenderInternals.deleteDirectory(dir));},diff --git a/packages/cli/src/bundle.ts b/packages/cli/src/bundle.tsindex 42e500c6d0..fc181ed02b 100644--- a/packages/cli/src/bundle.ts+++ b/packages/cli/src/bundle.ts@@ -97,11 +97,9 @@ export const bundleCommand = async (fullPath: file,logLevel,onDirectoryCreated: () => {},- bundlingStep: 0,indent: false,quietProgress: updatesDontOverwrite,publicDir,- steps: 1,remotionRoot,onProgressCallback: ({bundling, copying}) => {// Handle floating point inaccuraciesdiff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 844104e1f7..ade713015a 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -105,8 +105,6 @@ export const listCompositionsCommand = async (onProgress: () => undefined,indentOutput: false,logLevel,- bundlingStep: 0,- steps: 1,onDirectoryCreated: (dir) => {registerCleanupJob(() => RenderInternals.deleteDirectory(dir));},diff --git a/packages/cli/src/eta-string.ts b/packages/cli/src/eta-string.tsnew file mode 100644index 0000000000..e9702ea570--- /dev/null+++ b/packages/cli/src/eta-string.ts@@ -0,0 +1,20 @@+import {truthy} from './truthy';++export const formatEtaString = (timeRemainingInMilliseconds: number) => {+ // Get render estimated time value and extract hours, minutes, and seconds+ const remainingTime = timeRemainingInMilliseconds / 1000;+ const remainingTimeHours = Math.floor(remainingTime / 3600);+ const remainingTimeMinutes = Math.round((remainingTime % 3600) / 60);+ const remainingTimeSeconds = Math.round(remainingTime % 60);++ // Create estimated time string by concatenating them with colons+ const estimatedTimeString = [+ remainingTimeHours ? `${remainingTimeHours}h` : null,+ remainingTimeMinutes ? remainingTimeMinutes + 'm' : null,+ `${remainingTimeSeconds}s`,+ ]+ .filter(truthy)+ .join(' ');++ return estimatedTimeString;+};diff --git a/packages/cli/src/make-progress-bar.ts b/packages/cli/src/make-progress-bar.tsindex fa527534e7..2018edac68 100644--- a/packages/cli/src/make-progress-bar.ts+++ b/packages/cli/src/make-progress-bar.ts@@ -2,7 +2,7 @@ const full = 'β';const half = 'β΄';export const makeProgressBar = (percentage: number) => {- const totalBars = 20;+ const totalBars = 18;const barsToShow = Math.floor(percentage * totalBars);const extraBar = (percentage * totalBars) % barsToShow;diff --git a/packages/cli/src/progress-bar.ts b/packages/cli/src/progress-bar.tsindex 10a47ec975..d1e4fb14a8 100644--- a/packages/cli/src/progress-bar.ts+++ b/packages/cli/src/progress-bar.ts@@ -1,4 +1,4 @@-import type {CancelSignal} from '@remotion/renderer';+import type {CancelSignal, LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';import type {AggregateRenderProgress,@@ -13,12 +13,16 @@ import {getFileSizeDownloadBar,makeMultiDownloadProgress,} from './download-progress';+import {formatEtaString} from './eta-string';+import {Log} from './log';import {makeProgressBar} from './make-progress-bar';import {truthy} from './truthy';export type OverwriteableCliOutput = {update: (up: string, newline: boolean) => boolean;};+const LABEL_WIDTH = 22;+export const createOverwriteableCliOutput = (options: {quiet: boolean;cancelSignal: CancelSignal | null;@@ -81,19 +85,14 @@ export const createOverwriteableCliOutput = (options: {const makeBundlingProgress = ({bundlingState,- bundlingStep,- steps,}: {bundlingState: BundlingState;- bundlingStep: number;- steps: number;}) => {const {doneIn, progress} = bundlingState;return [- `(${bundlingStep + 1}/${steps})`,+ `${doneIn ? 'Bundled' : 'Bundling'} code`.padStart(LABEL_WIDTH, ' '),makeProgressBar(progress),- `${doneIn ? 'Bundled' : 'Bundling'} code`,doneIn === null? (progress * 100).toFixed(0) + '%': chalk.gray(`${doneIn}ms`),@@ -111,7 +110,7 @@ const makeCopyingProgress = (options: CopyingState) => {return [' +',options.doneIn ? makeProgressBar(1) : getFileSizeDownloadBar(options.bytes),- 'Copying public dir',+ 'Copying public dir'.padStart(LABEL_WIDTH, ' '),options.doneIn === null ? null : chalk.gray(`${options.doneIn}ms`),].filter(truthy)@@ -141,24 +140,18 @@ const makeSymlinkProgress = (options: SymbolicLinksState) => {export type SymbolicLinksState = {symlinks: string[]};-export const makeBundlingAndCopyProgress = (- {- bundling,- copying,- symLinks,- }: {- bundling: BundlingState;- copying: CopyingState;- symLinks: SymbolicLinksState;- },- bundlingStep: number,- steps: number,-) => {+export const makeBundlingAndCopyProgress = ({+ bundling,+ copying,+ symLinks,+}: {+ bundling: BundlingState;+ copying: CopyingState;+ symLinks: SymbolicLinksState;+}) => {return [makeBundlingProgress({bundlingState: bundling,- bundlingStep,- steps,}),makeCopyingProgress(copying),makeSymlinkProgress(symLinks),@@ -170,18 +163,28 @@ export const makeBundlingAndCopyProgress = (const makeRenderingProgress = ({frames,totalFrames,- steps,- concurrency,doneIn,+ timeRemainingInMilliseconds,}: RenderingProgressInput) => {const progress = frames / totalFrames;return [- `(${steps.indexOf('rendering') + 1}/${steps.length})`,- makeProgressBar(progress),- [doneIn ? 'Rendered' : 'Rendering', `frames (${concurrency}x)`]+ [doneIn ? 'Rendered' : 'Rendering', totalFrames === 1 ? 'still' : 'frames'].filter(truthy)- .join(' '),- doneIn === null ? `${frames}/${totalFrames}` : chalk.gray(`${doneIn}ms`),+ .join(' ')+ .padStart(LABEL_WIDTH, ' '),+ makeProgressBar(progress),+ doneIn === null+ ? [+ `${String(frames).padStart(String(totalFrames).length, ' ')}/${totalFrames}`,+ timeRemainingInMilliseconds+ ? chalk.gray(+ `${formatEtaString(timeRemainingInMilliseconds)} remaining`,+ )+ : null,+ ]+ .filter(truthy)+ .join(' ')+ : chalk.gray(`${doneIn}ms`),].filter(truthy).join(' ');@@ -189,13 +192,9 @@ const makeRenderingProgress = ({const makeStitchingProgress = ({stitchingProgress,- steps,- stitchingStep,isUsingParallelEncoding,}: {stitchingProgress: StitchingProgressInput;- steps: number;- stitchingStep: number;isUsingParallelEncoding: boolean;}) => {const {frames, totalFrames, doneIn, stage, codec} = stitchingProgress;@@ -208,12 +207,14 @@ const makeStitchingProgress = ({: 'video';return [- `(${stitchingStep + 1}/${steps})`,- makeProgressBar(progress),- stage === 'muxing' && isUsingParallelEncoding+ (stage === 'muxing' && isUsingParallelEncoding? `${doneIn ? 'Muxed' : 'Muxing'} ${mediaType}`- : `${doneIn ? 'Encoded' : 'Encoding'} ${mediaType}`,- doneIn === null ? `${frames}/${totalFrames}` : chalk.gray(`${doneIn}ms`),+ : `${doneIn ? 'Encoded' : 'Encoding'} ${mediaType}`+ ).padStart(LABEL_WIDTH, ' '),+ makeProgressBar(progress),+ doneIn === null+ ? `${String(frames).padStart(String(totalFrames).length, ' ')}/${totalFrames}`+ : chalk.gray(`${doneIn}ms`),].filter(truthy).join(' ');@@ -221,13 +222,9 @@ const makeStitchingProgress = ({export const makeRenderingAndStitchingProgress = ({prog,- steps,- stitchingStep,isUsingParallelEncoding,}: {prog: AggregateRenderProgress;- steps: number;- stitchingStep: number;isUsingParallelEncoding: boolean;}): {output: string;@@ -242,8 +239,6 @@ export const makeRenderingAndStitchingProgress = ({? null: makeStitchingProgress({stitchingProgress: stitching,- steps,- stitchingStep,isUsingParallelEncoding,}),]@@ -287,32 +282,47 @@ const getGuiProgressSubtitle = (progress: AggregateRenderProgress): string => {}// Get render estimated time value and extract hours, minutes, and seconds- const {renderEstimatedTime} = progress.rendering;- const remainingTime = renderEstimatedTime / 1000;- const remainingTimeHours = Math.floor(remainingTime / 3600);- const remainingTimeMinutes = Math.round((remainingTime % 3600) / 60);- const remainingTimeSeconds = Math.round(remainingTime % 60);+ const {timeRemainingInMilliseconds} = progress.rendering;// Create estimated time string by concatenating them with colonsconst estimatedTimeString =- remainingTime < 1- ? '<1s'- : [- remainingTimeHours ? `${remainingTimeHours}h` : null,- remainingTimeMinutes ? remainingTimeMinutes + 'm' : null,- `${remainingTimeSeconds}s`,- ]- .filter(truthy)- .join(' ');+ timeRemainingInMilliseconds === null+ ? null+ : formatEtaString(timeRemainingInMilliseconds);const allRendered =progress.rendering.frames === progress.rendering.totalFrames;if (!allRendered || !progress.stitching || progress.stitching.frames === 0) {const etaString =- remainingTime > 0 ? `, time remaining: ${estimatedTimeString}` : '';+ timeRemainingInMilliseconds && timeRemainingInMilliseconds > 0+ ? `, time remaining: ${estimatedTimeString}`+ : '';return `Rendered ${progress.rendering.frames}/${progress.rendering.totalFrames}${etaString}`;}return `Stitched ${progress.stitching.frames}/${progress.stitching.totalFrames}`;};++export const printFact =+ (printLevel: LogLevel) =>+ ({+ indent,+ logLevel,+ left,+ right,+ }: {+ indent: boolean;+ logLevel: LogLevel;+ left: string;+ right: string;+ }) => {+ if (RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose')) {+ Log[printLevel]({indent, logLevel}, chalk.gray(`${left} = ${right}`));++ return;+ }++ const leftPadded = left.padStart(LABEL_WIDTH, ' ');+ Log[printLevel]({indent, logLevel}, chalk.gray(`${leftPadded} ${right}`));+ };diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.tsindex e5c2441fff..b46953d456 100644--- a/packages/cli/src/render-flows/render.ts+++ b/packages/cli/src/render-flows/render.ts@@ -25,7 +25,6 @@ import type {CopyingState,DownloadProgress,JobProgressCallback,- RenderStep,RenderingProgressInput,StitchingProgressInput,} from '@remotion/studio-server';@@ -46,6 +45,7 @@ import {parsedCli, quietFlagProvided} from '../parsed-cli';import {createOverwriteableCliOutput,makeRenderingAndStitchingProgress,+ printFact,} from '../progress-bar';import {bundleOnCliOrTakeServeUrl} from '../setup-cache';import {shouldUseNonOverlayingLogger} from '../should-use-non-overlaying-logger';@@ -159,6 +159,16 @@ export const renderVideoFlow = async ({separateAudioTo: string | null;publicPath: string | null;}) => {+ const isVerbose = RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose');++ printFact('verbose')({+ indent,+ logLevel,+ left: 'Entry point',+ right: [fullEntryPoint, isVerbose ? `(${entryPointReason})` : null]+ .filter(truthy)+ .join(' '),+ });const downloads: DownloadProgress[] = [];const onBrowserDownload = defaultBrowserDownloadProgress({indent,@@ -194,12 +204,6 @@ export const renderVideoFlow = async ({indent,});- const steps: RenderStep[] = [- RenderInternals.isServeUrl(fullEntryPoint) ? null : ('bundling' as const),- 'rendering' as const,- shouldOutputImageSequence ? null : ('stitching' as const),- ].filter(truthy);-let bundlingProgress: BundlingState = {doneIn: null,progress: 0,@@ -229,8 +233,6 @@ export const renderVideoFlow = async ({const {output, message, progress} = makeRenderingAndStitchingProgress({prog: aggregateRenderProgress,- steps: steps.length,- stitchingStep: steps.indexOf('stitching'),isUsingParallelEncoding,});onProgress({message, value: progress, ...aggregateRenderProgress});@@ -252,8 +254,6 @@ export const renderVideoFlow = async ({},indentOutput: indent,logLevel,- bundlingStep: steps.indexOf('bundling'),- steps: steps.length,onDirectoryCreated: (dir) => {addCleanupCallback(() => RenderInternals.deleteDirectory(dir));},@@ -357,16 +357,34 @@ export const renderVideoFlow = async ({logLevel,});- Log.verbose(- {indent, logLevel},- chalk.gray(`Entry point = ${fullEntryPoint} (${entryPointReason})`),- );- Log.info(- {indent, logLevel},- chalk.gray(- `Composition = ${compositionId} (${reason}), Codec = ${codec} (${codecReason}), Output = ${relativeOutputLocation}`,- ),- );+ printFact('info')({+ indent,+ logLevel,+ left: 'Composition',+ right: [compositionId, isVerbose ? `(${reason})` : null]+ .filter(truthy)+ .join(' '),+ });+ printFact('info')({+ indent,+ logLevel,+ left: 'Codec',+ right: [codec, isVerbose ? `(${codecReason})` : null]+ .filter(truthy)+ .join(' '),+ });+ printFact('info')({+ indent,+ logLevel,+ left: 'Output',+ right: relativeOutputLocation,+ });+ printFact('info')({+ indent,+ logLevel,+ left: 'Concurrency',+ right: `${actualConcurrency}x`,+ });const absoluteOutputFile = getAndValidateAbsoluteOutputFile(relativeOutputLocation,@@ -393,10 +411,8 @@ export const renderVideoFlow = async ({renderingProgress = {frames: 0,totalFrames: totalFrames.length,- concurrency: actualConcurrency,doneIn: null,- renderEstimatedTime: 0,- steps,+ timeRemainingInMilliseconds: null,};const imageFormat = getVideoImageFormat({@@ -523,8 +539,9 @@ export const renderVideoFlow = async ({update.renderedDoneIn;(renderingProgress as RenderingProgressInput).frames =update.renderedFrames;- (renderingProgress as RenderingProgressInput).renderEstimatedTime =- update.renderEstimatedTime;+ (+ renderingProgress as RenderingProgressInput+ ).timeRemainingInMilliseconds = update.renderEstimatedTime;updateRenderProgress({newline: false, printToConsole: true});},puppeteerInstance,@@ -554,6 +571,9 @@ export const renderVideoFlow = async ({compositionStart: 0,onBrowserDownload,});+ if (!updatesDontOverwrite) {+ updateRenderProgress({newline: true, printToConsole: true});+ }Log.info({indent, logLevel},diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.tsindex 75937cdf19..915612ad6c 100644--- a/packages/cli/src/render-flows/still.ts+++ b/packages/cli/src/render-flows/still.ts@@ -13,7 +13,6 @@ import {RenderInternals} from '@remotion/renderer';import type {AggregateRenderProgress,JobProgressCallback,- RenderStep,} from '@remotion/studio-server';import {existsSync, mkdirSync} from 'node:fs';import path from 'node:path';@@ -32,6 +31,7 @@ import type {OverwriteableCliOutput} from '../progress-bar';import {createOverwriteableCliOutput,makeRenderingAndStitchingProgress,+ printFact,} from '../progress-bar';import {initialAggregateRenderProgress} from '../progress-types';import {bundleOnCliOrTakeServeUrl} from '../setup-cache';@@ -103,6 +103,12 @@ export const renderStillFlow = async ({binariesDirectory: string | null;publicPath: string | null;}) => {+ const isVerbose = RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose');+ Log.verbose(+ {indent, logLevel},+ chalk.gray(`Entry point = ${fullEntryPoint} (${entryPointReason})`),+ );+const aggregate: AggregateRenderProgress = initialAggregateRenderProgress();const updatesDontOverwrite = shouldUseNonOverlayingLogger({logLevel});@@ -113,11 +119,6 @@ export const renderStillFlow = async ({indent,});- const steps: RenderStep[] = [- RenderInternals.isServeUrl(fullEntryPoint) ? null : ('bundling' as const),- 'rendering' as const,- ].filter(truthy);-const updateRenderProgress = ({newline,printToConsole,@@ -129,8 +130,6 @@ export const renderStillFlow = async ({}) => {const {output, progress, message} = makeRenderingAndStitchingProgress({prog: aggregate,- steps: steps.length,- stitchingStep: steps.indexOf('stitching'),isUsingParallelEncoding,});if (printToConsole) {@@ -168,7 +167,6 @@ export const renderStillFlow = async ({{fullPath: fullEntryPoint,remotionRoot,- steps: steps.length,publicDir,onProgress: ({copying, bundling}) => {aggregate.bundling = bundling;@@ -181,7 +179,6 @@ export const renderStillFlow = async ({},indentOutput: indent,logLevel,- bundlingStep: steps.indexOf('bundling'),onDirectoryCreated: (dir) => {registerCleanupJob(() => {RenderInternals.deleteDirectory(dir);@@ -271,26 +268,36 @@ export const renderStillFlow = async ({recursive: true,});- Log.verbose(- {indent, logLevel},- chalk.gray(`Entry point = ${fullEntryPoint} (${entryPointReason})`),- );- Log.info(- {indent, logLevel},- chalk.gray(- `Composition = ${compositionId} (${reason}), Format = ${imageFormat} (${source}), Output = ${relativeOutputLocation}`,- ),- );+ printFact('info')({+ indent,+ left: 'Composition',+ logLevel,+ right: [compositionId, isVerbose ? `(${reason})` : null]+ .filter(truthy)+ .join(' '),+ });+ printFact('info')({+ indent,+ left: 'Format',+ logLevel,+ right: [imageFormat, isVerbose ? `(${source})` : null]+ .filter(truthy)+ .join(' '),+ });+ printFact('info')({+ indent,+ left: 'Output',+ logLevel,+ right: relativeOutputLocation,+ });const renderStart = Date.now();aggregate.rendering = {frames: 0,- concurrency: 1,doneIn: null,- steps,- renderEstimatedTime: 0,totalFrames: 1,+ timeRemainingInMilliseconds: null,};updateRenderProgress({@@ -343,11 +350,9 @@ export const renderStillFlow = async ({aggregate.rendering = {frames: 1,- concurrency: 1,doneIn: Date.now() - renderStart,- renderEstimatedTime: Date.now() - renderStart,- steps,totalFrames: 1,+ timeRemainingInMilliseconds: null,};updateRenderProgress({newline: true,diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.tsindex 4348f7ac84..5b4704c270 100644--- a/packages/cli/src/setup-cache.ts+++ b/packages/cli/src/setup-cache.ts@@ -22,8 +22,6 @@ export const bundleOnCliOrTakeServeUrl = async ({onProgress,indentOutput,logLevel,- bundlingStep,- steps,onDirectoryCreated,quietProgress,quietFlag,@@ -42,8 +40,6 @@ export const bundleOnCliOrTakeServeUrl = async ({}) => void;indentOutput: boolean;logLevel: LogLevel;- bundlingStep: number;- steps: number;onDirectoryCreated: (path: string) => void;quietProgress: boolean;quietFlag: boolean;@@ -83,8 +79,6 @@ export const bundleOnCliOrTakeServeUrl = async ({onProgressCallback: onProgress,indent: indentOutput,logLevel,- bundlingStep,- steps,onDirectoryCreated,quietProgress,quietFlag,@@ -108,8 +102,6 @@ export const bundleOnCli = async ({onProgressCallback,indent,logLevel,- bundlingStep,- steps,onDirectoryCreated,quietProgress,quietFlag,@@ -128,8 +120,6 @@ export const bundleOnCli = async ({}) => void;indent: boolean;logLevel: LogLevel;- bundlingStep: number;- steps: number;onDirectoryCreated: (path: string) => void;quietProgress: boolean;quietFlag: boolean;@@ -162,15 +152,11 @@ export const bundleOnCli = async ({const updateProgress = (newline: boolean) => {bundlingProgress.update(- makeBundlingAndCopyProgress(- {- bundling: bundlingState,- copying: copyingState,- symLinks: symlinkState,- },- bundlingStep,- steps,- ),+ makeBundlingAndCopyProgress({+ bundling: bundlingState,+ copying: copyingState,+ symLinks: symlinkState,+ }),newline,);onProgressCallback({diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex 2cb8a9ce51..4049dac793 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -691,6 +691,10 @@ const internalRenderMediaRaw = ({encodedFrames = frame;}+ if (encodedFrames === totalFramesToRender) {+ encodedDoneIn = Date.now() - stitchStart;+ }+if (frame > 0) {callUpdate();}@@ -712,12 +716,9 @@ const internalRenderMediaRaw = ({binariesDirectory,separateAudioTo,}),- stitchStart,]);})- .then(([buffer, stitchStart]) => {- encodedFrames = totalFramesToRender;- encodedDoneIn = Date.now() - stitchStart;+ .then(([buffer]) => {Log.verbose({indent, logLevel},'Stitching done in',diff --git a/packages/studio-server/src/index.ts b/packages/studio-server/src/index.tsindex 8ef874f4bd..b98b1c18c4 100644--- a/packages/studio-server/src/index.ts+++ b/packages/studio-server/src/index.ts@@ -17,7 +17,6 @@ export type {ProjectInfo,RenderJob,RenderJobWithCleanup,- RenderStep,RenderingProgressInput,RequiredChromiumOptions,StitchingProgressInput,diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.tsindex 3b0bc45315..ad282b2109 100644--- a/packages/studio-shared/src/index.ts+++ b/packages/studio-shared/src/index.ts@@ -51,7 +51,6 @@ export {JobProgressCallback,RenderJob,RenderJobWithCleanup,- RenderStep,RenderingProgressInput,RequiredChromiumOptions,StitchingProgressInput,diff --git a/packages/studio-shared/src/render-job.ts b/packages/studio-shared/src/render-job.tsindex 4f9813cfb8..6ff3b0c1f8 100644--- a/packages/studio-shared/src/render-job.ts+++ b/packages/studio-shared/src/render-job.ts@@ -17,15 +17,11 @@ type BaseRenderProgress = {value: number;};-export type RenderStep = 'bundling' | 'rendering' | 'stitching';-export type RenderingProgressInput = {frames: number;- renderEstimatedTime: number;totalFrames: number;- steps: RenderStep[];- concurrency: number;doneIn: number | null;+ timeRemainingInMilliseconds: number | null;};export type StitchingProgressInput = {