Skip to content

🎥 Make videos programmatically with React

get rid of getaudiochannels

Jonny Burgere3301c161f6d
diff --git a/packages/renderer/src/assets/get-audio-channels.ts b/packages/renderer/src/assets/get-audio-channels.ts
deleted file mode 100644
index 3d1e2e8d02..0000000000
--- a/packages/renderer/src/assets/get-audio-channels.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import execa from 'execa';
-
-export async function getAudioChannels(path: string) {
- const args = [
- ['-v', 'error'],
- ['-show_entries', 'stream=channels'],
- ['-of', 'default=nw=1'],
- [path],
- ]
- .reduce<(string | null)[]>((acc, val) => acc.concat(val), [])
- .filter(Boolean) as string[];
-
- const task = await execa('ffprobe', args);
- if (!task.stdout.includes('channels=')) {
- return 0;
- }
-
- const channels = parseInt(task.stdout.replace('channels=', ''), 10);
- if (isNaN(channels)) {
- throw new TypeError('Unexpected result from ffprobe for channel probing: ');
- }
-
- return channels;
-}
diff --git a/packages/renderer/src/calculate-ffmpeg-filters.ts b/packages/renderer/src/calculate-ffmpeg-filters.ts
index c972f8d76f..81d0e605f4 100644
--- a/packages/renderer/src/calculate-ffmpeg-filters.ts
+++ b/packages/renderer/src/calculate-ffmpeg-filters.ts
@@ -6,23 +6,16 @@ export const calculateFfmpegFilter = ({
asset,
fps,
durationInFrames,
- channels,
}: {
asset: MediaAsset;
fps: number;
durationInFrames: number;
- channels: number;
}): string | null => {
- if (channels === 0) {
- return null;
- }
-
const assetTrimLeft = asset.trimLeft / fps;
const assetTrimRight =
(asset.trimLeft + asset.duration * asset.playbackRate) / fps;
const filter = stringifyFfmpegFilter({
- channels,
startInVideo: asset.startInVideo,
trimLeft: assetTrimLeft,
trimRight: assetTrimRight,
diff --git a/packages/renderer/src/preprocess-audio-track.ts b/packages/renderer/src/preprocess-audio-track.ts
index fba88c0b50..f31b6793f3 100644
--- a/packages/renderer/src/preprocess-audio-track.ts
+++ b/packages/renderer/src/preprocess-audio-track.ts
@@ -1,6 +1,5 @@
import execa from 'execa';
import {FfmpegExecutable} from 'remotion';
-import {getAudioChannels} from './assets/get-audio-channels';
import {MediaAsset} from './assets/types';
import {calculateFfmpegFilter} from './calculate-ffmpeg-filters';
import {makeFfmpegFilterFile} from './ffmpeg-filter-file';
@@ -22,13 +21,10 @@ const preprocessAudioTrackUnlimited = async ({
expectedFrames,
fps,
}: Options): Promise<string | null> => {
- const channels = await getAudioChannels(resolveAssetSrc(asset.src));
-
const filter = calculateFfmpegFilter({
asset,
durationInFrames: expectedFrames,
fps,
- channels,
});
if (filter === null) {
diff --git a/packages/renderer/src/stringify-ffmpeg-filter.ts b/packages/renderer/src/stringify-ffmpeg-filter.ts
index 07b3e60e54..284753c8c7 100644
--- a/packages/renderer/src/stringify-ffmpeg-filter.ts
+++ b/packages/renderer/src/stringify-ffmpeg-filter.ts
@@ -6,7 +6,6 @@ import {AssetVolume} from './assets/types';
export const stringifyFfmpegFilter = ({
trimLeft,
trimRight,
- channels,
startInVideo,
volume,
fps,
@@ -15,7 +14,6 @@ export const stringifyFfmpegFilter = ({
}: {
trimLeft: number;
trimRight: number;
- channels: number;
startInVideo: number;
volume: AssetVolume;
fps: number;
@@ -44,15 +42,13 @@ export const stringifyFfmpegFilter = ({
`atrim=${trimLeft.toFixed(6)}:${trimRight.toFixed(6)}`,
// then set the tempo
calculateATempo(playbackRate),
- // For n channels, we delay n + 1 channels.
- // This is because `ffprobe` for some audio files reports the wrong amount
- // of channels.
- // This should be fine because FFMPEG documentation states:
+ // We delay up to 10 channels.
+ // Audio usually does not have more than than that and FFMEPG docs state:
// "Unused delays will be silently ignored."
// https://ffmpeg.org/ffmpeg-filters.html#adelay
startInVideoSeconds === 0
? null
- : `adelay=${new Array(channels + 1)
+ : `adelay=${new Array(10)
.fill((startInVideoSeconds * 1000).toFixed(0))
.join('|')}`,
// set the volume if needed
diff --git a/packages/renderer/src/test/get-audio-channels.test.ts b/packages/renderer/src/test/get-audio-channels.test.ts
deleted file mode 100644
index d4d640e5bc..0000000000
--- a/packages/renderer/src/test/get-audio-channels.test.ts
+++ /dev/null
@@ -1,60 +0,0 @@
-import {existsSync} from 'fs';
-import path from 'path';
-import {getAudioChannels} from '../assets/get-audio-channels';
-jest.setTimeout(10000);
-
-test('Get audio channels for video', async () => {
- const videoWithoutAudio = path.join(
- __dirname,
- '..',
- '..',
- '..',
- 'example',
- 'src',
- 'resources',
- 'framer-music.mp4'
- );
- expect(existsSync(videoWithoutAudio)).toBe(true);
- const channels = await getAudioChannels(videoWithoutAudio);
- expect(channels).toBe(2);
-});
-
-test('Get audio channels for video without music', async () => {
- const videoWithAudio = path.join(
- __dirname,
- '..',
- '..',
- '..',
- 'example',
- 'src',
- 'resources',
- 'framer.mp4'
- );
- expect(existsSync(videoWithAudio)).toBe(true);
- const channels = await getAudioChannels(videoWithAudio);
- expect(channels).toBe(0);
-});
-
-test('Get audio channels for video without music', async () => {
- const audio = path.join(
- __dirname,
- '..',
- '..',
- '..',
- 'example',
- 'src',
- 'resources',
- 'sound1.mp3'
- );
- expect(existsSync(audio)).toBe(true);
- const channels = await getAudioChannels(audio);
- expect(channels).toBe(2);
-});
-
-test('Throw error if parsing a non video file', () => {
- const tsFile = path.join(__dirname, '..', 'ffmpeg-flags.ts');
- expect(existsSync(tsFile)).toBe(true);
- expect(() => getAudioChannels(tsFile)).rejects.toThrow(
- /Invalid data found when processing input/
- );
-});