From e0da4622232ad670cea7de0b24c5acf23b2fc8a0 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 1 Nov 2020 10:37:17 -0600 Subject: [PATCH] add camera processors --- frigate/__main__.py | 27 +++++++++++++++++++++++---- frigate/video.py | 12 ++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/frigate/__main__.py b/frigate/__main__.py index 94808d7a6..ddbe6893c 100644 --- a/frigate/__main__.py +++ b/frigate/__main__.py @@ -13,7 +13,7 @@ from frigate.http import create_app from frigate.models import Event from frigate.mqtt import create_mqtt_client from frigate.object_processing import TrackedObjectProcessor -from frigate.video import get_frame_shape +from frigate.video import get_frame_shape, track_camera class FrigateApp(): def __init__(self): @@ -93,8 +93,26 @@ class FrigateApp(): self.detected_frames_queue, self.event_queue, self.stop_event) self.detected_frames_processor.start() - def start_frame_processors(self): - pass + def start_camera_processors(self): + self.camera_process_info = {} + for name, config in self.config['cameras'].items(): + self.camera_process_info[name] = { + 'camera_fps': mp.Value('d', 0.0), + 'skipped_fps': mp.Value('d', 0.0), + 'process_fps': mp.Value('d', 0.0), + 'detection_fps': mp.Value('d', 0.0), + 'detection_frame': mp.Value('d', 0.0), + 'read_start': mp.Value('d', 0.0), + 'ffmpeg_pid': mp.Value('i', 0), + 'frame_queue': mp.Queue(maxsize=2) + } + camera_process = mp.Process(target=track_camera, args=(name, config, + self.detection_queue, self.detection_out_events[name], self.detected_frames_queue, + self.camera_process_info[name])) + camera_process.daemon = True + self.camera_process_info[name]['process'] = camera_process + camera_process.start() + print(f"Camera process started for {name}: {camera_process.pid}") def start_camera_capture_processes(self): pass @@ -110,13 +128,14 @@ class FrigateApp(): self.init_mqtt() self.start_detectors() self.start_detected_frames_processor() - self.start_frame_processors() + self.start_camera_processors() self.start_camera_capture_processes() self.start_watchdog() self.flask_app.run(host='0.0.0.0', port=self.config['web_port'], debug=False) self.stop() def stop(self): + print(f"Stopping...") self.stop_event.set() self.detected_frames_processor.join() diff --git a/frigate/video.py b/frigate/video.py index c60714ca1..82d2fe916 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -241,7 +241,7 @@ def capture_camera(name, config, process_info, stop_event): camera_watchdog.start() camera_watchdog.join() -def track_camera(name, config, detection_queue, result_connection, detected_objects_queue, process_info, stop_event): +def track_camera(name, config, detection_queue, result_connection, detected_objects_queue, process_info): listen() frame_queue = process_info['frame_queue'] @@ -282,7 +282,7 @@ def track_camera(name, config, detection_queue, result_connection, detected_obje frame_manager = SharedMemoryFrameManager() process_frames(name, frame_queue, frame_shape, frame_manager, motion_detector, object_detector, - object_tracker, detected_objects_queue, process_info, objects_to_track, object_filters, mask, stop_event) + object_tracker, detected_objects_queue, process_info, objects_to_track, object_filters, mask) print(f"{name}: exiting subprocess") @@ -319,7 +319,7 @@ def process_frames(camera_name: str, frame_queue: mp.Queue, frame_shape, frame_manager: FrameManager, motion_detector: MotionDetector, object_detector: RemoteObjectDetector, object_tracker: ObjectTracker, detected_objects_queue: mp.Queue, process_info: Dict, - objects_to_track: List[str], object_filters: Dict, mask, stop_event: mp.Event, + objects_to_track: List[str], object_filters: Dict, mask, exit_on_empty: bool = False): fps = process_info['process_fps'] @@ -330,9 +330,9 @@ def process_frames(camera_name: str, frame_queue: mp.Queue, frame_shape, fps_tracker.start() while True: - if stop_event.is_set() or (exit_on_empty and frame_queue.empty()): - print(f"Exiting track_objects...") - break + if exit_on_empty and frame_queue.empty(): + print(f"Exiting track_objects...") + break try: frame_time = frame_queue.get(True, 10)