Repository navigation
fix(media-server): accept older video and audio codecs in imports again #4201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+292
−12
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e6ceb01
fix(media-server): accept older video and audio codecs in imports again
richiemcilroy 864989d
test(media-server): run the older-format tests in both image builds
richiemcilroy 95531db
Merge remote-tracking branch 'origin/main' into fix/media-legacy-deco…
richiemcilroy c483e16
fix(media-server): do not give the server the root group for open GPU…
richiemcilroy 8e856b1
chore(media-server): keep only comments that explain the codec lists
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
219 changes: 219 additions & 0 deletions
219
apps/media-server/src/__tests__/lib/legacy-codecs.integration.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | ||
| import { mkdtemp, rm } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { probeVideoFile } from "../../lib/media-probe"; | ||
| import { stopProbeWorkers } from "../../lib/media-probe-pool"; | ||
| import { spawn } from "../../lib/media-spawn"; | ||
|
|
||
| // Older codecs a regular Cap import can carry, in the containers the probe | ||
| // reads (Matroska, MP4 and 3GP). Each fixture is made with the local FFmpeg, | ||
| // then probed and transcoded to H.264 and AAC through the same hardened spawn | ||
| // the server uses, so the codec and decoder lists are what decides. A family | ||
| // whose encoder this FFmpeg lacks is skipped here. | ||
| type Fixture = { | ||
| name: string; | ||
| file: string; | ||
| video: string[]; | ||
| audio: string[] | null; | ||
| encoders: string[]; | ||
| }; | ||
|
|
||
| const FIXTURES: Fixture[] = [ | ||
| { | ||
| name: "MPEG-1 video with MPEG audio layer 2", | ||
| file: "mpeg1.mkv", | ||
| video: ["-c:v", "mpeg1video"], | ||
| audio: ["-c:a", "mp2"], | ||
| encoders: ["mpeg1video", "mp2"], | ||
| }, | ||
| { | ||
| name: "MPEG-2 video with MPEG audio layer 2", | ||
| file: "mpeg2.mkv", | ||
| video: ["-c:v", "mpeg2video"], | ||
| audio: ["-c:a", "mp2"], | ||
| encoders: ["mpeg2video", "mp2"], | ||
| }, | ||
| { | ||
| name: "Windows Media video 7 with Windows Media audio 1", | ||
| file: "wmv1.mkv", | ||
| video: ["-c:v", "wmv1"], | ||
| audio: ["-c:a", "wmav1"], | ||
| encoders: ["wmv1", "wmav1"], | ||
| }, | ||
| { | ||
| name: "Windows Media video 8 with Windows Media audio 2", | ||
| file: "wmv2.mkv", | ||
| video: ["-c:v", "wmv2"], | ||
| audio: ["-c:a", "wmav2"], | ||
| encoders: ["wmv2", "wmav2"], | ||
| }, | ||
| { | ||
| name: "early MPEG-4 (DivX 3) with Microsoft ADPCM", | ||
| file: "msmpeg4v3.mkv", | ||
| video: ["-c:v", "msmpeg4"], | ||
| audio: ["-c:a", "adpcm_ms"], | ||
| encoders: ["msmpeg4", "adpcm_ms"], | ||
| }, | ||
| { | ||
| name: "early MPEG-4 version 2 with IMA ADPCM", | ||
| file: "msmpeg4v2.mkv", | ||
| video: ["-c:v", "msmpeg4v2"], | ||
| audio: ["-c:a", "adpcm_ima_wav"], | ||
| encoders: ["msmpeg4v2", "adpcm_ima_wav"], | ||
| }, | ||
| { | ||
| name: "Flash video", | ||
| file: "flv1.mkv", | ||
| video: ["-c:v", "flv"], | ||
| audio: ["-c:a", "aac"], | ||
| encoders: ["flv", "aac"], | ||
| }, | ||
| { | ||
| name: "H.263 from a phone", | ||
| file: "phone.3gp", | ||
| video: ["-c:v", "h263"], | ||
| audio: ["-c:a", "aac", "-ar", "8000", "-ac", "1"], | ||
| encoders: ["h263", "aac"], | ||
| }, | ||
| { | ||
| name: "H.263 with AMR narrowband audio", | ||
| file: "amrnb.3gp", | ||
| video: ["-c:v", "h263"], | ||
| audio: ["-c:a", "libopencore_amrnb", "-ar", "8000", "-ac", "1"], | ||
| encoders: ["h263", "libopencore_amrnb"], | ||
| }, | ||
| { | ||
| name: "H.263 with AMR wideband audio", | ||
| file: "amrwb.3gp", | ||
| video: ["-c:v", "h263"], | ||
| audio: ["-c:a", "libvo_amrwbenc", "-ar", "16000", "-ac", "1"], | ||
| encoders: ["h263", "libvo_amrwbenc"], | ||
| }, | ||
| { | ||
| name: "Theora with Vorbis", | ||
| file: "theora.mkv", | ||
| video: ["-c:v", "libtheora"], | ||
| audio: ["-c:a", "libvorbis"], | ||
| encoders: ["libtheora", "libvorbis"], | ||
| }, | ||
| { | ||
| name: "H.264 with MPEG audio layer 2", | ||
| file: "h264-mp2.mkv", | ||
| video: ["-c:v", "libx264"], | ||
| audio: ["-c:a", "mp2"], | ||
| encoders: ["libx264", "mp2"], | ||
| }, | ||
| { | ||
| name: "H.264 with Windows Media audio 2", | ||
| file: "h264-wma.mkv", | ||
| video: ["-c:v", "libx264"], | ||
| audio: ["-c:a", "wmav2"], | ||
| encoders: ["libx264", "wmav2"], | ||
| }, | ||
| ]; | ||
|
|
||
| let dir = ""; | ||
| // Read when the file loads: skipIf decides before beforeAll runs. | ||
| const encoders = new Set( | ||
| Bun.spawnSync(["ffmpeg", "-hide_banner", "-encoders"]) | ||
| .stdout.toString() | ||
| .split("\n") | ||
| .map((line) => line.trim().split(/\s+/)[1] ?? ""), | ||
| ); | ||
|
|
||
| async function run(cmd: string[]): Promise<{ code: number; stderr: string }> { | ||
| const proc = Bun.spawn(cmd, { stdout: "pipe", stderr: "pipe" }); | ||
| const [code, stdout, stderr] = await Promise.all([ | ||
| proc.exited, | ||
| new Response(proc.stdout).text(), | ||
| new Response(proc.stderr).text(), | ||
| ]); | ||
| return { code, stderr: stderr || stdout }; | ||
| } | ||
|
|
||
| const available = (fixture: Fixture) => | ||
| fixture.encoders.every((name) => encoders.has(name)); | ||
|
|
||
| beforeAll(async () => { | ||
| dir = await mkdtemp(join(tmpdir(), "legacy-codecs-")); | ||
| for (const fixture of FIXTURES) { | ||
| if (!available(fixture)) continue; | ||
| const made = await run([ | ||
| "ffmpeg", | ||
| "-v", | ||
| "error", | ||
| "-y", | ||
| "-f", | ||
| "lavfi", | ||
| "-i", | ||
| "testsrc=d=1:s=176x144:r=25", | ||
| ...(fixture.audio ? ["-f", "lavfi", "-i", "sine=d=1:r=44100"] : []), | ||
| ...fixture.video, | ||
| ...(fixture.audio ?? []), | ||
| join(dir, fixture.file), | ||
| ]); | ||
| if (made.code !== 0) | ||
| throw new Error(`could not make ${fixture.file}: ${made.stderr}`); | ||
| } | ||
| }, 120_000); | ||
|
|
||
| afterAll(async () => { | ||
| stopProbeWorkers(); | ||
| await rm(dir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| describe("older formats a regular import can carry", () => { | ||
| for (const fixture of FIXTURES) { | ||
| test.skipIf(!available(fixture))( | ||
| `${fixture.name} probes and transcodes`, | ||
| async () => { | ||
| const input = join(dir, fixture.file); | ||
| const metadata = await probeVideoFile(input); | ||
| expect(metadata.width).toBe(176); | ||
| expect(metadata.height).toBe(144); | ||
|
|
||
| const output = join(dir, `${fixture.file}.mp4`); | ||
| const transcode = spawn({ | ||
| cmd: [ | ||
| "ffmpeg", | ||
| "-v", | ||
| "error", | ||
| "-y", | ||
| "-i", | ||
| input, | ||
| "-c:v", | ||
| "libx264", | ||
| "-preset", | ||
| "ultrafast", | ||
| "-c:a", | ||
| "aac", | ||
| output, | ||
| ], | ||
| stdout: "ignore", | ||
| stderr: "pipe", | ||
| }); | ||
| const [code, stderr] = await Promise.all([ | ||
| transcode.exited, | ||
| new Response(transcode.stderr).text(), | ||
| ]); | ||
| expect(stderr).not.toContain("not on whitelist"); | ||
| expect(code).toBe(0); | ||
|
|
||
| const streams = await run([ | ||
| "ffprobe", | ||
| "-v", | ||
| "error", | ||
| "-show_entries", | ||
| "stream=codec_type,codec_name", | ||
| "-of", | ||
| "csv=p=0", | ||
| output, | ||
| ]); | ||
| expect(streams.stderr).toContain("h264,video"); | ||
| if (fixture.audio) expect(streams.stderr).toContain("aac,audio"); | ||
| }, | ||
| 60_000, | ||
| ); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.