Skip to content

🎥 Make videos programmatically with React

compressaudio

Jonny Burger5c9aae606ff5
diff --git a/packages/renderer/src/compress-audio.ts b/packages/renderer/src/compress-audio.ts
index 43d84d3e11..a736699725 100644
--- a/packages/renderer/src/compress-audio.ts
+++ b/packages/renderer/src/compress-audio.ts
@@ -1,22 +1,40 @@
import type {AudioCodec} from './audio-codec';
-import {OUTPUT_FILTER_NAME} from './create-ffmpeg-merge-filter';
+import {mapAudioCodecToFfmpegAudioCodecName} from './audio-codec';
+import {callFf} from './call-ffmpeg';
+import type {LogLevel} from './log-level';
import {truthy} from './truthy';
-export const compressAudio = ({
+export const compressAudio = async ({
audioCodec,
- forceLossless,
outName,
+ binariesDirectory,
+ indent,
+ logLevel,
+ audioBitrate,
}: {
audioCodec: AudioCodec;
- forceLossless: boolean;
outName: string;
+ indent: boolean;
+ logLevel: LogLevel;
+ binariesDirectory: string | null;
+ audioBitrate: string | null;
}) => {
const args = [
- ['-c:a', forceLossless ? 'pcm_s16le' : 'libfdk_aac'],
- forceLossless ? null : ['-f', 'adts'],
- ['-map', `[${OUTPUT_FILTER_NAME}]`],
+ ['-c:a', mapAudioCodecToFfmpegAudioCodecName(audioCodec)],
+ audioCodec === 'aac' ? ['-f', 'adts'] : null,
+ audioCodec ? ['-b:a', audioBitrate || '320k'] : null,
+ audioCodec === 'aac' ? '-cutoff' : null,
+ audioCodec === 'aac' ? '18000' : null,
['-y', outName],
]
.filter(truthy)
.flat(2);
+
+ await callFf({
+ bin: 'ffmpeg',
+ args,
+ indent,
+ logLevel,
+ binariesDirectory,
+ });
};
diff --git a/packages/renderer/src/merge-audio-track.ts b/packages/renderer/src/merge-audio-track.ts
index d369087288..80a648f905 100644
--- a/packages/renderer/src/merge-audio-track.ts
+++ b/packages/renderer/src/merge-audio-track.ts
@@ -20,7 +20,6 @@ type Options = {
remotionRoot: string;
indent: boolean;
logLevel: LogLevel;
- forceLossless: boolean;
binariesDirectory: string | null;
};
@@ -32,7 +31,6 @@ const mergeAudioTrackUnlimited = async ({
remotionRoot,
indent,
logLevel,
- forceLossless,
binariesDirectory,
}: Options): Promise<void> => {
if (files.length === 0) {
@@ -65,7 +63,6 @@ const mergeAudioTrackUnlimited = async ({
remotionRoot,
indent,
logLevel,
- forceLossless: true,
binariesDirectory,
});
return chunkOutname;
@@ -86,7 +83,6 @@ const mergeAudioTrackUnlimited = async ({
remotionRoot,
indent,
logLevel,
- forceLossless: false,
binariesDirectory,
});
return;
@@ -101,14 +97,10 @@ const mergeAudioTrackUnlimited = async ({
downloadMap,
});
- // TODO: Make AAC dynamic
- // TODO: Add bitrate
- // TODO: Add cutoff
const args = [
...files.map((f) => ['-i', f.outName]),
mergeFilter,
- ['-c:a', forceLossless ? 'pcm_s16le' : 'libfdk_aac'],
- forceLossless ? null : ['-f', 'adts'],
+ ['-c:a', 'pcm_s16le'],
['-map', `[${OUTPUT_FILTER_NAME}]`],
['-y', outName],
]