fix(media): live radio gets an audio player — the meta carries the init segment's real type

`shade live video` wrote meta.mime from the container alone (video/webm,
video/mp4) before the init segment was seen, so an audio-only stream
(Opus/WebM, AAC/fMP4) played sound in a black 120 px video box. It now
reads until the splitter yields the init and uses its type
(audio/webm; codecs="opus"); the watch page then builds an <audio>, and
sound gets a player bar on the panel instead of a black stage.

Verified in Chromium, unmuted, through the relay: Opus/WebM and AAC/fMP4
radio both play (currentTime advancing, readyState 4) with measured
output (WebAudio RMS 0.044). Media suite 93/0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-18 22:48:00 +02:00
parent f1b4c1ade1
commit 1653060494
6 changed files with 16 additions and 6 deletions

View File

@@ -557,15 +557,18 @@ async function liveVideo(flags: Flags, pinned?: LiveContainer): Promise<number>
if (format !== undefined && format !== 'webm' && format !== 'fmp4') throw new UsageError('--format must be webm or fmp4');
const splitter = new MediaSplitter(format);
const stdin = Bun.stdin.stream().getReader();
// Read until the container is known, so the meta can carry the right type.
// Read until the init segment is out, so the meta carries the stream's real
// type: a radio stream is audio/webm, and a viewer should get a player for
// sound, not a black video box.
let first: ReturnType<MediaSplitter['push']> = [];
while (splitter.container === null) {
let init: { mime: string } | undefined;
while (init === undefined) {
const { value, done } = await stdin.read();
if (done) throw new UsageError('no input on stdin');
if (done) throw new UsageError(splitter.container === null ? 'no input on stdin' : 'the stream ended before its init segment');
first = first.concat(splitter.push(value));
init = first.find((p) => p.type === 'init');
}
const fallbackMime = splitter.container === 'webm' ? 'video/webm' : 'video/mp4';
const meta: MediaMeta = { name: str(flags, 'name') ?? 'Live', mime: str(flags, 'mime') ?? fallbackMime };
const meta: MediaMeta = { name: str(flags, 'name') ?? 'Live', mime: str(flags, 'mime') ?? init.mime };
const { client } = await startPublishing(flags, meta);
let pieces = 0;
const send = async (batch: ReturnType<MediaSplitter['push']>) => {

View File

@@ -31,7 +31,9 @@ const HTML = `<!doctype html>
#sub { color: var(--dim); font-size: 13px; width: 100%; }
#stage { background: #000; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: grid; gap: 0; min-height: 120px; }
#stage video, #stage img { display: block; width: 100%; max-height: 72vh; object-fit: contain; background: #000; }
#stage audio { width: 100%; padding: 18px; }
#stage audio { display: block; width: 100%; box-sizing: border-box; padding: 18px; }
/* Sound has no picture: a player bar on the page's own panel, not a black screen. */
#stage:has(> audio) { background: var(--panel); min-height: 0; }
#log { margin: 0; padding: 14px 16px; height: 62vh; overflow: auto; background: var(--panel); color: #d6dbe1; font: 12.5px/1.5 ui-monospace, "JetBrains Mono", Menlo, monospace; white-space: pre-wrap; word-break: break-word; }
footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
#status { font-size: 13px; color: var(--dim); display: inline-flex; align-items: center; gap: 8px; }