Ensure detect height and width are not None before using them in camera configuration

This commit is contained in:
Sergey Krashevich 2023-06-15 04:40:24 +03:00
parent cbb391160b
commit 747006cb13
No known key found for this signature in database
GPG Key ID: 625171324E7D3856
2 changed files with 24 additions and 20 deletions

View File

@ -671,25 +671,6 @@ class CameraConfig(FrigateBaseModel):
if has_rtmp: if has_rtmp:
config["ffmpeg"]["inputs"][0]["roles"].append("rtmp") config["ffmpeg"]["inputs"][0]["roles"].append("rtmp")
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(
f"Error detecting stream resolution automatically for {input.get('path')} Applying default values."
)
continue
super().__init__(**config) super().__init__(**config)
@property @property
@ -975,6 +956,29 @@ class FrigateConfig(FrigateBaseModel):
{"name": name, **merged_config} {"name": name, **merged_config}
) )
if (
camera_config.detect.height is None
or camera_config.detect.width is None
):
for input in camera_config.ffmpeg.inputs:
if "detect" in input.roles:
try:
streamInfo = get_video_properties(input.path)
camera_config.detect.width = streamInfo["width"]
camera_config.detect.height = streamInfo["height"]
break
except Exception:
camera_config.detect.width = DEFAULT_DETECT_DIMENSIONS[
"width"
]
camera_config.detect.height = DEFAULT_DETECT_DIMENSIONS[
"height"
]
logger.warn(
f"Error detecting stream resolution automatically for {input.path} Applying default values."
)
continue
# Default max_disappeared configuration # Default max_disappeared configuration
max_disappeared = camera_config.detect.fps * 5 max_disappeared = camera_config.detect.fps * 5
if camera_config.detect.max_disappeared is None: if camera_config.detect.max_disappeared is None:

View File

@ -1165,7 +1165,7 @@ def get_video_properties(url, get_duration=False):
# Release the video stream # Release the video stream
video.release() video.release()
result = {"width": width, "height": height} result = {"width": round(width), "height": round(height)}
if get_duration: if get_duration:
# Get the frames per second (fps) of the video stream # Get the frames per second (fps) of the video stream
fps = video.get(cv2.CAP_PROP_FPS) fps = video.get(cv2.CAP_PROP_FPS)