Hi @Elusive
GPT:
import threading
import queue
import cv2
# Initialize frame queue
frame_queue = queue.Queue()
save_frame = True
# Frame saving function
def save_frames(frame_queue):
while True:
frame, out_key = frame_queue.get()
if frame is None:
break
out[out_key].write(frame)
# Start the frame saving thread
saving_thread = threading.Thread(target=save_frames, args=(frame_queue,))
saving_thread.start()
# Main loop
for q in queues:
fps_handler.tick(f"{q['cam']} - {q['mx']}")
camera_key = f"{q['cam']} - {q['mx']}"
pkg = q["msgs"].pop(0)
frame = pkg.getCvFrame()
# draw_text(frame, text=f"{pkg.getTimestamp()}", org=(5, 45))
cv2.imshow(f"{q['cam']} - {q['mx']}", frame)
# width, height = new_msg.getWidth(), new_msg.getHeight()
if save_frame:
frame_queue.put((frame, f"{q['cam']} - {q['mx']}"))
# Signal the saving thread to exit and wait for it to finish
frame_queue.put((None, None))
saving_thread.join()