mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-30 19:09:13 +01:00
Add auto-configuration for detect width, height, and fps for input roles with detect in the CameraConfig class in config.py
This commit is contained in:
parent
535f710c2b
commit
63cd8e54c5
@ -267,7 +267,7 @@ class StationaryConfig(FrigateBaseModel):
|
||||
|
||||
|
||||
class DetectConfig(FrigateBaseModel):
|
||||
autoconf: bool = Field(default=False, title="Auto detect height, width and fps.")
|
||||
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.")
|
||||
fps: int = Field(
|
||||
@ -671,6 +671,21 @@ 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:
|
||||
(
|
||||
config["detect"]["width"],
|
||||
config["detect"]["height"],
|
||||
# config["detect"]["fps"],
|
||||
) = get_video_properties(input.get("path"))
|
||||
break
|
||||
except Exception:
|
||||
logger.debug("Error autoconf url " + input.get("path"))
|
||||
continue
|
||||
|
||||
super().__init__(**config)
|
||||
|
||||
@property
|
||||
@ -970,13 +985,6 @@ class FrigateConfig(FrigateBaseModel):
|
||||
for input in camera_config.ffmpeg.inputs:
|
||||
input.path = input.path.format(**FRIGATE_ENV_VARS)
|
||||
|
||||
if camera_config.detect.autoconf and ("detect" in input.roles):
|
||||
(
|
||||
camera_config.detect.width,
|
||||
camera_config.detect.height,
|
||||
camera_config.detect.fps,
|
||||
) = get_video_properties(input.path)
|
||||
|
||||
# ONVIF substitution
|
||||
if camera_config.onvif.user or camera_config.onvif.password:
|
||||
camera_config.onvif.user = camera_config.onvif.user.format(
|
||||
|
@ -1147,12 +1147,13 @@ def to_relative_box(
|
||||
|
||||
|
||||
def get_video_properties(url):
|
||||
width = height = 0
|
||||
# Open the video stream
|
||||
video = cv2.VideoCapture(url)
|
||||
|
||||
# Check if the video stream was opened successfully
|
||||
if not video.isOpened():
|
||||
print("Error opening video stream")
|
||||
logger.debug(f"Error opening video stream {url}.")
|
||||
return None
|
||||
|
||||
# Get the width of frames in the video stream
|
||||
@ -1162,9 +1163,9 @@ def get_video_properties(url):
|
||||
height = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
||||
|
||||
# Get the frames per second (fps) of the video stream
|
||||
fps = video.get(cv2.CAP_PROP_FPS)
|
||||
# fps = min(24.0, video.get(cv2.CAP_PROP_FPS))
|
||||
|
||||
# Release the video stream
|
||||
video.release()
|
||||
|
||||
return width, height, fps
|
||||
return width, height # , fps
|
||||
|
Loading…
Reference in New Issue
Block a user