mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-08-04 13:47:37 +02:00
Refactor code to retrieve video properties from input stream in CameraConfig class and add optional parameter to retrieve video duration in get_video_properties function
This commit is contained in:
parent
63cd8e54c5
commit
a53fc32d1a
@ -676,11 +676,10 @@ class CameraConfig(FrigateBaseModel):
|
|||||||
"detect" in input.get("roles", [])
|
"detect" in input.get("roles", [])
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
(
|
|
||||||
config["detect"]["width"],
|
streamInfo = get_video_properties(input.get("path"))
|
||||||
config["detect"]["height"],
|
config["detect"]["width"] = streamInfo["width"]
|
||||||
# config["detect"]["fps"],
|
config["detect"]["height"] = streamInfo["height"]
|
||||||
) = get_video_properties(input.get("path"))
|
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.debug("Error autoconf url " + input.get("path"))
|
logger.debug("Error autoconf url " + input.get("path"))
|
||||||
|
@ -1146,7 +1146,7 @@ def to_relative_box(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_video_properties(url):
|
def get_video_properties(url, get_duration=False):
|
||||||
width = height = 0
|
width = height = 0
|
||||||
# Open the video stream
|
# Open the video stream
|
||||||
video = cv2.VideoCapture(url)
|
video = cv2.VideoCapture(url)
|
||||||
@ -1162,10 +1162,16 @@ def get_video_properties(url):
|
|||||||
# Get the height of frames in the video stream
|
# Get the height of frames in the video stream
|
||||||
height = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
height = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
||||||
|
|
||||||
# Get the frames per second (fps) of the video stream
|
|
||||||
# fps = min(24.0, video.get(cv2.CAP_PROP_FPS))
|
|
||||||
|
|
||||||
# Release the video stream
|
# Release the video stream
|
||||||
video.release()
|
video.release()
|
||||||
|
|
||||||
return width, height # , fps
|
result = {"width": width, "height": height}
|
||||||
|
if get_duration:
|
||||||
|
# Get the frames per second (fps) of the video stream
|
||||||
|
fps = video.get(cv2.CAP_PROP_FPS)
|
||||||
|
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
||||||
|
duration = total_frames / fps
|
||||||
|
|
||||||
|
result["duration"] = duration
|
||||||
|
|
||||||
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user