Skip to content

🎥 Make videos programmatically with React

Ship empty audio detection fix in v4 and preserve explicit audio outputs

JonnyBurger5c4827e67251
diff --git a/packages/docs/docs/5-0-migration.mdx b/packages/docs/docs/5-0-migration.mdx
index 6dfd912547..2027848add 100644
--- a/packages/docs/docs/5-0-migration.mdx
+++ b/packages/docs/docs/5-0-migration.mdx
@@ -31,13 +31,6 @@ Upgrade `remotion` and all packages starting with `@remotion` to the latest vers
Run `npm i `, `yarn`, `pnpm i` or `bun i` respectively afterwards.
-## Videos without audio no longer include a silent audio track
-
-In Remotion 4, video renders could include a silent audio track even when [`enforceAudioTrack`](/docs/renderer/render-media#enforceaudiotrack) was `false`.
-Remotion 5 omits the track when there are no audio assets, including renders whose only media sources are videos without audio streams. Audio-only exports still produce an audio file, even when silent.
-
-**Required action**: If you need a silent track, set `enforceAudioTrack: true` or pass [`--enforce-audio-track`](/docs/cli/render#--enforce-audio-track). This is also required when using `separateAudioTo` without audio or [rendering chunks for concatenation](/docs/distributed-rendering). Remotion Lambda already enforces audio tracks for its chunks. `muted: true` still takes precedence.
-
## Runtime requirements
The minimum Node version is now <MinNodeVersion />. The minimum Bun version is <MinBunVersion />.
@@ -47,7 +40,7 @@ If you use `@remotion/eslint-config`, the minimum ESLint version is now <MinEsli
## Telemetry is now mandatory for Company License customers
Previously, we had no idea how many renders our company license customers are making, leading to a lack of accountability.
-If you upgrade to Remotion 5.0, you must [enable telemetry](/docs/telemetry) if you are a company license holder or contact Remotion to arrange a plausible delivery of render counts.
+If you upgrade to Remotion 5.0, you must [enable telemetry](/docs/telemetry) if you are a company license holder or contact Remotion to arrange a plausible delivery of render counts.
**Required action**: Pass license key to rendering APIs and in the [Remotion config file](/docs/config). If you are eligible for the free license, pass `"free-license"` as the license key.
@@ -170,8 +163,8 @@ When using `loadFonts()` from `@remotion/google-fonts`, you must now specify whi
import {loadFont} from '@remotion/google-fonts/Roboto';
loadFont('normal', {
- weights: ['400', '700'],
- subsets: ['latin'],
+ weights: ['400', '700'],
+ subsets: ['latin'],
});
```
diff --git a/packages/renderer/src/create-audio.ts b/packages/renderer/src/create-audio.ts
index d0251ae9c0..b2ea942164 100644
--- a/packages/renderer/src/create-audio.ts
+++ b/packages/renderer/src/create-audio.ts
@@ -1,5 +1,4 @@
import path from 'path';
-import {NoReactInternals} from 'remotion/no-react';
import {calculateAssetPositions} from './assets/calculate-asset-positions';
import {convertAssetsToFileUrls} from './assets/convert-assets-to-file-urls';
import type {RenderMediaOnDownload} from './assets/download-and-map-assets-to-file';
@@ -172,11 +171,7 @@ export const createAudio = async ({
]
: []),
];
- if (
- NoReactInternals.ENABLE_V5_BREAKING_CHANGES &&
- !enforceAudioTrack &&
- preprocessed.length === 0
- ) {
+ if (!enforceAudioTrack && preprocessed.length === 0) {
deleteDirectory(downloadMap.audioMixing);
onProgress(1);
return null;
diff --git a/packages/renderer/src/options/enforce-audio.tsx b/packages/renderer/src/options/enforce-audio.tsx
index 0839e930b0..cd173acac5 100644
--- a/packages/renderer/src/options/enforce-audio.tsx
+++ b/packages/renderer/src/options/enforce-audio.tsx
@@ -14,8 +14,11 @@ export const enforceAudioOption = {
<p>
Defaults to <code>false</code>. If <code>true</code>, include a silent
audio track when the render contains no audio. If <code>false</code>,
- omit the audio track when no audio is present. Audio-only exports still
- produce an audio file, even when silent.
+ omit the audio track when no audio is present. Audio-only exports and{' '}
+ <code>
+ {mode === 'cli' ? '--separate-audio-to' : 'separateAudioTo'}
+ </code>{' '}
+ still produce an audio file, even when silent.
</p>
<p>
{mode === 'cli' ? (
@@ -36,8 +39,8 @@ export const enforceAudioOption = {
precedence.
</p>
<p>
- In Remotion 4, video renders may still include a silent audio track when
- this option is <code>false</code>. This is fixed in Remotion 5.
+ Before Remotion 4.0.523, video renders could incorrectly include a
+ silent audio track when this option was <code>false</code>.
</p>
</>
),
diff --git a/packages/renderer/src/options/separate-audio.tsx b/packages/renderer/src/options/separate-audio.tsx
index 18cb2d69ad..7ef2e3d2ab 100644
--- a/packages/renderer/src/options/separate-audio.tsx
+++ b/packages/renderer/src/options/separate-audio.tsx
@@ -7,7 +7,7 @@ const cliFlag = 'separate-audio-to';
export const separateAudioOption = {
cliFlag,
description: () =>
- `If set, the audio will not be included in the main output but rendered as a separate file at the location you pass. It is recommended to use an absolute path. If a relative path is passed, it is relative to the Remotion Root.`,
+ `If set, the audio will not be included in the main output but rendered as a separate file at the location you pass. If the render contains no audio, a silent audio file is produced even when enforceAudioTrack is false. The muted option still takes precedence. It is recommended to use an absolute path. If a relative path is passed, it is relative to the Remotion Root.`,
docLink: 'https://remotion.dev/docs/renderer/render-media',
getValue: ({commandLine}) => {
if (commandLine[cliFlag]) {
diff --git a/packages/renderer/src/render-has-audio.ts b/packages/renderer/src/render-has-audio.ts
index a63e1732fa..b582ccb835 100644
--- a/packages/renderer/src/render-has-audio.ts
+++ b/packages/renderer/src/render-has-audio.ts
@@ -1,4 +1,3 @@
-import {NoReactInternals} from 'remotion/no-react';
import type {RenderAssetInfo} from './assets/download-map';
import type {Codec} from './codec';
import {codecSupportsMedia} from './codec-supports-media';
@@ -30,19 +29,15 @@ export const getShouldRenderAudio = ({
return 'maybe';
}
- if (NoReactInternals.ENABLE_V5_BREAKING_CHANGES) {
- if (!codecSupportsMedia(codec).video) {
- return 'yes';
- }
-
- return assetsInfo.assets.some(
- (frame) =>
- frame.audioAndVideoAssets.length > 0 ||
- frame.inlineAudioAssets.length > 0,
- )
- ? 'yes'
- : 'no';
+ if (!codecSupportsMedia(codec).video) {
+ return 'yes';
}
- return assetsInfo.assets.flat(1).length > 0 ? 'yes' : 'no';
+ return assetsInfo.assets.some(
+ (frame) =>
+ frame.audioAndVideoAssets.length > 0 ||
+ frame.inlineAudioAssets.length > 0,
+ )
+ ? 'yes'
+ : 'no';
};
diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.ts
index cdfe963b29..aaca541b82 100644
--- a/packages/renderer/src/stitch-frames-to-video.ts
+++ b/packages/renderer/src/stitch-frames-to-video.ts
@@ -184,11 +184,13 @@ const innerStitchFramesToVideo = async (
const proResProfileName = getProResProfileName(codec, proResProfile);
const mediaSupport = codecSupportsMedia(codec);
+ const enforceAudioTrackForOutput =
+ enforceAudioTrack || Boolean(separateAudioTo);
const renderAudioEvaluation = getShouldRenderAudio({
assetsInfo,
codec,
- enforceAudioTrack,
+ enforceAudioTrack: enforceAudioTrackForOutput,
muted,
});
if (renderAudioEvaluation === 'maybe') {
@@ -325,7 +327,7 @@ const innerStitchFramesToVideo = async (
trimRightOffset: assetsInfo.trimRightOffset,
forSeamlessAacConcatenation: assetsInfo.forSeamlessAacConcatenation,
sampleRate,
- enforceAudioTrack: enforceAudioTrack || !shouldRenderVideo,
+ enforceAudioTrack: enforceAudioTrackForOutput || !shouldRenderVideo,
})
: null;
@@ -374,7 +376,7 @@ const innerStitchFramesToVideo = async (
throw new Error(
`\`separateAudioTo\` was set to ${JSON.stringify(
separateAudioTo,
- )}, but this render included no audio. Set \`enforceAudioTrack: true\` to render a silent audio file.`,
+ )}, but this render included no audio. Audio output is disabled by the muted option or selected codec.`,
);
}
diff --git a/packages/renderer/src/test/empty-audio.test.ts b/packages/renderer/src/test/empty-audio.test.ts
index e2ecad4699..9375e3dfe3 100644
--- a/packages/renderer/src/test/empty-audio.test.ts
+++ b/packages/renderer/src/test/empty-audio.test.ts
@@ -3,7 +3,6 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import type {AudioOrVideoAsset, InlineAudioAsset} from 'remotion/no-react';
-import {NoReactInternals} from 'remotion/no-react';
import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';
import {callFf} from '../call-ffmpeg';
import type {Codec} from '../codec';
@@ -135,6 +134,30 @@ test(
codec: 'h264',
separate: true,
},
+ {
+ name: 'separate-video',
+ source: sourceVideo,
+ enforced: false,
+ muted: false,
+ codec: 'h264',
+ separate: true,
+ },
+ {
+ name: 'separate-audio',
+ source: path.join(examplePublic, 'audio-48000hz.wav'),
+ enforced: false,
+ muted: false,
+ codec: 'h264',
+ separate: true,
+ },
+ {
+ name: 'separate-muted',
+ source: null,
+ enforced: false,
+ muted: true,
+ codec: 'h264',
+ separate: true,
+ },
] satisfies {
name: string;
source: string | null;
@@ -228,12 +251,10 @@ test(
scenario.separate || scenario.codec === 'wav' ? 'pcm-16' : 'aac',
});
- if (
- NoReactInternals.ENABLE_V5_BREAKING_CHANGES &&
- scenario.name === 'separate-empty'
- ) {
- await expect(render).rejects.toThrow('enforceAudioTrack: true');
+ if (scenario.name === 'separate-muted') {
+ await expect(render).rejects.toThrow('Audio output is disabled');
expect(fs.existsSync(output)).toBe(false);
+ expect(fs.existsSync(separateAudioTo as string)).toBe(false);
continue;
}
@@ -255,13 +276,14 @@ test(
streams: {codec_type: string}[];
};
const hasSourceAudio =
- scenario.name === 'audio' || scenario.name === 'inline';
+ (scenario.source !== null && scenario.source !== sourceVideo) ||
+ scenario.name === 'inline';
const hasAudio =
!scenario.muted &&
(scenario.enforced ||
hasSourceAudio ||
scenario.codec === 'wav' ||
- !NoReactInternals.ENABLE_V5_BREAKING_CHANGES);
+ scenario.separate);
expect(
streams.map((stream) => stream.codec_type),
scenario.name,