mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 18:55:23 +03:00
Use ffprobe if cv2 failed
This commit is contained in:
parent
d7831ddf9f
commit
c58b8a883e
@ -123,9 +123,11 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
.order_by(Event.start_time)
|
.order_by(Event.start_time)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
start = datetime.datetime.now().timestamp()
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*(self.validate_segment(camera, events, r) for r in recordings)
|
*(self.validate_segment(camera, events, r) for r in recordings)
|
||||||
)
|
)
|
||||||
|
logger.error(f"The time took {datetime.datetime.now().timestamp() - start} seconds")
|
||||||
|
|
||||||
async def validate_segment(
|
async def validate_segment(
|
||||||
self, camera: str, events: Event, recording: dict[str, any]
|
self, camera: str, events: Event, recording: dict[str, any]
|
||||||
@ -145,7 +147,7 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
if cache_path in self.end_time_cache:
|
if cache_path in self.end_time_cache:
|
||||||
end_time, duration = self.end_time_cache[cache_path]
|
end_time, duration = self.end_time_cache[cache_path]
|
||||||
else:
|
else:
|
||||||
segment_info = get_video_properties(cache_path, duration=True)
|
segment_info = get_video_properties(cache_path, get_duration=True)
|
||||||
|
|
||||||
if segment_info["duration"]:
|
if segment_info["duration"]:
|
||||||
duration = float(segment_info["duration"])
|
duration = float(segment_info["duration"])
|
||||||
|
|||||||
@ -1154,11 +1154,32 @@ def get_video_properties(url, get_duration=False):
|
|||||||
video.release()
|
video.release()
|
||||||
|
|
||||||
result = {"width": round(width), "height": round(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)
|
||||||
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
||||||
|
logger.error(f"Got values {total_frames} / {fps} == {total_frames / max(fps, 1)}")
|
||||||
|
|
||||||
|
if fps and total_frames:
|
||||||
duration = total_frames / fps
|
duration = total_frames / fps
|
||||||
|
else:
|
||||||
|
# if cv2 failed need to use ffprobe
|
||||||
|
ffprobe_cmd = [
|
||||||
|
"ffprobe",
|
||||||
|
"-v",
|
||||||
|
"error",
|
||||||
|
"-show_entries",
|
||||||
|
"format=duration",
|
||||||
|
"-of",
|
||||||
|
"default=noprint_wrappers=1:nokey=1",
|
||||||
|
f"{url}",
|
||||||
|
]
|
||||||
|
p = sp.run(ffprobe_cmd, capture_output=True)
|
||||||
|
if p.returncode == 0 and p.stdout.decode():
|
||||||
|
duration = float(p.stdout.decode().strip())
|
||||||
|
else:
|
||||||
|
duration = -1
|
||||||
|
|
||||||
result["duration"] = duration
|
result["duration"] = duration
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user