🎥 Make videos programmatically with React
override from the command line
Jonny Burger1e644483f609
diff --git a/packages/cli/src/config/ffmpeg-override.ts b/packages/cli/src/config/ffmpeg-override.tsnew file mode 100644index 0000000000..8bd070f867--- /dev/null+++ b/packages/cli/src/config/ffmpeg-override.ts@@ -0,0 +1,11 @@+import type {FfmpegOverrideFn} from '@remotion/renderer';++let ffmpegOverrideFn: FfmpegOverrideFn = ({args}) => args;++export const setFfmpegOverrideFunction = (fn: FfmpegOverrideFn) => {+ ffmpegOverrideFn = fn;+};++export const getFfmpegOverrideFunction = () => {+ return ffmpegOverrideFn;+};diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 0f4426acfb..2bb9b98ba9 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -59,6 +59,10 @@ import {import {setDotEnvLocation} from './env-file';import {setEveryNthFrame} from './every-nth-frame';import {setFfmpegExecutable, setFfprobeExecutable} from './ffmpeg-executable';+import {+ getFfmpegOverrideFunction,+ setFfmpegOverrideFunction,+} from './ffmpeg-override';import {setFrameRange} from './frame-range';import {setImageFormat} from './image-format';import {setImageSequence} from './image-sequence';@@ -128,6 +132,7 @@ export const Config: ConfigType = {setCrf,setImageSequence,setProResProfile,+ overrideFfmpegCommand: setFfmpegOverrideFunction,},} as ConfigType;@@ -175,6 +180,7 @@ export const ConfigInternals = {setEnforceAudioTrack,getKeyboardShortcutsEnabled,getPublicDir,+ getFfmpegOverrideFunction,};export const overrideRemotion = () => {diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex cd0f4ca6c9..03ff263842 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -275,7 +275,7 @@ export const getCliOptions = async (options: {port: port ?? null,muted: ConfigInternals.getMuted(),enforceAudioTrack: ConfigInternals.getEnforceAudioTrack(),- keyboardShortcutsEnables: ConfigInternals.getKeyboardShortcutsEnabled(),publicDir: ConfigInternals.getPublicDir(),+ ffmpegOverride: ConfigInternals.getFfmpegOverrideFunction(),};};diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 340c42f461..26532d8374 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -79,6 +79,7 @@ export const render = async (remotionRoot: string) => {muted,enforceAudioTrack,publicDir,+ ffmpegOverride,} = await getCliOptions({isLambda: false,type: 'series',@@ -335,6 +336,8 @@ export const render = async (remotionRoot: string) => {downloadMap,muted,enforceAudioTrack,+ browserExecutable,+ ffmpegOverride,});Log.info();diff --git a/packages/core/src/config.ts b/packages/core/src/config.tsindex b58fa4fcbe..f206f451b4 100644--- a/packages/core/src/config.ts+++ b/packages/core/src/config.ts@@ -243,6 +243,16 @@ export type ConfigType = {| '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;};};export type {Concurrency, WebpackConfiguration, WebpackOverrideFn};diff --git a/packages/docs/docs/config.md b/packages/docs/docs/config.mdindex 5f3ca46c54..7a30c66899 100644--- a/packages/docs/docs/config.md+++ b/packages/docs/docs/config.md@@ -531,6 +531,37 @@ Config.Output.setCrf(16);The [command line flag](/docs/cli/render#--crf) `--crf` will take precedence over this option.+### overrideFfmpegCommand++_available from v3.2.22_++Modifies the FFMPEG command that Remotion uses under the hood. It works reducer-style, meaning that you pass a function that takes a command as an argument and returns a new command.++```tsx twoslash+import { Config } from "remotion";+// ---cut---+Config.Output.overrideFfmpegCommand(({ args }) => {+ return [...args, "-vf", "eq=brightness=0:saturation=1"];+});+```++The function you pass must accept an object as it's only parameter which contains the following properties:++- `type`: Either `"stitcher"` or `"pre-stitcher"`. If enough memory and CPU is available, Remotion may use parallel rendering and encoding, which means that a pre-stitcher process gets spawned before all frames are rendered. You can tell whether parallel encoding is enabled by adding `--log=verbose` to your render command.+- `args`: An array of strings that is passed as arguments to the FFMPEG command.++Your function must return a modified array of strings.++:::warning+Using this feature is discouraged. Before using it, we want to make you aware of some caveats:++- The render command can change with any new Remotion version, even when it is a patch upgrade. This might break your usage of this feature.+- Depending on the selected codec, available CPU and RAM, Remotion may or may not use "parallel encoding" which will result in multiple FFMPEG commands being executed. Your function must be able to handle being called multiple times.+- This feature is not available when using Remotion Lambda.++Before you use this hack, reach out to the Remotion team on [Discord](https://remotion.dev/discord) and ask us if we are open to implement the feature you need in a clean way - we often do implement new features quickly based on users feedback.+:::+## See also- [Encoding guide](/docs/encoding)