Skip to content

Bring camera audio back when it goes missing after a reconnect - #10

Open
hyngsk wants to merge 1 commit into
codextde:mainfrom
hyngsk:fix/recover-missing-audio
Open

hyngsk wants to merge 1 commit into
codextde:mainfrom
hyngsk:fix/recover-missing-audio

Conversation

@hyngsk

@hyngsk hyngsk commented Nov 24, 2026

Copy link
Copy Markdown

Problem

Sometimes the camera audio disappears for good after OpenCCTV restarts, or after the camera's RTSP server restarts, while video keeps working. Recordings, the AAC/Opus transcoders and the players all stay silent until go2rtc is restarted by hand. The Opus transcoder then logs Error opening input: Invalid data found when processing input every 5 s.

My camera is an LG/KT LPK6200WI. Its RTSP server restarts when a client connection drops, and the first DESCRIBE after that restart can come back with video only. When this happened, go2rtc's producer listed only video, recvonly, H264, although a DESCRIBE a minute later returned video + AAC.

go2rtc does not recover from this on its own. When a producer reconnects, it only re-attaches the receivers it already has (internal/streams/producer.go, reconnect):

  • If the first connection had no audio, the audio track is never added.
  • If a reconnect has no audio, the old audio receiver is left behind dead.

Deleting the stream and adding it back over the API does not help either. go2rtc only drops the name, and the running producer keeps its consumers.

The camera probe made it worse. If it runs in that window, it sees no audio and clears the camera's audio flag, which hides the speaker button in the app.

Change

  • audioMissing(info, stream) reports whether the camera's own connection is up without a recvonly audio track. It ignores our transcoders (ffmpeg:<stream>#…), which read from the stream itself.
  • AudioRecovery handles a camera that has audio but whose connection has been up without an audio track for 15 s. It asks for go2rtc.restart(), then retries after 1 and 5 minutes. After that it gives up and clears the audio flag. The flag is set again if audio comes back later.
    • The monitor loop calls it for pulled streams only; eufy and push cameras are skipped.
    • At most one go2rtc restart happens every 15 s, even when several cameras need one.
  • The probe no longer clears the audio flag by itself. It still sets the flag when it finds audio.

Restarting go2rtc briefly interrupts every camera. I chose it because it is the only way I found to make go2rtc connect to a camera again from scratch. It only happens when a camera that is known to have audio is sending none.

Testing

  • bun test passes (76 tests, including new ones for audioMissing and the backoff). bun run typecheck passes.
  • Live, on the same server, I ran a second OpenCCTV instance with its own data directory and ports. Its test camera read the main go2rtc's ?video restream and had its audio flag set. The instance logged camera stream has no audio track, reconnecting cameras and restarted its go2rtc after 15 s, then again a minute later. The main instance and its camera were not affected.

Some cameras answer the first DESCRIBE after their RTSP server restarts
with video only (seen on an LG/KT LPK6200WI, whose server restarts when
clients reconnect - for example when OpenCCTV restarts). go2rtc keeps that
connection, and when it reconnects it only re-attaches the tracks it
already had, so the audio never comes back by itself. Recordings, the
AAC/Opus transcoders and the players all stay silent until go2rtc is
restarted by hand.

The camera probe made it worse: it ran in that window, saw no audio and
cleared the camera's audio flag, which hides the speaker button.

Watch for it in the monitor loop: when a camera that has audio is
connected without an audio track for 15 s, restart go2rtc so it connects
again from scratch. Deleting and re-adding the stream over the API is not
enough, because go2rtc only drops the name and the running producer keeps
its consumers. Retry after 1 and 5 minutes, then give up and clear the
audio flag. The probe no longer clears the flag on its own.
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