Ensure at least 2 frames are saved per minute in preview video (#10337)

* simplify

* Formatting
This commit is contained in:
Nicolas Mowen 2024-03-08 16:24:47 -07:00 committed by GitHub
parent 086eb37ece
commit f7122a766e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -201,26 +201,18 @@ class PreviewRecorder:
frame_time: float, frame_time: float,
) -> bool: ) -> bool:
"""Decide if this frame should be added to PREVIEW.""" """Decide if this frame should be added to PREVIEW."""
preview_output_fps = ( active_objs = get_active_objects(
2 frame_time, self.config, current_tracked_objects
if any(
o["label"] == "car"
for o in get_active_objects(
frame_time, self.config, current_tracked_objects
)
)
else 1
) )
preview_output_fps = 2 if any(o["label"] == "car" for o in active_objs) else 1
# limit output to 1 fps # limit output to 1 fps
if (frame_time - self.last_output_time) < 1 / preview_output_fps: if (frame_time - self.last_output_time) < 1 / preview_output_fps:
return False return False
# send frame if a non-stationary object is in a zone # send frame if a non-stationary object is in a zone
if any( if len(active_objs > 0):
(len(o["current_zones"]) > 0 and not o["stationary"])
for o in current_tracked_objects
):
self.last_output_time = frame_time self.last_output_time = frame_time
return True return True
@ -228,6 +220,11 @@ class PreviewRecorder:
self.last_output_time = frame_time self.last_output_time = frame_time
return True return True
# ensure that at least 2 frames are written every minute
if frame_time - self.last_output_time > 30:
self.last_output_time = frame_time
return True
return False return False
def write_frame_to_cache(self, frame_time: float, frame) -> None: def write_frame_to_cache(self, frame_time: float, frame) -> None: