From d4eb37e9d363eb25d0882f8e6772ea6afc016901 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Fri, 30 Aug 2024 16:10:07 -0600 Subject: [PATCH] Simplify checks to rely on other cameras --- frigate/output/output.py | 14 ++++++++------ frigate/output/preview.py | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frigate/output/output.py b/frigate/output/output.py index 9160f861c..2f9f3a395 100644 --- a/frigate/output/output.py +++ b/frigate/output/output.py @@ -1,5 +1,6 @@ """Handle outputting raw frigate frames""" +import datetime import logging import multiprocessing as mp import os @@ -65,7 +66,6 @@ def output_frames( birdseye: Optional[Birdseye] = None preview_recorders: dict[str, PreviewRecorder] = {} preview_write_times: dict[str, float] = {} - last_preview_health_check: float = 0 move_preview_frames("cache") @@ -124,7 +124,7 @@ def output_frames( ) # send frames for low fps recording - preview_recorders[camera].write_data( + generated_preview = preview_recorders[camera].write_data( current_tracked_objects, motion_boxes, frame_time, frame ) preview_write_times[camera] = frame_time @@ -133,12 +133,14 @@ def output_frames( if camera in previous_frames: frame_manager.delete(f"{camera}{previous_frames[camera]}") - # every 10 seconds check if any cameras have stale frames - if frame_time - last_preview_health_check > 10: - last_preview_health_check = frame_time - for camera, time in preview_write_times.items(): + # if another camera generated a preview, + # check for any cameras that are currently offline + # and need to generate a preview + if generated_preview: + for camera, time in preview_write_times.copy().items(): if time != 0 and frame_time - time > 10: preview_recorders[camera].flag_offline(frame_time) + preview_write_times[camera] = frame_time previous_frames[camera] = frame_time diff --git a/frigate/output/preview.py b/frigate/output/preview.py index 6d08bb785..3c33ab072 100644 --- a/frigate/output/preview.py +++ b/frigate/output/preview.py @@ -299,13 +299,13 @@ class PreviewRecorder: motion_boxes: list[list[int]], frame_time: float, frame, - ) -> None: + ) -> bool: # always write the first frame if self.start_time == 0: self.start_time = frame_time self.output_frames.append(frame_time) self.write_frame_to_cache(frame_time, frame) - return + return False # check if PREVIEW clip should be generated and cached frames reset if frame_time >= self.segment_end: @@ -332,9 +332,11 @@ class PreviewRecorder: # include first frame to ensure consistent duration self.output_frames.append(frame_time) self.write_frame_to_cache(frame_time, frame) + return True elif self.should_write_frame(current_tracked_objects, motion_boxes, frame_time): self.output_frames.append(frame_time) self.write_frame_to_cache(frame_time, frame) + return False def flag_offline(self, frame_time: float) -> None: # check if PREVIEW clip should be generated and cached frames reset