NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Don't save preview frames if recording is not enabled (#13656)
Nicolas Mowen8db982484231
diff --git a/frigate/output/preview.py b/frigate/output/preview.pyindex 87efa3f11b..f5a0f2e719 100644--- a/frigate/output/preview.py+++ b/frigate/output/preview.py@@ -12,6 +12,7 @@ from pathlib import Pathimport cv2import numpy as np+from frigate.comms.config_updater import ConfigSubscriberfrom frigate.comms.inter_process import InterProcessRequestorfrom frigate.config import CameraConfig, RecordQualityEnumfrom frigate.const import CACHE_DIR, CLIPS_DIR, INSERT_PREVIEW, PREVIEW_FRAME_TYPE@@ -170,6 +171,7 @@ class PreviewRecorder:# create communication for finished previewsself.requestor = InterProcessRequestor()+ self.config_subscriber = ConfigSubscriber(f"config/record/{self.config.name}")y, u1, u2, v1, v2 = get_yuv_crop(self.config.frame_shape_yuv,@@ -243,6 +245,9 @@ class PreviewRecorder:frame_time: float,) -> bool:"""Decide if this frame should be added to PREVIEW."""+ if not self.config.record.enabled:+ return False+active_objs = get_active_objects(frame_time, self.config, current_tracked_objects)@@ -300,6 +305,12 @@ class PreviewRecorder:frame_time: float,frame,) -> bool:+ # check for updated record config+ _, updated_record_config = self.config_subscriber.check_for_update()++ if updated_record_config:+ self.config.record = updated_record_config+# always write the first frameif self.start_time == 0:self.start_time = frame_time@@ -309,14 +320,18 @@ class PreviewRecorder:# check if PREVIEW clip should be generated and cached frames resetif frame_time >= self.segment_end:- # save last frame to ensure consistent duration- self.output_frames.append(frame_time)- self.write_frame_to_cache(frame_time, frame)- FFMpegConverter(- self.config,- self.output_frames,- self.requestor,- ).start()+ if len(self.output_frames) > 0:+ # save last frame to ensure consistent duration+ if self.config.record:+ self.output_frames.append(frame_time)+ self.write_frame_to_cache(frame_time, frame)++ # write the preview if any frames exist for this hour+ FFMpegConverter(+ self.config,+ self.output_frames,+ self.requestor,+ ).start()# reset frame cacheself.segment_end = (@@ -330,8 +345,10 @@ class PreviewRecorder:self.output_frames: list[float] = []# include first frame to ensure consistent duration- self.output_frames.append(frame_time)- self.write_frame_to_cache(frame_time, frame)+ if self.config.record.enabled:+ self.output_frames.append(frame_time)+ self.write_frame_to_cache(frame_time, frame)+return Trueelif self.should_write_frame(current_tracked_objects, motion_boxes, frame_time):self.output_frames.append(frame_time)