diff --git a/detect_objects.py b/detect_objects.py index 46d9911c0..f239069b6 100644 --- a/detect_objects.py +++ b/detect_objects.py @@ -244,6 +244,7 @@ def main(): '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) } diff --git a/frigate/events.py b/frigate/events.py index 569b8d78a..6b4785c3f 100644 --- a/frigate/events.py +++ b/frigate/events.py @@ -26,7 +26,7 @@ class EventProcessor(threading.Thread): files_in_use = [] for process_data in self.camera_processes.values(): try: - ffmpeg_process = psutil.Process(pid=process_data['ffmpeg_process'].pid) + ffmpeg_process = psutil.Process(pid=process_data['ffmpeg_pid'].value) flist = ffmpeg_process.open_files() if flist: for nt in flist: diff --git a/frigate/video.py b/frigate/video.py index 91a7f9f5b..693dc54f1 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -167,7 +167,7 @@ def capture_frames(ffmpeg_process, camera_name, frame_shape, frame_manager: Fram frame_queue.put(current_frame.value) class CameraWatchdog(threading.Thread): - def __init__(self, name, config, frame_queue, camera_fps, stop_event): + def __init__(self, name, config, frame_queue, camera_fps, ffmpeg_pid, stop_event): threading.Thread.__init__(self) self.name = name self.config = config @@ -175,6 +175,7 @@ class CameraWatchdog(threading.Thread): self.ffmpeg_process = None self.stop_event = stop_event self.camera_fps = camera_fps + self.ffmpeg_pid = ffmpeg_pid self.frame_queue = frame_queue self.frame_shape = self.config['frame_shape'] self.frame_size = self.frame_shape[0] * self.frame_shape[1] * 3 // 2 @@ -207,6 +208,7 @@ class CameraWatchdog(threading.Thread): def start_ffmpeg(self): self.ffmpeg_process = start_or_restart_ffmpeg(self.config['ffmpeg_cmd'], self.frame_size) + self.ffmpeg_pid.value = self.ffmpeg_process.pid self.capture_thread = CameraCapture(self.name, self.ffmpeg_process, self.frame_shape, self.frame_queue, self.config['take_frame'], self.camera_fps, self.stop_event) self.capture_thread.start() @@ -234,7 +236,7 @@ class CameraCapture(threading.Thread): def capture_camera(name, config, process_info, stop_event): frame_queue = process_info['frame_queue'] - camera_watchdog = CameraWatchdog(name, config, frame_queue, process_info['camera_fps'], stop_event) + camera_watchdog = CameraWatchdog(name, config, frame_queue, process_info['camera_fps'], process_info['ffmpeg_pid'], stop_event) camera_watchdog.start() camera_watchdog.join()