Vellum/internal/transcode
mithral 365aac0cc6 Add the transcode session manager
Second step of ADR-008. A session spawns ffmpeg with the detected encoder's
args, packages the file as HLS, and is reused while it is alive so two range
requests do not start two ffmpegs.

Three things it has to get right, and all three are about not burning the GPU:
a session nobody is watching is reaped after a few minutes idle; concurrent
sessions are capped rather than queued, because a GPU encodes one or two
streams and a queue would just make everyone wait longer; and Shutdown stops
everything so a restart does not leave ffmpeg running.

Found a real bug in review, and it is the kind that only a real host catches.
The hardware args were placed BEFORE -i. ffmpeg reads options before the input
as INPUT options, so "-c:v h264_nvenc" was looked up as a decoder and failed
with "Unknown decoder 'h264_nvenc'". Transcoding would have produced nothing on
any NVENC host while looking correct in the code.

Verified against the real hardware rather than reasoned about: the same ffmpeg
command produces zero segments with the args before -i and a valid playlist and
segments with them after. The test now asserts the ordering directly and names
the reason, so a future reordering fails with an explanation instead of two arg
lists. Red-green: moving them back fails with "the hardware args must follow
the input".

Verified end-to-end on this host: the Manager started a session against a real
20-second file and produced a 132-byte EVENT playlist and segments.

Known limit: a stopped session leaves its segment directory on disk, so the
cache directory needs pruning out of band.
2026-10-12 11:54:20 -04:00
..
session.go Add the transcode session manager 2026-10-12 11:54:20 -04:00
session_test.go Add the transcode session manager 2026-10-12 11:54:20 -04:00
transcode.go Add the transcode session manager 2026-10-12 11:54:20 -04:00
transcode_test.go Detect transcode hardware, and prove it can actually encode 2026-10-12 11:49:05 -04:00