add camera processors

This commit is contained in:
Blake Blackshear 2020-11-01 10:37:17 -06:00
parent 75973fd4c0
commit a89dddcafa
2 changed files with 29 additions and 10 deletions

View File

@ -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()

View File

@ -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)