From 1639026242668a982dd7aff8e483dd68b980c8a2 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Sun, 23 Jul 2023 12:11:41 -0600 Subject: [PATCH] Calculate cache size --- frigate/record/maintainer.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py index 372e6a4fd..2d155239e 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -7,6 +7,7 @@ import multiprocessing as mp import os import queue import random +import shutil import string import subprocess as sp import threading @@ -28,6 +29,17 @@ from frigate.util.services import get_video_properties logger = logging.getLogger(__name__) +def calculate_max_segment_count(config: FrigateConfig) -> int: + """Calculate the maximum allowed segment count for each camera.""" + + # calculate total space allocated to cache + try: + total_cache = round(shutil.disk_usage(CACHE_DIR).total / pow(2, 20), 1) + except FileNotFoundError: + total_cache = 1074000000 # 1GiB + + # assuming a safe + class SegmentInfo: def __init__( self, motion_box_count: int, active_object_count: int, average_dBFS: int @@ -66,6 +78,7 @@ class RecordingMaintainer(threading.Thread): self.object_recordings_info: dict[str, list] = defaultdict(list) self.audio_recordings_info: dict[str, list] = defaultdict(list) self.end_time_cache: dict[str, Tuple[datetime.datetime, float]] = {} + self.max_segment_count = calculate_max_segment_count(config) async def move_files(self) -> None: cache_files = sorted(