diff --git a/frigate/config/camera/record.py b/frigate/config/camera/record.py index 3db61c569..dec629b6b 100644 --- a/frigate/config/camera/record.py +++ b/frigate/config/camera/record.py @@ -94,3 +94,10 @@ class RecordConfig(FrigateBaseModel): enabled_in_config: Optional[bool] = Field( default=None, title="Keep track of original state of recording." ) + + @property + def event_pre_capture(self) -> int: + return max( + self.alerts.pre_capture, + self.detections.pre_capture, + ) diff --git a/frigate/events/external.py b/frigate/events/external.py index edfb757a0..76b9e3208 100644 --- a/frigate/events/external.py +++ b/frigate/events/external.py @@ -70,7 +70,7 @@ class ExternalEventProcessor: "sub_label": sub_label, "score": score, "camera": camera, - "start_time": now, + "start_time": now - camera_config.record.event_pre_capture, "end_time": end, "thumbnail": thumbnail, "has_clip": camera_config.record.enabled and include_recording, diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py index 314ff3646..e97fb0a44 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -299,16 +299,12 @@ class RecordingMaintainer(threading.Thread): # if it doesn't overlap with an event, go ahead and drop the segment # if it ends more than the configured pre_capture for the camera else: - pre_capture = max( - record_config.alerts.pre_capture, - record_config.detections.pre_capture, - ) camera_info = self.object_recordings_info[camera] most_recently_processed_frame_time = ( camera_info[-1][0] if len(camera_info) > 0 else 0 ) retain_cutoff = datetime.datetime.fromtimestamp( - most_recently_processed_frame_time - pre_capture + most_recently_processed_frame_time - record_config.event_pre_capture ).astimezone(datetime.timezone.utc) if end_time < retain_cutoff: Path(cache_path).unlink(missing_ok=True)