Output frame name to frames processor

This commit is contained in:
Nicolas Mowen 2024-11-16 14:54:57 -07:00
parent f9c1600f0d
commit 571354e9fc

View File

@ -94,7 +94,6 @@ def capture_frames(
ffmpeg_process, ffmpeg_process,
config: CameraConfig, config: CameraConfig,
shm_frame_count: int, shm_frame_count: int,
shm_frames: list[str],
frame_shape, frame_shape,
frame_manager: FrameManager, frame_manager: FrameManager,
frame_queue, frame_queue,
@ -109,21 +108,20 @@ def capture_frames(
skipped_eps = EventsPerSecond() skipped_eps = EventsPerSecond()
skipped_eps.start() skipped_eps.start()
# pre-create shms
for i in range(shm_frame_count):
frame_manager.create(f"{config.name}{i}")
frame_index = 0
while True: while True:
fps.value = frame_rate.eps() fps.value = frame_rate.eps()
skipped_fps.value = skipped_eps.eps() skipped_fps.value = skipped_eps.eps()
current_frame.value = datetime.datetime.now().timestamp() current_frame.value = datetime.datetime.now().timestamp()
frame_name = f"{config.name}{current_frame.value}" frame_name = f"{config.name}{frame_index}"
frame_buffer = frame_manager.create(frame_name, frame_size) frame_buffer = frame_manager.create(frame_name, frame_size)
try: try:
frame_buffer[:] = ffmpeg_process.stdout.read(frame_size) frame_buffer[:] = ffmpeg_process.stdout.read(frame_size)
# update frame cache and cleanup existing frames
shm_frames.append(frame_name)
if len(shm_frames) > shm_frame_count:
expired_frame_name = shm_frames.pop(0)
frame_manager.delete(expired_frame_name)
except Exception: except Exception:
# always delete the frame # always delete the frame
frame_manager.delete(frame_name) frame_manager.delete(frame_name)
@ -147,12 +145,14 @@ def capture_frames(
# don't lock the queue to check, just try since it should rarely be full # don't lock the queue to check, just try since it should rarely be full
try: try:
# add to the queue # add to the queue
frame_queue.put(current_frame.value, False) frame_queue.put((frame_name, current_frame.value), False)
frame_manager.close(frame_name) frame_manager.close(frame_name)
except queue.Full: except queue.Full:
# if the queue is full, skip this frame # if the queue is full, skip this frame
skipped_eps.update() skipped_eps.update()
frame_index = 0 if frame_index == shm_frame_count - 1 else frame_index + 1
class CameraWatchdog(threading.Thread): class CameraWatchdog(threading.Thread):
def __init__( def __init__(
@ -171,7 +171,6 @@ class CameraWatchdog(threading.Thread):
self.camera_name = camera_name self.camera_name = camera_name
self.config = config self.config = config
self.shm_frame_count = shm_frame_count self.shm_frame_count = shm_frame_count
self.shm_frames: list[str] = []
self.capture_thread = None self.capture_thread = None
self.ffmpeg_detect_process = None self.ffmpeg_detect_process = None
self.logpipe = LogPipe(f"ffmpeg.{self.camera_name}.detect") self.logpipe = LogPipe(f"ffmpeg.{self.camera_name}.detect")
@ -304,7 +303,6 @@ class CameraWatchdog(threading.Thread):
self.capture_thread = CameraCapture( self.capture_thread = CameraCapture(
self.config, self.config,
self.shm_frame_count, self.shm_frame_count,
self.shm_frames,
self.ffmpeg_detect_process, self.ffmpeg_detect_process,
self.frame_shape, self.frame_shape,
self.frame_queue, self.frame_queue,
@ -345,7 +343,6 @@ class CameraCapture(threading.Thread):
self, self,
config: CameraConfig, config: CameraConfig,
shm_frame_count: int, shm_frame_count: int,
shm_frames: list[str],
ffmpeg_process, ffmpeg_process,
frame_shape, frame_shape,
frame_queue, frame_queue,
@ -373,7 +370,6 @@ class CameraCapture(threading.Thread):
self.ffmpeg_process, self.ffmpeg_process,
self.config, self.config,
self.shm_frame_count, self.shm_frame_count,
self.shm_frames,
self.frame_shape, self.frame_shape,
self.frame_manager, self.frame_manager,
self.frame_queue, self.frame_queue,