Skip to content

Offer Opus audio so live view keeps WebRTC - #5

Open
hyngsk wants to merge 1 commit into
codextde:mainfrom
hyngsk:fix/webrtc-opus-audio
Open

hyngsk wants to merge 1 commit into
codextde:mainfrom
hyngsk:fix/webrtc-opus-audio

Conversation

@hyngsk

@hyngsk hyngsk commented Nov 24, 2026

Copy link
Copy Markdown

Problem

The live player (video-rtc.js) starts WebRTC and MSE side by side and keeps whichever scores higher. Video plus audio beats video only.

Most cameras send AAC, which WebRTC cannot carry. The WebRTC stream therefore had no audio track and scored 0x220, while MSE with H.264 + AAC scored 0x311. WebRTC connected and was closed about a second later. Every live view ended up on MSE, or on HLS in the app after its 9 s timeout, with several seconds of delay.

I confirmed this with a packet capture. RTP was flowing to the phone over UDP 8555, then stopped about 2 s later while the MSE consumer stayed.

Change

go2rtcSources adds ffmpeg:<stream>#audio=opus next to the existing #audio=aac source. go2rtc starts the transcoder only when a consumer asks for Opus, so MSE, HLS and recording are unaffected. WebRTC now carries audio and wins the comparison. As a side effect, the app gets sound in real-time mode.

Testing

  • bun test passes, with brands.test.ts updated for the new source list.
  • I ran this on a real camera with AAC 16 kHz audio. The WebRTC answer now includes Opus, audio frames arrive, and the player stays on 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:<stream>#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant