How can I get two UVC cameras to stream through one USB port on a Linux device? [closed]

I’m running into an issue where I cannot seem to stream and record from two Arducam UVC cameras (B0202). My device can detect the cameras individually, but any attempt to stream from them both using a Python script results in only one being able to stream at a time. If I remove one of the cameras from the powered USB hub and connect it directly to one of the USB ports on my device, it works fine. I figure this has something to do with isochronous bandwidth allocation.

I modified an answer I found here Capturing multiple webcams (uvcvideo) with OpenCV on Linux to work with Zorin and a more modern kernel. Here are the steps I took:

  1. Get kernel source and set up directories:

    mkdir -p ~/Software/kernel-git
    cd ~/Software/kernel-git
    git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    
  2. Create driver directory and copy UVC files:

    mkdir -p ~/Software/uvcvideo_driver
    cd ~/Software/uvcvideo_driver
    cp -r ~/linux/drivers/media/usb/uvc .
    cd uvc
    
  3. Create Makefile:

    cat > Makefile << 'EOF'
    obj-m += aauvcvideo.o
    aauvcvideo-objs := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o 
                  uvc_status.o uvc_isight.o uvc_debugfs.o uvc_entity.o uvc_metadata.o
    all:
     make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
     make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    EOF
    
  4. Copy additional required files for modern kernel:

    cp ~/linux/drivers/media/usb/uvc/uvc_debugfs.c .
    cp ~/linux/drivers/media/usb/uvc/uvc_entity.c .
    cp ~/linux/drivers/media/usb/uvc/uvc_metadata.c .
    
  5. Modify bandwidth in uvc_video.c:

    nano uvc_video.c
    # Find uvc_fixup_video_ctrl() function and add before closing bracket:
    if (format->flags & UVC_FMT_FLAG_COMPRESSED) {
        ctrl->dwMaxPayloadTransferSize = 0x800;  # Using 0x800 instead of 0x400
    }
    
  6. Build and load the module:

    make
    sudo rmmod uvcvideo
    sudo insmod ./aauvcvideo.ko quirks=128
    
  7. Three different options and outcomes here using guvcview, which I did not quite understand. I could either:

    • run the cameras at 640×480 with an mjpg format can get them to both stream with full color

    • run the cameras at 1280×720 with an mjpg format and get them to both stream but have a green feed (extremely green tint to the image, as if the red and blue are being omitted);

    • switch the format to RGB3 and stream them both at 1920×1080 with no problems whatsoever. The confusing part about the last option is that it only works with guvcviewer, and technically, RGB3 is not one of the formats that Arducam lists as being supported (only YUYV, MJPG, and H.264 are listed as supported https://docs.arducam.com/UVC-Camera/Specs-and-Selection-Guide/).

      guvcview --device=/dev/video0 --format=rgb3 --resolution=1920x1080
      # In another terminal:
      guvcview --device=/dev/video4 --format=rgb3 --resolution=1920x1080
      

    Yet, I cannot, under any circumstances, seem to be able to get a python script to stream from both of them. It will generally not detect them at all with this modified driver.

  8. (Optional) To make the module load on startup:

    sudo cp aauvcvideo.ko /lib/modules/$(uname -r)/kernel/drivers/media/usb/uvc/
    sudo depmod -a
    sudo nano /etc/modules-load.d/aauvcvideo.conf
    # Add: aauvcvideo
    sudo nano /etc/modprobe.d/aauvcvideo.conf
    # Add: options aauvcvideo quirks=128
    

My questions are: why am I seeing this behavior in part (7)? And how can I get it to work with a simple python script and without using guvcviewer, given I would like to have the streaming as a part of a more complex application I’m building?

New contributor

S B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật