From d73f28807f72803282139c0c7a0ce52395b32bb0 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 4 Mar 2026 12:53:49 -0600 Subject: [PATCH] ensure previews dir exists when ffmpeg processes restart, there's a brief window where the preview frame generation pipeline is torn down and restarted. before these changes, ffmpeg only restarted on crash/stall recovery or full Frigate restart. Now that ffmpeg restarts happen on-demand via config changes, there's a higher chance a frontend request hits the preview_mp4 or preview_gif endpoints during that brief restart window when the directory might not exist yet. The existing os.listdir() call would throw FileNotFoundError without a directory existence check. this fix just checks if the directory exists and returns 404 if not, exactly how preview_thumbnail already handles the same scenario a few lines below --- frigate/api/media.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/frigate/api/media.py b/frigate/api/media.py index 3cfd97674..0028c6152 100644 --- a/frigate/api/media.py +++ b/frigate/api/media.py @@ -1263,6 +1263,13 @@ def preview_gif( else: # need to generate from existing images preview_dir = os.path.join(CACHE_DIR, "preview_frames") + + if not os.path.isdir(preview_dir): + return JSONResponse( + content={"success": False, "message": "Preview not found"}, + status_code=404, + ) + file_start = f"preview_{camera_name}" start_file = f"{file_start}-{start_ts}.{PREVIEW_FRAME_TYPE}" end_file = f"{file_start}-{end_ts}.{PREVIEW_FRAME_TYPE}" @@ -1438,6 +1445,13 @@ def preview_mp4( else: # need to generate from existing images preview_dir = os.path.join(CACHE_DIR, "preview_frames") + + if not os.path.isdir(preview_dir): + return JSONResponse( + content={"success": False, "message": "Preview not found"}, + status_code=404, + ) + file_start = f"preview_{camera_name}" start_file = f"{file_start}-{start_ts}.{PREVIEW_FRAME_TYPE}" end_file = f"{file_start}-{end_ts}.{PREVIEW_FRAME_TYPE}"