From 0206577f8d87fbc6e216c41d039a27c522f94829 Mon Sep 17 00:00:00 2001 From: Matt Clayton Date: Wed, 10 Nov 2021 14:17:38 +0000 Subject: [PATCH] Update timestamps used by Frigate for file management to be based on UTC to avoid issues around daylights saving changes. Initally as a fix to #2158 --- frigate/config.py | 2 +- frigate/record.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index 0ed749d72..e7a1e86c2 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -565,7 +565,7 @@ class CameraConfig(FrigateBaseModel): ffmpeg_output_args = ( record_args - + [f"{os.path.join(CACHE_DIR, self.name)}-%Y%m%d%H%M%S.mp4"] + + [f"{os.path.join(CACHE_DIR, self.name)}-%s.mp4"] + ffmpeg_output_args ) diff --git a/frigate/record.py b/frigate/record.py index 1035ea529..98913df64 100644 --- a/frigate/record.py +++ b/frigate/record.py @@ -77,7 +77,12 @@ class RecordingMaintainer(threading.Thread): cache_path = os.path.join(CACHE_DIR, f) basename = os.path.splitext(f)[0] camera, date = basename.rsplit("-", maxsplit=1) - start_time = datetime.datetime.strptime(date, "%Y%m%d%H%M%S") + try: + start_time = datetime.datetime.fromtimestamp(int(date)).astimezone(datetime.timezone.utc) + except: + # During the move to UTC time (to fix #2158) + # handle any straggling files in /tmp/cache with an old filename + start_time = datetime.datetime.strptime(date, "%Y%m%d%H%M%S").astimezone(datetime.timezone.utc) grouped_recordings[camera].append( { @@ -133,7 +138,7 @@ class RecordingMaintainer(threading.Thread): # if cached file's start_time is earlier than the retain_days for the camera if start_time <= ( ( - datetime.datetime.now() + datetime.datetime.now().astimezone(datetime.timezone.utc) - datetime.timedelta( days=self.config.cameras[camera].record.retain_days ) @@ -181,7 +186,7 @@ class RecordingMaintainer(threading.Thread): if not os.path.exists(directory): os.makedirs(directory) - file_name = f"{start_time.strftime('%M.%S.mp4')}" + file_name = f"{start_time.strftime('%M.%S.utc.mp4')}" file_path = os.path.join(directory, file_name) # copy then delete is required when recordings are stored on some network drives @@ -203,7 +208,7 @@ class RecordingMaintainer(threading.Thread): except Exception as e: logger.error(f"Unable to store recording segment {cache_path}") Path(cache_path).unlink(missing_ok=True) - logger.error(e) + logger.error(e, exc_info=True) def run(self): # Check for new files every 5 seconds @@ -216,7 +221,7 @@ class RecordingMaintainer(threading.Thread): logger.error( "Error occurred when attempting to maintain recording cache" ) - logger.error(e) + logger.error(e, exc_info=True) wait_time = max(0, 5 - (datetime.datetime.now().timestamp() - run_start)) logger.info(f"Exiting recording maintenance...")