Repository navigation
Conversation
The detector sampled with fps=2. When the stream's timestamps jump forward - the camera's RTSP server restarts or go2rtc reconnects and the RTP clock starts from a new base - fps=2 fills the gap with duplicate frames. A 6 h jump produced 13k frames in seconds and grew the ffmpeg process to 1.3 GB; on a real camera it grew to 6 GB in about ten minutes and pushed the host into swap until everything stalled. A jump backwards made fps=2 drop every frame until the clock caught up, so detection went silent. Sample with select instead: keep a frame when at least 0.5 s has passed since the last kept one, or when time went backwards. It only drops frames, so a jump costs nothing, and the rate stays at about 2 fps.
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.
Problem
The motion detector samples with
fps=2. When the stream's timestamps jump forward,fps=2fills the gap with duplicate frames. That happens when the camera's RTSP server restarts or go2rtc reconnects, because the RTP clock then starts from a new base.On my camera, that one ffmpeg process grew to 6 GB in about ten minutes after a reconnect. The 4 GB container went into swap and the whole NVR stopped responding for 20 minutes, including recording, live view and the API. The supervisor's stall check could not help, because it was starved too.
A jump backwards has the opposite effect.
fps=2drops every frame until the clock catches up, so detection goes silent.Reproduction
I used ffmpeg 9.0.2 from the image on a 10 s 1080p clip. A
setptsplaced before the detector's filter chain makes the timestamps jump by 6 h. Memory was capped withulimit -v 1500000.fps=2(before)select(this PR)Change
The detector now samples with
select. A frame is kept when at least 0.5 s has passed since the last kept frame, or when time went backwards. This filter only drops frames, so a jump costs nothing, and the rate stays at about 2 fps.The tracker counts hits by wall-clock time and ignores scores below the threshold. The duplicate frames
fps=2used to add had a score of about 0, so dropping them does not change event detection. This also holds in keyframes-only mode.All tests pass (
bun test: 74 tests, including a new one for the sampling filter).