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:
-
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
-
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
-
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
-
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 .
-
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 }
-
Build and load the module:
make sudo rmmod uvcvideo sudo insmod ./aauvcvideo.ko quirks=128
-
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.
-
-
(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?
S B is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.