Repository navigation
webadmin: play H.265 in the browser with a WebAssembly fallback - #54
Conversation
Nothing calls it, and its premise that browsers cannot play HEVC no longer holds for the web viewer.
Previous review (2026-11-30)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head The HEVC software fallback looks solid and its tests pass, but one share-page recovery path can leave a viewer stuck. Should fix
Minor (2)
|
Static files are browser-cached for a day, so a deploy could leave a page running old scripts. static_v() appends a hash of the file so a changed file gets a new URL.
FFmpeg 8.1.3's HEVC decoder and parser with libswscale, built with Emscripten 3.1.69 for the web viewer's software fallback. The wrapper takes Annex-B input in arbitrary chunks, splits access units with the parser and returns RGBA frames with their presentation time. build.sh reproduces the checked-in hevc-codec.js and hevc-codec.wasm.gz from the signed FFmpeg release; the LGPL text and source details are beside them.
Most desktop browsers on Linux, and Firefox generally, refuse HEVC in Media Source Extensions, so an H.265 slot showed nothing but a pointer to ffplay. When native playback rejects the stream, the owner and share pages now fall back to a worker that reads the same MPEG-TS WebSocket, demuxes it and decodes it with the WASM decoder. Frames go through a canvas captureStream() into the page's own <video>, so controls, pause and Picture-in-Picture keep working across reconnects. The worker reports a stream that is not HEVC so the page returns to native playback, recovers from loss at the next VPS/SPS/PPS or IRAP, and skips to a newer keyframe when it falls behind live while accepting a lasting network delay. Each page's player is reworked so stale callbacks from a superseded attempt are ignored, retries are serialised and native/software switching is bounded. The share page now uses mpegts.js whenever it is supported, which includes ManagedMediaSource on iOS 17.1+, and falls back to HLS when the video port cannot be reached.
Node tests run the worker over real HEVC MPEG-TS through the shipped WASM: exact decode order, chunk and PES boundaries, split PES headers, loss and discontinuity recovery, and lag handling on a continuous timeline against an independent clock. A VM harness covers the share page's mode transitions. An optional browser test drives the owner and share pages in headless Chrome with HEVC MSE refused, against a live ffmpeg publisher switching between HEVC and H.264.
|
Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head No open issues at head 8805140: the whole diff was re-reviewed and the Node worker, controller and webadmin pytest suites pass. All three findings from the review of 6c26b5c are fixed. The share page now gives MSE another try when a rejected HEVC stream returns as H.264, and a new test covers this. The worker script is downloaded with the decoder, so a failed fetch is retried instead of being fatal. The duplicated worker comment is gone. |
Most desktop browsers on Linux, and Firefox generally, refuse HEVC in Media Source Extensions, so an H.265 video slot showed nothing in the web viewer beyond a pointer to ffplay. This follows the approach AP_CameraGimbal uses for its own live view.
How it works
addSourceBufferNotSupportedError, an unsupported-codec error, or element decode errors), the page falls back to a worker that reads the same MPEG-TS WebSocket, demuxes it, and decodes with a WebAssembly build of FFmpeg 8.1.3's HEVC decoder and parser (329 KB gzipped, fetched only when needed).captureStream()feeds the page's existing<video>, so its controls, pause and Picture-in-Picture keep working across reconnects.static_v()), since static files are browser-cached for a day.webadmin/hevc/build.shreproduces the checked-inhevc-codec.js/hevc-codec.wasm.gzfrom the signed FFmpeg release with Emscripten 3.1.69. The LGPL text and source details are inwebadmin/static/vendor/hevc/.Testing
tests/test_hevc_browser.py, skipped unless Playwright and Chrome are available) drives both pages in headless Chrome against a live ffmpeg publisher switching HEVC → H.264 → HEVC, and checks that a user pause survives a publisher restart.Known limits
repeat-headers=1).log_play.html) is not covered yet.