Error when opening two cameras in FullHD using MSMF backend

I’m trying to get FullHD picture from two UC70 web cameras connected to a PC, however reading frame from the second camera fails with videoio(MSMF): can't grab frame. Error: -2147483638. Checked with OpenCV 4.5.1 and 4.6.

If CAP_DSHOW is used, then the error is gone, however with DirectShow there’s just 1 FPS so it’s unusable.

If after the error I re-create the capture and set 640x480 resolution, then it works (but we need both in FullHD).

If the first capture is released before creating the second one, then it works (but we need both simultaneously).

Error still happens if second camera is opened from another process.


import cv2
 
def copen(index, fullhd):    
    cap = cv2.VideoCapture(index)
    if fullhd:
        cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
        cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
    if not cap.isOpened():
        print(f"Cannot open webcam {index}")
    if not cap.read()[0]:
        print(f"Cannot read webcam {index}")
 
    return cap
 
cap1 = copen(0, True)
cap2 = copen(1, True)
 
cap1.release()
cap2.release()

Any ideas? Thanks!

set CAP_PROP_FOURCC to MJPG. order of set() calls matters. try this call last. works for most people.

the MSMF backend is fairly immature. when in doubt go with dshow.

USB has limited bandwidth, per controller (chip in your computer). cameras are designed to use up almost all of that. expect to be running one camera per controller. you’ll have to identify which ports belong to the same controller, and use just one of each group.

1 Like

Setting FOURCC and using DirectShow worked, thank you!

Also initial test was done in a VM, double FullHD actually worked on a real PC (but there’s a similar problem with double 4K).