Skip to content

🎥 Make videos programmatically with React

Migrate webpack-poll, disable-keyboard-shortcuts, enable-experimental-client-side-rendering, image-sequence-pattern to RemotionOption pattern

Jonny Burger104f1fdda448
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index e0ab20d8d3..b32ef9bf30 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -52,10 +52,7 @@ import type {WebpackOverrideFn} from './override-webpack';
import {overrideWebpackConfig} from './override-webpack';
import {setPort, setRendererPort, setStudioPort} from './preview-server';
import {setWebpackCaching} from './webpack-caching';
-import {
- getWebpackPolling,
- setWebpackPollingInMilliseconds,
-} from './webpack-poll';
+import {getWebpackPolling} from './webpack-poll';
export type {Concurrency, WebpackConfiguration, WebpackOverrideFn};
@@ -120,6 +117,7 @@ const {
overrideFpsOption,
overrideDurationOption,
outDirOption,
+ webpackPollOption,
} = BrowserSafeApis.options;
declare global {
@@ -659,7 +657,7 @@ export const Config: FlatConfig = {
setExperimentalClientSideRenderingEnabled:
experimentalClientSideRenderingOption.setConfig,
setNumberOfSharedAudioTags: numberOfSharedAudioTagsOption.setConfig,
- setWebpackPollingInMilliseconds,
+ setWebpackPollingInMilliseconds: webpackPollOption.setConfig,
setShouldOpenBrowser,
setBufferStateDelayInMilliseconds,
overrideWebpackConfig,
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index 4cecca6fd3..db40bf2de3 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -48,6 +48,10 @@ const {
overrideDurationOption,
outDirOption,
packageManagerOption,
+ webpackPollOption,
+ keyboardShortcutsOption,
+ experimentalClientSideRenderingOption,
+ imageSequencePatternOption,
} = BrowserSafeApis.options;
export type CommandLineOptions = {
@@ -112,8 +116,12 @@ export type CommandLineOptions = {
port: number;
frame: string | number;
['disable-headless']: boolean;
- ['disable-keyboard-shortcuts']: boolean;
- ['enable-experimental-client-side-rendering']: boolean;
+ [keyboardShortcutsOption.cliFlag]: TypeOfOption<
+ typeof keyboardShortcutsOption
+ >;
+ [experimentalClientSideRenderingOption.cliFlag]: TypeOfOption<
+ typeof experimentalClientSideRenderingOption
+ >;
muted: boolean;
[overrideHeightOption.cliFlag]: TypeOfOption<typeof overrideHeightOption>;
[overrideWidthOption.cliFlag]: TypeOfOption<typeof overrideWidthOption>;
@@ -124,7 +132,7 @@ export type CommandLineOptions = {
[enforceAudioOption.cliFlag]: TypeOfOption<typeof enforceAudioOption>;
gl: OpenGlRenderer;
[packageManagerOption.cliFlag]: TypeOfOption<typeof packageManagerOption>;
- ['webpack-poll']: number;
+ [webpackPollOption.cliFlag]: TypeOfOption<typeof webpackPollOption>;
['no-open']: boolean;
['browser']: string;
['browser-args']: string;
@@ -138,7 +146,9 @@ export type CommandLineOptions = {
typeof enableMultiprocessOnLinuxOption
>;
repro: boolean;
- 'image-sequence-pattern': string;
+ [imageSequencePatternOption.cliFlag]: TypeOfOption<
+ typeof imageSequencePatternOption
+ >;
'license-key': string;
[publicLicenseKeyOption.cliFlag]: string;
[forceNewStudioOption.cliFlag]: TypeOfOption<typeof forceNewStudioOption>;
@@ -173,8 +183,4 @@ export const parseCommandLine = () => {
) {
Config.setPublicLicenseKey(parsedCli['license-key']);
}
-
- if (typeof parsedCli['webpack-poll'] !== 'undefined') {
- Config.setWebpackPollingInMilliseconds(parsedCli['webpack-poll']);
- }
};
diff --git a/packages/cli/src/parsed-cli.ts b/packages/cli/src/parsed-cli.ts
index 76a1675fcf..378ea316d2 100644
--- a/packages/cli/src/parsed-cli.ts
+++ b/packages/cli/src/parsed-cli.ts
@@ -23,7 +23,8 @@ export const BooleanFlags = [
BrowserSafeApis.options.darkModeOption.cliFlag,
BrowserSafeApis.options.ignoreCertificateErrorsOption.cliFlag,
'disable-headless',
- 'disable-keyboard-shortcuts',
+ BrowserSafeApis.options.keyboardShortcutsOption.cliFlag,
+ BrowserSafeApis.options.experimentalClientSideRenderingOption.cliFlag,
'default-only',
'no-open',
BrowserSafeApis.options.ipv4Option.cliFlag,
diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.ts
index 1bf1f5aa37..e7531549cd 100644
--- a/packages/cli/src/studio.ts
+++ b/packages/cli/src/studio.ts
@@ -42,6 +42,7 @@ const {
numberOfSharedAudioTagsOption,
audioLatencyHintOption,
ipv4Option,
+ webpackPollOption,
} = BrowserSafeApis.options;
export const studioCommand = async (
@@ -158,7 +159,7 @@ export const studioCommand = async (
remotionRoot,
relativePublicDir,
webpackOverride: ConfigInternals.getWebpackOverrideFn(),
- poll: ConfigInternals.getWebpackPolling(),
+ poll: webpackPollOption.getValue({commandLine: parsedCli}).value,
getRenderDefaults,
getRenderQueue,
numberOfAudioTags: numberOfSharedAudioTagsOption.getValue({
diff --git a/packages/docs/docs/cli/render.mdx b/packages/docs/docs/cli/render.mdx
index c54eb2d826..3bf3a77db4 100644
--- a/packages/docs/docs/cli/render.mdx
+++ b/packages/docs/docs/cli/render.mdx
@@ -61,14 +61,7 @@ Inline JSON string isn't supported on Windows shells because it removes the `"`
### `--image-sequence-pattern` <AvailableFrom v="4.0.313" />
-[Pattern for naming image sequence files. Supports `[frame]` for the zero-padded frame number and `[ext]` for the file extension.]
-
-**Example:**
-
-```bash
-npx remotion render ... --sequence --image-sequence-pattern='frame_[frame]_custom.[ext]'
-# Produces: frame_0001_custom.jpeg, frame_0002_custom.jpeg, ...
-```
+<Options id="image-sequence-pattern" />
### `--config`<AvailableFrom v="1.2.0" />
diff --git a/packages/docs/docs/cli/studio.mdx b/packages/docs/docs/cli/studio.mdx
index 81907c98eb..ff45d58038 100644
--- a/packages/docs/docs/cli/studio.mdx
+++ b/packages/docs/docs/cli/studio.mdx
@@ -52,16 +52,15 @@ Specify a location for a dotenv file - Default `.env`. [Read about how environme
### `--disable-keyboard-shortcuts`<AvailableFrom v="3.2.11" />
-[Disables all keyboard shortcuts in the Studio](/docs/config#setkeyboardshortcutsenabled).
+<Options id="disable-keyboard-shortcuts" />
### `--enable-experimental-client-side-rendering`<AvailableFrom v="4.0.387" />
-[Enables experimental client-side rendering in the Studio](/docs/config#setexperimentalclientsiderenderingenabled). Default is `false`.
+<Options id="enable-experimental-client-side-rendering" />
### `--webpack-poll`<AvailableFrom v="3.3.11" />
-[Enables Webpack polling](/docs/config#setwebpackpollinginmilliseconds) instead of the file system event listeners for hot reloading. This is useful if you are inside a virtual machine or have a remote file system.
-Pass a value in milliseconds, for example `--webpack-poll=1000`.
+<Options id="webpack-poll" />
### `--no-open`<AvailableFrom v="3.3.19" />
diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdx
index 155c5f7c61..455d712199 100644
--- a/packages/docs/docs/config.mdx
+++ b/packages/docs/docs/config.mdx
@@ -141,7 +141,7 @@ Config.setMaxTimelineTracks(20);
## `setKeyboardShortcutsEnabled()`<AvailableFrom v="3.2.11" />
-Whether the Studio should react to keyboard shortcuts. Default `true`.
+<Options id="disable-keyboard-shortcuts" />
```ts twoslash title="remotion.config.ts"
import {Config} from '@remotion/cli/config';
@@ -153,7 +153,7 @@ The [command line flag](/docs/cli/studio#--disable-keyboard-shortcuts) `--disabl
## `setExperimentalClientSideRenderingEnabled()`<AvailableFrom v="4.0.387" />
-Enable experimental [client-side rendering](/docs/client-side-rendering) in the Remotion Studio. Default `false`.
+<Options id="enable-experimental-client-side-rendering" />
```ts twoslash title="remotion.config.ts"
import {Config} from '@remotion/cli/config';
@@ -165,8 +165,7 @@ The [command line flag](/docs/cli/studio#--enable-experimental-client-side-rende
## `setWebpackPollingInMilliseconds()`<AvailableFrom v="3.3.11" />
-Enables Webpack polling instead of the file system event listeners for hot reloading.
-This is useful if you are inside a virtual machine or have a remote file system.
+<Options id="webpack-poll" />
```ts twoslash title="remotion.config.ts"
import {Config} from '@remotion/cli/config';
@@ -1105,20 +1104,14 @@ The old way is deprecated, but will work for the foreseeable future.
- [Encoding guide](/docs/encoding)
-### setImageSequencePattern(pattern)
+### `setImageSequencePattern()`
-Set the pattern for naming image sequence files when rendering an image sequence.
-
-- `[frame]` will be replaced with the zero-padded frame number (e.g. 0001, 0002, ...)
-- `[ext]` will be replaced with the image format extension (e.g. jpeg, png)
-
-**Example:**
-
-```js
-// remotion.config.ts
-import {Config} from 'remotion';
+<Options id="image-sequence-pattern" />
+```ts twoslash title="remotion.config.ts"
+import {Config} from '@remotion/cli/config';
+// ---cut---
Config.setImageSequencePattern('frame_[frame]_custom.[ext]');
```
-This will produce files like `frame_0001_custom.jpeg`, `frame_0002_custom.jpeg`, ...
+The [command line flag](/docs/cli/render#--image-sequence-pattern) `--image-sequence-pattern` will take precedence over this option.
diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsx
index 9495f5a6c1..716bcb7faa 100644
--- a/packages/renderer/src/options/index.tsx
+++ b/packages/renderer/src/options/index.tsx
@@ -70,6 +70,7 @@ import {mediaCacheSizeInBytesOption} from './video-cache-size';
import {videoCodecOption} from './video-codec';
import {videoImageFormatOption} from './video-image-format';
import {webhookCustomDataOption} from './webhook-custom-data';
+import {webpackPollOption} from './webpack-poll';
import {x264Option} from './x264-preset';
export const allOptions = {
@@ -145,6 +146,7 @@ export const allOptions = {
overrideDurationOption,
outDirOption,
packageManagerOption,
+ webpackPollOption,
};
export type AvailableOptions = keyof typeof allOptions;
diff --git a/packages/renderer/src/options/webpack-poll.tsx b/packages/renderer/src/options/webpack-poll.tsx
new file mode 100644
index 0000000000..ceb35bcbe6
--- /dev/null
+++ b/packages/renderer/src/options/webpack-poll.tsx
@@ -0,0 +1,57 @@
+import type {AnyRemotionOption} from './option';
+
+const cliFlag = 'webpack-poll' as const;
+
+let webpackPolling: number | null = null;
+
+export const webpackPollOption = {
+ name: 'Webpack Polling',
+ cliFlag,
+ description: () => (
+ <>
+ Enables Webpack polling instead of the file system event listeners for hot
+ reloading. This is useful if you are inside a virtual machine or have a
+ remote file system. Pass a value in milliseconds.
+ </>
+ ),
+ ssrName: null,
+ docLink: 'https://www.remotion.dev/docs/config#setwebpackpollinginmilliseconds',
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag] !== undefined) {
+ const val = commandLine[cliFlag];
+ if (typeof val !== 'number') {
+ throw new TypeError(
+ `Webpack polling must be a number, got ${JSON.stringify(val)}`,
+ );
+ }
+
+ return {
+ source: 'cli',
+ value: val,
+ };
+ }
+
+ if (webpackPolling !== null) {
+ return {
+ source: 'config',
+ value: webpackPolling,
+ };
+ }
+
+ return {
+ source: 'default',
+ value: null,
+ };
+ },
+ setConfig: (value: number | null) => {
+ if (typeof value !== 'number' && value !== null) {
+ throw new TypeError(
+ `Polling must be a number or null, got ${JSON.stringify(value)} instead.`,
+ );
+ }
+
+ webpackPolling = value;
+ },
+ type: 0 as number | null,
+ id: cliFlag,
+} satisfies AnyRemotionOption<number | null>;