Skip to content

🎥 Make videos programmatically with React

render flow

Jonny Burgereac920f309c8
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index d6871a3c5f..84b0d3508e 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -254,7 +254,6 @@ export const benchmarkCommand = async (
for (const con of concurrency) {
const benchmarkProgress = createOverwriteableCliOutput({
quiet: quietFlagProvided(),
- indent: false,
});
Log.info();
Log.info(
diff --git a/packages/cli/src/download-progress.ts b/packages/cli/src/download-progress.ts
index d1c1072604..b513e46f85 100644
--- a/packages/cli/src/download-progress.ts
+++ b/packages/cli/src/download-progress.ts
@@ -1,4 +1,5 @@
import {formatBytes} from './format-bytes';
+import {INDENT_TOKEN} from './log';
import {makeProgressBar} from './make-progress-bar';
import type {DownloadProgress} from './progress-bar';
@@ -8,7 +9,10 @@ export const getFileSizeDownloadBar = (downloaded: number) => {
return `[${formatBytes(downloaded).padEnd(desiredLength - 2, ' ')}]`;
};
-export const makeMultiDownloadProgress = (progresses: DownloadProgress[]) => {
+export const makeMultiDownloadProgress = (
+ progresses: DownloadProgress[],
+ indent: boolean
+) => {
if (progresses.length === 0) {
return null;
}
@@ -20,6 +24,7 @@ export const makeMultiDownloadProgress = (progresses: DownloadProgress[]) => {
? progress.name.substring(0, 57) + '...'
: progress.name;
return [
+ indent ? INDENT_TOKEN : null,
` +`,
progress.progress
? makeProgressBar(progress.progress)
@@ -33,6 +38,7 @@ export const makeMultiDownloadProgress = (progresses: DownloadProgress[]) => {
);
return [
+ indent ? INDENT_TOKEN : null,
` +`,
everyFileHasContentLength
? makeProgressBar(
diff --git a/packages/cli/src/log.ts b/packages/cli/src/log.ts
index 4825fa06fd..d2a45937a0 100644
--- a/packages/cli/src/log.ts
+++ b/packages/cli/src/log.ts
@@ -5,7 +5,7 @@ import {chalk} from './chalk';
import {ConfigInternals} from './config';
import {truthy} from './truthy';
-export const INDENT_TOKEN = '│';
+export const INDENT_TOKEN = chalk.gray('│');
export const Log = {
verbose: (...args: Parameters<typeof console.log>) => {
@@ -20,9 +20,10 @@ export const Log = {
) => {
if (RenderInternals.isEqualOrBelowLogLevel(options.logLevel, 'verbose')) {
return console.log(
- ...[options.indent ? chalk.gray(INDENT_TOKEN) : null, ...args].filter(
- truthy
- )
+ ...[
+ options.indent ? INDENT_TOKEN : null,
+ ...args.map((a) => chalk.blueBright(a)),
+ ].filter(truthy)
);
}
},
@@ -38,9 +39,7 @@ export const Log = {
) => {
if (RenderInternals.isEqualOrBelowLogLevel(options.logLevel, 'info')) {
return console.log(
- ...[options.indent ? chalk.gray(INDENT_TOKEN) : null, ...args].filter(
- truthy
- )
+ ...[options.indent ? INDENT_TOKEN : null, ...args].filter(truthy)
);
}
},
@@ -56,9 +55,10 @@ export const Log = {
) => {
if (RenderInternals.isEqualOrBelowLogLevel(options.logLevel, 'warn')) {
return console.warn(
- ...[options.indent ? chalk.yellow(INDENT_TOKEN) : null, ...args].filter(
- truthy
- )
+ ...[
+ options.indent ? chalk.yellow(INDENT_TOKEN) : null,
+ ...args.map((a) => chalk.yellow(a)),
+ ].filter(truthy)
);
}
},
diff --git a/packages/cli/src/print-error.ts b/packages/cli/src/print-error.ts
index 796480697d..6f33788e20 100644
--- a/packages/cli/src/print-error.ts
+++ b/packages/cli/src/print-error.ts
@@ -6,7 +6,7 @@ import {createOverwriteableCliOutput} from './progress-bar';
export const printError = async (err: Error) => {
if (err instanceof RenderInternals.SymbolicateableError) {
- const output = createOverwriteableCliOutput({indent: false, quiet: false});
+ const output = createOverwriteableCliOutput({quiet: false});
output.update(
chalk.red('Symbolicating minified error message...\n' + err.message)
);
diff --git a/packages/cli/src/progress-bar.ts b/packages/cli/src/progress-bar.ts
index 00141b881b..4b704859dc 100644
--- a/packages/cli/src/progress-bar.ts
+++ b/packages/cli/src/progress-bar.ts
@@ -13,8 +13,7 @@ import type {RenderStep} from './step';
import {truthy} from './truthy';
export const createProgressBar = (
- quiet: boolean,
- indent: boolean
+ quiet: boolean
): {
update: (str: string) => boolean;
} => {
@@ -27,7 +26,7 @@ export const createProgressBar = (
return {update: () => false};
}
- return createOverwriteableCliOutput({quiet, indent});
+ return createOverwriteableCliOutput({quiet});
};
export type OverwriteableCliOutput = {
@@ -36,7 +35,6 @@ export type OverwriteableCliOutput = {
export const createOverwriteableCliOutput = (options: {
quiet: boolean;
- indent: boolean;
}): OverwriteableCliOutput => {
if (options.quiet) {
return {
@@ -46,23 +44,24 @@ export const createOverwriteableCliOutput = (options: {
const diff = new AnsiDiff();
return {
- update: (up: string): boolean =>
- process.stdout.write(
- diff.update((options.indent ? chalk.gray(INDENT_TOKEN) + ' ' : '') + up)
- ),
+ update: (up: string): boolean => process.stdout.write(diff.update(up)),
};
};
-const makeBundlingProgress = ({
- progress,
- steps,
- doneIn,
-}: {
- progress: number;
- steps: RenderStep[];
- doneIn: number | null;
-}) =>
+const makeBundlingProgress = (
+ {
+ progress,
+ steps,
+ doneIn,
+ }: {
+ progress: number;
+ steps: RenderStep[];
+ doneIn: number | null;
+ },
+ indent: boolean
+) =>
[
+ indent ? INDENT_TOKEN : null,
`(${steps.indexOf('bundling') + 1}/${steps.length})`,
makeProgressBar(progress),
`${doneIn ? 'Bundled' : 'Bundling'} code`,
@@ -73,13 +72,14 @@ const makeBundlingProgress = ({
.filter(truthy)
.join(' ');
-const makeCopyingProgress = (options: CopyingState) => {
+const makeCopyingProgress = (options: CopyingState, indent: boolean) => {
// Don't show copy progress lower than 200MB
if (options.bytes < 1000 * 1000 * 200) {
return null;
}
return [
+ indent ? INDENT_TOKEN : null,
' +',
options.doneIn ? makeProgressBar(1) : getFileSizeDownloadBar(options.bytes),
'Copying public dir',
@@ -89,7 +89,7 @@ const makeCopyingProgress = (options: CopyingState) => {
.join(' ');
};
-const makeSymlinkProgress = (options: SymbolicLinksState) => {
+const makeSymlinkProgress = (options: SymbolicLinksState, indent: boolean) => {
if (options.symlinks.length === 0) {
return null;
}
@@ -99,7 +99,11 @@ const makeSymlinkProgress = (options: SymbolicLinksState) => {
chalk.gray(` Found a symbolic link in the public folder:`),
chalk.gray(' ' + options.symlinks[0]),
chalk.gray(' The symlink will be forwarded in to the bundle.'),
- ].join('\n');
+ ]
+ .map((l) => {
+ return indent ? `${INDENT_TOKEN} ${l}` : null;
+ })
+ .join('\n');
}
return [
@@ -107,7 +111,11 @@ const makeSymlinkProgress = (options: SymbolicLinksState) => {
` Found ${options.symlinks.length} symbolic links in the public folder.`
),
chalk.gray(' The symlinks will be forwarded in to the bundle.'),
- ].join('\n');
+ ]
+ .map((l) => {
+ return indent ? `${INDENT_TOKEN} ${l}` : null;
+ })
+ .join('\n');
};
export type CopyingState = {
@@ -123,19 +131,22 @@ export type BundlingState = {
export type SymbolicLinksState = {symlinks: string[]};
-export const makeBundlingAndCopyProgress = ({
- bundling,
- copying,
- symLinks,
-}: {
- bundling: BundlingState;
- copying: CopyingState;
- symLinks: SymbolicLinksState;
-}) => {
+export const makeBundlingAndCopyProgress = (
+ {
+ bundling,
+ copying,
+ symLinks,
+ }: {
+ bundling: BundlingState;
+ copying: CopyingState;
+ symLinks: SymbolicLinksState;
+ },
+ indent: boolean
+) => {
return [
- makeBundlingProgress(bundling),
- makeCopyingProgress(copying),
- makeSymlinkProgress(symLinks),
+ makeBundlingProgress(bundling, indent),
+ makeCopyingProgress(copying, indent),
+ makeSymlinkProgress(symLinks, indent),
]
.filter(truthy)
.join('\n');
@@ -149,15 +160,13 @@ type RenderingProgressInput = {
doneIn: number | null;
};
-export const makeRenderingProgress = ({
- frames,
- totalFrames,
- steps,
- concurrency,
- doneIn,
-}: RenderingProgressInput) => {
+export const makeRenderingProgress = (
+ {frames, totalFrames, steps, concurrency, doneIn}: RenderingProgressInput,
+ indent: boolean
+) => {
const progress = frames / totalFrames;
return [
+ indent ? INDENT_TOKEN : null,
`(${steps.indexOf('rendering') + 1}/${steps.length})`,
makeProgressBar(progress),
[doneIn ? 'Rendered' : 'Rendering', `frames (${concurrency}x)`]
@@ -176,14 +185,10 @@ type StitchingProgressInput = {
codec: Codec;
};
-export const makeStitchingProgress = ({
- frames,
- totalFrames,
- steps,
- doneIn,
- stage,
- codec,
-}: StitchingProgressInput) => {
+export const makeStitchingProgress = (
+ {frames, totalFrames, steps, doneIn, stage, codec}: StitchingProgressInput,
+ indent: boolean
+) => {
const progress = frames / totalFrames;
const mediaType =
codec === 'gif'
@@ -193,6 +198,7 @@ export const makeStitchingProgress = ({
: 'video';
return [
+ indent ? INDENT_TOKEN : null,
`(${steps.indexOf('stitching') + 1}/${steps.length})`,
makeProgressBar(progress),
stage === 'muxing' && RenderInternals.canUseParallelEncoding(codec)
@@ -218,7 +224,8 @@ export type AggregateRenderProgress = {
};
export const makeRenderingAndStitchingProgress = (
- prog: AggregateRenderProgress
+ prog: AggregateRenderProgress,
+ indent: boolean
): {
output: string;
progress: number;
@@ -226,9 +233,9 @@ export const makeRenderingAndStitchingProgress = (
} => {
const {rendering, stitching, downloads, bundling} = prog;
const output = [
- rendering ? makeRenderingProgress(rendering) : null,
- makeMultiDownloadProgress(downloads),
- stitching === null ? null : makeStitchingProgress(stitching),
+ rendering ? makeRenderingProgress(rendering, indent) : null,
+ makeMultiDownloadProgress(downloads, indent),
+ stitching === null ? null : makeStitchingProgress(stitching, indent),
]
.filter(truthy)
.join('\n');
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index 7598521137..03cd6bee87 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -29,7 +29,7 @@ import {getCompositionWithDimensionOverride} from '../get-composition-with-dimen
import {getOutputFilename} from '../get-filename';
import {getRenderMediaOptions} from '../get-render-media-options';
import {getImageFormat} from '../image-formats';
-import {Log} from '../log';
+import {INDENT_TOKEN, Log} from '../log';
import type {DownloadProgress} from '../progress-bar';
import {
createOverwriteableCliOutput,
@@ -127,6 +127,7 @@ export const renderCompFlow = async ({
shouldDumpIo: RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose'),
chromiumOptions,
forceDeviceScaleFactor: scale,
+ indentationString: indentOutput ? INDENT_TOKEN + ' ' : '',
});
const steps: RenderStep[] = [
@@ -237,7 +238,6 @@ export const renderCompFlow = async ({
const renderProgress = createOverwriteableCliOutput({
quiet,
- indent: indentOutput,
});
const realFrameRange = RenderInternals.getRealFrameRange(
@@ -259,30 +259,33 @@ export const renderCompFlow = async ({
throw new Error('totalFrames should not be 0');
}
- const {output} = makeRenderingAndStitchingProgress({
- rendering: {
- frames: renderedFrames,
- totalFrames: totalFrames.length,
- concurrency: RenderInternals.getActualConcurrency(concurrency),
- doneIn: renderedDoneIn,
- steps,
+ const {output} = makeRenderingAndStitchingProgress(
+ {
+ rendering: {
+ frames: renderedFrames,
+ totalFrames: totalFrames.length,
+ concurrency: RenderInternals.getActualConcurrency(concurrency),
+ doneIn: renderedDoneIn,
+ steps,
+ },
+ stitching: shouldOutputImageSequence
+ ? null
+ : {
+ doneIn: encodedDoneIn,
+ frames: encodedFrames,
+ stage: stitchStage,
+ steps,
+ totalFrames: totalFrames.length,
+ codec,
+ },
+ downloads,
+ bundling: {
+ message: 'Bundled',
+ progress: 1,
+ },
},
- stitching: shouldOutputImageSequence
- ? null
- : {
- doneIn: encodedDoneIn,
- frames: encodedFrames,
- stage: stitchStage,
- steps,
- totalFrames: totalFrames.length,
- codec,
- },
- downloads,
- bundling: {
- message: 'Bundled',
- progress: 1,
- },
- });
+ indentOutput
+ );
return renderProgress.update(output);
};
@@ -349,6 +352,7 @@ export const renderCompFlow = async ({
});
updateRenderProgress();
+ Log.infoAdvanced({indent: indentOutput, logLevel});
Log.infoAdvanced(
{indent: indentOutput, logLevel},
chalk.cyan(`â–¶ ${absoluteOutputFile}`)
@@ -386,8 +390,11 @@ export const renderCompFlow = async ({
);
});
},
+ printLog: (...str) =>
+ Log.verboseAdvanced({indent: indentOutput, logLevel}, ...str),
});
+ Log.infoAdvanced({indent: indentOutput, logLevel});
Log.infoAdvanced(
{indent: indentOutput, logLevel},
chalk.cyan(`â–¶ ${absoluteOutputFile}`)
diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.ts
index e54953a7c9..134436718e 100644
--- a/packages/cli/src/render-flows/still.ts
+++ b/packages/cli/src/render-flows/still.ts
@@ -111,8 +111,10 @@ export const renderStillFlow = async ({
let renderProgress: OverwriteableCliOutput | null = null;
const updateProgress = () => {
- const {output, progress, message} =
- makeRenderingAndStitchingProgress(aggregate);
+ const {output, progress, message} = makeRenderingAndStitchingProgress(
+ aggregate,
+ indentOutput
+ );
if (renderProgress) {
renderProgress.update(output);
}
@@ -135,7 +137,7 @@ export const renderStillFlow = async ({
chromiumOptions,
shouldDumpIo,
forceDeviceScaleFactor: scale,
- indentationString: chalk.gray(INDENT_TOKEN + ' '),
+ indentationString: indentOutput ? INDENT_TOKEN + ' ' : '',
});
const steps: RenderStep[] = [
@@ -217,7 +219,6 @@ export const renderStillFlow = async ({
renderProgress = createOverwriteableCliOutput({
quiet: quietFlagProvided(),
- indent: true,
});
const renderStart = Date.now();
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index d8a2135491..d48757b044 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -65,7 +65,7 @@ export const render = async (remotionRoot: string, args: string[]) => {
fullEntryPoint,
remotionRoot,
browserExecutable,
- indentOutput: false,
+ indentOutput: true,
logLevel: ConfigInternals.Logging.getLogLevel(),
browser,
chromiumOptions,
diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.ts
index 0b2366a63b..2c82d12309 100644
--- a/packages/cli/src/setup-cache.ts
+++ b/packages/cli/src/setup-cache.ts
@@ -100,11 +100,14 @@ export const bundleOnCli = async ({
const updateProgress = (newline: boolean) => {
bundlingProgress.update(
- makeBundlingAndCopyProgress({
- bundling: bundlingState,
- copying: copyingState,
- symLinks: symlinkState,
- }) + (newline ? '\n' : '')
+ makeBundlingAndCopyProgress(
+ {
+ bundling: bundlingState,
+ copying: copyingState,
+ symLinks: symlinkState,
+ },
+ indent
+ ) + (newline ? '\n' : '')
);
// TODO: Take copying into account
onProgressCallback({
@@ -171,7 +174,6 @@ export const bundleOnCli = async ({
const bundleStartTime = Date.now();
const bundlingProgress = createOverwriteableCliOutput({
quiet: quietFlagProvided(),
- indent,
});
let bundlingState: BundlingState = {
diff --git a/packages/lambda/src/cli/commands/functions/deploy.ts b/packages/lambda/src/cli/commands/functions/deploy.ts
index bee50cd849..15bfea807a 100644
--- a/packages/lambda/src/cli/commands/functions/deploy.ts
+++ b/packages/lambda/src/cli/commands/functions/deploy.ts
@@ -54,7 +54,6 @@ CloudWatch Retention Period = ${cloudWatchLogRetentionPeriodInDays} days
const output = CliInternals.createOverwriteableCliOutput({
quiet: CliInternals.quietFlagProvided(),
- indent: false,
});
output.update('Deploying Lambda...');
const {functionName, alreadyExisted} = await deployFunction({
diff --git a/packages/lambda/src/cli/commands/functions/ls.ts b/packages/lambda/src/cli/commands/functions/ls.ts
index 2078090001..97b2fcca19 100644
--- a/packages/lambda/src/cli/commands/functions/ls.ts
+++ b/packages/lambda/src/cli/commands/functions/ls.ts
@@ -15,7 +15,6 @@ export const functionsLsCommand = async () => {
const region = getAwsRegion();
const fetchingOutput = CliInternals.createOverwriteableCliOutput({
quiet: CliInternals.quietFlagProvided(),
- indent: false,
});
fetchingOutput.update('Getting functions...');
diff --git a/packages/lambda/src/cli/commands/functions/rm.ts b/packages/lambda/src/cli/commands/functions/rm.ts
index dfe65a7510..58f96790fb 100644
--- a/packages/lambda/src/cli/commands/functions/rm.ts
+++ b/packages/lambda/src/cli/commands/functions/rm.ts
@@ -34,7 +34,6 @@ export const functionsRmCommand = async (args: string[]) => {
for (const functionName of args) {
const infoOutput = CliInternals.createOverwriteableCliOutput({
quiet: CliInternals.quietFlagProvided(),
- indent: false,
});
infoOutput.update('Getting function info...');
const info = await getFunctionInfo({
@@ -55,7 +54,6 @@ export const functionsRmCommand = async (args: string[]) => {
await confirmCli({delMessage: 'Delete? (Y/n)', allowForceFlag: true});
const output = CliInternals.createOverwriteableCliOutput({
quiet: CliInternals.quietFlagProvided(),
- indent: false,
});
output.update('Deleting...');
await deleteFunction({region, functionName});
diff --git a/packages/lambda/src/cli/commands/functions/rmall.ts b/packages/lambda/src/cli/commands/functions/rmall.ts
index 6496fcba1f..415dca2f5c 100644
--- a/packages/lambda/src/cli/commands/functions/rmall.ts
+++ b/packages/lambda/src/cli/commands/functions/rmall.ts
@@ -19,7 +19,6 @@ export const functionsRmallCommand = async () => {
for (const fun of functions) {
const infoOutput = CliInternals.createOverwriteableCliOutput({
quiet: CliInternals.quietFlagProvided(),
- indent: false,
});
infoOutput.update('Getting function info...');
const info = await getFunctionInfo({
@@ -40,7 +39,6 @@ export const functionsRmallCommand = async () => {
await confirmCli({delMessage: 'Delete? (Y/n)', allowForceFlag: true});
const output = CliInternals.createOverwriteableCliOutput({
quiet: CliInternals.quietFlagProvided(),
- indent: false,
});
output.update('Deleting...');
await deleteFunction({region, functionName: fun.functionName});
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 2a1cc5af88..85f0e32aff 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -140,7 +140,6 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
const progressBar = CliInternals.createOverwriteableCliOutput({
quiet: CliInternals.quietFlagProvided(),
- indent: false,
});
Log.info(
diff --git a/packages/lambda/src/cli/commands/sites/create.ts b/packages/lambda/src/cli/commands/sites/create.ts
index cfbd5c287c..e634bf20ab 100644
--- a/packages/lambda/src/cli/commands/sites/create.ts
+++ b/packages/lambda/src/cli/commands/sites/create.ts
@@ -63,7 +63,6 @@ export const sitesCreateSubcommand = async (
const progressBar = CliInternals.createOverwriteableCliOutput({
quiet: CliInternals.quietFlagProvided(),
- indent: false,
});
const multiProgress: {
diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.ts
index a0581e33e4..26d8646a31 100644
--- a/packages/renderer/src/render-media.ts
+++ b/packages/renderer/src/render-media.ts
@@ -110,6 +110,7 @@ export type RenderMediaOptions = {
videoBitrate?: string | null;
onSlowestFrames?: OnSlowestFrames;
disallowParallelEncoding?: boolean;
+ printLog?: (...data: unknown[]) => void;
} & ServeUrlOrWebpackBundle &
ConcurrencyOrParallelism;
@@ -228,24 +229,25 @@ export const renderMedia = ({
canUseParallelEncoding(codec);
if (options.verbose) {
- console.log(
+ const log = options.printLog ?? console.log;
+ log(
'[PRESTITCHER] Free memory:',
freeMemory,
'Estimated usage parallel encoding',
estimatedUsage
);
- console.log(
+ log(
'[PRESTITCHER]: Codec supports parallel rendering:',
canUseParallelEncoding(codec)
);
- console.log(
+ log(
'[PRESTITCHER]: User disallowed parallel encoding:',
Boolean(options.disallowParallelEncoding)
);
if (parallelEncoding) {
- console.log('[PRESTITCHER] Parallel encoding is enabled.');
+ log('[PRESTITCHER] Parallel encoding is enabled.');
} else {
- console.log('[PRESTITCHER] Parallel encoding is disabled.');
+ log('[PRESTITCHER] Parallel encoding is disabled.');
}
}