Skip to content

Commit ce0cfef

Browse files
committed
Add ffmpeg integration tests and fix pipe argument
1 parent ce3a52c commit ce0cfef

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed
2.27 KB
Binary file not shown.
12.1 KB
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { join } from "node:path";
3+
import { checkHasAudioTrack, extractAudio } from "../../lib/ffmpeg";
4+
5+
const FIXTURES_DIR = join(import.meta.dir, "..", "fixtures");
6+
const TEST_VIDEO_WITH_AUDIO = `file://${join(FIXTURES_DIR, "test-with-audio.mp4")}`;
7+
const TEST_VIDEO_NO_AUDIO = `file://${join(FIXTURES_DIR, "test-no-audio.mp4")}`;
8+
9+
describe("ffmpeg integration tests", () => {
10+
describe("checkHasAudioTrack", () => {
11+
test("detects audio track in video with audio", async () => {
12+
const hasAudio = await checkHasAudioTrack(TEST_VIDEO_WITH_AUDIO);
13+
expect(hasAudio).toBe(true);
14+
});
15+
16+
test("detects no audio track in video without audio", async () => {
17+
const hasAudio = await checkHasAudioTrack(TEST_VIDEO_NO_AUDIO);
18+
expect(hasAudio).toBe(false);
19+
});
20+
});
21+
22+
describe("extractAudio", () => {
23+
test("extracts audio from video with audio track", async () => {
24+
const audioData = await extractAudio(TEST_VIDEO_WITH_AUDIO);
25+
26+
expect(audioData).toBeInstanceOf(Uint8Array);
27+
expect(audioData.length).toBeGreaterThan(0);
28+
29+
const hasFtypBox =
30+
audioData[4] === 0x66 &&
31+
audioData[5] === 0x74 &&
32+
audioData[6] === 0x79 &&
33+
audioData[7] === 0x70;
34+
expect(hasFtypBox).toBe(true);
35+
});
36+
37+
test("throws error for video without audio track", async () => {
38+
await expect(extractAudio(TEST_VIDEO_NO_AUDIO)).rejects.toThrow();
39+
});
40+
});
41+
});

apps/media-server/src/lib/ffmpeg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function extractAudio(
4646
"ipod",
4747
"-movflags",
4848
"+frag_keyframe+empty_moov",
49-
"-pipe:1",
49+
"pipe:1",
5050
];
5151

5252
console.log(`[ffmpeg] Starting audio extraction: ${ffmpegArgs.join(" ")}`);
@@ -93,7 +93,7 @@ export async function extractAudioStream(
9393
"ipod",
9494
"-movflags",
9595
"+frag_keyframe+empty_moov",
96-
"-pipe:1",
96+
"pipe:1",
9797
];
9898

9999
console.log(

0 commit comments

Comments
 (0)