Skip to content

🎥 Make videos programmatically with React

encoding max rate

Jonny Burgerd2a196bc5866
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 2d0084bcb0..1a8ea97c3e 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -40,6 +40,7 @@ const {
enableMultiprocessOnLinuxOption,
glOption,
numberOfGifLoopsOption,
+ encodingMaxRateOption,
} = BrowserSafeApis.options;
const getValidConcurrency = (cliConcurrency: number | string | null) => {
@@ -191,7 +192,6 @@ export const benchmarkCommand = async (
pixelFormat,
everyNthFrame,
ffmpegOverride,
- encodingMaxRate,
encodingBufferSize,
height,
width,
@@ -340,6 +340,9 @@ export const benchmarkCommand = async (
const numberOfGifLoops = numberOfGifLoopsOption.getValue({
commandLine: parsedCli,
}).value;
+ const encodingMaxRate = encodingMaxRateOption.getValue({
+ commandLine: parsedCli,
+ }).value;
for (const composition of compositions) {
const {value: videoCodec, source: codecReason} = videoCodecOption.getValue(
diff --git a/packages/cli/src/config/bitrate.ts b/packages/cli/src/config/bitrate.ts
index 855d6fe7e7..73fe41a142 100644
--- a/packages/cli/src/config/bitrate.ts
+++ b/packages/cli/src/config/bitrate.ts
@@ -1,13 +1,3 @@
-let encodingMaxRate: string | null = null;
-
-export const setEncodingMaxRate = (bitrate: string | null) => {
- encodingMaxRate = bitrate;
-};
-
-export const getEncodingMaxRate = () => {
- return encodingMaxRate;
-};
-
/**
* encodingBufferSize is not a bitrate, but it is a bitrate-related option and get validated like a bitrate.
*/
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index 636ccbbf2c..0c3bbc58d2 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -48,12 +48,7 @@ import type {
import {BrowserSafeApis} from '@remotion/renderer/client';
import {StudioServerInternals} from '@remotion/studio-server';
import {getAudioCodec, setAudioCodec} from './audio-codec';
-import {
- getEncodingBufferSize,
- getEncodingMaxRate,
- setEncodingBufferSize,
- setEncodingMaxRate,
-} from './bitrate';
+import {getEncodingBufferSize, setEncodingBufferSize} from './bitrate';
import {setBrowserExecutable} from './browser-executable';
import {
getBufferStateDelayInMilliseconds,
@@ -121,6 +116,7 @@ const {
glOption,
numberOfGifLoopsOption,
beepOnFinishOption,
+ encodingMaxRateOption,
} = BrowserSafeApis.options;
declare global {
@@ -575,7 +571,7 @@ export const Config: FlatConfig = {
setJpegQuality: jpegQualityOption.setConfig,
setStillImageFormat,
setVideoImageFormat,
- setEncodingMaxRate,
+ setEncodingMaxRate: encodingMaxRateOption.setConfig,
setEncodingBufferSize,
setFrameRange,
setScale: scaleOption.setConfig,
@@ -642,7 +638,6 @@ export const ConfigInternals = {
getPublicDir,
getFfmpegOverrideFunction,
getEncodingBufferSize,
- getEncodingMaxRate,
getHeight,
getWidth,
getEntryPoint,
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index 15103b33d3..83d9eae057 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -81,7 +81,6 @@ export const getCliOptions = (options: {
defaultValue: !options.isLambda,
});
const encodingBufferSize = ConfigInternals.getEncodingBufferSize();
- const encodingMaxRate = ConfigInternals.getEncodingMaxRate();
const pixelFormat = ConfigInternals.getPixelFormat();
const proResProfile = getProResProfile();
const browserExecutable = ConfigInternals.getBrowserExecutable();
@@ -125,7 +124,6 @@ export const getCliOptions = (options: {
publicDir: ConfigInternals.getPublicDir(),
ffmpegOverride: ConfigInternals.getFfmpegOverrideFunction(),
encodingBufferSize,
- encodingMaxRate,
height,
width,
configFileImageFormat: ConfigInternals.getUserPreferredVideoImageFormat(),
diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.ts
index dc6ad09237..b25372e2d5 100644
--- a/packages/cli/src/get-render-defaults.ts
+++ b/packages/cli/src/get-render-defaults.ts
@@ -18,6 +18,7 @@ const {
glOption,
numberOfGifLoopsOption,
beepOnFinishOption,
+ encodingMaxRateOption,
} = BrowserSafeApis.options;
export const getRenderDefaults = (): RenderDefaults => {
@@ -69,9 +70,11 @@ export const getRenderDefaults = (): RenderDefaults => {
const beepOnFinish = beepOnFinishOption.getValue({
commandLine: parsedCli,
}).value;
+ const encodingMaxRate = encodingMaxRateOption.getValue({
+ commandLine: parsedCli,
+ }).value;
const encodingBufferSize = ConfigInternals.getEncodingBufferSize();
- const encodingMaxRate = ConfigInternals.getEncodingMaxRate();
const everyNthFrame = ConfigInternals.getEveryNthFrame();
const delayRenderTimeout = ConfigInternals.getCurrentPuppeteerTimeout();
const audioCodec = ConfigInternals.getAudioCodec();
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index ddbd6aee05..425ade8929 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -282,10 +282,6 @@ export const parseCommandLine = () => {
if (typeof parsedCli['buffer-size'] !== 'undefined') {
Config.setEncodingBufferSize(parsedCli['buffer-size']);
}
-
- if (typeof parsedCli['max-rate'] !== 'undefined') {
- Config.setEncodingMaxRate(parsedCli['max-rate']);
- }
};
export const quietFlagProvided = () => parsedCli.quiet || parsedCli.q;
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 565eaf9ca9..2d74a6e9b9 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -27,6 +27,7 @@ const {
enableMultiprocessOnLinuxOption,
glOption,
numberOfGifLoopsOption,
+ encodingMaxRateOption,
} = BrowserSafeApis.options;
export const render = async (
@@ -78,7 +79,6 @@ export const render = async (
ffmpegOverride,
proResProfile,
pixelFormat,
- encodingMaxRate,
encodingBufferSize,
repro,
} = getCliOptions({
@@ -121,6 +121,9 @@ export const render = async (
const numberOfGifLoops = numberOfGifLoopsOption.getValue({
commandLine: parsedCli,
}).value;
+ const encodingMaxRate = encodingMaxRateOption.getValue({
+ commandLine: parsedCli,
+ }).value;
const chromiumOptions: ChromiumOptions = {
disableWebSecurity,
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index c05b5d290a..e4d3f0a716 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -29,6 +29,7 @@ const {
numberOfGifLoopsOption,
enableMultiprocessOnLinuxOption,
glOption,
+ encodingMaxRateOption,
} = BrowserSafeApis.options;
export const renderCommand = async (
@@ -72,7 +73,6 @@ export const renderCommand = async (
pixelFormat,
proResProfile,
everyNthFrame,
- encodingMaxRate,
encodingBufferSize,
height,
width,
@@ -244,6 +244,10 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
const numberOfGifLoops = numberOfGifLoopsOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
+ const encodingMaxRate = encodingMaxRateOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
+
const res = await internalRenderMediaOnCloudrun({
cloudRunUrl,
serviceName: undefined,
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index d39f4aceba..ea0810ca6a 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -54,6 +54,7 @@ const {
enableMultiprocessOnLinuxOption,
glOption,
numberOfGifLoopsOption,
+ encodingMaxRateOption,
} = BrowserSafeApis.options;
export const renderCommand = async (
@@ -85,7 +86,6 @@ export const renderCommand = async (
puppeteerTimeout,
everyNthFrame,
overwrite,
- encodingMaxRate,
encodingBufferSize,
height,
width,
@@ -141,6 +141,9 @@ export const renderCommand = async (
const numberOfGifLoops = numberOfGifLoopsOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
+ const encodingMaxRate = encodingMaxRateOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
const chromiumOptions: ChromiumOptions = {
disableWebSecurity,
diff --git a/packages/renderer/src/options/encoding-max-rate.tsx b/packages/renderer/src/options/encoding-max-rate.tsx
index 03dadfc225..f7f385c1ba 100644
--- a/packages/renderer/src/options/encoding-max-rate.tsx
+++ b/packages/renderer/src/options/encoding-max-rate.tsx
@@ -1,8 +1,12 @@
import type {AnyRemotionOption} from './option';
+let encodingMaxRate: string | null = null;
+
+const cliFlag = 'max-rate' as const;
+
export const encodingMaxRateOption = {
name: 'FFmpeg -maxrate flag',
- cliFlag: 'max-rate' as const,
+ cliFlag,
description: () => (
<>
The value for the <code>-maxrate</code> flag of FFmpeg. Should be used in
@@ -13,4 +17,27 @@ export const encodingMaxRateOption = {
docLink:
'https://www.remotion.dev/docs/renderer/render-media#encodingmaxrate',
type: '' as string | null,
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag] !== undefined) {
+ return {
+ value: commandLine[cliFlag] as string,
+ source: 'cli',
+ };
+ }
+
+ if (encodingMaxRate !== null) {
+ return {
+ value: encodingMaxRate,
+ source: 'config',
+ };
+ }
+
+ return {
+ value: null,
+ source: 'default',
+ };
+ },
+ setConfig: (newMaxRate: string | null) => {
+ encodingMaxRate = newMaxRate;
+ },
} satisfies AnyRemotionOption<string | null>;