🎥 Make videos programmatically with React
Convert concurrency to a proper AnyRemotionOption
JonnyBurgerbff3ef1ed761
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 567c32a727..3f9463fb34 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -37,7 +37,6 @@ import {setBufferStateDelayInMilliseconds,} from './buffer-state-delay-in-milliseconds';import type {Concurrency} from './concurrency';-import {setConcurrency} from './concurrency';import {getEntryPoint, setEntryPoint} from './entry-point';import {setDotEnvLocation} from './env-file';import {@@ -63,6 +62,7 @@ import {getWidth, overrideWidth} from './width';export type {Concurrency, WebpackConfiguration, WebpackOverrideFn};const {+ concurrencyOption,offthreadVideoCacheSizeInBytesOption,x264Option,audioBitrateOption,@@ -664,7 +664,7 @@ export const Config: FlatConfig = {setChromiumOpenGlRenderer: glOption.setConfig,setChromiumUserAgent: userAgentOption.setConfig,setDotEnvLocation,- setConcurrency,+ setConcurrency: concurrencyOption.setConfig,setChromiumMultiProcessOnLinux: enableMultiprocessOnLinuxOption.setConfig,setChromiumDarkMode: darkModeOption.setConfig,setQuality: () => {diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex d37a614d58..3a57a0ca11 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -1,11 +1,13 @@import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';+import {BrowserSafeApis} from '@remotion/renderer/client';import fs from 'node:fs';import path from 'node:path';import {ConfigInternals} from './config';import {getEnvironmentVariables} from './get-env';import {getInputProps} from './get-input-props';import {Log} from './log';+import {parsedCli} from './parsed-cli';const getAndValidateFrameRange = (logLevel: LogLevel, indent: boolean) => {const frameRange = ConfigInternals.getRange();@@ -58,7 +60,9 @@ export const getCliOptions = (options: {? true: ConfigInternals.getShouldOutputImageSequence(frameRange);- const concurrency = ConfigInternals.getConcurrency();+ const concurrency = BrowserSafeApis.options.concurrencyOption.getValue({+ commandLine: parsedCli,+ }).value;const height = ConfigInternals.getHeight();const width = ConfigInternals.getWidth();diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.tsindex af0964ec6e..a00f199333 100644--- a/packages/cli/src/get-render-defaults.ts+++ b/packages/cli/src/get-render-defaults.ts@@ -8,6 +8,7 @@ const {x264Option,audioBitrateOption,offthreadVideoCacheSizeInBytesOption,+ concurrencyOption,offthreadVideoThreadsOption,scaleOption,jpegQualityOption,@@ -49,7 +50,7 @@ export const getRenderDefaults = (): RenderDefaults => {const logLevel = logLevelOption.getValue({commandLine: parsedCli}).value;const defaultCodec = ConfigInternals.getOutputCodecOrUndefined();const concurrency = RenderInternals.resolveConcurrency(- ConfigInternals.getConcurrency(),+ concurrencyOption.getValue({commandLine: parsedCli}).value,);const pixelFormat = pixelFormatOption.getValue({commandLine: parsedCli,diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex 1d0c8e8bdf..9d8e5e62ce 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -13,6 +13,7 @@ import {parsedCli} from './parsed-cli';const {beepOnFinishOption,colorSpaceOption,+ concurrencyOption,disallowParallelEncodingOption,offthreadVideoCacheSizeInBytesOption,encodingBufferSizeOption,@@ -75,7 +76,7 @@ export type CommandLineOptions = {[beepOnFinishOption.cliFlag]: TypeOfOption<typeof beepOnFinishOption>;version: string;codec: Codec;- concurrency: number;+ [concurrencyOption.cliFlag]: TypeOfOption<typeof concurrencyOption>;timeout: number;config: string;['public-dir']: string;@@ -140,10 +141,6 @@ export const parseCommandLine = () => {Config.setCachingEnabled(parsedCli['bundle-cache'] !== 'false');}- if (parsedCli.concurrency) {- Config.setConcurrency(parsedCli.concurrency);- }-if (parsedCli.height) {Config.overrideHeight(parsedCli.height);}@@ -177,10 +174,6 @@ export const parseCommandLine = () => {Config.setPublicLicenseKey(parsedCli['license-key']);}- if (parsedCli['public-license-key']) {- Config.setPublicLicenseKey(parsedCli['public-license-key']);- }-if (typeof parsedCli['webpack-poll'] !== 'undefined') {Config.setWebpackPollingInMilliseconds(parsedCli['webpack-poll']);}diff --git a/packages/docs/docs/cli/render.mdx b/packages/docs/docs/cli/render.mdxindex b1aea02c87..2b3a914168 100644--- a/packages/docs/docs/cli/render.mdx+++ b/packages/docs/docs/cli/render.mdx@@ -41,7 +41,7 @@ Inline JSON string isn't supported on Windows shells because it removes the `"`### `--concurrency`-[How many CPU threads to use.](/docs/config#setconcurrency) Minimum 1. The maximum is the amount of threads you have (In Node.JS `os.cpus().length`). You can also provide a percentage value (e.g. `50%`).+<Options id="concurrency" />### `--pixel-format`diff --git a/packages/docs/docs/cloudrun/cli/render.mdx b/packages/docs/docs/cloudrun/cli/render.mdxindex 9965b9561d..9265804c6a 100644--- a/packages/docs/docs/cloudrun/cli/render.mdx+++ b/packages/docs/docs/cloudrun/cli/render.mdx@@ -75,7 +75,7 @@ Specify a specific bucket name to be used for the output. The resulting Google C### `--concurrency`-A number or a string describing how many browser tabs should be opened. Default "50%".+<Options id="concurrency" />:::noteBefore v4.0.76, this was "100%" by default. It is now aligned to the other server-side rendering APIs.diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdxindex a4d42848ed..348ddfa60c 100644--- a/packages/docs/docs/config.mdx+++ b/packages/docs/docs/config.mdx@@ -307,8 +307,7 @@ The [command line flag](/docs/cli/render#--gl) `--gl` will take precedence over## `setConcurrency()`-Sets how many Puppeteer instances will work on rendering your video in parallel.-Default: `null`, meaning **half of the threads** available on your CPU.+<Options id="concurrency" />```ts twoslash title="remotion.config.ts"import {Config} from '@remotion/cli/config';diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.tsindex 90457f574e..e2c96e88bf 100644--- a/packages/renderer/src/index.ts+++ b/packages/renderer/src/index.ts@@ -103,6 +103,7 @@ export {openBrowser} from './open-browser';export type {ChromiumOptions} from './open-browser';export {ChromeMode} from './options/chrome-mode';export {ColorSpace} from './options/color-space';+export type {Concurrency} from './options/concurrency';export type {DeleteAfter} from './options/delete-after';export {OpenGlRenderer} from './options/gl';export {NumberOfGifLoops} from './options/number-of-gif-loops';diff --git a/packages/renderer/src/options/concurrency.tsx b/packages/renderer/src/options/concurrency.tsxnew file mode 100644index 0000000000..81314bd273--- /dev/null+++ b/packages/renderer/src/options/concurrency.tsx@@ -0,0 +1,46 @@+import type {AnyRemotionOption} from './option';++export type Concurrency = number | string | null;++let currentConcurrency: Concurrency = null;++const cliFlag = 'concurrency' as const;++export const concurrencyOption = {+ name: 'Concurrency',+ cliFlag,+ description: () => (+ <>+ How many CPU threads to use. Minimum 1. The maximum is the amount of+ threads you have (In Node.JS <code>os.cpus().length</code>). You can also+ provide a percentage value (e.g. <code>50%</code>).+ </>+ ),+ ssrName: 'concurrency' as const,+ docLink: 'https://www.remotion.dev/docs/config#setconcurrency',+ type: null as Concurrency,+ getValue: ({commandLine}) => {+ if (commandLine[cliFlag] !== undefined) {+ return {+ source: 'cli',+ value: commandLine[cliFlag] as Concurrency,+ };+ }++ if (currentConcurrency !== null) {+ return {+ source: 'config',+ value: currentConcurrency,+ };+ }++ return {+ source: 'default',+ value: null,+ };+ },+ setConfig: (value) => {+ currentConcurrency = value;+ },+ id: cliFlag,+} satisfies AnyRemotionOption<Concurrency>;diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsxindex 563a2b4c84..bb1e7dcb3f 100644--- a/packages/renderer/src/options/index.tsx+++ b/packages/renderer/src/options/index.tsx@@ -7,6 +7,7 @@ import {binariesDirectoryOption} from './binaries-directory';import {browserExecutableOption} from './browser-executable';import {chromeModeOption} from './chrome-mode';import {colorSpaceOption} from './color-space';+import {concurrencyOption} from './concurrency';import {crfOption} from './crf';import {enableCrossSiteIsolationOption} from './cross-site-isolation';import {darkModeOption} from './dark-mode';@@ -68,6 +69,7 @@ import {x264Option} from './x264-preset';export const allOptions = {audioCodecOption,browserExecutableOption,+ concurrencyOption,scaleOption,crfOption,jpegQualityOption,