feat(media): shade live record — a broadcast to files, or to a sealed film with its own link

`live record <link> [-o base] [--put --server URL]` writes what a channel
carries until the channel ends or Ctrl-C:
- text goes to base.txt;
- video and sound go to base.webm or base.mp4: the init, then every chunk in
  the order sent. A chunk that arrives late is left out and counted. A new
  init continues in base-2.…;
- pictures go to base-images/.

ffmpeg then rewrites each recording with -c copy, which adds an index for
seeking and starts the clock at 0:00. `--put` seals and uploads the recording
under the channel's name (several files become an album). LiveRecorder is
exported from @shade/media/node.

`live video` now sends a sticky meta frame like text and picture channels do.
The browser and Android players ignore it.

Verified against a real relay:
- A 30 s VP8/Opus broadcast was recorded and is 29–32 s long, starting at 0.
- It was uploaded as "Kveldssending.webm" and plays in Chromium, with a seek
  to 22 s (frame 14).
- Live playback with the meta frame still plays, with 2.4 s latency.

Tests:
- object-store's memory test now runs in its own process. RSS is process-wide,
  and other test files in the same `bun test` made it flaky (192 MiB). It now
  compares memory held after a collection at 128 MiB and 512 MiB, ~85 vs
  ~103 MiB, instead of using a magic number.
- The sweep test has its own prefix.
- tests/live-record.test.ts (4).
- media 122 green, 3 runs in a row. All 27 packages type-check.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-19 00:01:55 +02:00
parent ee93dee8db
commit 5cc9133b3c
10 changed files with 462 additions and 26 deletions

View File

@@ -64,6 +64,9 @@ ffmpeg -f v4l2 -i /dev/video0 -r 1 -c:v mjpeg -f image2pipe - \
# … a slideshow, or every new picture that lands in a folder.
shade live images Ferie/ --every 5 --server https://relay.example
shade live images --watch ~/Pictures/Screenshots --server https://relay.example
# Record a channel until it ends, and keep it as a sealed film with its own link.
shade live record '<link>' -o Kveldssending --put --server https://relay.example
```
`shade live video` recognises the container from the first bytes (`--format webm|fmp4`
@@ -76,6 +79,16 @@ their markers and chunks (a JPEG's EXIF thumbnail is a whole JPEG and does not e
picture). Each picture is a keyframe, so a late viewer opens on the latest. A watched
folder sends a file once its size has held still, because cameras write in pieces.
`shade live record` writes what the channel carries: text to `base.txt`, video or
sound to `base.webm`/`base.mp4` (the init segment, then every chunk, in the order they
were sent; a chunk that arrives after newer ones is left out and counted), pictures
to `base-images/`. If the publisher starts over with a different init, the recording
goes on in `base-2.…`. When the channel ends (or on Ctrl-C), ffmpeg, if present,
rewrites each recording without re-encoding: an index for seeking, the clock from
0:00. `--put` then seals and uploads it like `media put`, under the channel's name; a
recording of several files becomes an album. Every channel kind now sends its name as
a sticky `meta` frame, so a viewer without the grant's meta learns it too.
`--channel <file>` keeps a live channel's identity across restarts: the link keeps
working, and each run starts a new epoch.