NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Cache camera stream info to speed up future config generations (#11614)
Nicolas Mowend5f6decd309d
diff --git a/frigate/config.py b/frigate/config.pyindex 5cf8b2da48..6d0342d983 100644--- a/frigate/config.py+++ b/frigate/config.py@@ -1,6 +1,5 @@from __future__ import annotations-import asyncioimport jsonimport loggingimport os@@ -46,9 +45,9 @@ from frigate.util.builtin import (get_ffmpeg_arg_list,load_config_with_no_duplicates,)-from frigate.util.config import get_relative_coordinates+from frigate.util.config import StreamInfoRetriever, get_relative_coordinatesfrom frigate.util.image import create_mask-from frigate.util.services import auto_detect_hwaccel, get_video_properties+from frigate.util.services import auto_detect_hwaccellogger = logging.getLogger(__name__)@@ -73,6 +72,9 @@ DEFAULT_DETECTORS = {"cpu": {"type": "cpu"}}DEFAULT_DETECT_DIMENSIONS = {"width": 1280, "height": 720}DEFAULT_TIME_LAPSE_FFMPEG_ARGS = "-vf setpts=0.04*PTS -r 30"+# stream info handler+stream_info_retriever = StreamInfoRetriever()+class FrigateBaseModel(BaseModel):model_config = ConfigDict(extra="forbid", protected_namespaces=())@@ -1416,7 +1418,7 @@ class FrigateConfig(FrigateBaseModel):if need_detect_dimensions or need_record_fourcc:stream_info = {"width": 0, "height": 0, "fourcc": None}try:- stream_info = asyncio.run(get_video_properties(input.path))+ stream_info = stream_info_retriever.get_stream_info(input.path)except Exception:logger.warn(f"Error detecting stream parameters automatically for {input.path} Applying default values."diff --git a/frigate/util/config.py b/frigate/util/config.pyindex df2d0c1f1b..6f66a59922 100644--- a/frigate/util/config.py+++ b/frigate/util/config.py@@ -1,5 +1,6 @@"""configuration utils."""+import asyncioimport loggingimport osimport shutil@@ -8,6 +9,7 @@ from typing import Optional, Unionfrom ruamel.yaml import YAMLfrom frigate.const import CONFIG_DIR, EXPORT_DIR+from frigate.util.services import get_video_propertieslogger = logging.getLogger(__name__)@@ -194,3 +196,16 @@ def get_relative_coordinates(return maskreturn mask+++class StreamInfoRetriever:+ def __init__(self) -> None:+ self.stream_cache: dict[str, tuple[int, int]] = {}++ def get_stream_info(self, path: str) -> str:+ if path in self.stream_cache:+ return self.stream_cache[path]++ info = asyncio.run(get_video_properties(path))+ self.stream_cache[path] = info+ return info