Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle recording checks in utc #8379

Merged
merged 2 commits into from Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions frigate/record/maintainer.py
Expand Up @@ -260,8 +260,10 @@ async def validate_and_move_segment(
most_recently_processed_frame_time = (
camera_info[-1][0] if len(camera_info) > 0 else 0
)
retain_cutoff = most_recently_processed_frame_time - pre_capture
if end_time.timestamp() < retain_cutoff:
retain_cutoff = datetime.datetime.fromtimestamp(
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)
self.end_time_cache.pop(cache_path, None)
# else retain days includes this segment
Expand All @@ -273,7 +275,11 @@ async def validate_and_move_segment(
)

# 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
return await self.move_segment(
camera, start_time, end_time, duration, cache_path, record_mode
Expand Down
17 changes: 10 additions & 7 deletions frigate/video.py
Expand Up @@ -233,14 +233,15 @@ def run(self):
poll = p["process"].poll()

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(
"latest_segment_time", datetime.datetime.now().timestamp()
"latest_segment_time",
datetime.datetime.now().astimezone(datetime.timezone.utc),
)
)

if datetime.datetime.now().timestamp() > (
latest_segment_time + 120
if datetime.datetime.now().astimezone(datetime.timezone.utc) > (
latest_segment_time + datetime.timedelta(seconds=120)
):
self.logger.error(
f"No new recording segments were created for {self.camera_name} in the last 120s. restarting the ffmpeg record process..."
Expand Down Expand Up @@ -288,7 +289,7 @@ def start_ffmpeg_detect(self):
)
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."""
cache_files = sorted(
[
Expand All @@ -299,13 +300,15 @@ def get_latest_segment_timestamp(self, latest_timestamp) -> int:
and not d.startswith("clip_")
]
)
newest_segment_timestamp = latest_timestamp
newest_segment_timestamp = latest_segment

for file in cache_files:
if self.camera_name in file:
basename = os.path.splitext(file)[0]
_, 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:
newest_segment_timestamp = ts

Expand Down