Skip to content

Commit decc8aa

Browse files
authored
Incrase frequency of secondary pipeline updates (#22673)
* Incrase frequency of secondary pipeline updates when an object needs it * Handle buffer timestamps correctly * Consider LP that are not sub label
1 parent 831cfc2 commit decc8aa

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

frigate/camera/state.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@ def __init__(
5454
self.ptz_autotracker_thread = ptz_autotracker_thread
5555
self.prev_enabled = self.camera_config.enabled
5656

57+
# Minimum object area thresholds for fast-tracking updates to secondary
58+
# face/LPR pipelines when using a model without built-in detection.
59+
self.face_recognition_min_obj_area: int = 0
60+
self.lpr_min_obj_area: int = 0
61+
62+
if (
63+
self.camera_config.face_recognition.enabled
64+
and "face" not in config.objects.all_objects
65+
):
66+
# A face is roughly 1/8 of person box area; use a conservative
67+
# multiplier so fast-tracking starts slightly before the optimal zone
68+
self.face_recognition_min_obj_area = (
69+
self.camera_config.face_recognition.min_area * 6
70+
)
71+
72+
if (
73+
self.camera_config.lpr.enabled
74+
and "license_plate" not in self.camera_config.objects.track
75+
):
76+
# A plate is a smaller fraction of a vehicle box; use ~20x multiplier
77+
self.lpr_min_obj_area = self.camera_config.lpr.min_area * 20
78+
5779
def get_current_frame(self, draw_options: dict[str, Any] = {}) -> np.ndarray:
5880
with self.current_frame_lock:
5981
frame_copy = np.copy(self._current_frame)
@@ -372,13 +394,30 @@ def update(
372394

373395
updated_obj.last_updated = frame_time
374396

375-
# if it has been more than 5 seconds since the last thumb update
376-
# and the last update is greater than the last publish or
377-
# the object has changed significantly or
378-
# the object moved enough to update the path
397+
# Determine the staleness threshold for publishing updates.
398+
# Fast-track to 1s for objects in the optimal size range for
399+
# secondary face/LPR recognition that don't yet have a sub_label.
400+
obj_area = updated_obj.obj_data.get("area", 0)
401+
obj_label = updated_obj.obj_data.get("label")
402+
publish_threshold = 5
403+
404+
if (
405+
obj_label == "person"
406+
and self.face_recognition_min_obj_area > 0
407+
and obj_area >= self.face_recognition_min_obj_area
408+
and updated_obj.obj_data.get("sub_label") is None
409+
) or (
410+
obj_label in ("car", "motorcycle")
411+
and self.lpr_min_obj_area > 0
412+
and obj_area >= self.lpr_min_obj_area
413+
and updated_obj.obj_data.get("sub_label") is None
414+
and updated_obj.obj_data.get("recognized_license_plate") is None
415+
):
416+
publish_threshold = 1
417+
379418
if (
380419
(
381-
frame_time - updated_obj.last_published > 5
420+
frame_time - updated_obj.last_published > publish_threshold
382421
and updated_obj.last_updated > updated_obj.last_published
383422
)
384423
or significant_update

frigate/data_processing/post/review_descriptions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ def process_data(
149149
additional_buffer_per_side = (MIN_RECORDING_DURATION - duration) / 2
150150
buffer_extension = min(5, additional_buffer_per_side)
151151

152+
final_data["start_time"] -= buffer_extension
153+
final_data["end_time"] += buffer_extension
154+
152155
thumbs = self.get_recording_frames(
153156
camera,
154-
final_data["start_time"] - buffer_extension,
155-
final_data["end_time"] + buffer_extension,
157+
final_data["start_time"],
158+
final_data["end_time"],
156159
height=480, # Use 480p for good balance between quality and token usage
157160
)
158161

0 commit comments

Comments
 (0)