Skip to content

video: combined RGB and raw thermal Matroska stream - #57

Merged
tridge merged 6 commits into
ArduPilot:mainfrom
tridge:pr-video-mux
Dec 2, 2026
Merged

tridge merged 6 commits into
ArduPilot:mainfrom
tridge:pr-video-mux

Conversation

@tridge

@tridge tridge commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

An entry whose camera publishes RGB video to one video slot and raw thermal (FFV1 Matroska) to another can now serve both as one live Matroska stream with two video tracks. A viewer asks for /mux/A,B on the port of slot A, over HTTP or WebSocket, for example wss://HOST:PORT/mux/1,3.

This lets a browser viewer show RGB with the thermal picture inset from one connection, and save one file holding both. The camera's uplink is unchanged.

How it works

  • The mux exists only while it has viewers, plus 30 seconds. With no combined viewer nothing extra runs.
  • RGB: a second sandboxed ffmpeg child remuxes slot A's MPEG-TS to Matroska without transcoding. The proxy walks that output as EBML, so it still parses no codec bitstream. The sandbox and descriptor handling are the existing RTSP backend's, moved into a shared function (first commit, no change in behaviour).
  • Thermal: each BlockGroup is copied from the publisher's Cluster unchanged, BlockAdditional telemetry included. The publisher's head is checked once against the camera's profile (one V_FFV1 track, millisecond timestamps).
  • Output: one Cluster per frame, with strictly increasing millisecond timestamps on the proxy's clock, in the mux's own ring. Info carries a random SegmentUID for each run of the mux so a reconnecting viewer can tell a continuation from a new stream.
  • Viewers are ordinary VideoViewer objects that read the mux's ring; lapping, back-pressure and stall handling are unchanged. A slot's stream ending does not drop them: the other track carries on, and RGB resumes at a keyframe.
  • Access is by the entry's viewer password, or open viewing. A viewer token names one slot and is refused.
  • The web video page links to the combined stream in the configured live viewer when an entry has a video slot and a raw thermal slot publishing.

The README has the full behaviour, including the limits (one pair per entry, 8 viewers, no B-pictures, not recorded).

Testing

  • --selftest-video gains a selftest and a fuzz run for the EBML walker, the thermal profile check and the clock.
  • tests/test_video_mux.py (12 tests) drives a live H.264 encoder and a synthetic thermal publisher through the proxy. It checks the two tracks, thermal BlockGroups byte-identical to those published, keyframe start, strictly increasing timestamps, refusals (404, 409, 401, 503), password and token handling over HTTP, WebSocket and TLS WebSocket, thermal and RGB publisher restarts, a killed remuxer recovering without repeating a frame, and B-pictures refused.
  • The existing video suites (test_video_view, test_video_matroska, test_video_rtsp, test_video_child, test_video_ingest, test_video_record, test_video_rtsp_view) passed on the first version of this branch: 171 passed, 1 skipped. They have not been re-run since the review fixes below; the mux tests have.
  • With a SIYI MT11 publishing HEVC 1080p30 and raw thermal through a test server running the first version: both tracks decode with ffmpeg, every thermal frame keeps its metadata, and all RGB telemetry SEI records survive the remux. Added latency through the remuxer measured about 100 ms.
  • A Codex review of the first version found 2 High and 9 Medium issues (a publisher replaced inside the idle window, per-frame head comparison, the join point after the keyframe leaves the ring, a blocking child reap, unchecked pipe setup, and others). All are addressed in this version; it has not been reviewed again.

Not in this PR

  • Viewer tokens for the combined stream.
  • Server-side recording of the combined stream.

The sandbox, stdin/stdout wiring and descriptor closing done in a
forked ffmpeg backend move to video_backend_child_init(), so another
backend can use them. No change in behaviour for RTSP, RTMP or RTP.
@tridge tridge added the AIReview Request an automated AI review; picked up by the reviewprs sweep label Dec 1, 2026
A viewer asking for /mux/A,B on the port of slot A gets one live
Matroska stream with two video tracks: slot A's MPEG-TS video and
slot B's raw thermal (FFV1) stream.

The mux runs only while it has viewers. A second sandboxed ffmpeg
remuxes slot A without transcoding, and its output is walked as EBML,
so no codec bitstream is parsed here. Thermal BlockGroups are copied
with their BlockAdditional telemetry unchanged. Each frame is one
Cluster, with strictly increasing millisecond timestamps, in the mux's
own ring; viewers are ordinary viewers reading that ring.

Access is by viewer password or open viewing. A slot token is not
accepted, as it names one slot.
@AP-Review

AP-Review commented Dec 1, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-12-01)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 975afdef0d.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/supportproxy/57/1.html#prSupportProxy-57

One nonblocking issue: a raw-thermal reconnect that changes only the TrackUID ends the combined stream. Everything else checked out, including the build, selftests and fuzzing, the mux tests and the viewer auth paths.

Should fix

  • videomux.cpp:747: the thermal head check compares the whole TrackEntry, TrackUID included. A publisher that reconnects with the same format but a new UID then drops every combined-stream viewer, contrary to the README's "same format carries on". Compare the entry with TrackUID/CRC-32/Void removed, as the RGB walker already does, and keep sending the original entry. Blocks refer to the track number, so no remapping is needed. A reconnect test with a different UID would cover it, since the fixture always uses 77.

Not fully reviewed: the real MT11 thermal publisher (whether it varies TrackUID), VFR/HEVC/real RTSP sources across remuxer restarts, and playback in the external flight viewer.

Head moved during review: observed 780d5b143e0514cda237663f009b06bf771b8a19. This review covers only 975afdef0d861db55f4a18f67cd6349c3a968dfb; followup eligible.

@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head 780d5b143e.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/supportproxy/57/2.html#prSupportProxy-57

No open issues remain at 780d5b1, which this review covers in full.

Since the last review (at 975afde), the TrackUID reconnect issue has been fixed. A raw-thermal publisher that reconnects with the same format but a new TrackUID or track number now carries on: the head check compares a normalised format (videomux.cpp:856), and blocks are renumbered to the advertised track (videomux.cpp:331). The updated reconnect test (tests/test_video_mux.py:565) fails against 975afde and passes here. The full mux and video-page suites pass (95 tests).

The rest of the update also checked out: the HTTP wait before 503, pair switching, malformed /mux/ paths, the remuxer pipe's EPOLLOUT feed and the B-picture detection. As before, these were not exercised: the real MT11 camera, VFR/HEVC/real RTSP sources across remuxer restarts, and playback in the external flight viewer.

@tridge
tridge marked this pull request as ready for review December 2, 2026 02:15
@tridge
tridge merged commit 7d6ab5c into ArduPilot:main Dec 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIReview Request an automated AI review; picked up by the reviewprs sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants