Usb
在 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 控制器必須以其他方式處理它們。
如果兩個攝像頭都插入我 PC 上的單獨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 規則,更改名稱或添加 SYMLINK:
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==""
有沒有辦法讓他們同時錄製影片?
正如 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
-pixel_format和*-video_size**都*必須是
v4l2-ctl --list-formats-ext
輸出的組合,或者v4l2-ctl -d /dev/video0 (or other device) --list-formats-ext