Skip to content

🎥 Make videos programmatically with React

possible values for audiocodec

Jonny Burger637187e6c2ea
diff --git a/packages/docs/docs/cli/benchmark.md b/packages/docs/docs/cli/benchmark.md
index b2387a3be1..99306b883d 100644
--- a/packages/docs/docs/cli/benchmark.md
+++ b/packages/docs/docs/cli/benchmark.md
@@ -37,11 +37,11 @@ _optional_
Inherited from [`npx remotion render`](/docs/cli/render#--codec)
-### `--audio-codec`
+### `--audio-codec`<AvailableFrom v="3.3.42" />
_optional_
-Inherited from [`npx remotion render`](/docs/cli/render#--audio-codec)
+<Options id="audio-codec" />
### `--crf`
diff --git a/packages/docs/docs/cli/render.md b/packages/docs/docs/cli/render.md
index dea1924b66..24b06c1bc6 100644
--- a/packages/docs/docs/cli/render.md
+++ b/packages/docs/docs/cli/render.md
@@ -84,7 +84,7 @@ Sets the output file path, as an alternative to the `output-location` positional
### `--audio-codec`<AvailableFrom v="3.3.42" />
-[Set which codec the audio should have.](/docs/config#setaudiocodec) For defaults and possible values, refer to the [Encoding guide](/docs/encoding/#audio-codec).
+<Options id="audio-codec" />
### `--audio-bitrate`<AvailableFrom v="3.2.32" />
@@ -208,6 +208,10 @@ Lets you set a custom user agent that the headless Chrome browser assumes.
<Options cli id="binaries-directory" />
+### `--for-seamless-aac-concatenation`<AvailableFrom v="4.0.123" />
+
+<Options cli id="for-seamless-aac-concatenation" />
+
### `--separate-audio-to`<AvailableFrom v="4.0.123" />
<Options cli id="separate-audio-to" />
diff --git a/packages/docs/docs/cloudrun/cli/render.md b/packages/docs/docs/cloudrun/cli/render.md
index af78e9e251..2847e7569f 100644
--- a/packages/docs/docs/cloudrun/cli/render.md
+++ b/packages/docs/docs/cloudrun/cli/render.md
@@ -106,7 +106,7 @@ Specify the name of the service which should be used to perform the render. This
### `--audio-codec`
-[Set which codec the audio should have.](/docs/config#setaudiocodec) For defaults and possible values, refer to the [Encoding guide](/docs/encoding/#audio-codec).
+<Options id="audio-codec" />
### `--audio-bitrate`
diff --git a/packages/docs/docs/lambda/cli/render.md b/packages/docs/docs/lambda/cli/render.md
index 823d9fb16c..ff1ebb0bcd 100644
--- a/packages/docs/docs/lambda/cli/render.md
+++ b/packages/docs/docs/lambda/cli/render.md
@@ -131,7 +131,7 @@ Renamed to `jpegQuality` in `v4.0.0`.
### `--audio-codec`<AvailableFrom v="3.3.42" />
-[Set which codec the audio should have.](/docs/config#setaudiocodec) For defaults and possible values, refer to the [Encoding guide](/docs/encoding/#audio-codec).
+<Options id="audio-codec" />
### `--audio-bitrate`<AvailableFrom v="3.2.32" />
diff --git a/packages/renderer/src/client.ts b/packages/renderer/src/client.ts
index 63b42a180a..f52f8ff074 100644
--- a/packages/renderer/src/client.ts
+++ b/packages/renderer/src/client.ts
@@ -15,6 +15,7 @@ import {logLevels} from './log-level';
import {allOptions} from './options';
import {
defaultAudioCodecs,
+ getExtensionFromAudioCodec,
isAudioCodec,
supportedAudioCodecs,
validAudioCodecs,
@@ -62,4 +63,5 @@ export const BrowserSafeApis = {
codecSupportsVideoBitrate,
logLevels,
getOutputCodecOrUndefined,
+ getExtensionFromAudioCodec,
};
diff --git a/packages/renderer/src/options/for-seamless-aac-concatenation.tsx b/packages/renderer/src/options/for-seamless-aac-concatenation.tsx
index 0bb7557216..930944c415 100644
--- a/packages/renderer/src/options/for-seamless-aac-concatenation.tsx
+++ b/packages/renderer/src/options/for-seamless-aac-concatenation.tsx
@@ -18,6 +18,9 @@ export const forSeamlessAacConcatenationOption = {
If enabled, the audio is trimmed to the nearest AAC frame, which is
required for seamless concatenation of AAC files. This is a requirement if
you later want to combine multiple video snippets seamlessly.
+ <br />
+ <br /> This option is used internally. There is currently no documentation
+ yet for to concatenate the audio chunks.
</>
),
docLink: 'https://remotion.dev/docs/renderer',
diff --git a/packages/studio/src/components/RenderModal/RenderModal.tsx b/packages/studio/src/components/RenderModal/RenderModal.tsx
index 7a7d9a27cb..0b3e8568ad 100644
--- a/packages/studio/src/components/RenderModal/RenderModal.tsx
+++ b/packages/studio/src/components/RenderModal/RenderModal.tsx
@@ -71,6 +71,7 @@ import {VerticalTab} from '../Tabs/vertical';
import {useCrfState} from './CrfSetting';
import {DataEditor} from './DataEditor';
import {getDefaultCodecs} from './get-default-codecs';
+import {getStringBeforeSuffix} from './get-string-before-suffix';
import {validateOutnameGui} from './out-name-checker';
import type {RenderType} from './RenderModalAdvanced';
import {RenderModalAdvanced} from './RenderModalAdvanced';
@@ -599,16 +600,6 @@ const RenderModal: React.FC<
);
}, [resolvedComposition.durationInFrames, unclampedFrame]);
- const getStringBeforeSuffix = useCallback((fileName: string) => {
- const dotPos = fileName.lastIndexOf('.');
- if (dotPos === -1) {
- return fileName;
- }
-
- const bitBeforeDot = fileName.substring(0, dotPos);
- return bitBeforeDot;
- }, []);
-
const deriveFinalAudioCodec = useCallback(
(passedVideoCodec: Codec, passedAudioCodec: AudioCodec | null) => {
if (
@@ -662,7 +653,7 @@ const RenderModal: React.FC<
});
}
},
- [deriveFinalAudioCodec, getStringBeforeSuffix],
+ [deriveFinalAudioCodec],
);
const setAudioCodec = useCallback(
@@ -673,6 +664,16 @@ const RenderModal: React.FC<
codec: videoCodecForVideoTab,
audioCodec: newAudioCodec,
});
+ setSeparateAudioTo((prev) => {
+ if (prev === null) {
+ return null;
+ }
+
+ const newExtension =
+ BrowserSafeApis.getExtensionFromAudioCodec(newAudioCodec);
+ const newFileName = getStringBeforeSuffix(prev) + '.' + newExtension;
+ return newFileName;
+ });
},
[setDefaultOutName, videoCodecForVideoTab],
);
@@ -1332,6 +1333,7 @@ const RenderModal: React.FC<
setForSeamlessAacConcatenation={setForSeamlessAacConcatenation}
separateAudioTo={separateAudioTo}
setSeparateAudioTo={setSeparateAudioTo}
+ outName={outName}
/>
) : tab === 'gif' ? (
<RenderModalGif
diff --git a/packages/studio/src/components/RenderModal/RenderModalAudio.tsx b/packages/studio/src/components/RenderModal/RenderModalAudio.tsx
index 6dd84240f3..496ece11b4 100644
--- a/packages/studio/src/components/RenderModal/RenderModalAudio.tsx
+++ b/packages/studio/src/components/RenderModal/RenderModalAudio.tsx
@@ -44,6 +44,7 @@ export const RenderModalAudio: React.FC<{
codec: Codec;
setSeparateAudioTo: React.Dispatch<React.SetStateAction<string | null>>;
separateAudioTo: string | null;
+ outName: string;
}> = ({
muted,
setMuted,
@@ -61,6 +62,7 @@ export const RenderModalAudio: React.FC<{
setForSeamlessAacConcatenation,
separateAudioTo,
setSeparateAudioTo,
+ outName,
}) => {
const onShouldHaveTargetAudioBitrateChanged = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
@@ -149,6 +151,8 @@ export const RenderModalAudio: React.FC<{
<SeparateAudioOption
separateAudioTo={separateAudioTo}
setSeparateAudioTo={setSeparateAudioTo}
+ audioCodec={audioCodec}
+ outName={outName}
/>
) : null}
{audioCodec === 'aac' && !muted ? (
diff --git a/packages/studio/src/components/RenderModal/SeparateAudioOption.tsx b/packages/studio/src/components/RenderModal/SeparateAudioOption.tsx
index ff30c06333..85bae18657 100644
--- a/packages/studio/src/components/RenderModal/SeparateAudioOption.tsx
+++ b/packages/studio/src/components/RenderModal/SeparateAudioOption.tsx
@@ -1,8 +1,11 @@
+import type {AudioCodec} from '@remotion/renderer';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import type {ChangeEvent} from 'react';
-import React, {useCallback} from 'react';
+import React, {useCallback, useMemo} from 'react';
import {useFileExistence} from '../../helpers/use-file-existence';
import {Checkbox} from '../Checkbox';
import {Spacing} from '../layout';
+import {getStringBeforeSuffix} from './get-string-before-suffix';
import {input, label, optionRow, rightRow} from './layout';
import {OptionExplainerBubble} from './OptionExplainerBubble';
import {RenderModalOutputName} from './RenderModalOutputName';
@@ -10,7 +13,8 @@ import {RenderModalOutputName} from './RenderModalOutputName';
export const SeparateAudioOptionInput: React.FC<{
setSeparateAudioTo: React.Dispatch<React.SetStateAction<string | null>>;
separateAudioTo: string;
-}> = ({separateAudioTo, setSeparateAudioTo}) => {
+ audioCodec: AudioCodec;
+}> = ({separateAudioTo, setSeparateAudioTo, audioCodec}) => {
const existence = useFileExistence(separateAudioTo);
const onValueChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
@@ -20,6 +24,17 @@ export const SeparateAudioOptionInput: React.FC<{
[setSeparateAudioTo],
);
+ const validationMessage = useMemo(() => {
+ const expectedExtension =
+ BrowserSafeApis.getExtensionFromAudioCodec(audioCodec);
+ const actualExtension = separateAudioTo.split('.').pop();
+ if (actualExtension !== expectedExtension) {
+ return `Expected extension: .${expectedExtension}`;
+ }
+
+ return null;
+ }, [audioCodec, separateAudioTo]);
+
return (
<RenderModalOutputName
existence={existence}
@@ -27,8 +42,7 @@ export const SeparateAudioOptionInput: React.FC<{
onValueChange={onValueChange}
outName={separateAudioTo}
label={'Separate audio to'}
- // TODO
- validationMessage={'hi there'}
+ validationMessage={validationMessage}
/>
);
};
@@ -36,17 +50,22 @@ export const SeparateAudioOptionInput: React.FC<{
export const SeparateAudioOption: React.FC<{
setSeparateAudioTo: React.Dispatch<React.SetStateAction<string | null>>;
separateAudioTo: string | null;
-}> = ({separateAudioTo, setSeparateAudioTo}) => {
+ audioCodec: AudioCodec;
+ outName: string;
+}> = ({separateAudioTo, setSeparateAudioTo, audioCodec, outName}) => {
const onSeparateAudioChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
if (e.target.checked) {
- setSeparateAudioTo(String(e.target.checked));
+ const extension =
+ BrowserSafeApis.getExtensionFromAudioCodec(audioCodec);
+ setSeparateAudioTo(`${getStringBeforeSuffix(outName)}.${extension}`);
} else {
setSeparateAudioTo(null);
}
},
- [setSeparateAudioTo],
+ [audioCodec, outName, setSeparateAudioTo],
);
+
return (
<>
<div style={optionRow}>
@@ -69,6 +88,7 @@ export const SeparateAudioOption: React.FC<{
<SeparateAudioOptionInput
separateAudioTo={separateAudioTo}
setSeparateAudioTo={setSeparateAudioTo}
+ audioCodec={audioCodec}
/>
)}
</>
diff --git a/packages/studio/src/components/RenderModal/get-string-before-suffix.ts b/packages/studio/src/components/RenderModal/get-string-before-suffix.ts
new file mode 100644
index 0000000000..277bcf94ab
--- /dev/null
+++ b/packages/studio/src/components/RenderModal/get-string-before-suffix.ts
@@ -0,0 +1,8 @@
+export const getStringBeforeSuffix = (fileName: string) => {
+ const dotPos = fileName.lastIndexOf('.');
+ if (dotPos === -1) {
+ return fileName;
+ }
+
+ return fileName.substring(0, dotPos);
+};
diff --git a/packages/studio/src/components/RenderModal/out-name-checker.ts b/packages/studio/src/components/RenderModal/out-name-checker.ts
index 6532814df9..8dd45bf905 100644
--- a/packages/studio/src/components/RenderModal/out-name-checker.ts
+++ b/packages/studio/src/components/RenderModal/out-name-checker.ts
@@ -129,3 +129,49 @@ const isValidOutName = ({
}
}
};
+
+export const isValidSeparateAudioName = ({
+ audioCodec,
+ separateAudioTo,
+}: {
+ separateAudioTo: string;
+ audioCodec: AudioCodec;
+}): void => {
+ const prefix = separateAudioTo.substring(0, separateAudioTo.lastIndexOf('.'));
+
+ const expectedExtension =
+ BrowserSafeApis.getExtensionFromAudioCodec(audioCodec);
+ const actualExtension = separateAudioTo.split('.').pop();
+ if (actualExtension !== expectedExtension) {
+ throw new Error(`Expected extension: .${expectedExtension}`);
+ }
+
+ const hasDotAfterSlash = () => {
+ const substrings = prefix.split('/');
+ for (const str of substrings) {
+ if (str[0] === '.') {
+ return true;
+ }
+ }
+
+ return false;
+ };
+
+ const hasInvalidChar = () => {
+ return prefix.split('').some((char) => invalidCharacters.includes(char));
+ };
+
+ if (prefix.length < 1) {
+ throw new Error('The prefix must be at least 1 character long');
+ }
+
+ if (prefix[0] === '.' || hasDotAfterSlash()) {
+ throw new Error('The output name must not start with a dot');
+ }
+
+ if (hasInvalidChar()) {
+ throw new Error(
+ "Filename can't contain the following characters: ?, *, +, %, :",
+ );
+ }
+};