2024-09-28 22:21:42 +03:00
from enum import Enum
2025-12-22 11:10:40 -05:00
from typing import Optional , Union
2024-09-28 22:21:42 +03:00
from pydantic import Field
from frigate.const import MAX_PRE_CAPTURE
2024-12-19 09:46:14 -06:00
from frigate.review.types import SeverityEnum
2024-09-28 22:21:42 +03:00
from ..base import FrigateBaseModel
__all__ = [
"RecordConfig" ,
"RecordExportConfig" ,
"RecordPreviewConfig" ,
"RecordQualityEnum" ,
"EventsConfig" ,
"ReviewRetainConfig" ,
"RecordRetainConfig" ,
"RetainModeEnum" ,
]
2025-05-30 17:01:39 -06:00
class RecordRetainConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
days : float = Field (
default = 0 ,
ge = 0 ,
title = "Retention days" ,
description = "Days to retain recordings." ,
)
2025-05-30 17:01:39 -06:00
2024-09-28 22:21:42 +03:00
class RetainModeEnum ( str , Enum ):
all = "all"
motion = "motion"
active_objects = "active_objects"
class ReviewRetainConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
days : float = Field (
default = 10 ,
ge = 0 ,
title = "Retention days" ,
description = "Number of days to retain recordings of detection events." ,
)
mode : RetainModeEnum = Field (
default = RetainModeEnum . motion ,
title = "Retention mode" ,
description = "Mode for retention: all (save all segments), motion (save segments with motion), or active_objects (save segments with active objects)." ,
)
2024-09-28 22:21:42 +03:00
class EventsConfig ( FrigateBaseModel ):
pre_capture : int = Field (
2025-05-30 17:01:39 -06:00
default = 5 ,
2026-02-27 09:55:36 -06:00
title = "Pre-capture seconds" ,
description = "Number of seconds before the detection event to include in the recording." ,
2025-05-30 17:01:39 -06:00
le = MAX_PRE_CAPTURE ,
ge = 0 ,
)
post_capture : int = Field (
2026-02-27 09:55:36 -06:00
default = 5 ,
ge = 0 ,
title = "Post-capture seconds" ,
description = "Number of seconds after the detection event to include in the recording." ,
2024-09-28 22:21:42 +03:00
)
retain : ReviewRetainConfig = Field (
2026-02-27 09:55:36 -06:00
default_factory = ReviewRetainConfig ,
title = "Event retention" ,
description = "Retention settings for recordings of detection events." ,
2024-09-28 22:21:42 +03:00
)
class RecordQualityEnum ( str , Enum ):
very_low = "very_low"
low = "low"
medium = "medium"
high = "high"
very_high = "very_high"
class RecordPreviewConfig ( FrigateBaseModel ):
quality : RecordQualityEnum = Field (
2026-02-27 09:55:36 -06:00
default = RecordQualityEnum . medium ,
title = "Preview quality" ,
description = "Preview quality level (very_low, low, medium, high, very_high)." ,
2024-09-28 22:21:42 +03:00
)
class RecordExportConfig ( FrigateBaseModel ):
2025-12-22 11:10:40 -05:00
hwaccel_args : Union [ str , list [ str ]] = Field (
2026-02-27 09:55:36 -06:00
default = "auto" ,
title = "Export hwaccel args" ,
description = "Hardware acceleration args to use for export/transcode operations." ,
2025-12-22 11:10:40 -05:00
)
2024-09-28 22:21:42 +03:00
class RecordConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable recording" ,
description = "Enable or disable recording for all cameras; can be overridden per-camera." ,
)
2024-09-28 22:21:42 +03:00
expire_interval : int = Field (
default = 60 ,
2026-02-27 09:55:36 -06:00
title = "Record cleanup interval" ,
description = "Minutes between cleanup passes that remove expired recording segments." ,
2024-09-28 22:21:42 +03:00
)
2025-05-30 17:01:39 -06:00
continuous : RecordRetainConfig = Field (
default_factory = RecordRetainConfig ,
2026-02-27 09:55:36 -06:00
title = "Continuous retention" ,
description = "Number of days to retain recordings regardless of tracked objects or motion. Set to 0 if you only want to retain recordings of alerts and detections." ,
2025-05-30 17:01:39 -06:00
)
motion : RecordRetainConfig = Field (
2026-02-27 09:55:36 -06:00
default_factory = RecordRetainConfig ,
title = "Motion retention" ,
description = "Number of days to retain recordings triggered by motion regardless of tracked objects. Set to 0 if you only want to retain recordings of alerts and detections." ,
2024-09-28 22:21:42 +03:00
)
detections : EventsConfig = Field (
2026-02-27 09:55:36 -06:00
default_factory = EventsConfig ,
title = "Detection retention" ,
description = "Recording retention settings for detection events including pre/post capture durations." ,
2024-09-28 22:21:42 +03:00
)
alerts : EventsConfig = Field (
2026-02-27 09:55:36 -06:00
default_factory = EventsConfig ,
title = "Alert retention" ,
description = "Recording retention settings for alert events including pre/post capture durations." ,
2024-09-28 22:21:42 +03:00
)
export : RecordExportConfig = Field (
2026-02-27 09:55:36 -06:00
default_factory = RecordExportConfig ,
title = "Export config" ,
description = "Settings used when exporting recordings such as timelapse and hardware acceleration." ,
2024-09-28 22:21:42 +03:00
)
preview : RecordPreviewConfig = Field (
2026-02-27 09:55:36 -06:00
default_factory = RecordPreviewConfig ,
title = "Preview config" ,
description = "Settings controlling the quality of recording previews shown in the UI." ,
2024-09-28 22:21:42 +03:00
)
enabled_in_config : Optional [ bool ] = Field (
2026-02-27 09:55:36 -06:00
default = None ,
title = "Original recording state" ,
description = "Indicates whether recording was enabled in the original static configuration." ,
2024-09-28 22:21:42 +03:00
)
2024-10-31 06:31:01 -06:00
@property
def event_pre_capture ( self ) -> int :
return max (
self . alerts . pre_capture ,
self . detections . pre_capture ,
)
2024-12-19 09:46:14 -06:00
def get_review_pre_capture ( self , severity : SeverityEnum ) -> int :
if severity == SeverityEnum . alert :
return self . alerts . pre_capture
else :
return self . detections . pre_capture
def get_review_post_capture ( self , severity : SeverityEnum ) -> int :
if severity == SeverityEnum . alert :
return self . alerts . post_capture
else :
return self . detections . post_capture