Browse Source

make ffmpeg pid available for cache maintenance (fixes #271)

Blake Blackshear 4 năm trước cách đây
mục cha
commit
cee1ab000b
3 tập tin đã thay đổi với 6 bổ sung3 xóa
  1. 1 0
      detect_objects.py
  2. 1 1
      frigate/events.py
  3. 4 2
      frigate/video.py

+ 1 - 0
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)
         }
 

+ 1 - 1
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:

+ 4 - 2
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()