From 5a15b549b65b523e2ffcad0bd4ffe3ecb730ef76 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 24 Nov 2026 21:09:45 +0000 Subject: [PATCH] fix(media-use): accept CAF, W64, WavPack, AU and AC3 audio again (#8716) * fix(media-use): accept CAF, W64, WavPack, AU and AC3 audio again The self-contained reader lists left out five single-file audio containers, so recordings in those formats stopped probing. Each one holds its own media and opens no other file. Add their ffmpeg reader names (caf, w64, wv, au, ac3) to the skill's list and to the parsers fallback list. When a file is still refused, the message now names the accepted containers instead of saying ffmpeg cannot read it. * test(parsers): end ffprobe options with "--" in the container probe test * fix(cli): media-use resolve accepts CAF, W64, WavPack, AU and AC3 audio Add the same five single-file audio containers to the CLI media-use reader list, and to the drift check's stand-in demuxer listing. * chore(parsers): raise the unpacked size budget for the wider container list The five added reader names push @hyperframes/parsers a few bytes past its 1% tolerance; it was already within 0.1% of the limit on main. --- .../cli/src/media-use/lib/ff-binaries.mjs | 2 +- packages/cli/src/media-use/lib/probe.test.mjs | 4 ++- .../mediaGradeAnalyzer.vendoredParity.test.ts | 3 +- packages/parsers/src/ffBinaries.test.ts | 28 +++++++++++++++ packages/parsers/src/ffBinaries.ts | 2 +- scripts/package-size-budgets.json | 2 +- skills-manifest.json | 2 +- skills/media-use/audio/scripts/carve.mjs | 12 +++++-- skills/media-use/audio/scripts/carve.test.mjs | 2 +- .../audio/scripts/lib/media-input.mjs | 4 ++- .../media-use/audio/scripts/lib/recording.mjs | 8 +++-- .../audio/scripts/media-input.test.mjs | 34 +++++++++++++++++-- .../audio/scripts/recording.test.mjs | 4 +-- 13 files changed, 90 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/media-use/lib/ff-binaries.mjs b/packages/cli/src/media-use/lib/ff-binaries.mjs index 6940457da2..c87490af47 100644 --- a/packages/cli/src/media-use/lib/ff-binaries.mjs +++ b/packages/cli/src/media-use/lib/ff-binaries.mjs @@ -40,7 +40,7 @@ export const ffprobeBinary = () => configuredOr("ffprobe", "HYPERFRAMES_FFPROBE_ // Containers that hold their own media and name no other file. A project's file is opened only with these, so no // list, manifest, script, device or text-art reader runs on it, and nothing it names is opened. export const SELF_CONTAINED_FORMATS = - "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,gif,ico,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe"; + "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,caf,w64,wv,au,ac3,gif,ico,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe"; /** ffmpeg or ffprobe options, placed before the file, that read it as one local self-contained container. */ export function selfContainedInput(file) { diff --git a/packages/cli/src/media-use/lib/probe.test.mjs b/packages/cli/src/media-use/lib/probe.test.mjs index c37d753858..095dcf2a9b 100644 --- a/packages/cli/src/media-use/lib/probe.test.mjs +++ b/packages/cli/src/media-use/lib/probe.test.mjs @@ -269,7 +269,9 @@ test( make("tone.wav", ["-f", "lavfi", "-i", "sine=duration=1"]); make("clip.mp4", ["-f", "lavfi", "-i", "color=red:s=32x32:d=1"]); make("still.png", ["-f", "lavfi", "-i", "color=red:s=32x32", "-frames:v", "1"]); - for (const name of ["tone.mp3", "tone.wav", "clip.mp4", "still.png"]) { + const audio = ["tone.caf", "tone.w64", "tone.wv", "tone.au", "tone.ac3"]; + for (const name of audio) make(name, ["-f", "lavfi", "-i", "sine=duration=1"]); + for (const name of ["tone.mp3", "tone.wav", "clip.mp4", "still.png", ...audio]) { assert.ok(probe(join(dir, name)).codec, name); } // Each names the real clip next to it, which ffmpeg would open if it read the list. diff --git a/packages/core/src/mediaGradeAnalyzer.vendoredParity.test.ts b/packages/core/src/mediaGradeAnalyzer.vendoredParity.test.ts index b24bac4770..03563642f1 100644 --- a/packages/core/src/mediaGradeAnalyzer.vendoredParity.test.ts +++ b/packages/core/src/mediaGradeAnalyzer.vendoredParity.test.ts @@ -125,7 +125,8 @@ function standIns(dir: string): { const listing = [ "mov,mp4,m4a,3gp,3g2,mj2", ...["matroska,webm", "mxf", "avi", "mpeg", "mpegts", "mpegvideo", "flv", "asf", "ogg"], - ...["wav", "mp3", "aac", "flac", "aiff", "gif", "ico", "image2", "png_pipe", "jpeg_pipe"], + ...["wav", "mp3", "aac", "flac", "aiff", "caf", "w64", "wv", "au", "ac3"], + ...["gif", "ico", "image2", "png_pipe", "jpeg_pipe"], ...["webp_pipe", "bmp_pipe", "tiff_pipe", "hls", "concat", "dash", "avisynth", "tty"], ] .map((name) => ` D ${name} demuxer`) diff --git a/packages/parsers/src/ffBinaries.test.ts b/packages/parsers/src/ffBinaries.test.ts index bcf89af76c..dc444b333e 100644 --- a/packages/parsers/src/ffBinaries.test.ts +++ b/packages/parsers/src/ffBinaries.test.ts @@ -554,6 +554,34 @@ describe("mediaInputFormatArgs", () => { ]); expect(mediaInputFormatArgs(binary, "a.wav")).toEqual(["-format_whitelist", "wav"]); }); + + it("falls back to a list the installed ffprobe reads CAF, W64, WavPack, AU and AC3 with", async () => { + vi.resetModules(); + vi.doUnmock("node:fs"); + vi.doUnmock("node:child_process"); + const { findFfBinary, SELF_CONTAINED_FORMATS } = await importFresh(); + const [ffmpeg, ffprobe] = [findFfBinary("ffmpeg"), findFfBinary("ffprobe")]; + if (!ffmpeg || !ffprobe) return; + const dir = mkdtempSync(join(tmpdir(), "hf-audio-containers-")); + onTestFinished(() => rmSync(dir, { recursive: true, force: true })); + for (const ext of ["caf", "w64", "wv", "au", "ac3"]) { + const file = join(dir, `a.${ext}`); + spawnSync(ffmpeg, ["-v", "error", "-f", "lavfi", "-i", "sine=duration=1", file]); + const probe = spawnSync( + ffprobe, + ["-v", "error", "-format_whitelist", SELF_CONTAINED_FORMATS].concat([ + "-show_entries", + "format=format_name", + "-of", + "default=nw=1:nk=1", + "--", + file, + ]), + { encoding: "utf8" }, + ); + expect(probe.stdout.trim(), probe.stderr).toBe(ext); + } + }); }); describe("assertLiteralMediaInput", () => { diff --git a/packages/parsers/src/ffBinaries.ts b/packages/parsers/src/ffBinaries.ts index 06b901b999..fe549fd534 100644 --- a/packages/parsers/src/ffBinaries.ts +++ b/packages/parsers/src/ffBinaries.ts @@ -294,7 +294,7 @@ export function concatListInputArgs(concatListPath: string): string[] { /** What a render service lets a media input open: containers that name no other file. */ export const SELF_CONTAINED_FORMATS = - "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,gif,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe"; + "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,caf,w64,wv,au,ac3,gif,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe"; // Demuxers that open other files or URLs on their own. hls and concat stay allowed: ffmpeg copies the // format whitelist into every nested open, so a list cannot reach these, and the folder walk confines its paths. diff --git a/scripts/package-size-budgets.json b/scripts/package-size-budgets.json index 8bf83f057c..a12737b82b 100644 --- a/scripts/package-size-budgets.json +++ b/scripts/package-size-budgets.json @@ -29,7 +29,7 @@ }, "@hyperframes/parsers": { "packed": 215500, - "unpacked": 915000 + "unpacked": 930000 }, "@hyperframes/player": { "packed": 437000, diff --git a/skills-manifest.json b/skills-manifest.json index 517d89cb6d..25c3fadf8e 100644 --- a/skills-manifest.json +++ b/skills-manifest.json @@ -18,7 +18,7 @@ "files": 13 }, "media-use": { - "hash": "c308eba538e05979", + "hash": "527b640341cdd6a2", "files": 134 }, "remotion-to-hyperframes": { diff --git a/skills/media-use/audio/scripts/carve.mjs b/skills/media-use/audio/scripts/carve.mjs index fb33b3369c..72acffa016 100644 --- a/skills/media-use/audio/scripts/carve.mjs +++ b/skills/media-use/audio/scripts/carve.mjs @@ -29,7 +29,12 @@ import { readFileSync, realpathSync, statSync, writeFileSync } from "node:fs"; import { dirname, relative, resolve, sep } from "node:path"; import * as carveApi from "./lib/audio-carve.mjs"; import { isMainModule } from "./lib/main-module.mjs"; -import { isIndirectFormat, pinnedInput, probeFormat } from "./lib/media-input.mjs"; +import { + ACCEPTED_CONTAINERS, + isIndirectFormat, + pinnedInput, + probeFormat, +} from "./lib/media-input.mjs"; import { projectPath } from "./lib/project-path.mjs"; import { assertLiteralMediaPath } from "../../scripts/lib/literal-media-input.mjs"; @@ -202,7 +207,10 @@ export function mediaSource(compDir, src) { /** Mono float PCM for one media file, via ffmpeg reading that file alone. */ function decode(path) { const format = probeFormat(path); - if (!format) fail(`could not decode ${path}: ffmpeg cannot read it as media`); + if (!format) + fail( + `could not decode ${path}: it is not media in an accepted container (${ACCEPTED_CONTAINERS})`, + ); if (isIndirectFormat(format)) { fail(`${path} is a ${format} list that points at other files; give the media file itself`); } diff --git a/skills/media-use/audio/scripts/carve.test.mjs b/skills/media-use/audio/scripts/carve.test.mjs index 786037d21a..8ab020af72 100644 --- a/skills/media-use/audio/scripts/carve.test.mjs +++ b/skills/media-use/audio/scripts/carve.test.mjs @@ -416,7 +416,7 @@ test("a playlist saved under a media name inside the project is refused and open const before = readFileSync(join(project, "index.html"), "utf8"); const run = runCarve(project); assert.equal(run.status, 1, run.stderr); - assert.match(run.stderr, /list that points at other files|cannot read it as media/); + assert.match(run.stderr, /list that points at other files|not media in an accepted container/); assert.equal(readFileSync(join(project, "index.html"), "utf8"), before); })); diff --git a/skills/media-use/audio/scripts/lib/media-input.mjs b/skills/media-use/audio/scripts/lib/media-input.mjs index e1a44f5f8a..1ab510e00f 100644 --- a/skills/media-use/audio/scripts/lib/media-input.mjs +++ b/skills/media-use/audio/scripts/lib/media-input.mjs @@ -23,7 +23,9 @@ const INDIRECT_FORMATS = new Set([ // Opening a file runs its reader, and a script reader (avisynth, vapoursynth) runs the script, so even the // probe names the readers it may use: audio and video containers that hold their own media. export const SELF_CONTAINED_FORMATS = - "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff"; + "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,caf,w64,wv,au,ac3"; +export const ACCEPTED_CONTAINERS = + "MP4, M4A, MOV, MKV, WebM, MXF, AVI, MPEG, MPEG-TS, FLV, WMV, Ogg, WAV, W64, CAF, AU, MP3, AAC, AC3, FLAC, WavPack or AIFF"; const PROBE_INPUT = ["-protocol_whitelist", "file", "-format_whitelist", SELF_CONTAINED_FORMATS]; // The demuxer name for src, such as "mp3" or "mov,mp4,m4a,3gp,3g2,mj2"; null when it cannot tell. Some diff --git a/skills/media-use/audio/scripts/lib/recording.mjs b/skills/media-use/audio/scripts/lib/recording.mjs index 2eaa8b56b3..1021679d6b 100644 --- a/skills/media-use/audio/scripts/lib/recording.mjs +++ b/skills/media-use/audio/scripts/lib/recording.mjs @@ -5,7 +5,7 @@ import { assertLiteralMediaPath } from "../../../scripts/lib/literal-media-input import { spawnSync } from "node:child_process"; import { existsSync, mkdirSync, statSync } from "node:fs"; import { dirname } from "node:path"; -import { isIndirectFormat, pinnedInput, probeFormat } from "./media-input.mjs"; +import { ACCEPTED_CONTAINERS, isIndirectFormat, pinnedInput, probeFormat } from "./media-input.mjs"; import { projectPath } from "./project-path.mjs"; // ffmpeg's atempo takes 0.5..2 per stage; chain stages for the rest of the 0.1..3 speed range. @@ -44,7 +44,11 @@ export function stretchToWav(src, wavAbs, speed = 1) { if (!stat) return { ok: false, error: `recording not found: ${src}` }; if (!stat.isFile()) return { ok: false, error: `recording is not a file: ${src}` }; const format = probeFormat(src); - if (!format) return { ok: false, error: `ffmpeg cannot read ${src} as audio` }; + if (!format) + return { + ok: false, + error: `${src} is not audio in an accepted container (${ACCEPTED_CONTAINERS})`, + }; if (isIndirectFormat(format)) { return { ok: false, diff --git a/skills/media-use/audio/scripts/media-input.test.mjs b/skills/media-use/audio/scripts/media-input.test.mjs index 4a78fda8b0..dd4e60afdf 100644 --- a/skills/media-use/audio/scripts/media-input.test.mjs +++ b/skills/media-use/audio/scripts/media-input.test.mjs @@ -74,7 +74,17 @@ test( { skip: !hasFfmpeg }, (t) => { const dir = sandbox(t); - for (const name of ["a.wav", "a.mp3", "a.m4a", "a.mp4"]) { + for (const name of [ + "a.wav", + "a.mp3", + "a.m4a", + "a.mp4", + "a.caf", + "a.w64", + "a.wv", + "a.au", + "a.ac3", + ]) { const made = spawnSync("ffmpeg", [ "-v", "error", @@ -121,7 +131,7 @@ test("carve refuses a clip whose source is a script", { skip: !hasFfmpeg }, (t) encoding: "utf8", }); assert.equal(run.status, 1, run.stderr); - assert.match(run.stderr, /cannot read it as media/); + assert.match(run.stderr, /not media in an accepted container \(MP4, /); }); test("the recording path refuses a recording that is a script", { skip: !hasFfmpeg }, (t) => { @@ -140,5 +150,23 @@ test("the recording path refuses a recording that is a script", { skip: !hasFfmp }, ); assert.match(run.stdout, /line 01: recording failed — omitted/); - assert.match(run.stdout, /cannot read/); + assert.match(run.stdout, /not audio in an accepted container \(MP4, /); +}); + +test("carve decodes a CAF recording", { skip: !hasFfmpeg }, (t) => { + const dir = sandbox(t); + for (const name of ["bed.wav", "narration.caf"]) { + spawnSync("ffmpeg", ["-v", "error", "-f", "lavfi", "-i", "sine=duration=2", join(dir, name)]); + } + writeFileSync( + join(dir, "index.html"), + '\n' + + '\n', + ); + const run = spawnSync(process.execPath, [join(scripts, "carve.mjs"), "--comp", "index.html"], { + cwd: dir, + encoding: "utf8", + }); + assert.equal(run.status, 0, run.stderr); + assert.match(run.stdout, /voice narration/); }); diff --git a/skills/media-use/audio/scripts/recording.test.mjs b/skills/media-use/audio/scripts/recording.test.mjs index 0ebe7911ba..ecb639749d 100644 --- a/skills/media-use/audio/scripts/recording.test.mjs +++ b/skills/media-use/audio/scripts/recording.test.mjs @@ -199,13 +199,13 @@ for (const [label, name, list, reason] of [ "an HLS playlist", "take.m3u8", (media) => `#EXTM3U\n#EXT-X-TARGETDURATION:1\n#EXTINF:1,\n${media}\n#EXT-X-ENDLIST\n`, - /is a hls list that points at other files|cannot read/, + /is a hls list that points at other files|not audio in an accepted container/, ], [ "a concat list", "take.ffconcat", (media) => `ffconcat version 1.0\nfile '${media}'\n`, - /list that points at other files|cannot read/, + /list that points at other files|not audio in an accepted container/, ], ]) { test(`a recording that is ${label} naming an outside file is refused`, () => {