From 776bb79f0be540ce5c4b53d5d0939b14737837ca Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 23 Jan 2025 07:26:53 -0700 Subject: [PATCH] Consider pre and post capture when cleaning up recordings based on review segments (#16096) --- frigate/record/cleanup.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frigate/record/cleanup.py b/frigate/record/cleanup.py index b70a23b45..e526b020d 100644 --- a/frigate/record/cleanup.py +++ b/frigate/record/cleanup.py @@ -121,22 +121,29 @@ class RecordingCleanup(threading.Thread): review_start = 0 deleted_recordings = set() kept_recordings: list[tuple[float, float]] = [] + recording: Recordings for recording in recordings: keep = False mode = None # Now look for a reason to keep this recording segment for idx in range(review_start, len(reviews)): review: ReviewSegment = reviews[idx] + severity = review.severity + pre_capture = config.record.get_review_pre_capture(severity) + post_capture = config.record.get_review_post_capture(severity) # if the review starts in the future, stop checking reviews # and let this recording segment expire - if review.start_time > recording.end_time: + if review.start_time - pre_capture > recording.end_time: keep = False break # if the review is in progress or ends after the recording starts, keep it # and stop looking at reviews - if review.end_time is None or review.end_time >= recording.start_time: + if ( + review.end_time is None + or review.end_time + post_capture >= recording.start_time + ): keep = True mode = ( config.record.alerts.retain.mode @@ -149,7 +156,7 @@ class RecordingCleanup(threading.Thread): # this review and check the next review for an overlap. # since the review and recordings are sorted, we can skip review # that end before the previous recording segment started on future segments - if review.end_time < recording.start_time: + if review.end_time + post_capture < recording.start_time: review_start = idx # Delete recordings outside of the retention window or based on the retention mode