fix(video): stream canonical remux with bounded memory - #581
kstonekuan merged 2 commits into
Conversation
|
kstonekuan
left a comment
There was a problem hiding this comment.
Both halves of #580, including the cache-hit one, and iter_decoded_batches is the right accessor to land on since it is already the documented bounded-memory path.
The SQLite median is the part I wanted to be sure about, because a remux silently changing its declared frame rate is the kind of drift nobody notices for months. Ran it differentially against estimate_fps_from_log_times across both median parities, uniform and jittered streams, streams with a long stall, and the degenerate inputs: exact agreement on all ten, and all three error contracts match word for word.
Guards hold. Removing the cache-hit early return reddens 1, dropping the h264 check reddens 1, and replacing the median with the first interval reddens 2.
Guarding the early return on topic in self._video_fps as well as output.exists() is the detail that makes it correct rather than just fast, since _video_fps is a side effect of the old ordering.
2300 passed on the merge with main.
Canonical video remuxing previously retained the entire camera channel and joined all
H.264 payloads before invoking ffmpeg, creating multiple full-video allocations.
Use two batch-reading passes: estimate FPS with an exact disk-backed median, then stream
decoded access units into ffmpeg stdin. Preserve H.264/B-frame validation and atomic
output publication, with subprocess and temporary-file cleanup on failures.
Add regressions for incremental consumption, remuxing without channel materialization,
validation failures, broken pipes, and preservation of existing outputs.
Validation:
httpx.Ruff and type checks also passed.
bytes using a subprocess sink.
The change requires two reads and temporary disk storage. Memory measurements cover HFlow
allocations, not ffmpeg’s internal muxer metadata.