Protect RTSPS restream of AI Port cameras jumps audio timestamps back by the FLV relay's uptime (HA streams drop)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
This issue has not been assessed yet.
Description
What happened?
Since two Tapo cameras were paired to the virtual AI Port, Home Assistant (unifiprotect, which plays cameras from Protect's RTSPS restream on :7441) keeps losing their streams. Each loss starts with this error from HA's stream worker:
Error from stream worker: Timestamp discontinuity detected: last dts = 1999, dts = 4264000315
Error from stream worker: Timestamp discontinuity detected: last dts = 2138, dts = 4263763657
Error from stream worker: Timestamp discontinuity detected: last dts = 1991, dts = -4616844
The stream runs for about 2 seconds (dts climbs to ~2000), and then one packet's dts jumps to a value just below 2^32 (or a negative one). HA stops the stream and marks the camera entity unavailable until its retry backoff (20 s, growing to 2 min) runs out, so the camera flaps for as long as anything is viewing it. In about 30 minutes this happened 24 times per camera across both the high- and low-resolution channels. An Amcrest camera paired to the same Keystone, with no audio track, never hits it, and neither do the native UniFi cameras.
The jump equals the FLV relay's uptime. Read as a signed 32-bit number on a 1/48000 clock (the relay's AAC sample rate), the bad dts is minus the time since Keystone's FLV relay started:
| Time after FLV relay start | Bad dts | As signed / 48000 |
|---|---|---|
| 96 s | -4616844 |
-96 s |
| 658 s | 4263763657 (= 2^32 - 31,203,639) |
-650 s |
The offset resets when the relay restarts and then grows again at about 48,000 per second. So it looks as if, partway into each RTSPS session, Protect's audio timestamps fall back by the relay's uptime: Protect seems to rebase the first audio packets of a session, but a later packet still carries the timestamp from the FLV relay's own clock.
A fresh capture of the relay's command alone looks fine. Over 20 s to a file, audio starts at 1.562 s and video at 2.562 s, both increasing. So the mismatch seems to come from how Protect handles a long-running FLV audio track from the relay, not from ffmpeg producing bad timestamps outright.
Relay command (from ps, credentials removed):
ffmpeg -nostdin -hide_banner -loglevel error -fflags +genpts+nobuffer -rtsp_transport tcp -probesize 1000000 -analyzeduration 2000000 -i rtsp://…/stream1 -map 0:v:0 -c:v copy -tag:v 7 -map 0:a:0? -c:a aac -ar 48000 -ac 1 -b:a 64k -f flv -flvflags no_duration_filesize -metadata streamName=… pipe:1
Expected: Protect's RTSPS restream of a Keystone-relayed camera has steadily increasing audio timestamps, so RTSPS clients don't lose the stream.
Not confirmed: I can't capture Protect's RTSPS output directly here, so it's inferred and not proven that the bad packet is on the audio track. The evidence is the units (1/48000) and the match with relay uptime, and the fact that the camera without audio is unaffected. Things worth trying:
- Does Protect's own player or recording show an audio/video sync problem after the relay has been up a while?
- Does
-anon the relay (or audio timestamps rebased per FLV connection) stop it? I haven't tested either.
Not related to #228/#230: lowering the camera's RTSP sessions from 3 to 2 (audio detection off) changed nothing.
Keystone version / commit
v0.1.9 (installed with scripts/proxmox-lxc.sh, KEYSTONE_REF=v0.1.9).
UniFi Protect, UniFi OS, and console
UNVR. Protect version not captured. Home Assistant 2026.12.0 with its built-in unifiprotect integration as the RTSPS client.
Installation method
Proxmox LXC (Debian 13, unprivileged), systemd service. Analyzer decodes with VAAPI; the detector runs on CPU.
Relevant config (sanitized)
device:
enabled: false # AI-Port-only instance
aiport:
enabled: true
package_enabled: false
embeddings:
enabled: false
Keystone DEBUG logs
Nothing relevant is logged. The relays stay up the whole time (FLV relay active for … [video1|video2|video3] once at start, no reconnects), and Protect sends no RPCs when the drops happen.
Additional context
- Cameras: TP-Link Tapo C120 and C121 over ONVIF, H.264 1080p with audio (transcoded to AAC by the relay).
- Unaffected: an Amcrest paired the same way (no audio track) and the native UniFi cameras on the same console.
- Dominant language
- Python
- Stars
- 1k
- Forks
- 114
- Avg merge
- 1h 8m
- Merged PRs (30d)
- 147
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from seeARMS/keystone
-
needs-triage
Maintainers usually reply within 1 day
-
Maintainers usually reply within 1 day
-
accepted
seeARMS/keystone#246 · 1 comment ·
Maintainers usually reply within 1 day
-
Maintainers usually reply within 1 day
-
Maintainers usually reply within 1 day
All issues in seeARMS/keystone
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day