Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4829

Beginners • Re: How to send two camera streams from RPi 5 over TCP connection with PiCamera2

$
0
0
There are many ways to go about this, so I'm slightly hesitant to make a suggestion. You could certainly put a "capture_array()" in a loop where you could (compress?) and send the frames. The outline code below might give you some ideas too.

Code:

from picamera2 import Picamera2from picamera2.encoders import MJPEGEncoderfrom picamera2.outputs import Outputfrom queue import Queuecams = [Picamera2(0), Picamera2(1)]queue = Queue()class QueueOutput(Output):    def __init__(self, cam_id, *args):        super().__init__(*args)        self.cam_id = cam_id    def outputframe(self, frame, keyframe=True, timestamp=None):        queue.put((self.cam_id, timestamp, frame))for i, cam in enumerate(cams):    config = cam.create_video_configuration({'format': 'RGB888', 'size': (640, 480)})    cam.configure(config)    cam.start_recording(MJPEGEncoder(), QueueOutput(i))while True:    cam_id, timestamp, frame = queue.get()    # Collect a frame frome each camera at a matching timestamp, then send them.
Here, both cameras should dump encoded frames and timestamps into a common queue. The loop at the end will need to collect corresponding frames, one from each camera, and send them to the socket connection you had earlier.

Statistics: Posted by therealdavidp — Tue Jul 30, 2024 2:40 pm



Viewing all articles
Browse latest Browse all 4829

Trending Articles