mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-02-18 00:16:41 +01:00
Add auto configuration for height, width and fps in detect role
This commit is contained in:
parent
3efa77f302
commit
535f710c2b
@ -30,6 +30,7 @@ from frigate.util import (
|
||||
escape_special_characters,
|
||||
get_ffmpeg_arg_list,
|
||||
load_config_with_no_duplicates,
|
||||
get_video_properties,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -266,6 +267,7 @@ class StationaryConfig(FrigateBaseModel):
|
||||
|
||||
|
||||
class DetectConfig(FrigateBaseModel):
|
||||
autoconf: bool = Field(default=False, 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(
|
||||
@ -968,6 +970,13 @@ 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(
|
||||
|
@ -1144,3 +1144,27 @@ def to_relative_box(
|
||||
(box[2] - box[0]) / width, # w
|
||||
(box[3] - box[1]) / height, # h
|
||||
)
|
||||
|
||||
|
||||
def get_video_properties(url):
|
||||
# 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")
|
||||
return None
|
||||
|
||||
# Get the width of frames in the video stream
|
||||
width = video.get(cv2.CAP_PROP_FRAME_WIDTH)
|
||||
|
||||
# Get the height of frames in the video stream
|
||||
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)
|
||||
|
||||
# Release the video stream
|
||||
video.release()
|
||||
|
||||
return width, height, fps
|
||||
|
Loading…
Reference in New Issue
Block a user