feat(media): live fragmented MP4 (H.264/HEVC/AV1 + AAC/Opus), shade live video

Fmp4Splitter cuts ftyp+moov into the sticky init and moof+mdat into frames,
reading sync samples from trun/tfhd/trex flags so fragments shorter than a
GOP still mark where late joiners may start. Codec strings come from the
sample entries. MediaSplitter sniffs WebM vs fMP4; the CLI's new
`live video` uses it (`live webm` stays as the pinned form).

Verified: 9 new tests on real ffmpeg output; H.264/AAC live in headless
Chromium (49/49 fragments appended, late join, 3.2 s latency) and a sealed
H.264 film seeking to 24 s.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-18 21:27:50 +02:00
parent c5b897b924
commit 75dbf530ce
12 changed files with 710 additions and 26 deletions

View File

@@ -25,16 +25,19 @@ New package **`@shade/media`** — see `docs/media.md`.
`shade.shareMedia(peer, grant)` / `shade.onMediaGrant(handler)` in the SDK —
or in a `#shade=` link fragment that never reaches a server.
- **Browser.** A Service Worker plays sealed files in native
`<video>`/`<audio>`/`<img>` with seeking; `LivePlayer` plays live WebM via
MSE; the relay serves a `/watch/` page that opens any link.
`<video>`/`<audio>`/`<img>` with seeking; `LivePlayer` plays live WebM or
fragmented MP4 (H.264/HEVC/AV1 + AAC/Opus) via MSE; the relay serves a `/watch/` page that opens any link.
- **Server.** `createMediaService`: disk-backed sealed store with signed
owner uploads and immutable objects, a WebSocket live relay with bounded
backlog and slow-viewer shedding, and the watch page. Mounted by the
container when `SHADE_MEDIA_DIR` is set (no in-memory fallback);
`SHADE_MEDIA_OWNERS` lists who may upload and open channels.
- **CLI.** `shade media serve|put|get|ls|rm|whoami`,
`shade live text|webm|watch` (`tail -f … | shade live text`,
`ffmpeg … -f webm - | shade live webm`).
`shade live text|video|watch` (`tail -f … | shade live text`,
`ffmpeg … -f webm - | shade live video`, or `-f mp4 -movflags
frag_keyframe+empty_moov` for H.264/AAC; the container is detected).
`MediaSplitter`, `WebmSplitter` and `Fmp4Splitter` are exported for apps
that publish from their own source.
- **Kotlin.** `no.zyon.shade.media`: SMF1 reader and sealer, grants, live
subscriber and publisher — byte-for-byte against `test-vectors/media.json`.