How many parallel VideoCapture's can one camera handle?

I want to read from one camera in many parallel processes.

Here is what I’ve tried.

from multiprocessing import Process

import cv2
import time
import random

def get_capture():
    time.sleep(random.randint(0, 3))

    cap = cv2.VideoCapture(0)
    w, h = cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

    if (w, h) == (0, 0):
        print("Seemingly failed to construct the capture.")

    print(f"Feed dimensions are {w}x{h}.")

    success, _ = cap.read()
    if not success:
        print("Failed frame reading.")


if __name__ == "__main__":
    pcs = []
    for _ in range(256):
        p = Process(target=get_capture)
        pcs.append(p)
        p.start()

    for p in pcs:
        p.join()

The frame reading is likely to fail in many processes.

Does Open CV support creating multiple VideoCaptures for the same camera and reading from them? If it does, what am I doing wrong?

The code is only an illustration of what I want to achieve. For instance, in my real project, I have no easy method to read frames from one process and consume them from other processes.

you can’t. you shouldn’t want to.

one physical camera can only be used from one process at the same time. that’s how most operating system’s media APIs work. one program gets to control the capture properties. I do not mean OpenCV. I mean system APIs.

you should present the goal. your goal is not the code you wrote. your goal is why you wrote that code.

Assume you’re writing a media server, your goal is to stream the video from that camera to multiple clients in parallel. You must serve each user from separate processes or threads, you won’t do it sequentially.

There must be some way to “broadcast” the frames that you read to multiple consumer processes.

one program gets to control the capture properties. I do not mean OpenCV. I mean system APIs.

Your Teams and your Python program using Open CV can read from your laptop camera at the same time. Try it.