From 2fff932979b68d9423478aeebb36db66b25c3319 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Thu, 15 Jun 2023 04:13:28 +0300 Subject: [PATCH] Add default detect dimensions if autoconfiguration failed and log a warning message --- frigate/config.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index 48e785c53..7b2fc03e5 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -44,6 +44,7 @@ FRIGATE_ENV_VARS = {k: v for k, v in os.environ.items() if k.startswith("FRIGATE DEFAULT_TRACKED_OBJECTS = ["person"] DEFAULT_DETECTORS = {"cpu": {"type": "cpu"}} +DEFAULT_DETECT_DIMENSIONS = {"width": 1280, "height": 720} class FrigateBaseModel(BaseModel): @@ -267,9 +268,8 @@ class StationaryConfig(FrigateBaseModel): class DetectConfig(FrigateBaseModel): - autoconf: bool = Field(default=True, title="Auto detect height, width and fps.") - height: int = Field(default=720, title="Height of the stream for the detect role.") - width: int = Field(default=1280, title="Width of the stream for the detect role.") + height: Optional[int] = Field(title="Height of the stream for the detect role.") + width: Optional[int] = Field(title="Width of the stream for the detect role.") fps: int = Field( default=5, title="Number of frames per second to process through detection." ) @@ -671,18 +671,26 @@ class CameraConfig(FrigateBaseModel): if has_rtmp: config["ffmpeg"]["inputs"][0]["roles"].append("rtmp") - for input in config["ffmpeg"]["inputs"]: - if config["detect"].get("autoconf") and ( - "detect" in input.get("roles", []) - ): - try: - streamInfo = get_video_properties(input.get("path")) - config["detect"]["width"] = streamInfo["width"] - config["detect"]["height"] = streamInfo["height"] - break - except Exception: - logger.debug("Error autoconf url " + input.get("path")) - continue + if ( + config["detect"].get("height") is None + or config["detect"].get("width") is None + ): + for input in config["ffmpeg"]["inputs"]: + if "detect" in input.get("roles", []): + try: + streamInfo = get_video_properties(input.get("path")) + config["detect"]["width"] = streamInfo["width"] + config["detect"]["height"] = streamInfo["height"] + break + except Exception: + config["detect"]["width"] = DEFAULT_DETECT_DIMENSIONS["width"] + config["detect"]["height"] = DEFAULT_DETECT_DIMENSIONS["height"] + logger.warn( + "Error autoconfiguration url " + + input.get("path") + + ". Appliing default values." + ) + continue super().__init__(**config)