Skip to content

🎥 Make videos programmatically with React

enforce audio

Jonny Burger0f1e933a956c
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index d18981d37b..91fd45706e 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -30,6 +30,7 @@ const {
crfOption,
jpegQualityOption,
videoBitrateOption,
+ enforceAudioOption,
} = BrowserSafeApis.options;
const getValidConcurrency = (cliConcurrency: number | string | null) => {
@@ -183,7 +184,6 @@ export const benchmarkCommand = async (
numberOfGifLoops,
everyNthFrame,
muted,
- enforceAudioTrack,
ffmpegOverride,
encodingMaxRate,
encodingBufferSize,
@@ -311,6 +311,9 @@ export const benchmarkCommand = async (
const videoBitrate = videoBitrateOption.getValue({
commandLine: parsedCli,
}).value;
+ const enforceAudioTrack = enforceAudioOption.getValue({
+ commandLine: parsedCli,
+ }).value;
for (const composition of compositions) {
const {codec, reason: codecReason} = getFinalOutputCodec({
diff --git a/packages/cli/src/config/enforce-audio-track.ts b/packages/cli/src/config/enforce-audio-track.ts
deleted file mode 100644
index 0e0e6b0c7b..0000000000
--- a/packages/cli/src/config/enforce-audio-track.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-const DEFAULT_ENFORCE_AUDIO_TRACK = true;
-
-let enforceAudioTrackState = DEFAULT_ENFORCE_AUDIO_TRACK;
-
-export const setEnforceAudioTrack = (enforceAudioTrack: boolean) => {
- enforceAudioTrackState = enforceAudioTrack;
-};
-
-export const getEnforceAudioTrack = () => {
- return enforceAudioTrackState;
-};
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index a73045dd3c..65078afa2e 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -77,10 +77,6 @@ import {setCodec} from './codec';
import {getColorSpace, setColorSpace} from './color-space';
import type {Concurrency} from './concurrency';
import {setConcurrency} from './concurrency';
-import {
- getEnforceAudioTrack,
- setEnforceAudioTrack,
-} from './enforce-audio-track';
import {getEntryPoint, setEntryPoint} from './entry-point';
import {setDotEnvLocation} from './env-file';
import {getEveryNthFrame, setEveryNthFrame} from './every-nth-frame';
@@ -129,6 +125,7 @@ const {
scaleOption,
crfOption,
jpegQualityOption,
+ enforceAudioOption,
} = BrowserSafeApis.options;
declare global {
@@ -592,7 +589,7 @@ export const Config: FlatConfig = {
setEveryNthFrame,
setNumberOfGifLoops,
setMuted,
- setEnforceAudioTrack,
+ setEnforceAudioTrack: enforceAudioOption.setConfig,
setOutputLocation,
setOverwriteOutput,
setPixelFormat,
@@ -653,8 +650,6 @@ export const ConfigInternals = {
defaultOverrideFunction,
setMuted,
getMuted,
- getEnforceAudioTrack,
- setEnforceAudioTrack,
getKeyboardShortcutsEnabled,
getPublicDir,
getFfmpegOverrideFunction,
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index 0823552755..0607c6ad7f 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -127,7 +127,6 @@ export const getCliOptions = (options: {
chromiumOptions,
overwrite,
muted: ConfigInternals.getMuted(),
- enforceAudioTrack: ConfigInternals.getEnforceAudioTrack(),
publicDir: ConfigInternals.getPublicDir(),
ffmpegOverride: ConfigInternals.getFfmpegOverrideFunction(),
encodingBufferSize,
diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.ts
index 2e74abff37..d1037daba4 100644
--- a/packages/cli/src/get-render-defaults.ts
+++ b/packages/cli/src/get-render-defaults.ts
@@ -11,6 +11,7 @@ const {
scaleOption,
jpegQualityOption,
videoBitrateOption,
+ enforceAudioOption,
} = BrowserSafeApis.options;
export const getRenderDefaults = (): RenderDefaults => {
@@ -23,7 +24,6 @@ export const getRenderDefaults = (): RenderDefaults => {
ConfigInternals.getConcurrency(),
);
const muted = ConfigInternals.getMuted();
- const enforceAudioTrack = ConfigInternals.getEnforceAudioTrack();
const pixelFormat = ConfigInternals.getPixelFormat();
const proResProfile = ConfigInternals.getProResProfile() ?? 'hq';
@@ -43,6 +43,9 @@ export const getRenderDefaults = (): RenderDefaults => {
const videoBitrate = videoBitrateOption.getValue({
commandLine: parsedCli,
}).value;
+ const enforceAudioTrack = enforceAudioOption.getValue({
+ commandLine: parsedCli,
+ }).value;
const encodingBufferSize = ConfigInternals.getEncodingBufferSize();
const encodingMaxRate = ConfigInternals.getEncodingMaxRate();
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 44a0ac6ed4..bb23da9882 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -21,6 +21,7 @@ const {
crfOption,
jpegQualityOption,
videoBitrateOption,
+ enforceAudioOption,
} = BrowserSafeApis.options;
export const render = async (
@@ -68,7 +69,6 @@ export const render = async (
width,
ffmpegOverride,
muted,
- enforceAudioTrack,
proResProfile,
pixelFormat,
encodingMaxRate,
@@ -98,6 +98,9 @@ export const render = async (
const videoBitrate = videoBitrateOption.getValue({
commandLine: parsedCli,
}).value;
+ const enforceAudioTrack = enforceAudioOption.getValue({
+ commandLine: parsedCli,
+ }).value;
const crf = shouldOutputImageSequence
? null
: crfOption.getValue({commandLine: parsedCli}).value;
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index 5f44817b1f..6527da378a 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -23,6 +23,7 @@ const {
crfOption,
jpegQualityOption,
videoBitrateOption,
+ enforceAudioOption,
} = BrowserSafeApis.options;
export const renderCommand = async (
@@ -69,7 +70,6 @@ export const renderCommand = async (
height,
width,
browserExecutable,
- enforceAudioTrack,
colorSpace,
} = CliInternals.getCliOptions({
type: 'series',
@@ -208,6 +208,9 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
const videoBitrate = videoBitrateOption.getValue({
commandLine: CliInternals.parsedCli,
}).value;
+ const enforceAudioTrack = enforceAudioOption.getValue({
+ commandLine: CliInternals.parsedCli,
+ }).value;
const res = await internalRenderMediaOnCloudrun({
cloudRunUrl,
serviceName: undefined,
diff --git a/packages/renderer/src/options/enforce-audio.tsx b/packages/renderer/src/options/enforce-audio.tsx
index 72190c41a9..2dd4054635 100644
--- a/packages/renderer/src/options/enforce-audio.tsx
+++ b/packages/renderer/src/options/enforce-audio.tsx
@@ -1,12 +1,41 @@
import type {AnyRemotionOption} from './option';
+const DEFAULT_ENFORCE_AUDIO_TRACK = true;
+
+let enforceAudioTrackState = DEFAULT_ENFORCE_AUDIO_TRACK;
+
+const cliFlag = 'enforce-audio-track' as const;
+
export const enforceAudioOption = {
name: 'Enforce Audio Track',
- cliFlag: 'enforce-audio-track' as const,
+ cliFlag,
description: () => (
<>Render a silent audio track if there would be none otherwise.</>
),
ssrName: 'enforceAudioTrack',
docLink: 'https://www.remotion.dev/docs/config#setenforceaudiotrack-',
type: false as boolean,
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag] !== undefined) {
+ return {
+ source: 'cli',
+ value: commandLine[cliFlag] as boolean,
+ };
+ }
+
+ if (enforceAudioTrackState !== DEFAULT_ENFORCE_AUDIO_TRACK) {
+ return {
+ source: 'config',
+ value: enforceAudioTrackState,
+ };
+ }
+
+ return {
+ source: 'default',
+ value: DEFAULT_ENFORCE_AUDIO_TRACK,
+ };
+ },
+ setConfig: (value) => {
+ enforceAudioTrackState = value;
+ },
} satisfies AnyRemotionOption<boolean>;