Skip to content

🎥 Make videos programmatically with React

encoding buffer size

Jonny Burgerc262db6c7de3
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 1a8ea97c3e..a564c2afe7 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -41,6 +41,7 @@ const {
glOption,
numberOfGifLoopsOption,
encodingMaxRateOption,
+ encodingBufferSizeOption,
} = BrowserSafeApis.options;
const getValidConcurrency = (cliConcurrency: number | string | null) => {
@@ -192,7 +193,6 @@ export const benchmarkCommand = async (
pixelFormat,
everyNthFrame,
ffmpegOverride,
- encodingBufferSize,
height,
width,
concurrency: unparsedConcurrency,
@@ -343,6 +343,9 @@ export const benchmarkCommand = async (
const encodingMaxRate = encodingMaxRateOption.getValue({
commandLine: parsedCli,
}).value;
+ const encodingBufferSize = encodingBufferSizeOption.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
deleted file mode 100644
index 73fe41a142..0000000000
--- a/packages/cli/src/config/bitrate.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * encodingBufferSize is not a bitrate, but it is a bitrate-related option and get validated like a bitrate.
- */
-let encodingBufferSize: string | null = null;
-
-export const setEncodingBufferSize = (bitrate: string | null) => {
- encodingBufferSize = bitrate;
-};
-
-export const getEncodingBufferSize = () => {
- return encodingBufferSize;
-};
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index 0c3bbc58d2..498651ef84 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -48,7 +48,6 @@ import type {
import {BrowserSafeApis} from '@remotion/renderer/client';
import {StudioServerInternals} from '@remotion/studio-server';
import {getAudioCodec, setAudioCodec} from './audio-codec';
-import {getEncodingBufferSize, setEncodingBufferSize} from './bitrate';
import {setBrowserExecutable} from './browser-executable';
import {
getBufferStateDelayInMilliseconds,
@@ -117,6 +116,7 @@ const {
numberOfGifLoopsOption,
beepOnFinishOption,
encodingMaxRateOption,
+ encodingBufferSizeOption,
} = BrowserSafeApis.options;
declare global {
@@ -572,7 +572,7 @@ export const Config: FlatConfig = {
setStillImageFormat,
setVideoImageFormat,
setEncodingMaxRate: encodingMaxRateOption.setConfig,
- setEncodingBufferSize,
+ setEncodingBufferSize: encodingBufferSizeOption.setConfig,
setFrameRange,
setScale: scaleOption.setConfig,
setEveryNthFrame,
@@ -637,7 +637,6 @@ export const ConfigInternals = {
getKeyboardShortcutsEnabled,
getPublicDir,
getFfmpegOverrideFunction,
- getEncodingBufferSize,
getHeight,
getWidth,
getEntryPoint,
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index 83d9eae057..931daa3395 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -80,7 +80,6 @@ export const getCliOptions = (options: {
const overwrite = ConfigInternals.getShouldOverwrite({
defaultValue: !options.isLambda,
});
- const encodingBufferSize = ConfigInternals.getEncodingBufferSize();
const pixelFormat = ConfigInternals.getPixelFormat();
const proResProfile = getProResProfile();
const browserExecutable = ConfigInternals.getBrowserExecutable();
@@ -123,7 +122,6 @@ export const getCliOptions = (options: {
overwrite,
publicDir: ConfigInternals.getPublicDir(),
ffmpegOverride: ConfigInternals.getFfmpegOverrideFunction(),
- encodingBufferSize,
height,
width,
configFileImageFormat: ConfigInternals.getUserPreferredVideoImageFormat(),
diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.ts
index b25372e2d5..a9fb91dd54 100644
--- a/packages/cli/src/get-render-defaults.ts
+++ b/packages/cli/src/get-render-defaults.ts
@@ -19,6 +19,7 @@ const {
numberOfGifLoopsOption,
beepOnFinishOption,
encodingMaxRateOption,
+ encodingBufferSizeOption,
} = BrowserSafeApis.options;
export const getRenderDefaults = (): RenderDefaults => {
@@ -73,8 +74,10 @@ export const getRenderDefaults = (): RenderDefaults => {
const encodingMaxRate = encodingMaxRateOption.getValue({
commandLine: parsedCli,
}).value;
+ const encodingBufferSize = encodingBufferSizeOption.getValue({
+ commandLine: parsedCli,
+ }).value;
- const encodingBufferSize = ConfigInternals.getEncodingBufferSize();
const everyNthFrame = ConfigInternals.getEveryNthFrame();
const delayRenderTimeout = ConfigInternals.getCurrentPuppeteerTimeout();
const audioCodec = ConfigInternals.getAudioCodec();
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 2d74a6e9b9..605bbbd349 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -28,6 +28,7 @@ const {
glOption,
numberOfGifLoopsOption,
encodingMaxRateOption,
+ encodingBufferSizeOption,
} = BrowserSafeApis.options;
export const render = async (
@@ -79,7 +80,6 @@ export const render = async (
ffmpegOverride,
proResProfile,
pixelFormat,
- encodingBufferSize,
repro,
} = getCliOptions({
isLambda: false,
@@ -124,6 +124,9 @@ export const render = async (
const encodingMaxRate = encodingMaxRateOption.getValue({
commandLine: parsedCli,
}).value;
+ const encodingBufferSize = encodingBufferSizeOption.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 e4d3f0a716..0b5e8cf83b 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -30,6 +30,7 @@ const {
enableMultiprocessOnLinuxOption,
glOption,
encodingMaxRateOption,
+ encodingBufferSizeOption,
} = BrowserSafeApis.options;
export const renderCommand = async (
@@ -73,7 +74,6 @@ export const renderCommand = async (
pixelFormat,
proResProfile,
everyNthFrame,
- encodingBufferSize,
height,
width,
browserExecutable,
@@ -247,6 +247,9 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
const encodingMaxRate = encodingMaxRateOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
+ const encodingBufferSize = encodingBufferSizeOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
const res = await internalRenderMediaOnCloudrun({
cloudRunUrl,
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index ea0810ca6a..41b8765bb8 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -55,6 +55,7 @@ const {
glOption,
numberOfGifLoopsOption,
encodingMaxRateOption,
+ encodingBufferSizeOption,
} = BrowserSafeApis.options;
export const renderCommand = async (
@@ -86,7 +87,6 @@ export const renderCommand = async (
puppeteerTimeout,
everyNthFrame,
overwrite,
- encodingBufferSize,
height,
width,
browserExecutable,
@@ -144,6 +144,9 @@ export const renderCommand = async (
const encodingMaxRate = encodingMaxRateOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
+ const encodingBufferSize = encodingBufferSizeOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
const chromiumOptions: ChromiumOptions = {
disableWebSecurity,
diff --git a/packages/renderer/src/options/encoding-buffer-size.tsx b/packages/renderer/src/options/encoding-buffer-size.tsx
index 750e470872..111989b0c7 100644
--- a/packages/renderer/src/options/encoding-buffer-size.tsx
+++ b/packages/renderer/src/options/encoding-buffer-size.tsx
@@ -1,8 +1,19 @@
import type {AnyRemotionOption} from './option';
+/**
+ * encodingBufferSize is not a bitrate, but it is a bitrate-related option and get validated like a bitrate.
+ */
+let encodingBufferSize: string | null = null;
+
+const setEncodingBufferSize = (bitrate: string | null) => {
+ encodingBufferSize = bitrate;
+};
+
+const cliFlag = 'buffer-size' as const;
+
export const encodingBufferSizeOption = {
name: 'FFmpeg -bufsize flag',
- cliFlag: 'buffer-size' as const,
+ cliFlag,
description: () => (
<>
The value for the <code>-bufsize</code> flag of FFmpeg. Should be used in
@@ -13,4 +24,25 @@ export const encodingBufferSizeOption = {
docLink:
'https://www.remotion.dev/docs/renderer/render-media#encodingbuffersize',
type: '' as string | null,
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag] !== undefined) {
+ return {
+ value: commandLine[cliFlag] as string,
+ source: 'cli',
+ };
+ }
+
+ if (encodingBufferSize !== null) {
+ return {
+ value: encodingBufferSize,
+ source: 'config',
+ };
+ }
+
+ return {
+ value: null,
+ source: 'default',
+ };
+ },
+ setConfig: setEncodingBufferSize,
} satisfies AnyRemotionOption<string | null>;