fix(go2rtc): sanitize RTSP source fragments and honor #noaudio (#429)#436
Merged
Conversation
go2rtc's RTSP source parses the URL fragment with strings.Cut + ParseQuery and only acts on a fixed set of keys (transport, timeout, backchannel, media, pkt_size, log_level, source, mp4). Any other token an operator appends to the camera URL — most commonly "#noaudio" — is silently swallowed: it does nothing and rides along in the stored source. Worse, LightNVR ignored the "#noaudio" intent entirely and still injected the ffmpeg:<id>#audio=aac#audio=opus producer. Sanitize the fragment of native rtsp:// sources before appending our own parameters: drop unsupported tokens (with a warning so it isn't silent), and promote "#noaudio"/"#no-audio" into an actual suppression of the audio producer. This gives operators a working lever to turn the audio pipeline off per-stream, which doubles as a clean isolation test for the remaining WebRTC-audio investigation on #429. Non-RTSP sources (ffmpeg:, wyze://, onvif://, http://) are untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves LightNVR’s go2rtc stream registration for native rtsp:// / rtsps:// sources by sanitizing #fragment tokens before LightNVR appends its own go2rtc RTSP options, and by honoring operator intent flags like #noaudio to suppress LightNVR’s injected ffmpeg audio producer.
Changes:
- Added an allowlist-based sanitizer for RTSP URL fragment tokens, dropping unknown tokens (with warnings) before appending LightNVR’s own
#transport=.../#timeout=...params. - Recognizes
#noaudio/#no-audioand suppresses injection of theffmpeg:<id>#audio=...producer when present. - Leaves non-RTSP schemes untouched.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When an operator appends a fragment to a camera URL, go2rtc's RTSP source
parses it with
strings.Cut(rawURL, "#")+ParseQuery(
go2rtc/internal/rtsp/rtsp.go:96) and only acts on a fixed key set:transport, timeout, backchannel, media, pkt_size, log_level, source, mp4.Anything else — most commonly
#noaudio— is silently swallowed: it errors onnothing and does nothing, but stays in the stored source. And LightNVR ignored
the
#noaudiointent entirely and still injectedffmpeg:<id>#audio=aac#audio=opus.This sanitizes the fragment of native
rtsp://sources ingo2rtc_stream_register()before we append our own params:log_warn, so it isn't silent), keeping onlythe keys go2rtc actually honors;
#noaudio/#no-audiointo a real suppression of the audio producer.Non-RTSP sources (
ffmpeg:,wyze://,onvif://,http://) are untouched.Why
Part of #429. It gives operators a working per-stream lever to turn the audio
pipeline off, which also serves as a clean isolation test for the remaining
WebRTC-audio investigation on that issue (does video come back when the audio
producer is gone?).
Test
go2rtc_sanitize_rtsp_fragments()verified against the relevant cases:#noaudio,#noaudio#transport=tcp#timeout=30,#transport=tcp,#foo=bar#noaudio#media=video, no-fragment,#no-audio— supported keyspreserved,
#noaudiosuppresses audio, unknown tokens dropped.cmake --buildoflightnvris green.🤖 Generated with Claude Code