Skip to content

fix(ffmpeg): back off exponentially when camera is unreachable - #1461

Open
fluffyspace wants to merge 1 commit into
roflcoopter:devfrom
fluffyspace:fix/ffmpeg-camera-restart-backoff
Open

fix(ffmpeg): back off exponentially when camera is unreachable#1461
fluffyspace wants to merge 1 commit into
roflcoopter:devfrom
fluffyspace:fix/ffmpeg-camera-restart-backoff

Conversation

@fluffyspace

Copy link
Copy Markdown
Contributor

Summary

A dead or unreachable camera makes the frame reader spawn a new decode process every few seconds indefinitely (sleep 5s → spawn ffmpeg → 5s connect timeout → repeat). On a host with a camera that is powered off or off the network, this burns a full CPU core of pure wasted work, forever.

Consecutive decode failures now back off exponentially instead of retrying at a constant 5s:

Consecutive failures Wait before next restart
1 5s
2 10s
3 20s
4 40s
5+ 60s (capped)

A successful frame resets the backoff to the base 5s delay, so a camera that comes back online is reconnected with no noticeable lag.

Applied to both the ffmpeg and gstreamer camera components (identical logic), with new unit tests covering the exponential sequence and the reset-on-success behavior.

Motivation

On our standby Viseron instance the EZVIZ camera has been offline for two weeks; the container was spending ~30–40% of one core just cycling 'Restarting frame pipe' against the dead RTSP endpoint (~15k restarts over 3 days). This fix drops that to a single attempt every 60s.

Tests

  • New: tests/components/ffmpeg/test_camera.py (2 tests) — exponential backoff sequence and reset-on-success.
  • Existing ffmpeg/gstreamer/domain-camera suites: 86 passed (10 pre-existing postgres-fixture errors in the ad-hoc runner, unrelated).

A dead or unreachable camera makes the frame reader spawn a new decode
process every few seconds indefinitely (sleep 5s, connect, 5s timeout,
repeat), wasting a full CPU core for a camera that will not come back on
its own.

Consecutive decode failures now back off exponentially (5s, 10s, 20s,
40s, capped at 60s) instead of retrying at a constant 5s. A successful
frame resets the backoff to its base delay. Applied to both the ffmpeg
and gstreamer camera components.
@netlify

netlify Bot commented Aug 20, 2026

Copy link
Copy Markdown

Deploy Preview for viseron ready!

Name Link
🔨 Latest commit 51ad94a
🔍 Latest deploy log https://app.netlify.com/projects/viseron/deploys/6a86b391202ef60008860752
😎 Deploy Preview https://deploy-preview-1461--viseron.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@roflcoopter

Copy link
Copy Markdown
Owner

Thank you, would you mind taking a look at the pylint error?

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