3

I want to use 2 identical USB cameras to record video on Raspberry Pi 4 1GB (Raspbian 10). Both cameras have identical VID:PID (05a3:9530) and Serial number (SN5100), so only one of them records video at any given time.

What is strange to me, if I take photo with them:

fswebcam -d /dev/video0

or

fswebcam -d /dev/video2

it always takes photo by correct camera. So there must be some other way the OS or USB Controller is adressing them.

If both cameras are plugged in separate USB controllers on my PC, they both record video simultaneously. However, RPi doesn't have that option.

What I tried:

  • Adding both cameras to OBS - only first added works
  • Using them with MotionEye - same as OBS
  • Using 2 different USB cameras - both work simultaneously, unfortunately this workaround is not the solution for my problem

  • Playing stream from cameras with ffmpeg:

ffplay -f video4linux2 -i /dev/video0

and

ffplay -f video4linux2 -i /dev/video2

First one plays OK, the second camera outputs in terminal:

nan: 0.000 fd= 0 aq= 0KB vq= 0KB sq= 0KB f= 0/0

When terminating first stream, second camera starts working instantly.

  • Problem persists on any computer I tried when plugged in USB ports managed by same USB controller
  • Using USB hub
  • Writing in sys/bus/usb/devices/1-1.4/idProduct new PID - file not writable

  • Adding custom udev rule for 1 USB port changing NAME or adding SYMLINK:

KERNEL=="1-1.4", NAME="device_1_4"

or

KERNEL=="1-1.4", SYMLINK+="device_1_4"

Note that there is no other way to distuinguish between them based on output from:

udevadm info --attribute-walk --path=/sys/bus/usb/devices/1-1.4

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4':
    KERNEL=="1-1.4"
    SUBSYSTEM=="usb"
    DRIVER=="usb"
    ATTR{manufacturer}=="Sonix Technology Co., Ltd."
    ATTR{maxchild}=="0"
    ATTR{idVendor}=="05a3"
    ATTR{bNumInterfaces}==" 2"
    ATTR{authorized}=="1"
    ATTR{bMaxPacketSize0}=="64"
    ATTR{devpath}=="1.4"
    ATTR{bNumConfigurations}=="1"
    ATTR{configuration}==""
    ATTR{removable}=="unknown"
    ATTR{urbnum}=="55639"
    ATTR{rx_lanes}=="1"
    ATTR{bmAttributes}=="80"
    ATTR{version}==" 2.00"
    ATTR{idProduct}=="9530"
    ATTR{serial}=="SN5100"
    ATTR{bDeviceSubClass}=="02"
    ATTR{bDeviceClass}=="ef"
    ATTR{bDeviceProtocol}=="01"
    ATTR{product}=="USB 2.0 Camera"
    ATTR{devspec}=="  (null)"
    ATTR{avoid_reset_quirk}=="0"
    ATTR{ltm_capable}=="no"
    ATTR{devnum}=="11"
    ATTR{bMaxPower}=="256mA"
    ATTR{quirks}=="0x0"
    ATTR{tx_lanes}=="1"
    ATTR{speed}=="480"
    ATTR{bcdDevice}=="0100"
    ATTR{bConfigurationValue}=="1"
    ATTR{busnum}=="1"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{busnum}=="1"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{speed}=="480"
    ATTRS{urbnum}=="455"
    ATTRS{product}=="USB2.0 Hub"
    ATTRS{quirks}=="0x0"
    ATTRS{devspec}=="  (null)"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{ltm_capable}=="no"
    ATTRS{idProduct}=="3431"
    ATTRS{idVendor}=="2109"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{maxchild}=="4"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{tx_lanes}=="1"
    ATTRS{devnum}=="2"
    ATTRS{removable}=="unknown"
    ATTRS{bcdDevice}=="0421"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{configuration}==""
    ATTRS{version}==" 2.10"
    ATTRS{rx_lanes}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{devpath}=="1"
    ATTRS{authorized}=="1"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{speed}=="480"
    ATTRS{idProduct}=="0002"
    ATTRS{maxchild}=="1"
    ATTRS{bcdDevice}=="0419"
    ATTRS{devnum}=="1"
    ATTRS{tx_lanes}=="1"
    ATTRS{manufacturer}=="Linux 4.19.97-v7l+ xhci-hcd"
    ATTRS{idVendor}=="1d6b"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{removable}=="unknown"
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{busnum}=="1"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{serial}=="0000:01:00.0"
    ATTRS{authorized}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{devspec}=="  (null)"
    ATTRS{version}==" 2.00"
    ATTRS{bDeviceClass}=="09"
    ATTRS{urbnum}=="201"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{ltm_capable}=="no"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{devpath}=="0"
    ATTRS{rx_lanes}=="1"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{configuration}==""

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0':
    KERNELS=="0000:01:00.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{consistent_dma_mask_bits}=="64"
    ATTRS{local_cpus}=="f"
    ATTRS{enable}=="1"
    ATTRS{broken_parity_status}=="0"
    ATTRS{devspec}==""
    ATTRS{dma_mask_bits}=="64"
    ATTRS{device}=="0x3483"
    ATTRS{max_link_width}=="1"
    ATTRS{class}=="0x0c0330"
    ATTRS{driver_override}=="(null)"
    ATTRS{irq}=="54"
    ATTRS{ari_enabled}=="0"
    ATTRS{subsystem_device}=="0x3483"
    ATTRS{msi_bus}=="1"
    ATTRS{vendor}=="0x1106"
    ATTRS{subsystem_vendor}=="0x1106"
    ATTRS{revision}=="0x01"
    ATTRS{current_link_width}=="1"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{current_link_speed}=="5 GT/s"
    ATTRS{max_link_speed}=="5 GT/s"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0':
    KERNELS=="0000:00:00.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="pcieport"
    ATTRS{max_link_speed}=="5 GT/s"
    ATTRS{broken_parity_status}=="0"
    ATTRS{subsystem_vendor}=="0x0000"
    ATTRS{aer_rootport_total_err_cor}=="0"
    ATTRS{max_link_width}=="1"
    ATTRS{current_link_width}=="1"
    ATTRS{secondary_bus_number}=="1"
    ATTRS{driver_override}=="(null)"
    ATTRS{vendor}=="0x14e4"
    ATTRS{class}=="0x060400"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{irq}=="53"
    ATTRS{device}=="0x2711"
    ATTRS{subsystem_device}=="0x0000"
    ATTRS{subordinate_bus_number}=="1"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{msi_bus}=="1"
    ATTRS{devspec}==""
    ATTRS{current_link_speed}=="5 GT/s"
    ATTRS{aer_rootport_total_err_fatal}=="0"
    ATTRS{local_cpus}=="f"
    ATTRS{ari_enabled}=="0"
    ATTRS{revision}=="0x10"
    ATTRS{aer_rootport_total_err_nonfatal}=="0"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{enable}=="1"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/platform/scb/fd500000.pcie':
    KERNELS=="fd500000.pcie"
    SUBSYSTEMS=="platform"
    DRIVERS=="brcm-pcie"
    ATTRS{dmabounce_stats}=="m:0/0 s:0/0 f:0 s:0 b:0/0 a:0/0"
    ATTRS{driver_override}=="(null)"

  looking at parent device '/devices/platform/scb':
    KERNELS=="scb"
    SUBSYSTEMS=="platform"
    DRIVERS==""
    ATTRS{driver_override}=="(null)"

  looking at parent device '/devices/platform':
    KERNELS=="platform"
    SUBSYSTEMS==""
    DRIVERS==""

And for second camera:

udevadm info --attribute-walk --path=/sys/bus/usb/devices/1-1.1

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1':
    KERNEL=="1-1.1"
    SUBSYSTEM=="usb"
    DRIVER=="usb"
    ATTR{devspec}=="  (null)"
    ATTR{urbnum}=="146921"
    ATTR{tx_lanes}=="1"
    ATTR{configuration}==""
    ATTR{speed}=="480"
    ATTR{bNumInterfaces}==" 2"
    ATTR{manufacturer}=="Sonix Technology Co., Ltd."
    ATTR{bDeviceProtocol}=="01"
    ATTR{devpath}=="1.1"
    ATTR{busnum}=="1"
    ATTR{bcdDevice}=="0100"
    ATTR{bMaxPower}=="256mA"
    ATTR{version}==" 2.00"
    ATTR{serial}=="SN5100"
    ATTR{bDeviceClass}=="ef"
    ATTR{bConfigurationValue}=="1"
    ATTR{product}=="USB 2.0 Camera"
    ATTR{idProduct}=="9530"
    ATTR{avoid_reset_quirk}=="0"
    ATTR{idVendor}=="05a3"
    ATTR{bNumConfigurations}=="1"
    ATTR{bDeviceSubClass}=="02"
    ATTR{rx_lanes}=="1"
    ATTR{authorized}=="1"
    ATTR{maxchild}=="0"
    ATTR{removable}=="unknown"
    ATTR{bMaxPacketSize0}=="64"
    ATTR{ltm_capable}=="no"
    ATTR{bmAttributes}=="80"
    ATTR{devnum}=="9"
    ATTR{quirks}=="0x0"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{quirks}=="0x0"
    ATTRS{bmAttributes}=="e0"
    ATTRS{tx_lanes}=="1"
    ATTRS{devnum}=="2"
    ATTRS{configuration}==""
    ATTRS{authorized}=="1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{product}=="USB2.0 Hub"
    ATTRS{idProduct}=="3431"
    ATTRS{idVendor}=="2109"
    ATTRS{busnum}=="1"
    ATTRS{devpath}=="1"
    ATTRS{urbnum}=="473"
    ATTRS{bcdDevice}=="0421"
    ATTRS{removable}=="unknown"
    ATTRS{maxchild}=="4"
    ATTRS{speed}=="480"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{devspec}=="  (null)"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{rx_lanes}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{version}==" 2.10"
    ATTRS{avoid_reset_quirk}=="0"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{tx_lanes}=="1"
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{rx_lanes}=="1"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{idVendor}=="1d6b"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{urbnum}=="210"
    ATTRS{devpath}=="0"
    ATTRS{bmAttributes}=="e0"
    ATTRS{ltm_capable}=="no"
    ATTRS{idProduct}=="0002"
    ATTRS{bDeviceClass}=="09"
    ATTRS{configuration}==""
    ATTRS{version}==" 2.00"
    ATTRS{bcdDevice}=="0419"
    ATTRS{serial}=="0000:01:00.0"
    ATTRS{busnum}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{devnum}=="1"
    ATTRS{manufacturer}=="Linux 4.19.97-v7l+ xhci-hcd"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{speed}=="480"
    ATTRS{authorized}=="1"
    ATTRS{devspec}=="  (null)"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{quirks}=="0x0"
    ATTRS{maxchild}=="1"
    ATTRS{removable}=="unknown"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bNumConfigurations}=="1"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0':
    KERNELS=="0000:01:00.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{class}=="0x0c0330"
    ATTRS{current_link_speed}=="5 GT/s"
    ATTRS{msi_bus}=="1"
    ATTRS{revision}=="0x01"
    ATTRS{vendor}=="0x1106"
    ATTRS{driver_override}=="(null)"
    ATTRS{max_link_width}=="1"
    ATTRS{broken_parity_status}=="0"
    ATTRS{devspec}==""
    ATTRS{dma_mask_bits}=="64"
    ATTRS{ari_enabled}=="0"
    ATTRS{enable}=="1"
    ATTRS{irq}=="54"
    ATTRS{subsystem_vendor}=="0x1106"
    ATTRS{device}=="0x3483"
    ATTRS{max_link_speed}=="5 GT/s"
    ATTRS{current_link_width}=="1"
    ATTRS{consistent_dma_mask_bits}=="64"
    ATTRS{subsystem_device}=="0x3483"
    ATTRS{local_cpus}=="f"
    ATTRS{local_cpulist}=="0-3"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0':
    KERNELS=="0000:00:00.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="pcieport"
    ATTRS{revision}=="0x10"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{irq}=="53"
    ATTRS{subsystem_device}=="0x0000"
    ATTRS{msi_bus}=="1"
    ATTRS{max_link_width}=="1"
    ATTRS{broken_parity_status}=="0"
    ATTRS{enable}=="1"
    ATTRS{subordinate_bus_number}=="1"
    ATTRS{subsystem_vendor}=="0x0000"
    ATTRS{current_link_width}=="1"
    ATTRS{driver_override}=="(null)"
    ATTRS{device}=="0x2711"
    ATTRS{aer_rootport_total_err_cor}=="0"
    ATTRS{ari_enabled}=="0"
    ATTRS{local_cpus}=="f"
    ATTRS{class}=="0x060400"
    ATTRS{max_link_speed}=="5 GT/s"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{aer_rootport_total_err_nonfatal}=="0"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{current_link_speed}=="5 GT/s"
    ATTRS{aer_rootport_total_err_fatal}=="0"
    ATTRS{secondary_bus_number}=="1"
    ATTRS{devspec}==""
    ATTRS{vendor}=="0x14e4"

  looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/platform/scb/fd500000.pcie':
    KERNELS=="fd500000.pcie"
    SUBSYSTEMS=="platform"
    DRIVERS=="brcm-pcie"
    ATTRS{driver_override}=="(null)"
    ATTRS{dmabounce_stats}=="m:0/0 s:0/0 f:0 s:0 b:0/0 a:0/0"

  looking at parent device '/devices/platform/scb':
    KERNELS=="scb"
    SUBSYSTEMS=="platform"
    DRIVERS==""
    ATTRS{driver_override}=="(null)"

  looking at parent device '/devices/platform':
    KERNELS=="platform"
    SUBSYSTEMS==""
    DRIVERS==""

Is there a way to make them record video both at once?

7
  • How are you trying to record video from them? May 14, 2020 at 15:50
  • I tried Motioneye, ffmpeg, OBS - same results on all of them
    – Loproc
    May 14, 2020 at 17:42
  • Great. Please add that to your question because it's useful information and it doesn't deserve to get lost in a list of comments. May 14, 2020 at 17:42
  • 1
    Maybe the USB is saturated. With USB 2.0 you can use effective speeds of around 40 MB/s. Recording raw 720p yuyv422 images at 15 fps will hit that limit already.
    – Hermann
    May 15, 2020 at 9:03
  • 2
    I do not know how to check USB utilization on-wire. I looked at the data-rate of one camera with ffmpeg -hide_banner -loglevel error -f v4l2 -pixel_format yuyv422 -video_size 1280x720 -framerate 15 -i /dev/video0 -c:v copy -f rawvideo - | pv > /dev/null. pv shows you an approximate value. I do not know how bad the overhead of is. It is possible that one camera at 40MB/s works, but two cameras work only on 10MB/s since you lose the other 20MB/s due to switching communication on the bus.
    – Hermann
    May 15, 2020 at 9:48

1 Answer 1

1

As stated by Hermann in comments, streaming video from both USB cameras was made possible with:

  • FFMPEG:
ffplay -f v4l2 -pixel_format mjpeg -video_size 1280x720 -framerate 30 -i /dev/video0

and

ffplay -f v4l2 -pixel_format mjpeg -video_size 1280x720 -framerate 30 -i /dev/video2

Both -pixel_format and -video_size must be combination from v4l2-ctl --list-formats-ext output or v4l2-ctl -d /dev/video0 (or other device) --list-formats-ext

2
  • 1
    Regarding the low frame-rate: It is possible that the cameras cannot supply high frame-rates when delivering uncompressed (YUV) frames. Compressed (MJPEG) streams might yield higher frame-rates. You can ask the driver what is possible via v4l2-ctl --list-formats-ext.
    – Hermann
    May 20, 2020 at 23:14
  • Thank you, it worked. Updated the solution.
    – Loproc
    May 25, 2020 at 9:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .