Add default detect dimensions if autoconfiguration failed and log a warning message

This commit is contained in:
Sergey Krashevich 2023-06-15 04:13:28 +03:00
parent 838f246b06
commit 2fff932979
No known key found for this signature in database
GPG Key ID: 625171324E7D3856

View File

@ -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,17 +671,25 @@ 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", [])
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:
logger.debug("Error autoconf url " + input.get("path"))
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)