mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-01-31 00:18:55 +01:00
Handle recording checks in utc (#8379)
* Handle recording checks in utc * Formatting
This commit is contained in:
parent
9d717b371c
commit
e89dafa82e
@ -260,8 +260,10 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
most_recently_processed_frame_time = (
|
most_recently_processed_frame_time = (
|
||||||
camera_info[-1][0] if len(camera_info) > 0 else 0
|
camera_info[-1][0] if len(camera_info) > 0 else 0
|
||||||
)
|
)
|
||||||
retain_cutoff = most_recently_processed_frame_time - pre_capture
|
retain_cutoff = datetime.datetime.fromtimestamp(
|
||||||
if end_time.timestamp() < retain_cutoff:
|
most_recently_processed_frame_time - pre_capture
|
||||||
|
).astimezone(datetime.timezone.utc)
|
||||||
|
if end_time.astimezone(datetime.timezone.utc) < retain_cutoff:
|
||||||
Path(cache_path).unlink(missing_ok=True)
|
Path(cache_path).unlink(missing_ok=True)
|
||||||
self.end_time_cache.pop(cache_path, None)
|
self.end_time_cache.pop(cache_path, None)
|
||||||
# else retain days includes this segment
|
# else retain days includes this segment
|
||||||
@ -273,7 +275,11 @@ class RecordingMaintainer(threading.Thread):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# ensure delayed segment info does not lead to lost segments
|
# ensure delayed segment info does not lead to lost segments
|
||||||
if most_recently_processed_frame_time >= end_time.timestamp():
|
if datetime.datetime.fromtimestamp(
|
||||||
|
most_recently_processed_frame_time
|
||||||
|
).astimezone(datetime.timezone.utc) >= end_time.astimezone(
|
||||||
|
datetime.timezone.utc
|
||||||
|
):
|
||||||
record_mode = self.config.cameras[camera].record.retain.mode
|
record_mode = self.config.cameras[camera].record.retain.mode
|
||||||
return await self.move_segment(
|
return await self.move_segment(
|
||||||
camera, start_time, end_time, duration, cache_path, record_mode
|
camera, start_time, end_time, duration, cache_path, record_mode
|
||||||
|
@ -233,14 +233,15 @@ class CameraWatchdog(threading.Thread):
|
|||||||
poll = p["process"].poll()
|
poll = p["process"].poll()
|
||||||
|
|
||||||
if self.config.record.enabled and "record" in p["roles"]:
|
if self.config.record.enabled and "record" in p["roles"]:
|
||||||
latest_segment_time = self.get_latest_segment_timestamp(
|
latest_segment_time = self.get_latest_segment_datetime(
|
||||||
p.get(
|
p.get(
|
||||||
"latest_segment_time", datetime.datetime.now().timestamp()
|
"latest_segment_time",
|
||||||
|
datetime.datetime.now().astimezone(datetime.timezone.utc),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if datetime.datetime.now().timestamp() > (
|
if datetime.datetime.now().astimezone(datetime.timezone.utc) > (
|
||||||
latest_segment_time + 120
|
latest_segment_time + datetime.timedelta(seconds=120)
|
||||||
):
|
):
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
f"No new recording segments were created for {self.camera_name} in the last 120s. restarting the ffmpeg record process..."
|
f"No new recording segments were created for {self.camera_name} in the last 120s. restarting the ffmpeg record process..."
|
||||||
@ -288,7 +289,7 @@ class CameraWatchdog(threading.Thread):
|
|||||||
)
|
)
|
||||||
self.capture_thread.start()
|
self.capture_thread.start()
|
||||||
|
|
||||||
def get_latest_segment_timestamp(self, latest_timestamp) -> int:
|
def get_latest_segment_datetime(self, latest_segment: datetime.datetime) -> int:
|
||||||
"""Checks if ffmpeg is still writing recording segments to cache."""
|
"""Checks if ffmpeg is still writing recording segments to cache."""
|
||||||
cache_files = sorted(
|
cache_files = sorted(
|
||||||
[
|
[
|
||||||
@ -299,13 +300,15 @@ class CameraWatchdog(threading.Thread):
|
|||||||
and not d.startswith("clip_")
|
and not d.startswith("clip_")
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
newest_segment_timestamp = latest_timestamp
|
newest_segment_timestamp = latest_segment
|
||||||
|
|
||||||
for file in cache_files:
|
for file in cache_files:
|
||||||
if self.camera_name in file:
|
if self.camera_name in file:
|
||||||
basename = os.path.splitext(file)[0]
|
basename = os.path.splitext(file)[0]
|
||||||
_, date = basename.rsplit("-", maxsplit=1)
|
_, date = basename.rsplit("-", maxsplit=1)
|
||||||
ts = datetime.datetime.strptime(date, "%Y%m%d%H%M%S").timestamp()
|
ts = datetime.datetime.strptime(date, "%Y%m%d%H%M%S").astimezone(
|
||||||
|
datetime.timezone.utc
|
||||||
|
)
|
||||||
if ts > newest_segment_timestamp:
|
if ts > newest_segment_timestamp:
|
||||||
newest_segment_timestamp = ts
|
newest_segment_timestamp = ts
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user