mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
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.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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`)
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
},
|
||||
"@hyperframes/parsers": {
|
||||
"packed": 215500,
|
||||
"unpacked": 915000
|
||||
"unpacked": 930000
|
||||
},
|
||||
"@hyperframes/player": {
|
||||
"packed": 437000,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"files": 13
|
||||
},
|
||||
"media-use": {
|
||||
"hash": "c308eba538e05979",
|
||||
"hash": "527b640341cdd6a2",
|
||||
"files": 134
|
||||
},
|
||||
"remotion-to-hyperframes": {
|
||||
|
||||
@@ -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`);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}));
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"),
|
||||
'<audio id="music-bed" src="bed.wav" data-start="0"></audio>\n' +
|
||||
'<audio id="narration" src="narration.caf" data-start="0"></audio>\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/);
|
||||
});
|
||||
|
||||
@@ -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`, () => {
|
||||
|
||||
Reference in New Issue
Block a user