NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Cleanup after recordings refactor (#13518)
Nicolas Mowene66f47bdf69b
diff --git a/frigate/config.py b/frigate/config.pyindex 20433e6443..ef3375ad0f 100644--- a/frigate/config.py+++ b/frigate/config.py@@ -301,13 +301,18 @@ class RecordRetainConfig(FrigateBaseModel):mode: RetainModeEnum = Field(default=RetainModeEnum.all, title="Retain mode.")+class ReviewRetainConfig(FrigateBaseModel):+ days: float = Field(default=10, title="Default retention period.")+ mode: RetainModeEnum = Field(default=RetainModeEnum.motion, title="Retain mode.")++class EventsConfig(FrigateBaseModel):pre_capture: int = Field(default=5, title="Seconds to retain before event starts.", le=MAX_PRE_CAPTURE)post_capture: int = Field(default=5, title="Seconds to retain after event ends.")- retain: RecordRetainConfig = Field(- default_factory=RecordRetainConfig, title="Event retention settings."+ retain: ReviewRetainConfig = Field(+ default_factory=ReviewRetainConfig, title="Event retention settings.")diff --git a/frigate/events/external.py b/frigate/events/external.pyindex 00f7cee4f5..edfb757a04 100644--- a/frigate/events/external.py+++ b/frigate/events/external.py@@ -57,11 +57,7 @@ class ExternalEventProcessor:thumbnail = self._write_images(camera_config, label, event_id, draw, snapshot_frame)- end = (- now + duration + camera_config.record.events.post_capture- if duration is not None- else None- )+ end = now + duration if duration is not None else Noneself.event_sender.publish((@@ -74,7 +70,7 @@ class ExternalEventProcessor:"sub_label": sub_label,"score": score,"camera": camera,- "start_time": now - camera_config.record.events.pre_capture,+ "start_time": now,"end_time": end,"thumbnail": thumbnail,"has_clip": camera_config.record.enabled and include_recording,diff --git a/frigate/record/cleanup.py b/frigate/record/cleanup.pyindex 9f00fb50e4..7703da8ea2 100644--- a/frigate/record/cleanup.py+++ b/frigate/record/cleanup.py@@ -5,9 +5,11 @@ import itertoolsimport loggingimport osimport threading+from functools import reducefrom multiprocessing.synchronize import Event as MpEventfrom pathlib import Path+from peewee import operatorfrom playhouse.sqlite_ext import SqliteExtDatabasefrom frigate.config import CameraConfig, FrigateConfig, RetainModeEnum@@ -71,17 +73,26 @@ class RecordingCleanup(threading.Thread):).timestamp()expired_reviews: ReviewSegment = (ReviewSegment.select(ReviewSegment.id)+ .where(ReviewSegment.camera == "front_cam").where(- ReviewSegment.camera == config.name- and (- (- ReviewSegment.severity == "alert"- and ReviewSegment.end_time < alert_expire_date- )- or (- ReviewSegment.severity == "detection"- and ReviewSegment.end_time < detection_expire_date- )+ reduce(+ operator.or_,+ [+ reduce(+ operator.and_,+ [+ (ReviewSegment.severity == "alert"),+ (ReviewSegment.end_time < alert_expire_date),+ ],+ ),+ reduce(+ operator.and_,+ [+ (ReviewSegment.severity == "detection"),+ (ReviewSegment.end_time < detection_expire_date),+ ],+ ),+ ],)).namedtuples()@@ -89,7 +100,6 @@ class RecordingCleanup(threading.Thread):max_deletes = 100000deleted_reviews_list = list(map(lambda x: x[0], expired_reviews))- logger.info(f"the list is {deleted_reviews_list}")for i in range(0, len(deleted_reviews_list), max_deletes):ReviewSegment.delete().where(ReviewSegment.id << deleted_reviews_list[i : i + max_deletes]