From 5676281445c973ee640dc136f4c48150de350075 Mon Sep 17 00:00:00 2001 From: Hyeong Seok <41688671+hyngsk@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:12:10 +0900 Subject: [PATCH] Offer Opus audio so live view keeps WebRTC The player (video-rtc.js) starts WebRTC and MSE side by side and keeps the one with the higher score: video+audio beats video only. Most cameras send AAC, which WebRTC cannot carry, so the WebRTC stream had no audio track and scored 0x220 against 0x311 for MSE with H.264+AAC. WebRTC was closed a second after it connected and every live view ended up on MSE or HLS, with several seconds of delay. Add an ffmpeg:#audio=opus source next to the existing #audio=aac one. go2rtc starts the transcoder only when a consumer asks for Opus, so MSE/HLS viewers and recordings are unaffected, and WebRTC now carries audio and wins. --- server/src/cameras.ts | 5 ++++- server/test/brands.test.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/server/src/cameras.ts b/server/src/cameras.ts index e81a1be..ca7aea2 100644 --- a/server/src/cameras.ts +++ b/server/src/cameras.ts @@ -132,7 +132,10 @@ export function go2rtcSources(c: CameraRecord, ffmpegAvailable: boolean, eufySou for (const e of c.caps.extra ?? []) main.push(e); if (ffmpegAvailable) { if (c.kind === "http") main.push(`ffmpeg:${c.streamKey}#video=h264`); - else main.push(`ffmpeg:${c.streamKey}#audio=aac`, `ffmpeg:${c.streamKey}#video=mjpeg`); + // Opus lets WebRTC carry the camera audio. Without it the player's WebRTC stream has video only and + // video-rtc.js drops it in favour of MSE (H.264+AAC scores higher), so live view never gets WebRTC latency. + // go2rtc only starts these transcoders when a consumer asks for that codec. + else main.push(`ffmpeg:${c.streamKey}#audio=aac`, `ffmpeg:${c.streamKey}#audio=opus`, `ffmpeg:${c.streamKey}#video=mjpeg`); } out.push({ name: c.streamKey, sources: main }); if (c.subUrl) out.push({ name: `${c.streamKey}_sub`, sources: [c.subUrl] }); diff --git a/server/test/brands.test.ts b/server/test/brands.test.ts index 8770f70..8820bd7 100644 --- a/server/test/brands.test.ts +++ b/server/test/brands.test.ts @@ -88,7 +88,7 @@ describe("go2rtc sources", () => { test("main + sub with ffmpeg helpers", () => { const s = go2rtcSources(base, true); expect(s[0]!.name).toBe("c1"); - expect(s[0]!.sources).toEqual(["rtsp://a/1", "ffmpeg:c1#audio=aac", "ffmpeg:c1#video=mjpeg"]); + expect(s[0]!.sources).toEqual(["rtsp://a/1", "ffmpeg:c1#audio=aac", "ffmpeg:c1#audio=opus", "ffmpeg:c1#video=mjpeg"]); expect(s[1]).toEqual({ name: "c1_sub", sources: ["rtsp://a/2"] }); }); test("push camera has no source", () => {