Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 3ca5ee63527c10589d49df8758548a0f870b7d64
parent 48eef435363ba21d0e047f121559d0729577a723
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 25 Nov 2026 01:47:28 -0500

transcode + cast test: state an AAC bitrate (ffmpeg 9.1 loops forever on 16 kHz mono without one)

ffmpeg 9.1 (upgraded here 20 Nov) never finishes an encode with its own AAC encoder on some
16 kHz mono audio when no bitrate is given and the default coder is used: it writes a 44-byte
file, one thread spins, SIGTERM does not stop it. Any of -b:a, -ar 44100/48000, -ac 2 or the fast
coder avoids it.

- transcodeAudio's m4a args state -b:a 160k. A new test feeds it the exact synthetic voice
  that hung (red before: aborted at 30 s with no audio.m4a; green after).
- umtool cast.test.mjs: the fixture's window audio is written into the wav (no filter chain)
  and encoded at 48 kHz with a bitrate; ffmpeg runs with no stdin and is SIGKILLed after 60 s,
  so a hang fails the test instead of sticking the suite (8/8 in 195 s).

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Acommon/controller/transcode.test.ts | 44++++++++++++++++++++++++++++++++++++++++++++
Mcommon/controller/transcode.ts | 4+++-
Meditor/CHANGELOG.md | 7+++++++
Mumtool/lib/report/cast.test.mjs | 16+++++++++++-----
4 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/common/controller/transcode.test.ts b/common/controller/transcode.test.ts @@ -0,0 +1,44 @@ +// transcodeAudio's m4a: a 16 kHz mono voice (an ASR-rate source: an imported or recorded voice file) must come out. +// ffmpeg 9.1's own AAC encoder, given no bitrate and its default coder, never finishes on such a source: it writes a +// 44-byte file and loops, and SIGTERM does not stop it (measured 25 Nov 2026 on the cast fixture's voice). A stated +// bitrate avoids it, so CODEC_ARGS states one. +import assert from "node:assert/strict"; +import { existsSync, mkdtempSync, rmSync, statSync, writeFileSync } from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import test from "node:test"; +import { encodeWav16 } from "../lib/montage/voiceMatch.mjs"; +import { VOICE_A, syntheticVoice, withSilence } from "../testing/audio/syntheticVoice.mjs"; +import { hasFfmpeg } from "../testing/audio/corruptAudio.mjs"; +import type { Paths } from "../lib/paths"; +import { transcodeAudio } from "./transcode"; + +test("a 16 kHz mono voice transcodes to m4a and the encode finishes", { skip: !hasFfmpeg() && "no ffmpeg" }, async () => { + const dir = mkdtempSync(path.join(os.tmpdir(), "transcode-aac-")); + try { + const videoDir = path.join(dir, "data", "v1"); + const { mkdirSync } = await import("node:fs"); + mkdirSync(videoDir, { recursive: true }); + // The exact samples the cast fixture's encode hung on: 2.5 s of VOICE_A, 2.3 s of silence before, 3.8 s after. + writeFileSync( + path.join(videoDir, "source.wav"), + encodeWav16(withSilence(syntheticVoice({ ...VOICE_A, seconds: 2.5 }), { before: 2.3, after: 3.8 })), + ); + const log: string[] = []; + const started = Date.now(); + await transcodeAudio({ + paths: { ffmpegBin: process.env.FFMPEG_BIN ?? "ffmpeg" } as Paths, + videoDir, + sourceFilename: "source.wav", + targetFormat: "m4a", + onLog: (s) => log.push(s), + // A hung encode is aborted (execa force-kills 5 s later) and transcodeAudio returns with no file. + signal: AbortSignal.timeout(30_000), + }); + const out = path.join(videoDir, "audio.m4a"); + assert.ok(existsSync(out), `audio.m4a written (took ${Date.now() - started} ms)\n${log.join("")}`); + assert.ok(statSync(out).size > 10_000, `audio.m4a holds the audio, not a bare header: ${statSync(out).size} B`); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); diff --git a/common/controller/transcode.ts b/common/controller/transcode.ts @@ -7,7 +7,9 @@ import { tierMediaFile } from "../lib/mediaTier-server"; import "../lib/childKillGuard"; const CODEC_ARGS: Record<AudioFormat, string[]> = { - m4a: ["-c:a", "aac"], + // A stated bitrate: ffmpeg 9.1's own AAC encoder with no bitrate (its default coder) never finishes on some 16 kHz + // mono sources (a 44-byte file, a loop SIGTERM does not stop: transcode.test.ts). 160k, as the other encodes. + m4a: ["-c:a", "aac", "-b:a", "160k"], mp3: ["-c:a", "libmp3lame"], opus: ["-c:a", "libopus"], }; diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog ## [Unreleased] +- **An m4a transcode of a 16 kHz mono source no longer hangs forever.** + - ffmpeg 9.1's own AAC encoder, with no bitrate and its default coder, never finishes on some 16 kHz mono audio. + It writes a 44-byte file, loops at full CPU, and does not stop on SIGTERM. + - The video's `audio.m4a` transcode now states a bitrate (160k, as the app's other encodes). It is used by the + app's extraction, the audio-checked download, landing media and the video page's Transcode. + - umtool's cast test fixture hit the same loop, which stuck its suite and every gate run that included it. It now + encodes at 48 kHz with a bitrate, and its ffmpeg calls are killed after 60 s. - **Free up space: `/cleanup/space`, every disk the archive writes to and what frees space on each.** - The disks, the fullest first and marked: each one's size, free space now, how much of it is the archive's (by kind: media, text, clip windows, saved videos, playable copies, site builds, umtool reports, the index) and how diff --git a/umtool/lib/report/cast.test.mjs b/umtool/lib/report/cast.test.mjs @@ -29,10 +29,12 @@ const FAKE_EMBED = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ". process.env.VOICE_MATCH_PYTHON = process.execPath; process.env.VOICE_MATCH_SCRIPT = FAKE_EMBED; process.env.VOICE_MATCH_MODEL = "fake.onnx"; -const ff = (args) => execFileSync("ffmpeg", ["-v", "error", "-y", ...args]); -const wavOf = async (file, voice, seconds = 2.5) => { +// ffmpeg with no stdin and a time limit, killed outright (a looping ffmpeg ignores SIGTERM, and execFileSync then waits +// for it for good): a hang is a failure, not a stuck suite. +const ff = (args) => execFileSync("ffmpeg", ["-nostdin", "-v", "error", "-y", ...args], { stdio: ["ignore", "pipe", "pipe"], timeout: 60_000, killSignal: "SIGKILL" }); +const wavOf = async (file, voice, seconds = 2.5, { before = 0.3, after = 0.3 } = {}) => { await mkdir(path.dirname(file), { recursive: true }); - await writeFile(file, encodeWav16(withSilence(syntheticVoice({ ...voice, seconds }), { before: 0.3, after: 0.3 }))); + await writeFile(file, encodeWav16(withSilence(syntheticVoice({ ...voice, seconds }), { before, after }))); }; const io = () => { const lines = []; @@ -61,8 +63,12 @@ const CH = path.join(ROOT, "channels"); const d = path.join(CH, "chan", "data", `v${id}`); await mkdir(path.join(d, "clips"), { recursive: true }); await writeFile(path.join(d, "transcript.cues.json"), JSON.stringify({ id: `v${id}`, cues: [{ start: 102.5, end: 104, text: "slow news day" }] })); - await wavOf(path.join(d, "clips", "x.wav"), VOICE_A, 2.5); - ff(["-i", path.join(d, "clips", "x.wav"), "-af", "adelay=2000:all=1,apad=pad_dur=3.5", "-c:a", "aac", path.join(d, "clips", "100.00-108.00.mp4")]); + // The window's audio: 2 s more silence before (adelay 2000) and 3.5 s more after (apad) than a plain voice, + // written into the wav itself so the encode needs no filter chain. + await wavOf(path.join(d, "clips", "x.wav"), VOICE_A, 2.5, { before: 2.3, after: 3.8 }); + // At 48 kHz and a stated bitrate: ffmpeg 9.1's own AAC encoder (its default coder, no bitrate given) never + // finishes on this 16 kHz mono synthetic voice (it wrote a 44-byte file and looped for days, 21-25 Nov 2026). + ff(["-i", path.join(d, "clips", "x.wav"), "-ar", "48000", "-c:a", "aac", "-b:a", "128k", path.join(d, "clips", "100.00-108.00.mp4")]); await rm(path.join(d, "clips", "x.wav")); timeline.push({ type: "clip", id, channel: "chan", video: `v${id}`, start: 100, end: 108, cutStart: 102.5, cutEnd: 104, cite: 102.5, quote: "slow news day" }); }