Skip to content

🎥 Make videos programmatically with React

less redundancy

Jonny Burger3e9d18f2b520
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index 6ce3cc1ef0..84875483d2 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -99,24 +99,36 @@ import {
} from './webpack-poll';
import {getWidth, overrideWidth} from './width';
-export const Config: ConfigType = {
+const Preview = {
setMaxTimelineTracks,
setKeyboardShortcutsEnabled,
setNumberOfSharedAudioTags,
setWebpackPollingInMilliseconds,
setShouldOpenBrowser,
+};
+
+const Bundling = {
overrideWebpackConfig,
setCachingEnabled: setWebpackCaching,
setPort,
setPublicDir,
setEntryPoint,
+};
+
+const Log = {
setLevel: setLogLevel,
+};
+
+const Puppeteer = {
setBrowserExecutable,
setTimeoutInMilliseconds: setPuppeteerTimeout,
setChromiumDisableWebSecurity,
setChromiumIgnoreCertificateErrors,
setChromiumHeadlessMode,
setChromiumOpenGlRenderer,
+};
+
+const Rendering = {
setDotEnvLocation,
setConcurrency,
setQuality,
@@ -129,6 +141,9 @@ export const Config: ConfigType = {
setNumberOfGifLoops,
setMuted,
setEnforceAudioTrack,
+};
+
+const Output = {
setOutputLocation,
setOverwriteOutput,
setPixelFormat,
@@ -142,66 +157,27 @@ export const Config: ConfigType = {
overrideHeight,
overrideWidth,
overrideFfmpegCommand: setFfmpegOverrideFunction,
- Preview: {
- setMaxTimelineTracks,
- setKeyboardShortcutsEnabled,
- setNumberOfSharedAudioTags,
- setWebpackPollingInMilliseconds,
- setShouldOpenBrowser,
- },
- Bundling: {
- overrideWebpackConfig,
- setCachingEnabled: setWebpackCaching,
- setPort,
- setPublicDir,
- setEntryPoint,
- },
- Log: {
- setLevel: setLogLevel,
- },
- Puppeteer: {
- setBrowserExecutable,
- setTimeoutInMilliseconds: setPuppeteerTimeout,
- setChromiumDisableWebSecurity,
- setChromiumIgnoreCertificateErrors,
- setChromiumHeadlessMode,
- setChromiumOpenGlRenderer,
- },
- Rendering: {
- setDotEnvLocation,
- setConcurrency,
- setQuality,
- setImageFormat,
- setFrameRange,
- setFfmpegExecutable,
- setFfprobeExecutable,
- setScale,
- setEveryNthFrame,
- setNumberOfGifLoops,
- setMuted,
- setEnforceAudioTrack,
- },
- Output: {
- setOutputLocation,
- setOverwriteOutput,
- setPixelFormat,
- setOutputFormat,
- setCodec,
- setCrf,
- setImageSequence,
- setProResProfile,
- setAudioBitrate,
- setVideoBitrate,
- overrideHeight,
- overrideWidth,
- overrideFfmpegCommand: setFfmpegOverrideFunction,
- },
+};
+
+export const Config: ConfigType = {
+ // New flat config format
+ ...Preview,
+ ...Bundling,
+ ...Log,
+ ...Puppeteer,
+ ...Rendering,
+ ...Output,
+ // Legacy config format
+ Preview,
+ Bundling,
+ Log,
+ Puppeteer,
+ Rendering,
+ Output,
} as ConfigType;
export type {Concurrency, WebpackConfiguration, WebpackOverrideFn};
-// eslint-disable-next-line no-restricted-imports
-
export const ConfigInternals = {
getRange,
getOutputCodecOrUndefined,
diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts
index e2a242f70a..3beb83365c 100644
--- a/packages/core/src/config.ts
+++ b/packages/core/src/config.ts
@@ -27,293 +27,17 @@ type CodecOrUndefined =
| undefined;
type Crf = number | undefined;
-type FlatConfig = {
- /**
- * Preview
- */
- /**
- * Change the maximum amount of tracks that are shown in the timeline.
- * @param maxTracks The maximum amount of timeline tracks that you would like to show.
- * @default 15
- */
- readonly setMaxTimelineTracks: (maxTracks: number) => void;
- /**
- * Enable Keyboard shortcuts in the Remotion Preview.
- * @param enabled Boolean whether to enable the keyboard shortcuts
- * @default true
- */
- readonly setKeyboardShortcutsEnabled: (enableShortcuts: boolean) => void;
- /**
- * Set number of shared audio tags. https://www.remotion.dev/docs/player/autoplay#use-the-numberofsharedaudiotags-property
- * @param numberOfAudioTags
- * @default 0
- */
- readonly setNumberOfSharedAudioTags: (numberOfAudioTags: number) => void;
- /**
- * Enable Webpack polling instead of file system listeners for hot reloading in the preview.
- * This is useful if you are using a remote directory or a virtual machine.
- * @param interval
- * @default null
- */
- readonly setWebpackPollingInMilliseconds: (interval: number | null) => void;
- /**
- * Whether Remotion should open a browser when starting the Preview.
- * @param should
- * @default true
- */
- readonly setShouldOpenBrowser: (should: boolean) => void;
-
- /**
- * Bundling
- */
-
- /**
- * Specify the entry point so you don't have to specify it in the
- * CLI command
- */
- readonly setEntryPoint: (src: string) => void;
- /**
- * Pass in a function which takes the current Webpack config
- * and return a modified Webpack configuration.
- * Docs: http://remotion.dev/docs/webpack
- */
- readonly overrideWebpackConfig: (fn: WebpackOverrideFn) => void;
- /**
- * Whether Webpack bundles should be cached to make
- * subsequent renders faster. Default: true
- */
- readonly setCachingEnabled: (flag: boolean) => void;
- /**
- * Define on which port Remotion should start it's HTTP servers during preview and rendering.
- * By default, Remotion will try to find a free port.
- * If you specify a port, but it's not available, Remotion will throw an error.
- */
- readonly setPort: (port: number | undefined) => void;
- /**
- * Define the location of the public/ directory.
- * By default it is a folder named "public" inside the current working directory.
- * You can set an absolute path or a relative path that will be resolved from the closest package.json location.
- */
- readonly setPublicDir: (publicDir: string | null) => void;
-
- /**
- * Log
- */
-
- /**
- * Set the log level.
- * Acceptable values: 'error' | 'warning' | 'info' | 'verbose'
- * Default value: 'info'
- *
- * Set this to 'verbose' to get browser logs and other IO.
- */
- readonly setLevel: (
- newLogLevel: 'verbose' | 'info' | 'warn' | 'error'
- ) => void;
-
- /**
- * Puppeter
- */
- /**
- * Specify executable path for the browser to use.
- * Default: null, which will make Remotion find or download a version of said browser.
- */
- readonly setBrowserExecutable: (
- newBrowserExecutablePath: BrowserExecutable
- ) => void;
- /**
- * Set how many milliseconds a frame may take to render before it times out.
- * Default: `30000`
- */
- readonly setTimeoutInMilliseconds: (newPuppeteerTimeout: number) => void;
- /**
- * Setting deciding whether to disable CORS and other Chrome security features.
- * Default: false
- */
- readonly setChromiumDisableWebSecurity: (should: boolean) => void;
- /**
- * Setting whether to ignore any invalid SSL certificates, such as self-signed ones.
- * Default: false
- */
- readonly setChromiumIgnoreCertificateErrors: (should: boolean) => void;
- /**
- * If false, will open an actual browser during rendering to observe progress.
- * Default: true
- */
- readonly setChromiumHeadlessMode: (should: boolean) => void;
- /**
- * Set the OpenGL rendering backend for Chrome. Possible values: 'egl', 'angle', 'swiftshader' and 'swangle'.
- * Default: 'swangle' in Lambda, null elsewhere.
- */
- readonly setChromiumOpenGlRenderer: (
- renderer: 'swangle' | 'angle' | 'egl' | 'swiftshader'
- ) => void;
-
- /**
- * Rendering
- */
- /**
- * Set a custom location for a .env file.
- * Default: `.env`
- */
- readonly setDotEnvLocation: (file: string) => void;
- /**
- * Sets how many Puppeteer instances will work on rendering your video in parallel.
- * Default: `null`, meaning half of the threads available on your CPU.
- */
- readonly setConcurrency: (newConcurrency: Concurrency) => void;
- /**
- * Set the JPEG quality for the frames.
- * Must be between 0 and 100.
- * Must be between 0 and 100.
- * Default: 80
- */
- readonly setQuality: (q: number | undefined) => void;
- /** Decide in which image format to render. Can be either 'jpeg' or 'png'.
- * PNG is slower, but supports transparency.
- */
- readonly setImageFormat: (format: 'png' | 'jpeg' | 'none') => void;
- /**
- * Render only a subset of a video.
- * Pass in a tuple [20, 30] to only render frames 20-30 into a video.
- * Pass in a single number `20` to only render a single frame as an image.
- * The frame count starts at 0.
- */
- readonly setFrameRange: (newFrameRange: FrameRange | null) => void;
- /**
- * Specify local ffmpeg executable.
- * Default: null, which will use ffmpeg available in PATH.
- */
- readonly setFfmpegExecutable: (ffmpegPath: FfmpegExecutable) => void;
- /**
- * Specify local ffprobe executable.
- * Default: null, which will use ffprobe available in PATH.
- */
- readonly setFfprobeExecutable: (ffprobePath: FfmpegExecutable) => void;
- /**
- * Scales the output dimensions by a factor.
- * Default: 1.
- */
- readonly setScale: (newScale: number) => void;
- /**
- * Specify which frames should be picked for rendering a GIF
- * Default: 1, which means every frame
- * https://remotion.dev/docs/render-as-gif
- */
- readonly setEveryNthFrame: (frame: number) => void;
- /**
- * Specify the number of Loop a GIF should have.
- * Default: null (means GIF will loop infinite)
- */
- readonly setNumberOfGifLoops: (newLoop: Loop) => void;
- /**
- * Disable audio output.
- * Default: false
- */
- readonly setMuted: (muted: boolean) => void;
- /**
- * Don't render an audio track if it would be silent.
- * Default: true
- */
- readonly setEnforceAudioTrack: (enforceAudioTrack: boolean) => void;
-
- /**
- * Output
- */
-
- /**
- * Set the output file location string. Default: `out/{composition}.{codec}`
- */
- readonly setOutputLocation: (newOutputLocation: string) => void;
- /**
- * If the video file already exists, should Remotion overwrite
- * the output? Default: true
- */
- readonly setOverwriteOutput: (newOverwrite: boolean) => void;
- /**
- * Sets the pixel format in FFMPEG.
- * See https://trac.ffmpeg.org/wiki/Chroma%20Subsampling for an explanation.
- * You can override this using the `--pixel-format` Cli flag.
- */
- readonly setPixelFormat: (
- format:
- | 'yuv420p'
- | 'yuva420p'
- | 'yuv422p'
- | 'yuv444p'
- | 'yuv420p10le'
- | 'yuv422p10le'
- | 'yuv444p10le'
- | 'yuva444p10le'
- ) => void;
- /**
- * @deprecated Use setCodec() and setImageSequence() instead.
- * Specify what kind of output you, either `mp4` or `png-sequence`.
- */
- readonly setOutputFormat: (newLegacyFormat: 'mp4' | 'png-sequence') => void;
- /**
- * Specify the codec for stitching the frames into a video.
- * Can be `h264` (default), `h265`, `vp8` or `vp9`
- */
- readonly setCodec: (newCodec: CodecOrUndefined) => void;
- /**
- * Set the Constant Rate Factor to pass to FFMPEG.
- * Lower values mean better quality, but be aware that the ranges of
- * possible values greatly differs between codecs.
- */
- readonly setCrf: (newCrf: Crf) => void;
- /**
- * Set to true if don't want a video but an image sequence as the output.
- */
- readonly setImageSequence: (newImageSequence: boolean) => void;
- /**
- * Overrides the height of a composition
- */
- readonly overrideHeight: (newHeight: number) => void;
- /**
- * Overrides the width of a composition
- */
- readonly overrideWidth: (newWidth: number) => void;
- /**
- * Set the ProRes profile.
- * This method is only valid if the codec has been set to 'prores'.
- * Possible values: 4444-xq, 4444, hq, standard, light, proxy. Default: 'hq'
- * See https://avpres.net/FFmpeg/im_ProRes.html for meaning of possible values.
- */
- readonly setProResProfile: (
- profile:
- | '4444-xq'
- | '4444'
- | 'hq'
- | 'standard'
- | 'light'
- | 'proxy'
- | undefined
- ) => void;
- /**
- * Override the arguments that Remotion passes to FFMPEG.
- * Consult https://remotion.dev/docs/renderer/render-media#ffmpegoverride before using this feature.
- */
- readonly overrideFfmpegCommand: (
- command: (info: {
- type: 'pre-stitcher' | 'stitcher';
- args: string[];
- }) => string[]
- ) => void;
-
- /**
- * Set a target audio bitrate to be passed to FFMPEG.
- */
- readonly setAudioBitrate: (bitrate: string | null) => void;
-
+// NEW CONFIG FORMAT: Add new options only here.
+type FlatConfig = ObjectConfig['Bundling'] &
+ ObjectConfig['Log'] &
+ ObjectConfig['Preview'] &
+ ObjectConfig['Puppeteer'] &
+ ObjectConfig['Output'];
+// LEGACY CONFIG FORMAT: New options to not need to be added here.
+type ObjectConfig = {
/**
- * Set a target video bitrate to be passed to FFMPEG.
- * Mutually exclusive with setCrf().
+ * @deprecated New flat config format: You can now replace `Config.Preview.` with `Config.`
*/
- readonly setVideoBitrate: (bitrate: string | null) => void;
-};
-
-type ObjectConfig = {
readonly Preview: {
/**
* Change the maximum amount of tracks that are shown in the timeline.
@@ -347,6 +71,9 @@ type ObjectConfig = {
*/
readonly setShouldOpenBrowser: (should: boolean) => void;
};
+ /**
+ * @deprecated New flat config format: You can now replace `Config.Bundling.` with `Config.`
+ */
readonly Bundling: {
/**
* Specify the entry point so you don't have to specify it in the
@@ -377,6 +104,9 @@ type ObjectConfig = {
*/
readonly setPublicDir: (publicDir: string | null) => void;
};
+ /**
+ * @deprecated New flat config format: You can now replace `Config.Log.` with `Config.`
+ */
readonly Log: {
/**
* Set the log level.
@@ -389,6 +119,9 @@ type ObjectConfig = {
newLogLevel: 'verbose' | 'info' | 'warn' | 'error'
) => void;
};
+ /**
+ * @deprecated New flat config format: You can now replace `Config.Puppeteer.` with `Config.`
+ */
readonly Puppeteer: {
/**
* Specify executable path for the browser to use.
@@ -425,6 +158,9 @@ type ObjectConfig = {
renderer: 'swangle' | 'angle' | 'egl' | 'swiftshader'
) => void;
};
+ /**
+ * @deprecated New flat config format: You can now replace `Config.Rendering.` with `Config.`
+ */
readonly Rendering: {
/**
* Set a custom location for a .env file.
@@ -491,6 +227,9 @@ type ObjectConfig = {
*/
readonly setEnforceAudioTrack: (enforceAudioTrack: boolean) => void;
};
+ /**
+ * @deprecated New flat config format: You can now replace `Config.Output.` with `Config.`
+ */
readonly Output: {
/**
* Set the output file location string. Default: `out/{composition}.{codec}`
diff --git a/packages/example/remotion.config.ts b/packages/example/remotion.config.ts
index eceb2d7000..c2f112cd17 100644
--- a/packages/example/remotion.config.ts
+++ b/packages/example/remotion.config.ts
@@ -1,6 +1,6 @@
import {Config} from 'remotion';
import {webpackOverride} from './src/webpack-override';
-Config.Output.setOverwriteOutput(true);
+Config.setOverwriteOutput(true);
Config.Bundling.overrideWebpackConfig(webpackOverride);
-Config.Bundling.setPort(8080);
+Config.setPort(8080);