0

How do I get two USB webcams to operate simultaneously on a Raspberry Pi 4 running openSUSE Leap 15.2?

I ultimately want this to work with Motion and seem to have eliminated that as I also fail with just ffplay from the command line.

I have two webcams plugged in to a powered USB hub. Both webcams work independently but not together. As a test, plugging the webcams directly in to the Pi or removing power from the hub gives me device descriptor read/64 error -110 so the hub is providing power correctly.

If I start the first cam as follows, I get a picture:

# ffplay -f v4l2 /dev/video0

But when I then start the second, I don't get a picture (the first will continue to work); we just wait here and don't appear to timeout (can't say I've waited for more than a few minutes, though):

# ffplay -loglevel debug -f v4l2 /dev/video2
ffplay version 3.4.8 Copyright (c) 2003-2020 the FFmpeg developers
  built with gcc 7 (SUSE Linux)
  configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --incdir=/usr/include/ffmpeg --extra-cflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g' --optflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g' --disable-htmlpages --enable-pic --disable-stripping --enable-shared --disable-static --enable-gpl --disable-openssl --enable-avresample --enable-libcdio --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcelt --enable-libcdio --enable-libdc1394 --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libzimg --enable-libzvbi --enable-vaapi --enable-vdpau --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-libx264 --enable-libx265 --enable-libxvid
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Initialized opengl renderer.
[video4linux2,v4l2 @ 0xffff40000b50] fd:11 capabilities:84a000010   
[video4linux2,v4l2 @ 0xffff40000b50] Current input_channel: 0, input_name: Camera 1, input_std: 0
[video4linux2,v4l2 @ 0xffff40000b50] Querying the device for the current frame size
[video4linux2,v4l2 @ 0xffff40000b50] Setting frame size to 1280x720
[video4linux2,v4l2 @ 0xffff40000b50] The V4L2 driver changed the pixel format from 0x32315559 to 0x47504A4D
[video4linux2,v4l2 @ 0xffff40000b50] Trying to set codec:rawvideo pix_fmt:yuv420p
[video4linux2,v4l2 @ 0xffff40000b50] The V4L2 driver changed the pixel format from 0x32315559 to 0x47504A4D
[video4linux2,v4l2 @ 0xffff40000b50] Trying to set codec:rawvideo pix_fmt:yuv420p
[video4linux2,v4l2 @ 0xffff40000b50] The V4L2 driver changed the pixel format from 0x32315659 to 0x47504A4D
[video4linux2,v4l2 @ 0xffff40000b50] Trying to set codec:rawvideo pix_fmt:yuv422p
[video4linux2,v4l2 @ 0xffff40000b50] The V4L2 driver changed the pixel format from 0x50323234 to 0x47504A4D
[video4linux2,v4l2 @ 0xffff40000b50] Trying to set codec:rawvideo pix_fmt:yuyv422
    nan    :  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0

Nothing in dmesg; journalctl shows this when first cam is started:

Dec 29 16:23:17 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Scheduling inhibition from ":1.14" "My SDL application" with cookie 18 and reason "Playing a game"
Dec 29 16:23:22 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Enforcing inhibition from ":1.14" "My SDL application" with cookie 18 and reason "Playing a game"
Dec 29 16:23:22 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Added change screen settings
Dec 29 16:23:22 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Added interrupt session
Dec 29 16:23:22 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Disabling DPMS due to inhibition
Dec 29 16:23:22 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Can't contact ck

...And then when the second is started

Dec 29 16:24:07 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Scheduling inhibition from ":1.14" "My SDL application" with cookie 19 and reason "Playing a game"
Dec 29 16:24:12 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Enforcing inhibition from ":1.14" "My SDL application" with cookie 19 and reason "Playing a game"
Dec 29 16:24:12 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Added change screen settings
Dec 29 16:24:12 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Added interrupt session
Dec 29 16:24:12 shed-pi4.xxx.xxx org_kde_powerdevil[2497]: powerdevil: Can't contact ck

Which might be the key or a red herring. The jury are still out according to Google!

If I stop ffplay for the first cam (video0), then the second 'hung' session (video2) will immediately spring in to life.

Other info:

# ls -lah /dev/v4l/by-path/
total 0
drwxr-xr-x 2 root root 120 Oct 21 15:01 .
drwxr-xr-x 4 root root  80 Oct 21 15:01 ..
lrwxrwxrwx 1 root root  12 Oct 21 15:01 platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4.3:1.0-video-index0 -> ../../video0
lrwxrwxrwx 1 root root  12 Oct 21 15:01 platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4.3:1.0-video-index1 -> ../../video1
lrwxrwxrwx 1 root root  12 Oct 21 15:01 platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4.4:1.0-video-index0 -> ../../video2
lrwxrwxrwx 1 root root  12 Oct 21 15:01 platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4.4:1.0-video-index1 -> ../../video3

# ls -lah /dev/v4l/by-id/
total 0
drwxr-xr-x 2 root root 80 Oct 21 15:01 .
drwxr-xr-x 4 root root 80 Oct 21 15:01 ..
lrwxrwxrwx 1 root root 12 Oct 21 15:01 usb-HD_Camera_Manufacturer_USB_2.0_Camera-video-index0 -> ../../video0
lrwxrwxrwx 1 root root 12 Oct 21 15:01 usb-HD_Camera_Manufacturer_USB_2.0_Camera-video-index1 -> ../../video1

# hwinfo --usb [Edit]
03: USB 00.1: 0000 Unclassified device
  [Created at usb.122]
  Unique ID: VfPh.nrd9O+1TtQ3
  Parent ID: 33sj.xvTGa+XkbXF
  SysFS ID: /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.4/1-1.4.4:1.1
  SysFS BusID: 1-1.4.4:1.1
  Hardware Class: unknown
  Model: "ARC International USB 2.0 Camera"
  Hotplug: USB
  Vendor: usb 0x05a3 "ARC International"
  Device: usb 0x9310 "USB 2.0 Camera"
  Driver: "uvcvideo"
  Driver Modules: "uvcvideo"
  Speed: 480 Mbps
  Module Alias: "usb:v05A3p9310d0000dcEFdsc02dp01ic0Eisc02ip00in01"
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #4 (Hub)

05: USB 00.2: 0000 Unclassified device
  [Created at usb.122]
  Unique ID: Wi1b.nrd9O+1TtQ3
  Parent ID: 33sj.xvTGa+XkbXF
  SysFS ID: /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.3/1-1.4.3:1.2
  SysFS BusID: 1-1.4.3:1.2
  Hardware Class: unknown
  Model: "ARC International USB 2.0 Camera"
  Hotplug: USB
  Vendor: usb 0x05a3 "ARC International"
  Device: usb 0x9310 "USB 2.0 Camera"
  Driver: "snd-usb-audio"
  Driver Modules: "snd_usb_audio"
  Speed: 480 Mbps
  Module Alias: "usb:v05A3p9310d0000dcEFdsc02dp01ic01isc01ip00in02"
  Driver Info #0:
    Driver Status: snd_usb_audio is active
    Driver Activation Cmd: "modprobe snd_usb_audio"
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #4 (Hub)


# lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
    |__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=uas, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 1: Dev 8, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 1: Dev 8, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 3: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 3: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 4: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
            |__ Port 4: Dev 7, If 1, Class=Video, Driver=uvcvideo, 480M
            |__ Port 4: Dev 7, If 2, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 4: Dev 7, If 0, Class=Video, Driver=uvcvideo, 480M
            |__ Port 4: Dev 7, If 3, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 3: Dev 6, If 2, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 3: Dev 6, If 0, Class=Video, Driver=uvcvideo, 480M
            |__ Port 3: Dev 6, If 3, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 3: Dev 6, If 1, Class=Video, Driver=uvcvideo, 480M
     
# v4l2-ctl --list-devices --verbose
USB 2.0 Camera: HD USB Camera (usb-0000:01:00.0-1.4.3):
        /dev/video0
        /dev/video1

USB 2.0 Camera: HD USB Camera (usb-0000:01:00.0-1.4.4):
        /dev/video2
        /dev/video3

VIDIOC_QUERYCAP: ok

I've been Googling all afternoon but so far drawn a blank. How can I get both cameras up and running simultaneously? I'm hoping that if I can get it working with ffplay then it will work with Motion.

Thanks in advance.

0

OK... I think this one is solved and, now I know what I am looking for, the answer is everywhere!

I'd set up my first camera at a resolution of 1280x720 and it worked a treat, with the Pi running at < 20% CPU so figured I could just plug in another camera and still have capacity to spare.

No. It seems the bottleneck is USB not CPU.

Firstly, if I plug multiple USB2 devices in to a USB3 hub, all the USB2 devices share one 480Mbs space, they don't each get a new one. I kind of knew that implicitly but I had it demonstrated explicitly! (D'oh!)

Secondly, the first camera appears to take all available bandwidth rather than just what it needs, so subsequent cameras don't get any. In my case, no errors, no warnings, we just sit there and wait. And wait. This problem can be fixed by setting a flag UVC_QUIRK_FIX_BANDWIDTH as follows:

# rmmod uvcvideo
# modprobe uvcvideo quirks=128

And make it permanent with

# cat /etc/modprobe.d/uvcvideo.conf
options uvcvideo quirks=128

Thirdly, and sadly, even this wasn't enough on its own and I had to drop the resolution to 640x480 and frame rate to 20.

Now Motion is all working with two cameras. It has been an interesting exercise but it's not until I discovered uvcvideo quirks and put that back in to Google I realised this issue is very well known indeed and has been answered many many times before. ...But you need to know about quirks to find out about quirks.

Heigh ho!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.