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

This commit is contained in:
Blake Blackshear 2020-10-26 07:59:05 -05:00
parent 3ff98770c1
commit cee1ab000b
3 changed files with 6 additions and 3 deletions

View File

@ -244,6 +244,7 @@ def main():
'detection_fps': mp.Value('d', 0.0), 'detection_fps': mp.Value('d', 0.0),
'detection_frame': mp.Value('d', 0.0), 'detection_frame': mp.Value('d', 0.0),
'read_start': mp.Value('d', 0.0), 'read_start': mp.Value('d', 0.0),
'ffmpeg_pid': mp.Value('i', 0),
'frame_queue': mp.Queue(maxsize=2) 'frame_queue': mp.Queue(maxsize=2)
} }

View File

@ -26,7 +26,7 @@ class EventProcessor(threading.Thread):
files_in_use = [] files_in_use = []
for process_data in self.camera_processes.values(): for process_data in self.camera_processes.values():
try: 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() flist = ffmpeg_process.open_files()
if flist: if flist:
for nt in flist: for nt in flist:

View File

@ -167,7 +167,7 @@ def capture_frames(ffmpeg_process, camera_name, frame_shape, frame_manager: Fram
frame_queue.put(current_frame.value) frame_queue.put(current_frame.value)
class CameraWatchdog(threading.Thread): 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) threading.Thread.__init__(self)
self.name = name self.name = name
self.config = config self.config = config
@ -175,6 +175,7 @@ class CameraWatchdog(threading.Thread):
self.ffmpeg_process = None self.ffmpeg_process = None
self.stop_event = stop_event self.stop_event = stop_event
self.camera_fps = camera_fps self.camera_fps = camera_fps
self.ffmpeg_pid = ffmpeg_pid
self.frame_queue = frame_queue self.frame_queue = frame_queue
self.frame_shape = self.config['frame_shape'] self.frame_shape = self.config['frame_shape']
self.frame_size = self.frame_shape[0] * self.frame_shape[1] * 3 // 2 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): def start_ffmpeg(self):
self.ffmpeg_process = start_or_restart_ffmpeg(self.config['ffmpeg_cmd'], self.frame_size) 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.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.config['take_frame'], self.camera_fps, self.stop_event)
self.capture_thread.start() self.capture_thread.start()
@ -234,7 +236,7 @@ class CameraCapture(threading.Thread):
def capture_camera(name, config, process_info, stop_event): def capture_camera(name, config, process_info, stop_event):
frame_queue = process_info['frame_queue'] 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.start()
camera_watchdog.join() camera_watchdog.join()