feat(media): live video --input — a film, a webcam or an IP camera without writing the ffmpeg line

`shade live video` needed a hand-written ffmpeg pipeline. --input <file |
/dev/video0 | rtsp://…> probes the source and runs ffmpeg itself:
H.264 and AAC are copied (a camera's own encoder, no CPU), anything else
becomes H.264 with a keyframe every 2 s whatever the frame rate (where
late joiners start) and AAC (>6 channels downmixed to 5.1), out as
low-latency fragmented MP4. A file is paced (-re) as if live; RTSP goes
over TCP; /dev/videoN opens as v4l2. ffmpeg's failure is reported with
its own last lines.

Verified: liveEncodePlan unit tests (copy, encode, pacing, RTSP/v4l2,
audio-only, nothing-to-send); Chromium through the relay: VP9/Opus WebM
encoded → live H.264/AAC, keyframe every 4th 0.5 s fragment, 0.96 s
latency; H.264/AAC MKV copied, 1.8 s latency. Media suite 97/0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-18 22:56:19 +02:00
parent d87db5f4dc
commit 0bbeb5682b
8 changed files with 140 additions and 7 deletions

View File

@@ -49,6 +49,11 @@ ffmpeg -re -i camera.mp4 -c:v libx264 -tune zerolatency -g 30 -c:a aac \
-f mp4 -movflags frag_keyframe+empty_moov+default_base_moof -frag_duration 250000 - \
| shade live video --server https://relay.example --name "Kamera 1"
# Or let shade run ffmpeg: a film, a webcam, an IP camera. H.264/AAC is copied,
# anything else encoded (H.264 with a keyframe every 2 s, AAC); a file plays at its own pace.
shade live video --input rtsp://camera.local/stream1 --server https://relay.example --name "Inngang"
shade live video --input Film.mkv --server https://relay.example --name "Filmkveld"
# Live radio: the same, with sound only — the page and the app give it an audio player.
ffmpeg -re -i radio.mp3 -c:a libopus -f webm -live 1 -cluster_time_limit 1000 - \
| shade live video --server https://relay.example --name "Radio"