Skip to content

🎥 Make videos programmatically with React

make callback customizable

Jonny Burger50a81b6e4204
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index e96288be6d..18aa2faa80 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -6,6 +6,7 @@ import type {
import {RenderInternals} from '@remotion/renderer';
import {BrowserSafeApis} from '@remotion/renderer/client';
import {NoReactInternals} from 'remotion/no-react';
+import {defaultBrowserDownloadProgress} from './browser-download-bar';
import {chalk} from './chalk';
import {registerCleanupJob} from './cleanup-before-quit';
import {ConfigInternals} from './config';
@@ -232,6 +233,8 @@ export const benchmarkCommand = async (
userAgent,
};
+ const onBrowserDownload = defaultBrowserDownloadProgress(false, logLevel);
+
const browserInstance = RenderInternals.internalOpenBrowser({
browser: 'chrome',
browserExecutable,
@@ -240,6 +243,7 @@ export const benchmarkCommand = async (
indent: false,
viewport: null,
logLevel,
+ onBrowserDownload,
});
const {urlOrBundle: bundleLocation, cleanup: cleanupBundle} =
@@ -299,6 +303,7 @@ export const benchmarkCommand = async (
binariesDirectory: binariesDirectoryOption.getValue({
commandLine: parsedCli,
}).value,
+ onBrowserDownload,
});
const ids = (
@@ -472,6 +477,7 @@ export const benchmarkCommand = async (
commandLine: parsedCli,
}).value,
compositionStart: 0,
+ onBrowserDownload,
},
(run, progress) => {
benchmarkProgress.update(
diff --git a/packages/cli/src/browser-download-bar.ts b/packages/cli/src/browser-download-bar.ts
new file mode 100644
index 0000000000..46bff00b88
--- /dev/null
+++ b/packages/cli/src/browser-download-bar.ts
@@ -0,0 +1,25 @@
+import type {LogLevel, OnBrowserDownload} from '@remotion/renderer';
+import {RenderInternals} from '@remotion/renderer';
+import {Log} from './log';
+
+export const defaultBrowserDownloadProgress =
+ (indent: boolean, logLevel: LogLevel): OnBrowserDownload =>
+ () => {
+ Log.info(
+ {indent, logLevel},
+ 'No local browser could be found. Downloading Chrome Headless Shell https://www.remotion.dev/docs/miscellaneous/chrome-headless-shell',
+ );
+ return (progress) => {
+ let lastProgress = 0;
+ if (progress.downloaded > lastProgress + 10_000_000) {
+ lastProgress = progress.downloaded;
+
+ Log.info(
+ {indent, logLevel},
+ `Downloading Chrome Headless Shell - ${RenderInternals.toMegabytes(
+ progress.downloaded,
+ )}/${RenderInternals.toMegabytes(progress.totalSize as number)}`,
+ );
+ }
+ };
+ };
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.ts
index b226407e91..94eae3f262 100644
--- a/packages/cli/src/compositions.ts
+++ b/packages/cli/src/compositions.ts
@@ -2,6 +2,7 @@ import type {ChromiumOptions, LogLevel} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
import {BrowserSafeApis} from '@remotion/renderer/client';
import {NoReactInternals} from 'remotion/no-react';
+import {defaultBrowserDownloadProgress} from './browser-download-bar';
import {registerCleanupJob} from './cleanup-before-quit';
import {getRendererPortFromConfigFileAndCliFlag} from './config/preview-server';
import {findEntryPoint} from './entry-point';
@@ -141,6 +142,7 @@ export const listCompositionsCommand = async (
server: undefined,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload: defaultBrowserDownloadProgress(false, logLevel),
});
printCompositions(compositions, logLevel);
diff --git a/packages/cli/src/get-composition-id.ts b/packages/cli/src/get-composition-id.ts
index 802f2772b1..401f7faa48 100644
--- a/packages/cli/src/get-composition-id.ts
+++ b/packages/cli/src/get-composition-id.ts
@@ -3,6 +3,7 @@ import type {
ChromiumOptions,
HeadlessBrowser,
LogLevel,
+ OnBrowserDownload,
RemotionServer,
} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
@@ -51,6 +52,7 @@ export const getCompositionId = async ({
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
}: {
args: string[];
compositionIdFromUi: string | null;
@@ -67,6 +69,7 @@ export const getCompositionId = async ({
server: RemotionServer;
offthreadVideoCacheSizeInBytes: number | null;
binariesDirectory: string | null;
+ onBrowserDownload: OnBrowserDownload;
}): Promise<{
compositionId: string;
reason: string;
@@ -99,6 +102,7 @@ export const getCompositionId = async ({
onBrowserLog: null,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
});
if (propsSize > 10_000_000) {
@@ -141,6 +145,7 @@ export const getCompositionId = async ({
serializedInputPropsWithCustomSchema,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
});
const {compositionId, reason} = await showSingleCompositionsPicker(
comps,
diff --git a/packages/cli/src/get-composition-with-dimension-override.ts b/packages/cli/src/get-composition-with-dimension-override.ts
index dc50ffe620..d398086f49 100644
--- a/packages/cli/src/get-composition-with-dimension-override.ts
+++ b/packages/cli/src/get-composition-with-dimension-override.ts
@@ -3,6 +3,7 @@ import type {
ChromiumOptions,
HeadlessBrowser,
LogLevel,
+ OnBrowserDownload,
RemotionServer,
} from '@remotion/renderer';
import type {VideoConfig} from 'remotion';
@@ -26,6 +27,7 @@ export const getCompositionWithDimensionOverride = async ({
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
}: {
height: number | null;
width: number | null;
@@ -44,6 +46,7 @@ export const getCompositionWithDimensionOverride = async ({
server: RemotionServer;
offthreadVideoCacheSizeInBytes: number | null;
binariesDirectory: string | null;
+ onBrowserDownload: OnBrowserDownload;
}): Promise<{
compositionId: string;
reason: string;
@@ -66,6 +69,7 @@ export const getCompositionWithDimensionOverride = async ({
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
});
return {
diff --git a/packages/cli/src/gpu.ts b/packages/cli/src/gpu.ts
index 82729edeb6..b6e90ce18d 100644
--- a/packages/cli/src/gpu.ts
+++ b/packages/cli/src/gpu.ts
@@ -1,6 +1,7 @@
import type {ChromiumOptions, LogLevel} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
import {BrowserSafeApis} from '@remotion/renderer/client';
+import {defaultBrowserDownloadProgress} from './browser-download-bar';
import {chalk} from './chalk';
import {getCliOptions} from './get-cli-options';
import {Log} from './log';
@@ -52,6 +53,7 @@ export const gpuCommand = async (logLevel: LogLevel) => {
logLevel,
chromiumOptions,
timeoutInMilliseconds: puppeteerTimeout,
+ onBrowserDownload: defaultBrowserDownloadProgress(false, logLevel),
});
for (const {feature, status} of statuses) {
Log.info({indent: false, logLevel}, `${feature}: ${colorStatus(status)}`);
diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsx
index 6093f96b15..3046086017 100644
--- a/packages/cli/src/index.tsx
+++ b/packages/cli/src/index.tsx
@@ -132,6 +132,7 @@ export const cli = async () => {
};
import {StudioServerInternals} from '@remotion/studio-server';
+import {defaultBrowserDownloadProgress} from './browser-download-bar';
export const CliInternals = {
createOverwriteableCliOutput,
@@ -155,4 +156,5 @@ export const CliInternals = {
listOfRemotionPackages,
shouldUseNonOverlayingLogger,
getCompositionWithDimensionOverride,
+ defaultBrowserDownloadProgress,
};
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index b2f0e4dbcb..b31f207ef5 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -33,6 +33,7 @@ import fs, {existsSync} from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {NoReactInternals} from 'remotion/no-react';
+import {defaultBrowserDownloadProgress} from '../browser-download-bar';
import {chalk} from '../chalk';
import {ConfigInternals} from '../config';
import {getAndValidateAbsoluteOutputFile} from '../get-cli-options';
@@ -159,6 +160,7 @@ export const renderVideoFlow = async ({
publicPath: string | null;
}) => {
const downloads: DownloadProgress[] = [];
+ const onBrowserDownload = defaultBrowserDownloadProgress(indent, logLevel);
const browserInstance = RenderInternals.internalOpenBrowser({
browser,
@@ -168,6 +170,7 @@ export const renderVideoFlow = async ({
indent,
viewport: null,
logLevel,
+ onBrowserDownload,
});
let isUsingParallelEncoding = false;
@@ -302,6 +305,7 @@ export const renderVideoFlow = async ({
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
});
const {value: codec, source: codecReason} =
@@ -448,6 +452,7 @@ export const renderVideoFlow = async ({
binariesDirectory,
compositionStart: 0,
forSeamlessAacConcatenation,
+ onBrowserDownload,
});
updateRenderProgress({newline: true, printToConsole: true});
@@ -537,6 +542,7 @@ export const renderVideoFlow = async ({
separateAudioTo: absoluteSeparateAudioTo,
forSeamlessAacConcatenation,
compositionStart: 0,
+ onBrowserDownload,
});
Log.info(
diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.ts
index 2fa7bc6aa7..cb5536e85f 100644
--- a/packages/cli/src/render-flows/still.ts
+++ b/packages/cli/src/render-flows/still.ts
@@ -18,6 +18,7 @@ import type {
import {existsSync, mkdirSync} from 'node:fs';
import path from 'node:path';
import {NoReactInternals} from 'remotion/no-react';
+import {defaultBrowserDownloadProgress} from '../browser-download-bar';
import {chalk} from '../chalk';
import {registerCleanupJob} from '../cleanup-before-quit';
import {ConfigInternals} from '../config';
@@ -139,6 +140,8 @@ export const renderStillFlow = async ({
onProgress({message, value: progress, ...aggregate});
};
+ const onBrowserDownload = defaultBrowserDownloadProgress(indent, logLevel);
+
const browserInstance = RenderInternals.internalOpenBrowser({
browser,
browserExecutable,
@@ -147,6 +150,7 @@ export const renderStillFlow = async ({
indent,
viewport: null,
logLevel,
+ onBrowserDownload,
});
const {cleanup: cleanupBundle, urlOrBundle} = await bundleOnCliOrTakeServeUrl(
@@ -221,6 +225,7 @@ export const renderStillFlow = async ({
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
});
const {format: imageFormat, source} = determineFinalStillImageFormat({
@@ -321,6 +326,7 @@ export const renderStillFlow = async ({
}).serializedString,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
});
aggregate.rendering = {
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index 7ddcfc7552..4badfea9c5 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -141,6 +141,8 @@ export const renderCommand = async (
forceIPv4: false,
});
+ const indent = false;
+
const {compositionId} =
await CliInternals.getCompositionWithDimensionOverride({
args: args.slice(1),
@@ -149,7 +151,7 @@ export const renderCommand = async (
chromiumOptions,
envVariables,
height,
- indent: false,
+ indent,
port: ConfigInternals.getRendererPortFromConfigFileAndCliFlag(),
puppeteerInstance: undefined,
serveUrlOrWebpackUrl: serveUrl,
@@ -165,6 +167,10 @@ export const renderCommand = async (
}).serializedString,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload: CliInternals.defaultBrowserDownloadProgress(
+ indent,
+ logLevel,
+ ),
});
composition = compositionId;
}
diff --git a/packages/cloudrun/src/cli/commands/still.ts b/packages/cloudrun/src/cli/commands/still.ts
index 4ab34a3210..b5d2073c54 100644
--- a/packages/cloudrun/src/cli/commands/still.ts
+++ b/packages/cloudrun/src/cli/commands/still.ts
@@ -109,11 +109,13 @@ export const stillCommand = async (
forceIPv4: false,
});
+ const indent = false;
+
const {compositionId} =
await CliInternals.getCompositionWithDimensionOverride({
args: args.slice(1),
compositionIdFromUi: null,
- indent: false,
+ indent,
serveUrlOrWebpackUrl: serveUrl,
logLevel,
browserExecutable,
@@ -133,6 +135,10 @@ export const stillCommand = async (
server: await server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload: CliInternals.defaultBrowserDownloadProgress(
+ indent,
+ logLevel,
+ ),
});
composition = compositionId;
}
diff --git a/packages/cloudrun/src/functions/helpers/get-composition-from-body.ts b/packages/cloudrun/src/functions/helpers/get-composition-from-body.ts
index 645366e6a5..998b698221 100644
--- a/packages/cloudrun/src/functions/helpers/get-composition-from-body.ts
+++ b/packages/cloudrun/src/functions/helpers/get-composition-from-body.ts
@@ -25,6 +25,9 @@ export const getCompositionFromBody = async (body: CloudRunPayloadType) => {
RenderInternals.DEFAULT_TIMEOUT,
offthreadVideoCacheSizeInBytes: body.offthreadVideoCacheSizeInBytes,
binariesDirectory: null,
+ onBrowserDownload: () => {
+ throw new Error('Should not download a browser in Cloud Run');
+ },
},
);
diff --git a/packages/cloudrun/src/functions/render-media-single-thread.ts b/packages/cloudrun/src/functions/render-media-single-thread.ts
index db2d0d5d55..d0c8581021 100644
--- a/packages/cloudrun/src/functions/render-media-single-thread.ts
+++ b/packages/cloudrun/src/functions/render-media-single-thread.ts
@@ -124,6 +124,9 @@ export const renderMediaSingleThread = async (
separateAudioTo: null,
forSeamlessAacConcatenation: false,
compositionStart: 0,
+ onBrowserDownload: () => {
+ throw new Error('Should not download a browser in Cloud Run');
+ },
});
const storage = new Storage();
diff --git a/packages/cloudrun/src/functions/render-still-single-thread.ts b/packages/cloudrun/src/functions/render-still-single-thread.ts
index d155ac78a7..3bb543c9fd 100644
--- a/packages/cloudrun/src/functions/render-still-single-thread.ts
+++ b/packages/cloudrun/src/functions/render-still-single-thread.ts
@@ -94,6 +94,9 @@ export const renderStillSingleThread = async (
server: undefined,
offthreadVideoCacheSizeInBytes: body.offthreadVideoCacheSizeInBytes,
binariesDirectory: null,
+ onBrowserDownload: () => {
+ throw new Error('Should not download a browser in Cloud Run');
+ },
});
Log.info({indent: false, logLevel: body.logLevel}, 'Still rendered');
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 0493b65c67..94624b4064 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -206,6 +206,8 @@ export const renderCommand = async (
forceIPv4: false,
});
+ const indent = false;
+
const {compositionId} =
await CliInternals.getCompositionWithDimensionOverride({
args: args.slice(1),
@@ -214,7 +216,7 @@ export const renderCommand = async (
chromiumOptions,
envVariables,
height,
- indent: false,
+ indent,
serializedInputPropsWithCustomSchema:
NoReactInternals.serializeJSONWithDate({
indent: undefined,
@@ -230,6 +232,10 @@ export const renderCommand = async (
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload: CliInternals.defaultBrowserDownloadProgress(
+ indent,
+ logLevel,
+ ),
});
composition = compositionId;
}
diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.ts
index 17cc03108f..f84c0aeb13 100644
--- a/packages/lambda/src/cli/commands/still.ts
+++ b/packages/lambda/src/cli/commands/still.ts
@@ -137,10 +137,12 @@ export const stillCommand = async (
forceIPv4: false,
});
+ const indent = false;
+
const {compositionId} = await getCompositionWithDimensionOverride({
args: args.slice(1),
compositionIdFromUi: null,
- indent: false,
+ indent,
serveUrlOrWebpackUrl: serveUrl,
logLevel,
browserExecutable,
@@ -160,6 +162,10 @@ export const stillCommand = async (
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload: CliInternals.defaultBrowserDownloadProgress(
+ indent,
+ logLevel,
+ ),
});
composition = compositionId;
}
diff --git a/packages/lambda/src/functions/compositions.ts b/packages/lambda/src/functions/compositions.ts
index eff18bb36f..9cbbe4975b 100644
--- a/packages/lambda/src/functions/compositions.ts
+++ b/packages/lambda/src/functions/compositions.ts
@@ -82,6 +82,9 @@ export const compositionsHandler = async (
offthreadVideoCacheSizeInBytes:
lambdaParams.offthreadVideoCacheSizeInBytes,
binariesDirectory: null,
+ onBrowserDownload: () => {
+ throw new Error('Should not download a browser in Lambda');
+ },
});
return Promise.resolve({
diff --git a/packages/lambda/src/functions/helpers/get-browser-instance.ts b/packages/lambda/src/functions/helpers/get-browser-instance.ts
index 280dd0eb6e..084ebb5877 100644
--- a/packages/lambda/src/functions/helpers/get-browser-instance.ts
+++ b/packages/lambda/src/functions/helpers/get-browser-instance.ts
@@ -99,6 +99,9 @@ export const getBrowserInstance = async (
indent: false,
viewport: null,
logLevel,
+ onBrowserDownload: () => {
+ throw new Error('Should not download a browser in Lambda');
+ },
});
instance.on('disconnected', () => {
RenderInternals.Log.info(
diff --git a/packages/lambda/src/functions/helpers/validate-composition.ts b/packages/lambda/src/functions/helpers/validate-composition.ts
index 1959b52947..cb3f9cbeb5 100644
--- a/packages/lambda/src/functions/helpers/validate-composition.ts
+++ b/packages/lambda/src/functions/helpers/validate-composition.ts
@@ -1,6 +1,7 @@
import type {
ChromiumOptions,
LogLevel,
+ OnBrowserDownload,
openBrowser,
RemotionServer,
} from '@remotion/renderer';
@@ -23,6 +24,7 @@ type ValidateCompositionOptions = {
logLevel: LogLevel;
server: RemotionServer | undefined;
offthreadVideoCacheSizeInBytes: number | null;
+ onBrowserDownload: OnBrowserDownload;
};
export const validateComposition = async ({
@@ -39,6 +41,7 @@ export const validateComposition = async ({
logLevel,
server,
offthreadVideoCacheSizeInBytes,
+ onBrowserDownload,
}: ValidateCompositionOptions): Promise<VideoConfig> => {
const {metadata: comp} = await RenderInternals.internalSelectComposition({
id: composition,
@@ -56,6 +59,7 @@ export const validateComposition = async ({
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory: null,
+ onBrowserDownload,
});
return {
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index 8307bce200..50f33e984f 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -158,6 +158,9 @@ const innerLaunchHandler = async ({
logLevel: params.logLevel,
server: undefined,
offthreadVideoCacheSizeInBytes: params.offthreadVideoCacheSizeInBytes,
+ onBrowserDownload: () => {
+ throw new Error('Should not download a browser in Lambda');
+ },
});
RenderInternals.Log.info(
logOptions,
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index 56c9ae4876..6c3b6cc1fd 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -277,6 +277,9 @@ const renderHandler = async (
separateAudioTo: audioOutputLocation,
forSeamlessAacConcatenation: seamlessAudio,
compositionStart: params.compositionStart,
+ onBrowserDownload: () => {
+ throw new Error('Should not download a browser in Lambda');
+ },
})
.then(({slowestFrames}) => {
RenderInternals.Log.verbose(
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index 79ee04e1a4..9892ba34f6 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -143,6 +143,9 @@ const innerStillHandler = async ({
logLevel: lambdaParams.logLevel,
server,
offthreadVideoCacheSizeInBytes: lambdaParams.offthreadVideoCacheSizeInBytes,
+ onBrowserDownload: () => {
+ throw new Error('Should not download a browser in Lambda');
+ },
});
const renderMetadata: RenderMetadata = {
@@ -181,6 +184,11 @@ const innerStillHandler = async ({
downloadBehavior: null,
customCredentials: null,
});
+
+ const onBrowserDownload = () => {
+ throw new Error('Should not download a browser in Lambda');
+ };
+
await RenderInternals.internalRenderStill({
composition,
output: outputPath,
@@ -215,6 +223,7 @@ const innerStillHandler = async ({
}).serializedString,
offthreadVideoCacheSizeInBytes: lambdaParams.offthreadVideoCacheSizeInBytes,
binariesDirectory: null,
+ onBrowserDownload,
});
const {key, renderBucketName, customCredentials} = getExpectedOutName(
diff --git a/packages/renderer/src/browser/BrowserFetcher.ts b/packages/renderer/src/browser/BrowserFetcher.ts
index a6d86e6ad1..b7edaa19bd 100644
--- a/packages/renderer/src/browser/BrowserFetcher.ts
+++ b/packages/renderer/src/browser/BrowserFetcher.ts
@@ -26,6 +26,7 @@ import {downloadFile} from '../assets/download-file';
import {makeFileExecutableIfItIsNot} from '../compositor/make-file-executable';
import type {LogLevel} from '../log-level';
import {Log} from '../logger';
+import type {DownloadBrowserProgressFn} from '../options/on-browser-download';
import {getDownloadsCacheDir} from './get-download-destination';
const downloadURLs: Record<Platform, string> = {
@@ -86,6 +87,7 @@ const getDownloadsFolder = () => {
export const downloadBrowser = async (options: {
logLevel: LogLevel;
indent: boolean;
+ onProgress: DownloadBrowserProgressFn;
}): Promise<BrowserFetcherRevisionInfo | undefined> => {
const platform = getPlatform();
const downloadURL = getChromeDownloadUrl(platform);
@@ -121,21 +123,19 @@ export const downloadBrowser = async (options: {
}
try {
- let lastProgress = 0;
await downloadFile({
url: downloadURL,
to: () => archivePath,
onProgress: (progress) => {
- if (progress.downloaded > lastProgress + 10_000_000) {
- lastProgress = progress.downloaded;
-
- Log.info(
- {indent: options.indent, logLevel: options.logLevel},
- `Downloading Chrome Headless Shell - ${toMegabytes(
- progress.downloaded,
- )}/${toMegabytes(progress.totalSize as number)}`,
- );
+ if (progress.totalSize === null || progress.percent === null) {
+ throw new Error('Expected totalSize and percent to be defined');
}
+
+ options.onProgress({
+ downloaded: progress.downloaded,
+ totalSize: progress.totalSize,
+ percent: progress.percent,
+ });
},
indent: options.indent,
logLevel: options.logLevel,
@@ -187,8 +187,3 @@ export const getRevisionInfo = (): BrowserFetcherRevisionInfo => {
url,
};
};
-
-function toMegabytes(bytes: number) {
- const mb = bytes / 1024 / 1024;
- return `${Math.round(mb * 10) / 10} Mb`;
-}
diff --git a/packages/renderer/src/browser/browser-download-progress-bar.ts b/packages/renderer/src/browser/browser-download-progress-bar.ts
new file mode 100644
index 0000000000..e920458c8f
--- /dev/null
+++ b/packages/renderer/src/browser/browser-download-progress-bar.ts
@@ -0,0 +1,26 @@
+import type {LogLevel} from '../log-level';
+import {Log} from '../logger';
+import type {OnBrowserDownload} from '../options/on-browser-download';
+import {toMegabytes} from '../to-megabytes';
+
+export const defaultBrowserDownloadProgress =
+ (indent: boolean, logLevel: LogLevel): OnBrowserDownload =>
+ () => {
+ Log.info(
+ {indent, logLevel},
+ 'No local browser could be found. Downloading Chrome Headless Shell https://www.remotion.dev/docs/miscellaneous/chrome-headless-shell',
+ );
+ return (progress) => {
+ let lastProgress = 0;
+ if (progress.downloaded > lastProgress + 10_000_000) {
+ lastProgress = progress.downloaded;
+
+ Log.info(
+ {indent, logLevel},
+ `Downloading Chrome Headless Shell - ${toMegabytes(
+ progress.downloaded,
+ )}/${toMegabytes(progress.totalSize as number)}`,
+ );
+ }
+ };
+ };
diff --git a/packages/renderer/src/ensure-browser.ts b/packages/renderer/src/ensure-browser.ts
index 71c5164717..547f1cb6fb 100644
--- a/packages/renderer/src/ensure-browser.ts
+++ b/packages/renderer/src/ensure-browser.ts
@@ -3,7 +3,7 @@ import type {BrowserExecutable} from './browser-executable';
import {downloadBrowser, getRevisionInfo} from './browser/BrowserFetcher';
import {getLocalBrowser} from './get-local-browser';
import type {LogLevel} from './log-level';
-import {Log} from './logger';
+import type {OnBrowserDownload} from './options/on-browser-download';
export type BrowserStatus =
| {
@@ -25,39 +25,33 @@ export type BrowserStatus =
export const ensureLocalBrowser = async ({
indent,
logLevel,
- preferredBrowserExecutable,
+ browserExecutable,
+ onBrowserDownload,
}: {
- preferredBrowserExecutable: BrowserExecutable;
+ browserExecutable: BrowserExecutable;
logLevel: LogLevel;
indent: boolean;
+ onBrowserDownload: OnBrowserDownload;
}) => {
- const status = getBrowserStatus(preferredBrowserExecutable, logLevel, indent);
+ const status = getBrowserStatus(browserExecutable);
if (status.type === 'no-browser') {
- Log.info(
- {indent, logLevel},
- 'No local browser could be found. Downloading Chrome Headless Shell https://www.remotion.dev/docs/miscellaneous/chrome-headless-shell',
- );
- await downloadBrowser({indent, logLevel});
+ const onProgress = onBrowserDownload();
+
+ await downloadBrowser({indent, logLevel, onProgress});
}
};
const getBrowserStatus = (
- browserExecutablePath: BrowserExecutable,
- logLevel: LogLevel,
- indent: boolean,
+ browserExecutable: BrowserExecutable,
): BrowserStatus => {
- if (browserExecutablePath) {
- if (!fs.existsSync(browserExecutablePath)) {
- Log.warn(
- {
- indent,
- logLevel,
- },
- `Browser executable was specified as '${browserExecutablePath}' but the path doesn't exist.`,
+ if (browserExecutable) {
+ if (!fs.existsSync(browserExecutable)) {
+ throw new Error(
+ `"browserExecutable" was specified as '${browserExecutable}' but the path doesn't exist. Pass "null" for "browserExecutable" to download a browser automatically.`,
);
}
- return {path: browserExecutablePath, type: 'user-defined-path'};
+ return {path: browserExecutable, type: 'user-defined-path'};
}
const localBrowser = getLocalBrowser();
diff --git a/packages/renderer/src/get-browser-instance.ts b/packages/renderer/src/get-browser-instance.ts
index 28a31703ce..eb17e57a8a 100644
--- a/packages/renderer/src/get-browser-instance.ts
+++ b/packages/renderer/src/get-browser-instance.ts
@@ -5,6 +5,7 @@ import type {Page} from './browser/BrowserPage';
import type {LogLevel} from './log-level';
import type {ChromiumOptions} from './open-browser';
import {internalOpenBrowser} from './open-browser';
+import type {OnBrowserDownload} from './options/on-browser-download';
export const getPageAndCleanupFn = async ({
passedInInstance,
@@ -13,6 +14,7 @@ export const getPageAndCleanupFn = async ({
forceDeviceScaleFactor,
indent,
logLevel,
+ onBrowserDownload,
}: {
passedInInstance: HeadlessBrowser | undefined;
browserExecutable: BrowserExecutable | null;
@@ -20,6 +22,7 @@ export const getPageAndCleanupFn = async ({
indent: boolean;
forceDeviceScaleFactor: number | undefined;
logLevel: LogLevel;
+ onBrowserDownload: OnBrowserDownload;
}): Promise<{
cleanup: () => Promise<void>;
page: Page;
@@ -47,6 +50,7 @@ export const getPageAndCleanupFn = async ({
indent,
viewport: null,
logLevel,
+ onBrowserDownload,
});
const browserPage = await browserInstance.newPage(
() => null,
diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.ts
index f4b1bb49e7..0059034b0f 100644
--- a/packages/renderer/src/get-compositions.ts
+++ b/packages/renderer/src/get-compositions.ts
@@ -3,6 +3,7 @@ import {NoReactInternals} from 'remotion/no-react';
import type {BrowserExecutable} from './browser-executable';
import type {BrowserLog} from './browser-log';
import type {HeadlessBrowser} from './browser/Browser';
+import {defaultBrowserDownloadProgress} from './browser/browser-download-progress-bar';
import type {Page} from './browser/BrowserPage';
import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
import {handleJavascriptException} from './error-handling/handle-javascript-exception';
@@ -160,6 +161,7 @@ const internalGetCompositionsRaw = async ({
logLevel,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
}: InternalGetCompositionsOptions) => {
const {page, cleanup: cleanupPage} = await getPageAndCleanupFn({
passedInInstance: puppeteerInstance,
@@ -168,6 +170,7 @@ const internalGetCompositionsRaw = async ({
forceDeviceScaleFactor: undefined,
indent,
logLevel,
+ onBrowserDownload,
});
const cleanup: CleanupFn[] = [cleanupPage];
@@ -220,6 +223,7 @@ const internalGetCompositionsRaw = async ({
logLevel,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
});
})
@@ -264,8 +268,15 @@ export const getCompositions = (
port,
puppeteerInstance,
timeoutInMilliseconds,
- logLevel,
+ logLevel: passedLogLevel,
+ onBrowserDownload,
+ binariesDirectory,
+ offthreadVideoCacheSizeInBytes,
} = config ?? {};
+
+ const indent = false;
+ const logLevel = passedLogLevel ?? 'info';
+
return internalGetCompositions({
browserExecutable: browserExecutable ?? null,
chromiumOptions: chromiumOptions ?? {},
@@ -276,16 +287,17 @@ export const getCompositions = (
indent: undefined,
staticBase: null,
}).serializedString,
- indent: false,
+ indent,
onBrowserLog: onBrowserLog ?? null,
port: port ?? null,
puppeteerInstance: puppeteerInstance ?? undefined,
serveUrlOrWebpackUrl,
server: undefined,
timeoutInMilliseconds: timeoutInMilliseconds ?? DEFAULT_TIMEOUT,
- logLevel: logLevel ?? 'info',
- offthreadVideoCacheSizeInBytes:
- config?.offthreadVideoCacheSizeInBytes ?? null,
- binariesDirectory: config?.binariesDirectory ?? null,
+ logLevel,
+ offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,
+ binariesDirectory: binariesDirectory ?? null,
+ onBrowserDownload:
+ onBrowserDownload ?? defaultBrowserDownloadProgress(indent, logLevel),
});
};
diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.ts
index 15c3552202..85eeb4f208 100644
--- a/packages/renderer/src/index.ts
+++ b/packages/renderer/src/index.ts
@@ -81,7 +81,6 @@ export type {FfmpegOverrideFn} from './ffmpeg-override';
export {FileExtension} from './file-extensions';
export {FrameRange} from './frame-range';
export {getCompositions, GetCompositionsOptions} from './get-compositions';
-export {ensureLocalBrowser} from './get-local-browser-executable';
export {getSilentParts} from './get-silent-parts';
export {getVideoMetadata, VideoMetadata} from './get-video-metadata';
export {
@@ -99,6 +98,10 @@ export {ColorSpace} from './options/color-space';
export {DeleteAfter} from './options/delete-after';
export {OpenGlRenderer} from './options/gl';
export {NumberOfGifLoops} from './options/number-of-gif-loops';
+export {
+ DownloadBrowserProgressFn,
+ OnBrowserDownload,
+} from './options/on-browser-download';
export {AnyRemotionOption, RemotionOption, ToOptions} from './options/option';
export {X264Preset} from './options/x264-preset';
export {PixelFormat} from './pixel-format';
@@ -139,6 +142,7 @@ import {
supportedAudioCodecs,
} from './options/audio-codec';
import {getShouldRenderAudio} from './render-has-audio';
+import {toMegabytes} from './to-megabytes';
import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';
import {validateBitrate} from './validate-videobitrate';
import {
@@ -230,6 +234,7 @@ export const RenderInternals = {
resolveAudioCodec,
getShouldRenderAudio,
codecSupportsMedia,
+ toMegabytes,
};
// Warn of potential performance issues with Apple Silicon (M1 chip under Rosetta)
diff --git a/packages/renderer/src/open-browser.ts b/packages/renderer/src/open-browser.ts
index 4fb005573e..b23a528eaa 100644
--- a/packages/renderer/src/open-browser.ts
+++ b/packages/renderer/src/open-browser.ts
@@ -1,16 +1,16 @@
import type {Browser} from './browser';
import type {HeadlessBrowser} from './browser/Browser';
+import {defaultBrowserDownloadProgress} from './browser/browser-download-progress-bar';
import {puppeteer} from './browser/node';
import type {Viewport} from './browser/PuppeteerViewport';
-import {
- ensureLocalBrowser,
- getLocalBrowserExecutable,
-} from './get-local-browser-executable';
+import {ensureLocalBrowser} from './ensure-browser';
+import {getLocalBrowserExecutable} from './get-local-browser-executable';
import {getIdealVideoThreadsFlag} from './get-video-threads-flag';
import {isEqualOrBelowLogLevel, type LogLevel} from './log-level';
import {Log} from './logger';
import type {validOpenGlRenderers} from './options/gl';
import {DEFAULT_OPENGL_RENDERER, validateOpenGlRenderer} from './options/gl';
+import type {OnBrowserDownload} from './options/on-browser-download';
type OpenGlRenderer = (typeof validOpenGlRenderers)[number];
@@ -70,6 +70,7 @@ type InternalOpenBrowserOptions = {
indent: boolean;
browser: Browser;
logLevel: LogLevel;
+ onBrowserDownload: OnBrowserDownload;
};
export type OpenBrowserOptions = {
@@ -87,6 +88,7 @@ export const internalOpenBrowser = async ({
indent,
viewport,
logLevel,
+ onBrowserDownload,
}: InternalOpenBrowserOptions): Promise<HeadlessBrowser> => {
// @ts-expect-error Firefox
if (browser === 'firefox') {
@@ -96,9 +98,10 @@ export const internalOpenBrowser = async ({
}
await ensureLocalBrowser({
- preferredBrowserExecutable: browserExecutable,
+ browserExecutable,
logLevel,
indent,
+ onBrowserDownload,
});
const executablePath = getLocalBrowserExecutable(browserExecutable);
@@ -221,13 +224,18 @@ export const openBrowser = (
forceDeviceScaleFactor,
shouldDumpIo,
} = options ?? {};
+
+ const indent = false;
+ const logLevel = shouldDumpIo ? 'verbose' : 'info';
+
return internalOpenBrowser({
browser,
browserExecutable: browserExecutable ?? null,
chromiumOptions: chromiumOptions ?? {},
forceDeviceScaleFactor,
- indent: false,
+ indent,
viewport: null,
- logLevel: shouldDumpIo ? 'verbose' : 'info',
+ logLevel,
+ onBrowserDownload: defaultBrowserDownloadProgress(indent, logLevel),
});
};
diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsx
index f51b1793ee..21a786cf4b 100644
--- a/packages/renderer/src/options/index.tsx
+++ b/packages/renderer/src/options/index.tsx
@@ -19,6 +19,7 @@ import {logLevelOption} from './log-level';
import {mutedOption} from './mute';
import {numberOfGifLoopsOption} from './number-of-gif-loops';
import {offthreadVideoCacheSizeInBytesOption} from './offthreadvideo-cache-size';
+import {onBrowserDownloadOption} from './on-browser-download';
import type {AnyRemotionOption} from './option';
import {overwriteOption} from './overwrite';
import {preferLosslessAudioOption} from './prefer-lossless';
@@ -67,6 +68,7 @@ export const allOptions = {
separateAudioOption,
publicPathOption,
publicDirOption,
+ onBrowserDownloadOption,
};
export type AvailableOptions = keyof typeof allOptions;
diff --git a/packages/renderer/src/options/on-browser-download.tsx b/packages/renderer/src/options/on-browser-download.tsx
new file mode 100644
index 0000000000..2f598aed5b
--- /dev/null
+++ b/packages/renderer/src/options/on-browser-download.tsx
@@ -0,0 +1,33 @@
+import type {AnyRemotionOption} from './option';
+
+export type DownloadBrowserProgressFn = (progress: {
+ percent: number;
+ downloaded: number;
+ totalSize: number;
+}) => void;
+
+export type OnBrowserDownload = () => DownloadBrowserProgressFn;
+
+const cliFlag = 'no-browser-flag-available' as const;
+
+export const onBrowserDownloadOption = {
+ name: 'Browser download callback function',
+ cliFlag,
+ description: () => (
+ // TODO: Add a documentation function
+ <>
+ Gets called when this API needs to download a browser. Return another
+ function to receive download progress.
+ </>
+ ),
+ ssrName: 'onBrowserDownload' as const,
+ // TODO: Make sure the URL is correct
+ docLink: 'https://www.remotion.dev/docs/renderer/ensure-local-browser',
+ type: undefined as unknown as OnBrowserDownload,
+ getValue: () => {
+ throw new Error('does not support config file');
+ },
+ setConfig: () => {
+ throw new Error('does not support config file');
+ },
+} satisfies AnyRemotionOption<OnBrowserDownload>;
diff --git a/packages/renderer/src/options/options-map.ts b/packages/renderer/src/options/options-map.ts
index 92a5963cc9..853fd9c0b6 100644
--- a/packages/renderer/src/options/options-map.ts
+++ b/packages/renderer/src/options/options-map.ts
@@ -13,6 +13,7 @@ import {logLevelOption} from './log-level';
import {mutedOption} from './mute';
import {numberOfGifLoopsOption} from './number-of-gif-loops';
import {offthreadVideoCacheSizeInBytesOption} from './offthreadvideo-cache-size';
+import {onBrowserDownloadOption} from './on-browser-download';
import {preferLosslessAudioOption} from './prefer-lossless';
import {reproOption} from './repro';
import {scaleOption} from './scale';
@@ -42,6 +43,7 @@ export const optionsMap = {
forSeamlessAacConcatenation: forSeamlessAacConcatenationOption,
separateAudioTo: separateAudioOption,
audioCodec: audioCodecOption,
+ onBrowserDownload: onBrowserDownloadOption,
},
stitchFramesToVideo: {
separateAudioTo: separateAudioOption,
@@ -52,18 +54,21 @@ export const optionsMap = {
logLevel: logLevelOption,
timeoutInMilliseconds: delayRenderTimeoutInMillisecondsOption,
binariesDirectory: binariesDirectoryOption,
+ onBrowserDownload: onBrowserDownloadOption,
},
getCompositions: {
offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytesOption,
logLevel: logLevelOption,
timeoutInMilliseconds: delayRenderTimeoutInMillisecondsOption,
binariesDirectory: binariesDirectoryOption,
+ onBrowserDownload: onBrowserDownloadOption,
},
selectComposition: {
offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytesOption,
logLevel: logLevelOption,
timeoutInMilliseconds: delayRenderTimeoutInMillisecondsOption,
binariesDirectory: binariesDirectoryOption,
+ onBrowserDownload: onBrowserDownloadOption,
},
renderFrames: {
forSeamlessAacConcatenation: forSeamlessAacConcatenationOption,
diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.ts
index b83a9fdf38..2d1317d0c1 100644
--- a/packages/renderer/src/render-frames.ts
+++ b/packages/renderer/src/render-frames.ts
@@ -12,6 +12,7 @@ import {DEFAULT_BROWSER} from './browser';
import type {BrowserExecutable} from './browser-executable';
import type {BrowserLog} from './browser-log';
import type {HeadlessBrowser} from './browser/Browser';
+import {defaultBrowserDownloadProgress} from './browser/browser-download-progress-bar';
import type {Page} from './browser/BrowserPage';
import type {ConsoleMessage} from './browser/ConsoleMessage';
import {isTargetClosedErr} from './browser/is-target-closed-err';
@@ -35,11 +36,13 @@ import {
import {getRealFrameRange} from './get-frame-to-render';
import type {VideoImageFormat} from './image-format';
import {DEFAULT_JPEG_QUALITY, validateJpegQuality} from './jpeg-quality';
+import type {LogLevel} from './log-level';
import {Log} from './logger';
import type {CancelSignal} from './make-cancel-signal';
import {cancelErrorMessages, isUserCancelledRender} from './make-cancel-signal';
import type {ChromiumOptions} from './open-browser';
import {internalOpenBrowser} from './open-browser';
+import type {OnBrowserDownload} from './options/on-browser-download';
import type {ToOptions} from './options/option';
import type {optionsMap} from './options/options-map';
import {startPerfMeasure, stopPerfMeasure} from './perf';
@@ -98,6 +101,7 @@ export type InternalRenderFramesOptions = {
serializedResolvedPropsWithCustomSchema: string;
parallelEncodingEnabled: boolean;
compositionStart: number;
+ onBrowserDownload: OnBrowserDownload;
} & ToOptions<typeof optionsMap.renderFrames>;
type InnerRenderFramesOptions = {
@@ -182,6 +186,7 @@ export type RenderFramesOptions = {
composition: VideoConfig;
muted?: boolean;
concurrency?: number | string | null;
+ onBrowserDownload?: OnBrowserDownload;
serveUrl: string;
} & Partial<ToOptions<typeof optionsMap.renderFrames>>;
@@ -702,6 +707,7 @@ const internalRenderFramesRaw = ({
binariesDirectory,
forSeamlessAacConcatenation,
compositionStart,
+ onBrowserDownload,
}: InternalRenderFramesOptions): Promise<RenderFramesOutput> => {
validateDimension(
composition.height,
@@ -735,6 +741,7 @@ const internalRenderFramesRaw = ({
indent,
viewport: null,
logLevel,
+ onBrowserDownload,
});
const browserInstance = puppeteerInstance ?? makeBrowser();
@@ -909,9 +916,10 @@ export const renderFrames = (
timeoutInMilliseconds,
verbose,
quality,
- logLevel,
+ logLevel: passedLogLevel,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
} = options;
if (!composition) {
@@ -932,6 +940,10 @@ export const renderFrames = (
);
}
+ const logLevel: LogLevel =
+ verbose || dumpBrowserLogs ? 'verbose' : passedLogLevel ?? 'info';
+ const indent = false;
+
return internalRenderFrames({
browserExecutable: browserExecutable ?? null,
cancelSignal,
@@ -942,7 +954,7 @@ export const renderFrames = (
everyNthFrame: everyNthFrame ?? 1,
frameRange: frameRange ?? null,
imageFormat: imageFormat ?? 'jpeg',
- indent: false,
+ indent,
jpegQuality: jpegQuality ?? DEFAULT_JPEG_QUALITY,
onDownload: onDownload ?? null,
serializedInputPropsWithCustomSchema:
@@ -966,7 +978,7 @@ export const renderFrames = (
outputDir,
port: port ?? null,
scale: scale ?? 1,
- logLevel: verbose || dumpBrowserLogs ? 'verbose' : logLevel ?? 'info',
+ logLevel,
timeoutInMilliseconds: timeoutInMilliseconds ?? DEFAULT_TIMEOUT,
webpackBundleOrServeUrl: serveUrl,
server: undefined,
@@ -975,5 +987,7 @@ export const renderFrames = (
binariesDirectory: binariesDirectory ?? null,
compositionStart: 0,
forSeamlessAacConcatenation: false,
+ onBrowserDownload:
+ onBrowserDownload ?? defaultBrowserDownloadProgress(indent, logLevel),
});
};
diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.ts
index 3391526a68..747771bc72 100644
--- a/packages/renderer/src/render-media.ts
+++ b/packages/renderer/src/render-media.ts
@@ -8,6 +8,7 @@ import {type RenderMediaOnDownload} from './assets/download-and-map-assets-to-fi
import type {BrowserExecutable} from './browser-executable';
import type {BrowserLog} from './browser-log';
import type {HeadlessBrowser} from './browser/Browser';
+import {defaultBrowserDownloadProgress} from './browser/browser-download-progress-bar';
import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
import {canUseParallelEncoding} from './can-use-parallel-encoding';
import type {Codec} from './codec';
@@ -239,6 +240,7 @@ const internalRenderMediaRaw = ({
separateAudioTo,
forSeamlessAacConcatenation,
compositionStart,
+ onBrowserDownload,
}: InternalRenderMediaOptions): Promise<RenderMediaResult> => {
if (repro) {
enableRepro({
@@ -629,6 +631,7 @@ const internalRenderMediaRaw = ({
binariesDirectory,
compositionStart,
forSeamlessAacConcatenation,
+ onBrowserDownload,
});
return renderFramesProc;
@@ -838,13 +841,14 @@ export const renderMedia = ({
preferLossless,
verbose,
quality,
- logLevel,
+ logLevel: passedLogLevel,
offthreadVideoCacheSizeInBytes,
colorSpace,
repro,
binariesDirectory,
separateAudioTo,
forSeamlessAacConcatenation,
+ onBrowserDownload,
}: RenderMediaOptions): Promise<RenderMediaResult> => {
if (quality !== undefined) {
console.warn(
@@ -852,6 +856,10 @@ export const renderMedia = ({
);
}
+ const indent = false;
+ const logLevel =
+ verbose || dumpBrowserLogs ? 'verbose' : passedLogLevel ?? 'info';
+
return internalRenderMedia({
proResProfile: proResProfile ?? undefined,
x264Preset: x264Preset ?? null,
@@ -895,9 +903,9 @@ export const renderMedia = ({
videoBitrate: videoBitrate ?? null,
encodingMaxRate: encodingMaxRate ?? null,
encodingBufferSize: encodingBufferSize ?? null,
- logLevel: verbose || dumpBrowserLogs ? 'verbose' : logLevel ?? 'info',
+ logLevel,
preferLossless: preferLossless ?? false,
- indent: false,
+ indent,
onCtrlCExit: () => undefined,
server: undefined,
serializedResolvedPropsWithCustomSchema:
@@ -913,6 +921,8 @@ export const renderMedia = ({
binariesDirectory: binariesDirectory ?? null,
separateAudioTo: separateAudioTo ?? null,
forSeamlessAacConcatenation: forSeamlessAacConcatenation ?? false,
+ onBrowserDownload:
+ onBrowserDownload ?? defaultBrowserDownloadProgress(indent, logLevel),
// TODO: In the future, introduce this as a public API when launching the distributed rendering API
compositionStart: 0,
});
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index 9b9106ef31..d1e39d53e8 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -8,6 +8,7 @@ import {DEFAULT_BROWSER} from './browser';
import type {BrowserExecutable} from './browser-executable';
import type {BrowserLog} from './browser-log';
import type {HeadlessBrowser} from './browser/Browser';
+import {defaultBrowserDownloadProgress} from './browser/browser-download-progress-bar';
import type {ConsoleMessage} from './browser/ConsoleMessage';
import type {SourceMapGetter} from './browser/source-map-getter';
import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
@@ -128,6 +129,7 @@ const innerRenderStill = async ({
logLevel,
indent,
serializedResolvedPropsWithCustomSchema,
+ onBrowserDownload,
}: InternalRenderStillOptions & {
downloadMap: DownloadMap;
serveUrl: string;
@@ -204,6 +206,7 @@ const innerRenderStill = async ({
indent,
viewport: null,
logLevel,
+ onBrowserDownload,
}));
const page = await browserInstance.newPage(sourceMapGetter, logLevel, indent);
await page.setViewport({
@@ -434,8 +437,9 @@ export const renderStill = (
verbose,
quality,
offthreadVideoCacheSizeInBytes,
- logLevel,
+ logLevel: passedLogLevel,
binariesDirectory,
+ onBrowserDownload,
} = options;
if (typeof jpegQuality !== 'undefined' && imageFormat !== 'jpeg') {
@@ -450,6 +454,10 @@ export const renderStill = (
);
}
+ const logLevel =
+ passedLogLevel ?? (verbose || dumpBrowserLogs ? 'verbose' : 'info');
+ const indent = false;
+
return internalRenderStill({
composition,
browserExecutable: browserExecutable ?? null,
@@ -458,7 +466,7 @@ export const renderStill = (
envVariables: envVariables ?? {},
frame: frame ?? 0,
imageFormat: imageFormat ?? DEFAULT_STILL_IMAGE_FORMAT,
- indent: false,
+ indent,
serializedInputPropsWithCustomSchema:
NoReactInternals.serializeJSONWithDate({
staticBase: null,
@@ -476,7 +484,7 @@ export const renderStill = (
server: undefined,
serveUrl,
timeoutInMilliseconds: timeoutInMilliseconds ?? DEFAULT_TIMEOUT,
- logLevel: logLevel ?? (verbose || dumpBrowserLogs ? 'verbose' : 'info'),
+ logLevel,
serializedResolvedPropsWithCustomSchema:
NoReactInternals.serializeJSONWithDate({
indent: undefined,
@@ -485,5 +493,7 @@ export const renderStill = (
}).serializedString,
offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,
binariesDirectory: binariesDirectory ?? null,
+ onBrowserDownload:
+ onBrowserDownload ?? defaultBrowserDownloadProgress(indent, logLevel),
});
};
diff --git a/packages/renderer/src/select-composition.ts b/packages/renderer/src/select-composition.ts
index 074ad643bc..7f9136a211 100644
--- a/packages/renderer/src/select-composition.ts
+++ b/packages/renderer/src/select-composition.ts
@@ -3,6 +3,7 @@ import {NoReactInternals} from 'remotion/no-react';
import type {BrowserExecutable} from './browser-executable';
import type {BrowserLog} from './browser-log';
import type {HeadlessBrowser} from './browser/Browser';
+import {defaultBrowserDownloadProgress} from './browser/browser-download-progress-bar';
import type {Page} from './browser/BrowserPage';
import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
import {handleJavascriptException} from './error-handling/handle-javascript-exception';
@@ -195,6 +196,7 @@ export const internalSelectCompositionRaw = async (
timeoutInMilliseconds,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
} = options;
const {page, cleanup: cleanupPage} = await getPageAndCleanupFn({
@@ -204,6 +206,7 @@ export const internalSelectCompositionRaw = async (
forceDeviceScaleFactor: undefined,
indent,
logLevel,
+ onBrowserDownload,
});
cleanup.push(() => cleanupPage());
@@ -257,6 +260,7 @@ export const internalSelectCompositionRaw = async (
server,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
});
})
@@ -301,11 +305,15 @@ export const selectComposition = async (
puppeteerInstance,
timeoutInMilliseconds,
verbose,
- logLevel,
+ logLevel: passedLogLevel,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ onBrowserDownload,
} = options;
+ const indent = false;
+ const logLevel = passedLogLevel ?? verbose ? 'verbose' : 'info';
+
const data = await internalSelectComposition({
id,
serveUrl,
@@ -322,11 +330,13 @@ export const selectComposition = async (
port: port ?? null,
puppeteerInstance,
timeoutInMilliseconds: timeoutInMilliseconds ?? DEFAULT_TIMEOUT,
- logLevel: logLevel ?? verbose ? 'verbose' : 'info',
- indent: false,
+ logLevel,
+ indent,
server: undefined,
offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,
binariesDirectory: binariesDirectory ?? null,
+ onBrowserDownload:
+ onBrowserDownload ?? defaultBrowserDownloadProgress(indent, logLevel),
});
return data.metadata;
};
diff --git a/packages/renderer/src/test-gpu.ts b/packages/renderer/src/test-gpu.ts
index 965ccda595..f28ee67980 100644
--- a/packages/renderer/src/test-gpu.ts
+++ b/packages/renderer/src/test-gpu.ts
@@ -2,6 +2,7 @@ import type {BrowserExecutable} from './browser-executable';
import {getPageAndCleanupFn} from './get-browser-instance';
import type {LogLevel} from './log-level';
import type {ChromiumOptions} from './open-browser';
+import type {OnBrowserDownload} from './options/on-browser-download';
import {puppeteerEvaluateWithCatch} from './puppeteer-evaluate';
type Item = {
@@ -15,12 +16,14 @@ export const getChromiumGpuInformation = async ({
logLevel,
chromiumOptions,
timeoutInMilliseconds,
+ onBrowserDownload,
}: {
browserExecutable: BrowserExecutable;
indent: boolean;
logLevel: LogLevel;
chromiumOptions: ChromiumOptions;
timeoutInMilliseconds: number;
+ onBrowserDownload: OnBrowserDownload;
}) => {
const {page, cleanup} = await getPageAndCleanupFn({
passedInInstance: undefined,
@@ -29,6 +32,7 @@ export const getChromiumGpuInformation = async ({
forceDeviceScaleFactor: undefined,
indent,
logLevel,
+ onBrowserDownload,
});
await page.goto({url: 'chrome://gpu', timeout: 12000});
diff --git a/packages/renderer/src/to-megabytes.ts b/packages/renderer/src/to-megabytes.ts
new file mode 100644
index 0000000000..da4a7742f7
--- /dev/null
+++ b/packages/renderer/src/to-megabytes.ts
@@ -0,0 +1,4 @@
+export function toMegabytes(bytes: number) {
+ const mb = bytes / 1024 / 1024;
+ return `${Math.round(mb * 10) / 10} Mb`;
+}