Skip to content

🎥 Make videos programmatically with React

`@remotion/cli`: Migrate runs, gl, repro, and muted CLI flags to options system

JonnyBurgeree489bea5e1f
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 2df9a95262..9c8d94b7a7 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -24,8 +24,6 @@ import {shouldUseNonOverlayingLogger} from './should-use-non-overlaying-logger';
import {showMultiCompositionsPicker} from './show-compositions-picker';
import {truthy} from './truthy';
-const DEFAULT_RUNS = 3;
-
const {
audioBitrateOption,
x264Option,
@@ -73,6 +71,7 @@ const {
overrideFpsOption,
overrideDurationOption,
bundleCacheOption,
+ runsOption,
} = BrowserSafeApis.options;
const getValidConcurrency = (cliConcurrency: number | string | null) => {
@@ -188,7 +187,7 @@ export const benchmarkCommand = async (
args: string[],
logLevel: LogLevel,
) => {
- const runs: number = parsedCli.runs ?? DEFAULT_RUNS;
+ const runs = runsOption.getValue({commandLine: parsedCli}).value;
const {file, reason, remainingArgs} = findEntryPoint({
args,
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index 5e62cdd070..28806252a4 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -1,6 +1,5 @@
import type {
AudioCodec,
- OpenGlRenderer,
StillImageFormat,
VideoImageFormat,
} from '@remotion/renderer';
@@ -61,6 +60,10 @@ const {
versionFlagOption,
bundleCacheOption,
envFileOption,
+ glOption,
+ runsOption,
+ reproOption,
+ mutedOption,
} = BrowserSafeApis.options;
export type CommandLineOptions = {
@@ -131,15 +134,15 @@ export type CommandLineOptions = {
[experimentalClientSideRenderingOption.cliFlag]: TypeOfOption<
typeof experimentalClientSideRenderingOption
>;
- muted: boolean;
+ [mutedOption.cliFlag]: TypeOfOption<typeof mutedOption>;
[overrideHeightOption.cliFlag]: TypeOfOption<typeof overrideHeightOption>;
[overrideWidthOption.cliFlag]: TypeOfOption<typeof overrideWidthOption>;
[overrideFpsOption.cliFlag]: TypeOfOption<typeof overrideFpsOption>;
[overrideDurationOption.cliFlag]: TypeOfOption<typeof overrideDurationOption>;
- runs: number;
+ [runsOption.cliFlag]: TypeOfOption<typeof runsOption>;
concurrencies: string;
[enforceAudioOption.cliFlag]: TypeOfOption<typeof enforceAudioOption>;
- gl: OpenGlRenderer;
+ [glOption.cliFlag]: TypeOfOption<typeof glOption>;
[packageManagerOption.cliFlag]: TypeOfOption<typeof packageManagerOption>;
[webpackPollOption.cliFlag]: TypeOfOption<typeof webpackPollOption>;
['no-open']: boolean;
@@ -154,7 +157,7 @@ export type CommandLineOptions = {
[enableMultiprocessOnLinuxOption.cliFlag]: TypeOfOption<
typeof enableMultiprocessOnLinuxOption
>;
- repro: boolean;
+ [reproOption.cliFlag]: TypeOfOption<typeof reproOption>;
[imageSequencePatternOption.cliFlag]: TypeOfOption<
typeof imageSequencePatternOption
>;
diff --git a/packages/docs/docs/cli/benchmark.mdx b/packages/docs/docs/cli/benchmark.mdx
index 5ea0e29252..dcbaba37ee 100644
--- a/packages/docs/docs/cli/benchmark.mdx
+++ b/packages/docs/docs/cli/benchmark.mdx
@@ -21,7 +21,7 @@ If `composition-ids` is not passed, Remotion will let you select compositions fr
### `--runs`
-Specify how many times video must be rendered. Default value is 3.
+<Options id="runs" />
### `--concurrencies`
@@ -93,7 +93,7 @@ Inherited from [`npx remotion render`](/docs/cli/render#--disable-web-security)
### `--gl`
-Inherited from [`npx remotion render`](/docs/cli/render#--gl)
+<Options id="gl" cli />
### `--chrome-mode`<AvailableFrom v="4.0.248" />
diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsx
index 877b934942..5e262b2aba 100644
--- a/packages/renderer/src/options/index.tsx
+++ b/packages/renderer/src/options/index.tsx
@@ -62,6 +62,7 @@ import {publicDirOption} from './public-dir';
import {publicLicenseKeyOption} from './public-license-key';
import {publicPathOption} from './public-path';
import {reproOption} from './repro';
+import {runsOption} from './runs';
import {scaleOption} from './scale';
import {separateAudioOption} from './separate-audio';
import {stillFrameOption} from './still-frame';
@@ -107,6 +108,7 @@ export const allOptions = {
beepOnFinishOption,
numberOfGifLoopsOption,
reproOption,
+ runsOption,
pixelFormatOption,
preferLosslessOption: preferLosslessAudioOption,
proResProfileOption,
diff --git a/packages/renderer/src/options/runs.tsx b/packages/renderer/src/options/runs.tsx
new file mode 100644
index 0000000000..7118ba2ea3
--- /dev/null
+++ b/packages/renderer/src/options/runs.tsx
@@ -0,0 +1,47 @@
+import type {AnyRemotionOption} from './option';
+
+const DEFAULT_RUNS = 3;
+
+let currentRuns: number = DEFAULT_RUNS;
+
+const cliFlag = 'runs' as const;
+
+export const runsOption = {
+ name: 'Benchmark runs',
+ cliFlag,
+ description: () => (
+ <>
+ Specify how many times the video should be rendered during a benchmark.
+ Default <code>{DEFAULT_RUNS}</code>.
+ </>
+ ),
+ ssrName: null,
+ docLink: 'https://www.remotion.dev/docs/cli/benchmark#--runs',
+ type: DEFAULT_RUNS as number,
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag] !== undefined) {
+ const value = Number(commandLine[cliFlag]);
+ if (isNaN(value) || value < 1) {
+ throw new Error(
+ `--runs must be a positive number, but got ${commandLine[cliFlag]}`,
+ );
+ }
+
+ return {value, source: 'cli'};
+ }
+
+ if (currentRuns !== DEFAULT_RUNS) {
+ return {value: currentRuns, source: 'config'};
+ }
+
+ return {value: DEFAULT_RUNS, source: 'default'};
+ },
+ setConfig: (value: number) => {
+ if (typeof value !== 'number' || isNaN(value) || value < 1) {
+ throw new Error(`Runs must be a positive number, but got ${value}`);
+ }
+
+ currentRuns = value;
+ },
+ id: cliFlag,
+} satisfies AnyRemotionOption<number>;