Skip to content

🎥 Make videos programmatically with React

audio bitrate

Jonny Burger86e689648a70
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 2a6f627eb2..62e153fb55 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -22,6 +22,8 @@ import {truthy} from './truthy';
const DEFAULT_RUNS = 3;
+const {audioBitrateOption, x264Option} = BrowserSafeApis.options;
+
const getValidConcurrency = (cliConcurrency: number | string | null) => {
const {concurrencies} = parsedCli;
@@ -179,7 +181,6 @@ export const benchmarkCommand = async (
muted,
enforceAudioTrack,
ffmpegOverride,
- audioBitrate,
videoBitrate,
encodingMaxRate,
encodingBufferSize,
@@ -292,7 +293,8 @@ export const benchmarkCommand = async (
let count = 1;
- const {value: x264Preset} = BrowserSafeApis.options.x264Option.getValue({
+ const {value: x264Preset} = x264Option.getValue({commandLine: parsedCli});
+ const {value: audioBitrate} = audioBitrateOption.getValue({
commandLine: parsedCli,
});
diff --git a/packages/cli/src/config/bitrate.ts b/packages/cli/src/config/bitrate.ts
index 5cf0f4d62a..e1b4c003bc 100644
--- a/packages/cli/src/config/bitrate.ts
+++ b/packages/cli/src/config/bitrate.ts
@@ -1,13 +1,3 @@
-let audioBitrate: string | null = null;
-
-export const setAudioBitrate = (bitrate: string | null) => {
- audioBitrate = bitrate;
-};
-
-export const getAudioBitrate = () => {
- return audioBitrate;
-};
-
let videoBitrate: string | null = null;
export const setVideoBitrate = (bitrate: string | null) => {
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index ad504d8f77..79137a1910 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -59,11 +59,9 @@ import {StudioServerInternals} from '@remotion/studio-server';
import {getAudioCodec, setAudioCodec} from './audio-codec';
import {getBeepOnFinish, setBeepOnFinish} from './beep-on-finish';
import {
- getAudioBitrate,
getEncodingBufferSize,
getEncodingMaxRate,
getVideoBitrate,
- setAudioBitrate,
setEncodingBufferSize,
setEncodingMaxRate,
setVideoBitrate,
@@ -606,7 +604,9 @@ export const Config: FlatConfig = {
setX264Preset: (preset) => {
BrowserSafeApis.options.x264Option.setConfig(preset);
},
- setAudioBitrate,
+ setAudioBitrate: (bitrate) => {
+ BrowserSafeApis.options.audioBitrateOption.setConfig(bitrate);
+ },
setVideoBitrate,
overrideHeight,
overrideWidth,
@@ -663,7 +663,6 @@ export const ConfigInternals = {
getKeyboardShortcutsEnabled,
getPublicDir,
getFfmpegOverrideFunction,
- getAudioBitrate,
getVideoBitrate,
getEncodingBufferSize,
getEncodingMaxRate,
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index dcd3aeab1e..02503f7542 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -144,7 +144,6 @@ export const getCliOptions = (options: {
enforceAudioTrack: ConfigInternals.getEnforceAudioTrack(),
publicDir: ConfigInternals.getPublicDir(),
ffmpegOverride: ConfigInternals.getFfmpegOverrideFunction(),
- audioBitrate: ConfigInternals.getAudioBitrate(),
videoBitrate,
encodingBufferSize,
encodingMaxRate,
diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.ts
index 7e87dcfe04..9e4b7cd8ec 100644
--- a/packages/cli/src/get-render-defaults.ts
+++ b/packages/cli/src/get-render-defaults.ts
@@ -4,6 +4,8 @@ import type {RenderDefaults} from '@remotion/studio';
import {ConfigInternals} from './config';
import {parsedCli} from './parse-command-line';
+const {x264Option, audioBitrateOption} = BrowserSafeApis.options;
+
export const getRenderDefaults = (): RenderDefaults => {
const defaultJpegQuality = ConfigInternals.getJpegQuality();
const defaultScale = ConfigInternals.getScale();
@@ -17,10 +19,12 @@ export const getRenderDefaults = (): RenderDefaults => {
const pixelFormat = ConfigInternals.getPixelFormat();
const proResProfile = ConfigInternals.getProResProfile() ?? 'hq';
- const x264Preset = BrowserSafeApis.options.x264Option.getValue({
+ const x264Preset = x264Option.getValue({
+ commandLine: parsedCli,
+ }).value;
+ const audioBitrate = audioBitrateOption.getValue({
commandLine: parsedCli,
}).value;
- const audioBitrate = ConfigInternals.getAudioBitrate();
const videoBitrate = ConfigInternals.getVideoBitrate();
const encodingBufferSize = ConfigInternals.getEncodingBufferSize();
const encodingMaxRate = ConfigInternals.getEncodingMaxRate();
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index d9198cb812..cae7259a86 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -13,6 +13,8 @@ import {Log} from './log';
import {parsedCli, quietFlagProvided} from './parse-command-line';
import {renderVideoFlow} from './render-flows/render';
+const {x264Option, audioBitrateOption} = BrowserSafeApis.options;
+
export const render = async (
remotionRoot: string,
args: string[],
@@ -60,7 +62,6 @@ export const render = async (
width,
crf,
ffmpegOverride,
- audioBitrate,
muted,
enforceAudioTrack,
proResProfile,
@@ -79,7 +80,8 @@ export const render = async (
logLevel,
});
- const {value: x264Preset} = BrowserSafeApis.options.x264Option.getValue({
+ const {value: x264Preset} = x264Option.getValue({commandLine: parsedCli});
+ const {value: audioBitrate} = audioBitrateOption.getValue({
commandLine: parsedCli,
});
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index 12b735c544..f2c59e1bde 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -15,6 +15,8 @@ import {renderArgsCheck} from './helpers/renderArgsCheck';
export const RENDER_COMMAND = 'render';
+const {audioBitrateOption, x264Option} = BrowserSafeApis.options;
+
export const renderCommand = async (
args: string[],
remotionRoot: string,
@@ -57,7 +59,6 @@ export const renderCommand = async (
everyNthFrame,
numberOfGifLoops,
muted,
- audioBitrate,
videoBitrate,
encodingMaxRate,
encodingBufferSize,
@@ -182,7 +183,10 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
}
};
- const x264Preset = BrowserSafeApis.options.x264Option.getValue({
+ const x264Preset = x264Option.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
+ const audioBitrate = audioBitrateOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
diff --git a/packages/docs/docs/cli/render.md b/packages/docs/docs/cli/render.md
index 256ae726d0..36c0f90fd4 100644
--- a/packages/docs/docs/cli/render.md
+++ b/packages/docs/docs/cli/render.md
@@ -88,11 +88,7 @@ Sets the output file path, as an alternative to the `output-location` positional
### `--audio-bitrate`<AvailableFrom v="3.2.32" />
-Specify the target bitrate for the generated audio.
-The syntax for FFMPEGs `-b:a` parameter should be used.
-FFMPEG may encode the video in a way that will not result in the exact audio bitrate specified.
-Example values: `128K` for 128 kbps, `1M` for 1 Mbps.
-Default: `320k`
+<Options id="audio-bitrate" />
### `--video-bitrate`<AvailableFrom v="3.2.32" />
diff --git a/packages/docs/docs/cloudrun/cli/render.md b/packages/docs/docs/cloudrun/cli/render.md
index e51f0c644e..d80b8cda61 100644
--- a/packages/docs/docs/cloudrun/cli/render.md
+++ b/packages/docs/docs/cloudrun/cli/render.md
@@ -110,11 +110,7 @@ Specify the name of the service which should be used to perform the render. This
### `--audio-bitrate`
-Specify the target bitrate for the generated audio.
-The syntax for FFMPEGs `-b:a` parameter should be used.
-FFMPEG may encode the video in a way that will not result in the exact audio bitrate specified.
-Example values: `128K` for 128 kbps, `1M` for 1 Mbps.
-Default: `320k`
+<Options id="audio-bitrate" />
### `--video-bitrate`
diff --git a/packages/docs/docs/config.md b/packages/docs/docs/config.md
index 63e93f352e..ad9613793f 100644
--- a/packages/docs/docs/config.md
+++ b/packages/docs/docs/config.md
@@ -701,11 +701,7 @@ The [command line flag](/docs/cli/render#--max-rate) `--max-rate` will take prec
## `setAudioBitrate()`<AvailableFrom v="3.2.32" />
-Specify the target bitrate for the generated audio.
-The syntax for FFMPEGs `-b:a` parameter should be used.
-FFmpeg may encode the video in a way that will not result in the exact audio bitrate specified.
-Example values: `128K` for 128 kbps, `1M` for 1 Mbps.
-Default: `320k`
+<Options id="audio-bitrate" />
```ts twoslash title="remotion.config.ts"
import { Config } from "@remotion/cli/config";
diff --git a/packages/docs/docs/lambda/cli/render.md b/packages/docs/docs/lambda/cli/render.md
index a7311672d5..4d8c3121e2 100644
--- a/packages/docs/docs/lambda/cli/render.md
+++ b/packages/docs/docs/lambda/cli/render.md
@@ -135,11 +135,7 @@ Renamed to `jpegQuality` in `v4.0.0`.
### `--audio-bitrate`<AvailableFrom v="3.2.32" />
-Specify the target bitrate for the generated audio.
-The syntax for FFMPEGs `-b:a` parameter should be used.
-FFMPEG may encode the video in a way that will not result in the exact audio bitrate specified.
-Example values: `128K` for 128 kbps, `1M` for 1 Mbps.
-Default: `320k`
+<Options id="audio-bitrate" />
### `--video-bitrate`<AvailableFrom v="3.2.32" />
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 82b7729205..02ad5d0d05 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -40,6 +40,8 @@ function getTotalFrames(status: RenderProgress): number | null {
: null;
}
+const {x264Option, audioBitrateOption} = BrowserSafeApis.options;
+
export const renderCommand = async (
args: string[],
remotionRoot: string,
@@ -75,7 +77,6 @@ export const renderCommand = async (
numberOfGifLoops,
muted,
overwrite,
- audioBitrate,
videoBitrate,
encodingMaxRate,
encodingBufferSize,
@@ -92,7 +93,10 @@ export const renderCommand = async (
logLevel,
});
- const x264Preset = BrowserSafeApis.options.x264Option.getValue({
+ const x264Preset = x264Option.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
+ const audioBitrate = audioBitrateOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
diff --git a/packages/renderer/src/options/audio-bitrate.tsx b/packages/renderer/src/options/audio-bitrate.tsx
index ad7aa7b59b..734752c8b2 100644
--- a/packages/renderer/src/options/audio-bitrate.tsx
+++ b/packages/renderer/src/options/audio-bitrate.tsx
@@ -1,8 +1,12 @@
import type {AnyRemotionOption} from './option';
+const cliFlag = 'audio-bitrate' as const;
+
+let audioBitrate: string | null = null;
+
export const audioBitrateOption = {
name: 'Audio Bitrate',
- cliFlag: 'audio-bitrate' as const,
+ cliFlag,
description: () => (
<>
Specify the target bitrate for the generated video. The syntax for FFMPEGs
@@ -15,4 +19,27 @@ export const audioBitrateOption = {
ssrName: 'audioBitrate',
docLink: 'https://www.remotion.dev/docs/renderer/render-media#audiobitrate-',
type: '0' as string,
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag]) {
+ return {
+ value: commandLine[cliFlag] as string,
+ source: 'cli',
+ };
+ }
+
+ if (audioBitrate) {
+ return {
+ value: audioBitrate,
+ source: 'config file',
+ };
+ }
+
+ return {
+ value: '320k',
+ source: 'default',
+ };
+ },
+ setConfig: (value: string | null) => {
+ audioBitrate = value;
+ },
} satisfies AnyRemotionOption<string>;