在 Raspberry PI 上使用 2 个相同的摄像头同时录制视频

在 Raspberry PI 上使用 2 个相同的摄像头同时录制视频

我想使用 2 个相同的 USB 摄像头在 Raspberry Pi 4 1GB (Raspbian 10) 上录制视频。两台摄像机具有相同的 VID:PID ( 05a3:9530) 和序列号 (SN5100),因此在任何给定时间只有其中一台录制视频。

如果我和他们合影,我会觉得奇怪:

fswebcam -d /dev/video0

或者

fswebcam -d /dev/video2

它总是用正确的相机拍照。因此操作系统或 USB 控制器必须有其他方式来处理它们。

如果两个摄像头均已插入分离我的电脑上有 USB 控制器,它们同时录制视频。然而,RPi 没有这个选项。

我尝试过的:

  • 将两个摄像机添加到 OBS - 仅第一个添加的作品
  • 将它们与 MotionEye 一起使用 - 与 OBS 相同
  • 使用 2 个不同的 USB 摄像头 - 两个摄像头同时工作,不幸的是这个解决方法不能解决我的问题

  • 使用 ffmpeg 播放来自摄像机的流:

ffplay -f video4linux2 -i /dev/video0

ffplay -f video4linux2 -i /dev/video2

第一个摄像头播放正常,第二个摄像头在终端输出:

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

当终止第一个流时,第二个摄像头立即开始工作。

  • 当插入由我管理的 USB 端口时,问题仍然存在于我尝试过的任何计算机上相同的USB控制器
  • 使用 USB 集线器
  • 写入sys/bus/usb/devices/1-1.4/idProduct新 PID - 文件不可写

  • 为 1 个 USB 端口添加自定义 udev 规则,更改名称或添加符号链接:

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

或者

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

请注意,没有其他方法可以根据以下输出来区分它们:

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==""

对于第二个相机:

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==""

有没有办法让他们同时录制视频?

答案1

正如 Hermann 在评论中所述,两个 USB 摄像头的流式传输视频是通过以下方式实现的:

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

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

两个都-像素格式-视频大小必须是v4l2-ctl --list-formats-ext输出的组合或v4l2-ctl -d /dev/video0 (or other device) --list-formats-ext

相关内容