mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-02 17:25:22 +03:00
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
This commit is contained in:
parent
51fb532e1a
commit
0206577f8d
@ -565,7 +565,7 @@ class CameraConfig(FrigateBaseModel):
|
|||||||
|
|
||||||
ffmpeg_output_args = (
|
ffmpeg_output_args = (
|
||||||
record_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
|
+ ffmpeg_output_args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -77,7 +77,12 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
cache_path = os.path.join(CACHE_DIR, f)
|
cache_path = os.path.join(CACHE_DIR, f)
|
||||||
basename = os.path.splitext(f)[0]
|
basename = os.path.splitext(f)[0]
|
||||||
camera, date = basename.rsplit("-", maxsplit=1)
|
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(
|
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 cached file's start_time is earlier than the retain_days for the camera
|
||||||
if start_time <= (
|
if start_time <= (
|
||||||
(
|
(
|
||||||
datetime.datetime.now()
|
datetime.datetime.now().astimezone(datetime.timezone.utc)
|
||||||
- datetime.timedelta(
|
- datetime.timedelta(
|
||||||
days=self.config.cameras[camera].record.retain_days
|
days=self.config.cameras[camera].record.retain_days
|
||||||
)
|
)
|
||||||
@ -181,7 +186,7 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
os.makedirs(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)
|
file_path = os.path.join(directory, file_name)
|
||||||
|
|
||||||
# copy then delete is required when recordings are stored on some network drives
|
# 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:
|
except Exception as e:
|
||||||
logger.error(f"Unable to store recording segment {cache_path}")
|
logger.error(f"Unable to store recording segment {cache_path}")
|
||||||
Path(cache_path).unlink(missing_ok=True)
|
Path(cache_path).unlink(missing_ok=True)
|
||||||
logger.error(e)
|
logger.error(e, exc_info=True)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Check for new files every 5 seconds
|
# Check for new files every 5 seconds
|
||||||
@ -216,7 +221,7 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
logger.error(
|
logger.error(
|
||||||
"Error occurred when attempting to maintain recording cache"
|
"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))
|
wait_time = max(0, 5 - (datetime.datetime.now().timestamp() - run_start))
|
||||||
|
|
||||||
logger.info(f"Exiting recording maintenance...")
|
logger.info(f"Exiting recording maintenance...")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user