From 52f50a7396ebdef7a22aa9682b275ca4828f6399 Mon Sep 17 00:00:00 2001
From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
Date: Sun, 20 Sep 2026 13:45:24 -0500
Subject: [PATCH] Tweaks (#24418)
* don't display audio transcription provider message as health notice
* show remote provider for audio transcription in health pane
* adjust trigger and notifications messages to be consistent with the rest of the settings UI
* disable save buttons when there are no changes in config editor
* fix audio manager crash when a camera is added at runtime
The audio processor and the camera maintainer both poll the same `add` config update on their own one second timers, and the maintainer is what creates `camera_metrics[name]`. When the audio processor got there first it looked the new camera up before that entry existed, and the `KeyError` took down the whole `frigate.audio_manager` process. Whether it happens depends purely on which poll fires first, so cloning a camera from the UI fails or succeeds at random. `spawn_if_needed` now skips a camera whose metrics aren't there yet and picks it up on the next poll, the same way it already waits on a late ffmpeg update.
`AudioEventMaintainer` holds the `CameraMetrics` object now instead of indexing the manager dict on every audio chunk, which drops the IPC round trips and means a removed camera can't `KeyError` out of `detect_audio` after the maintainer pops the entry. The audio process is also registered with the watchdog, since a crash there previously left audio detection dead for every camera until a full restart, and it now receives the shared `DataProcessorMetrics` so `AudioTranscriptionRealTimeProcessor` gets the same type as the other real time processors.
* fix stationary max_frames dropping other tracked objects
When `max_frames` was set for a label, deregistering one object rebuilt norfair's list with a filter that kept an object only if it was both not the target and already on its way out, so every other healthy object of that label was dropped along with it. Any car leaving the frame took the rest of the cars with it and they came back as new tracked objects a few frames later. The filter now removes only the target, and objects that are expiring are still reaped by norfair on the next update.
* fix test
* fix skip_motion_threshold permanently disabling motion detection
The skip check returned before the two `accumulateWeighted` calls at the end of `detect`, so a skipped frame never made it into the background and setting `calibrating` there only picked a faster alpha for calls that never ran. `avg_frame` starts as an all zero image and a normally lit scene differs from black across nearly the whole frame, so the cameras I tested measure 0.84 to 0.98 against it. Any `skip_motion_threshold` below that number skips the first frame, leaves the background black, and skips every frame after it. Motion detection is dead for that camera until the setting is removed or Frigate restarts, with no motion boxes, no motion recordings, and no regions for the tracker since the detector stays calibrating.
Startup isn't the only way in. `update_mask` zeroes the background on any motion config change, and once a camera has calibrated the first IR switch or PTZ move freezes the background on the old scene, so it can't transition to the new one, which is the case the option exists for. The frame is now blended in before the early return at the same 0.2 alpha the calibrating path uses elsewhere, so a large scene change is still suppressed while the background catches up, about a second on a 5 fps camera, and then motion comes back.
* dump ffmpeg logs on every restart
The record watchdog restarted ffmpeg without flushing its `LogPipe`, so a camera whose recording segments went stale never showed a single line of ffmpeg output. The dump now happens in `start_or_restart_ffmpeg` right after the stop, which covers the stale record path, the record crash path, and the audio restart. `reset_capture_thread` and the audio `log_and_restart` fallback keep their own dumps since both pass `ffmpeg_process=None`.
* dump ffmpeg logs once per restart
The audio restart path dumped the log pipe itself before calling the helper, so the restart dump printed a second "last 100 lines" heading over an already drained deque and split the tail that `stop_ffmpeg` flushed into its own section. The heading is now only printed when there's something under it, and the audio path leaves the dump to the restart so each failure produces one section.
* keep all logpipe dumps consistent
---
frigate/app.py | 14 ++-
frigate/events/audio.py | 77 +++++++++-------
frigate/log.py | 8 ++
frigate/motion/improved_motion.py | 6 +-
frigate/test/test_audio_spawn.py | 90 +++++++++++++++++++
frigate/test/test_motion_detector.py | 29 ++++++
frigate/track/norfair_tracker.py | 4 +-
frigate/util/ffmpeg.py | 3 +
frigate/video/ffmpeg.py | 4 -
web/e2e/helpers/monaco.ts | 11 +++
web/e2e/specs/config-editor.spec.ts | 5 ++
web/public/locales/en/views/settings.json | 6 +-
.../section-configs/audio_transcription.ts | 1 -
.../NotificationsSettingsExtras.tsx | 49 ++++------
web/src/pages/ConfigEditor.tsx | 2 +
web/src/types/frigateConfig.ts | 3 +
web/src/utils/health.ts | 2 +-
web/src/views/settings/TriggerView.tsx | 30 ++-----
18 files changed, 240 insertions(+), 104 deletions(-)
create mode 100644 frigate/test/test_audio_spawn.py
diff --git a/frigate/app.py b/frigate/app.py
index ba4f2ad4e0..9c49cabb1b 100644
--- a/frigate/app.py
+++ b/frigate/app.py
@@ -483,7 +483,7 @@ class FrigateApp:
def start_audio_processor(self) -> None:
self.audio_process = AudioProcessor(
- self.config, self.camera_metrics, self.stop_event
+ self.config, self.camera_metrics, self.embeddings_metrics, self.stop_event
)
self.audio_process.start()
self.processes["audio_detector"] = self.audio_process.pid or 0
@@ -556,10 +556,20 @@ class FrigateApp:
"output",
lambda: OutputProcess(self.config, self.stop_event),
),
+ (
+ "audio_process",
+ "audio_detector",
+ lambda: AudioProcessor(
+ self.config,
+ self.camera_metrics,
+ self.embeddings_metrics,
+ self.stop_event,
+ ),
+ ),
]
for attr, key, factory in specs:
- if not hasattr(self, attr):
+ if getattr(self, attr, None) is None:
continue
def on_restart(
diff --git a/frigate/events/audio.py b/frigate/events/audio.py
index 457b1d967d..3d1bfbee06 100644
--- a/frigate/events/audio.py
+++ b/frigate/events/audio.py
@@ -11,6 +11,7 @@ from typing import Any
import numpy as np
+from frigate.camera import CameraMetrics
from frigate.comms.detections_updater import DetectionPublisher, DetectionTypeEnum
from frigate.comms.inter_process import InterProcessRequestor
from frigate.config import CameraConfig, CameraInput, FrigateConfig
@@ -36,6 +37,7 @@ from frigate.data_processing.common.audio_transcription.model import (
from frigate.data_processing.real_time.audio_transcription import (
AudioTranscriptionRealTimeProcessor,
)
+from frigate.data_processing.types import DataProcessorMetrics
from frigate.ffmpeg_presets import parse_preset_input
from frigate.log import LogPipe, suppress_stderr_during
from frigate.util.builtin import get_ffmpeg_arg_list, load_labels
@@ -86,6 +88,7 @@ class AudioProcessor(FrigateProcess):
self,
config: FrigateConfig,
camera_metrics: DictProxy,
+ embeddings_metrics: DataProcessorMetrics,
stop_event: MpEvent,
):
super().__init__(
@@ -93,8 +96,38 @@ class AudioProcessor(FrigateProcess):
)
self.camera_metrics = camera_metrics
+ self.embeddings_metrics = embeddings_metrics
self.config = config
+ def spawn_if_needed(self, camera: CameraConfig) -> None:
+ """Start an audio maintainer for the camera once everything it needs
+ has arrived. Returning early leaves the camera for the next poll."""
+ name = camera.name
+ if name is None or name in self.audio_threads:
+ return
+ if not camera.enabled or not camera.audio.enabled:
+ return
+ # ffmpeg update may not have arrived yet
+ if not any("audio" in i.roles for i in camera.ffmpeg.inputs):
+ return
+ # the camera maintainer creates metrics on its own poll of the same
+ # add update and may not have gotten there yet
+ metrics = self.camera_metrics.get(name)
+ if metrics is None:
+ return
+ thread = AudioEventMaintainer(
+ camera,
+ self.config,
+ metrics,
+ self.embeddings_metrics,
+ self.transcription_model_runner,
+ self.stop_event, # type: ignore[arg-type]
+ self.genai_manager,
+ )
+ self.audio_threads[name] = thread
+ thread.start()
+ self.logger.info(f"Audio maintainer started for {name}")
+
def __stop_audio_thread(self, camera: str) -> None:
thread = self.audio_threads.pop(camera, None)
if thread is None:
@@ -150,29 +183,8 @@ class AudioProcessor(FrigateProcess):
],
)
- def spawn_if_needed(camera: CameraConfig) -> None:
- name = camera.name
- if name is None or name in self.audio_threads:
- return
- if not camera.enabled or not camera.audio.enabled:
- return
- # ffmpeg update may not have arrived yet; wait for next poll
- if not any("audio" in i.roles for i in camera.ffmpeg.inputs):
- return
- thread = AudioEventMaintainer(
- camera,
- self.config,
- self.camera_metrics,
- self.transcription_model_runner,
- self.stop_event, # type: ignore[arg-type]
- self.genai_manager,
- )
- self.audio_threads[name] = thread
- thread.start()
- self.logger.info(f"Audio maintainer started for {name}")
-
for camera in self.config.cameras.values():
- spawn_if_needed(camera)
+ self.spawn_if_needed(camera)
self.logger.info(f"Audio processor started (pid: {self.pid})")
@@ -182,15 +194,14 @@ class AudioProcessor(FrigateProcess):
updated_topics = config_subscriber.check_for_updates()
# stop maintainers for removed cameras so their ffmpeg process is
- # torn down and they stop touching camera_metrics (which the camera
- # maintainer has already popped for the removed camera)
+ # torn down
for removed_camera in updated_topics.get(
CameraConfigUpdateEnum.remove.name, []
):
self.__stop_audio_thread(removed_camera)
for camera in self.config.cameras.values():
- spawn_if_needed(camera)
+ self.spawn_if_needed(camera)
config_subscriber.stop()
@@ -212,7 +223,8 @@ class AudioEventMaintainer(threading.Thread):
self,
camera: CameraConfig,
config: FrigateConfig,
- camera_metrics: DictProxy,
+ metrics: CameraMetrics,
+ embeddings_metrics: DataProcessorMetrics,
audio_transcription_model_runner: AudioTranscriptionModelRunner | None,
stop_event: threading.Event,
genai_manager: Any = None,
@@ -221,7 +233,11 @@ class AudioEventMaintainer(threading.Thread):
self.config = config
self.camera_config = camera
- self.camera_metrics = camera_metrics
+ # hold the metrics object rather than indexing the manager dict per
+ # chunk, which costs an IPC round trip and breaks once the camera
+ # maintainer pops the entry on removal
+ self.metrics = metrics
+ self.embeddings_metrics = embeddings_metrics
self.stop_event = stop_event
# per-camera stop signal so a single maintainer can be torn down at
# runtime (e.g. on camera removal) without stopping the whole process
@@ -265,7 +281,7 @@ class AudioEventMaintainer(threading.Thread):
camera_config=self.camera_config,
requestor=self.requestor,
model_runner=self.audio_transcription_model_runner,
- metrics=self.camera_metrics[self.camera_config.name],
+ metrics=self.embeddings_metrics,
stop_event=self.stop_event,
genai_manager=self.genai_manager,
)
@@ -291,8 +307,8 @@ class AudioEventMaintainer(threading.Thread):
audio_as_float: np.ndarray = audio.astype(np.float32)
rms, dBFS = self.calculate_audio_levels(audio_as_float)
- self.camera_metrics[self.camera_config.name].audio_rms.value = rms
- self.camera_metrics[self.camera_config.name].audio_dBFS.value = dBFS
+ self.metrics.audio_rms.value = rms
+ self.metrics.audio_dBFS.value = dBFS
audio_detections: list[tuple[str, float]] = []
@@ -377,7 +393,6 @@ class AudioEventMaintainer(threading.Thread):
return
time.sleep(self.camera_config.ffmpeg.retry_interval)
- self.logpipe.dump()
self.start_or_restart_ffmpeg()
if self.audio_listener is None or self.audio_listener.stdout is None:
diff --git a/frigate/log.py b/frigate/log.py
index 693d70e8c9..632db56738 100644
--- a/frigate/log.py
+++ b/frigate/log.py
@@ -144,6 +144,14 @@ class LogPipe(threading.Thread):
self.pipeReader.close()
def dump(self) -> None:
+ if not self.deque:
+ return
+
+ self.logger.log(
+ self.level,
+ "The following ffmpeg logs include the last 100 lines prior to exit.",
+ )
+
while len(self.deque) > 0:
self.logger.log(self.level, self.deque.popleft())
diff --git a/frigate/motion/improved_motion.py b/frigate/motion/improved_motion.py
index 598eeacd1d..bbcaee23af 100644
--- a/frigate/motion/improved_motion.py
+++ b/frigate/motion/improved_motion.py
@@ -188,8 +188,12 @@ class ImprovedMotionDetector(MotionDetector):
self.config.skip_motion_threshold is not None
and pct_motion > self.config.skip_motion_threshold
):
- # force a recalibration so we transition to the new background
+ # recalibrate so we transition to the new background. the frame
+ # still has to be blended in here, otherwise the background stays
+ # frozen and every subsequent frame skips as well
self.calibrating = True
+ cv2.accumulateWeighted(resized_frame, self.avg_frame, 0.2)
+ self.motion_frame_count = 0
return []
# once the motion is less than 5% and the number of contours is < 4, assume its calibrated
diff --git a/frigate/test/test_audio_spawn.py b/frigate/test/test_audio_spawn.py
new file mode 100644
index 0000000000..6c1c31a6a5
--- /dev/null
+++ b/frigate/test/test_audio_spawn.py
@@ -0,0 +1,90 @@
+"""Tests for audio maintainer spawning on runtime camera adds."""
+
+import threading
+import unittest
+from unittest.mock import MagicMock, patch
+
+from frigate.config import FrigateConfig
+from frigate.events.audio import AudioProcessor
+
+
+def _build_config() -> FrigateConfig:
+ return FrigateConfig(
+ **{
+ "mqtt": {"host": "mqtt"},
+ "cameras": {
+ "front_door": {
+ "ffmpeg": {
+ "inputs": [
+ {
+ "path": "rtsp://10.0.0.1:554/video",
+ "roles": ["detect", "audio"],
+ }
+ ]
+ },
+ "audio": {"enabled": True},
+ }
+ },
+ }
+ )
+
+
+class TestAudioSpawnIfNeeded(unittest.TestCase):
+ def _processor(self, config: FrigateConfig, camera_metrics: dict) -> AudioProcessor:
+ processor = AudioProcessor.__new__(AudioProcessor)
+ processor.config = config
+ processor.camera_metrics = camera_metrics
+ processor.embeddings_metrics = MagicMock()
+ processor.audio_threads = {}
+ processor.transcription_model_runner = None
+ processor.genai_manager = None
+ processor.stop_event = threading.Event()
+ processor.logger = MagicMock()
+ return processor
+
+ def test_skips_camera_whose_metrics_have_not_been_created_yet(self):
+ """The camera maintainer creates metrics on its own poll of the add
+ update, so the audio processor can see the camera first."""
+ config = _build_config()
+ processor = self._processor(config, {})
+
+ with patch("frigate.events.audio.AudioEventMaintainer") as maintainer:
+ processor.spawn_if_needed(config.cameras["front_door"])
+
+ maintainer.assert_not_called()
+ assert processor.audio_threads == {}
+
+ def test_spawns_once_metrics_exist_and_passes_the_metrics_object(self):
+ config = _build_config()
+ metrics = object()
+ processor = self._processor(config, {"front_door": metrics})
+
+ with patch("frigate.events.audio.AudioEventMaintainer") as maintainer:
+ processor.spawn_if_needed(config.cameras["front_door"])
+
+ assert maintainer.call_args.args[2] is metrics
+ assert "front_door" in processor.audio_threads
+ maintainer.return_value.start.assert_called_once()
+
+ def test_does_not_respawn_for_a_camera_already_running(self):
+ config = _build_config()
+ processor = self._processor(config, {"front_door": object()})
+ processor.audio_threads["front_door"] = MagicMock()
+
+ with patch("frigate.events.audio.AudioEventMaintainer") as maintainer:
+ processor.spawn_if_needed(config.cameras["front_door"])
+
+ maintainer.assert_not_called()
+
+ def test_skips_camera_whose_ffmpeg_update_has_not_arrived_yet(self):
+ """The add update carries the camera before its ffmpeg inputs are
+ applied, so the audio role can be briefly missing."""
+ config = _build_config()
+ camera = config.cameras["front_door"]
+ camera.ffmpeg.inputs[0].roles = ["detect"]
+ processor = self._processor(config, {"front_door": object()})
+
+ with patch("frigate.events.audio.AudioEventMaintainer") as maintainer:
+ processor.spawn_if_needed(camera)
+
+ maintainer.assert_not_called()
diff --git a/frigate/test/test_motion_detector.py b/frigate/test/test_motion_detector.py
index cdf4210a51..6fb7a68efc 100644
--- a/frigate/test/test_motion_detector.py
+++ b/frigate/test/test_motion_detector.py
@@ -73,6 +73,35 @@ class TestImprovedMotionDetector(unittest.TestCase):
"Motion boxes should be empty when scene change exceeds skip threshold",
)
+ def _bright_frame(self, offset: int) -> np.ndarray:
+ """Produce a bright frame with a small dark object that moves."""
+ frame = np.full((self.frame_shape[0], self.frame_shape[1]), 200, dtype=np.uint8)
+ x = 10 + (offset * 5) % 60
+ frame[40:60, x : x + 15] = 20
+ return frame
+
+ def test_skip_motion_threshold_recovers_after_skip(self):
+ """Skipped frames must still be blended into the background.
+
+ A bright scene differs from the zeroed background across the whole
+ frame, so the first frames are skipped. The background has to catch up
+ anyway, otherwise motion detection never returns.
+ """
+ self.config.skip_motion_threshold = 0.5
+ self.config.improve_contrast = False
+ self.detector.config = self.config
+ self.detector.update_mask()
+
+ boxes = [len(self.detector.detect(self._bright_frame(i))) for i in range(40)]
+
+ self.assertEqual(boxes[0], 0, "First frame should exceed the skip threshold")
+ self.assertGreater(
+ self.detector.avg_frame.max(),
+ 0,
+ "Background was never updated while frames were skipped",
+ )
+ self.assertTrue(any(boxes), "Motion detection never recovered after a skip")
+
def test_skip_motion_threshold_does_not_affect_calibration(self):
"""Even when skipping, the detector should go into calibrating state."""
self.config.skip_motion_threshold = 0.4
diff --git a/frigate/track/norfair_tracker.py b/frigate/track/norfair_tracker.py
index 6b39885c0d..b2e8221f27 100644
--- a/frigate/track/norfair_tracker.py
+++ b/frigate/track/norfair_tracker.py
@@ -324,9 +324,7 @@ class NorfairTracker(ObjectTracker):
):
tracker = self.get_tracker(obj["label"])
tracker.tracked_objects = [
- o
- for o in tracker.tracked_objects
- if str(o.global_id) != track_id and o.hit_counter < 0
+ o for o in tracker.tracked_objects if str(o.global_id) != track_id
]
del self.track_id_map[track_id]
diff --git a/frigate/util/ffmpeg.py b/frigate/util/ffmpeg.py
index fed2fd2c3f..e0e9879cde 100644
--- a/frigate/util/ffmpeg.py
+++ b/frigate/util/ffmpeg.py
@@ -49,6 +49,9 @@ def start_or_restart_ffmpeg(
if ffmpeg_process is not None:
stop_ffmpeg(ffmpeg_process, logger)
+ # flush after the stop so the logs cover ffmpeg's output up to exit
+ logpipe.dump()
+
if frame_size is None:
process = sp.Popen(
ffmpeg_cmd,
diff --git a/frigate/video/ffmpeg.py b/frigate/video/ffmpeg.py
index c55c127498..a676cfc670 100644
--- a/frigate/video/ffmpeg.py
+++ b/frigate/video/ffmpeg.py
@@ -319,9 +319,6 @@ class CameraWatchdog(threading.Thread):
f"Capture thread for {self.config.name} did not exit in time"
)
- self.logger.error(
- "The following ffmpeg logs include the last 100 lines prior to exit."
- )
self.logpipe.dump()
self.logger.info("Restarting ffmpeg...")
self.start_ffmpeg_detect()
@@ -543,7 +540,6 @@ class CameraWatchdog(threading.Thread):
f"{self.config.name}/status/{role.value}", "offline"
)
- p["logpipe"].dump()
p["process"] = start_or_restart_ffmpeg(
p["cmd"], self.logger, p["logpipe"], ffmpeg_process=p["process"]
)
diff --git a/web/e2e/helpers/monaco.ts b/web/e2e/helpers/monaco.ts
index 6e9bcd871a..f9a551a3d7 100644
--- a/web/e2e/helpers/monaco.ts
+++ b/web/e2e/helpers/monaco.ts
@@ -56,3 +56,14 @@ export async function waitForErrorMarker(
.poll(() => hasErrorMarkers(page), { timeout: timeoutMs })
.toBe(true);
}
+
+/**
+ * Append a trailing comment so the editor content differs from the
+ * loaded config. The save buttons are disabled until then.
+ */
+export async function makeMonacoEdit(page: Page): Promisehttps://…). This is a browser limitation. Access Frigate securely to use notifications.",
- "descPwa": "On iOS, web push notifications are only available when Frigate is installed to your Home Screen. Open the Share menu, choose Add to Home Screen, then open Frigate from the new icon to register this device for notifications."
+ "desc": "Web push notifications require a secure context (https://…). This is a browser limitation. Access Frigate securely to use notifications.",
+ "descPwa": "On iOS, web push notifications are only available when Frigate is installed to your Home Screen. Open the Share menu, choose Add to Home Screen, then open Frigate from the new icon to register this device for notifications."
},
"globalSettings": {
"title": "Global Settings",
@@ -1316,7 +1315,6 @@
"triggers": {
"documentTitle": "Triggers",
"semanticSearch": {
- "title": "Semantic Search is disabled",
"desc": "Semantic Search must be enabled to use Triggers."
},
"management": {
diff --git a/web/src/components/config-form/section-configs/audio_transcription.ts b/web/src/components/config-form/section-configs/audio_transcription.ts
index c359611b86..f1cc6680d1 100644
--- a/web/src/components/config-form/section-configs/audio_transcription.ts
+++ b/web/src/components/config-form/section-configs/audio_transcription.ts
@@ -45,7 +45,6 @@ const audioTranscription: SectionConfigOverrides = {
fieldMessages: [
{
key: "genai-provider-ignores-local-settings",
- health: (ctx) => ctx.fullConfig.audio_transcription?.enabled === true,
field: "device",
messageKey: "configMessages.audioTranscription.genaiProviderSelected",
severity: "info",
diff --git a/web/src/components/config-form/sectionExtras/NotificationsSettingsExtras.tsx b/web/src/components/config-form/sectionExtras/NotificationsSettingsExtras.tsx
index de61340735..2644ff89a5 100644
--- a/web/src/components/config-form/sectionExtras/NotificationsSettingsExtras.tsx
+++ b/web/src/components/config-form/sectionExtras/NotificationsSettingsExtras.tsx
@@ -24,7 +24,7 @@ import {
} from "react";
import { useForm } from "react-hook-form";
import { LuCheck, LuExternalLink, LuX } from "react-icons/lu";
-import { CiCircleAlert } from "react-icons/ci";
+import { ConfigFieldMessage } from "../ConfigFieldMessage";
import { Link } from "react-router-dom";
import { toast } from "sonner";
import useSWR from "swr";
@@ -44,8 +44,7 @@ import {
import { formatUnixTimestampToDateTime } from "@/utils/dateUtil";
import { use24HourTime } from "@/hooks/use-date-utils";
import FilterSwitch from "@/components/filter/FilterSwitch";
-import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
-import { Trans, useTranslation } from "react-i18next";
+import { useTranslation } from "react-i18next";
import { useDateLocale } from "@/hooks/use-date-locale";
import { useDocDomain } from "@/hooks/use-doc-domain";
import { isPWA } from "@/utils/isPWA";
@@ -467,37 +466,19 @@ export default function NotificationsSettingsExtras({
-