Skip to content

fix(go2rtc): sanitize RTSP source fragments and honor #noaudio (#429)#436

Merged
matteius merged 4 commits into
mainfrom
fix/429-rtsp-fragment-noaudio
Jun 9, 2026
Merged

fix(go2rtc): sanitize RTSP source fragments and honor #noaudio (#429)#436
matteius merged 4 commits into
mainfrom
fix/429-rtsp-fragment-noaudio

Conversation

@matteius

@matteius matteius commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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 on
nothing and does nothing, but stays in the stored source. And LightNVR ignored
the #noaudio intent entirely and still injected ffmpeg:<id>#audio=aac#audio=opus.

This sanitizes the fragment of native rtsp:// sources in
go2rtc_stream_register() before we append our own params:

  • drop unsupported tokens (with a log_warn, so it isn't silent), keeping only
    the keys go2rtc actually honors;
  • promote #noaudio/#no-audio into 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

  • New 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 keys
    preserved, #noaudio suppresses audio, unknown tokens dropped.
  • cmake --build of lightnvr is green.

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-audio and suppresses injection of the ffmpeg:<id>#audio=... producer when present.
  • Leaves non-RTSP schemes untouched.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/video/go2rtc/go2rtc_stream.c Outdated
Comment thread src/video/go2rtc/go2rtc_stream.c Outdated
Comment thread src/video/go2rtc/go2rtc_stream.c Outdated
matteius and others added 3 commits June 9, 2026 00:05
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>
@matteius matteius merged commit 03971c7 into main Jun 9, 2026
3 checks passed
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.

2 participants