首先是一些规格:我的电脑是 HP EliteBook 8460p。它带有一个集成的 Chicony HP 高清网络摄像头。
我的问题是很多应用程序(至少是 Skype 和 guvcview)为同一个网络摄像头显示多行;事实上,如果我这样做ls -l /dev | grep video
,我会得到以下信息:
crw-rw---- 1 root video 29, 0 Apr 16 08:13 fb0
crw-rw---- 1 root video 243, 0 Apr 16 08:13 media0
crw-rw----+ 1 root video 81, 0 Apr 16 08:13 video0
crw-rw----+ 1 root video 81, 1 Apr 16 08:13 video1
我有 2 个/dev/video[n]
,只有一个(集成)网络摄像头;Skype 可以正常工作/dev/video0
,但不能正常工作/dev/video1
。guvcview 也一样。
如果我插入另一个 USB 网络摄像头,例如罗技网络摄像头,我会得到以下信息dmesg
:
[21222.638802] usb 2-2: new high-speed USB device number 20 using xhci_hcd
[21222.970684] usb 2-2: New USB device found, idVendor=046d, idProduct=08c2, bcdDevice= 0.05
[21222.970755] usb 2-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[21222.972518] uvcvideo: Found UVC 1.00 device <unnamed> (046d:08c2)
[21226.044535] uvcvideo 2-2:1.0: Entity type for entity Extension 4 was not initialized!
[21226.044538] uvcvideo 2-2:1.0: Entity type for entity Extension 8 was not initialized!
[21226.044540] uvcvideo 2-2:1.0: Entity type for entity Extension 10 was not initialized!
[21226.044541] uvcvideo 2-2:1.0: Entity type for entity Extension 9 was not initialized!
[21226.044543] uvcvideo 2-2:1.0: Entity type for entity Extension 3 was not initialized!
[21226.044545] uvcvideo 2-2:1.0: Entity type for entity Processing 2 was not initialized!
[21226.044547] uvcvideo 2-2:1.0: Entity type for entity Camera 1 was not initialized!
[21226.044746] input: UVC Camera (046d:08c2) as /devices/pci0000:00/0000:00:1c.7/0000:25:00.0/usb2/2-2/2-2:1.0/input/input35
[21226.137559] usb 2-2: Warning! Unlikely big volume range (=3072), cval->res is probably wrong.
[21226.137569] usb 2-2: [5] FU [Mic Capture Volume] ch = 1, val = 4608/7680/1
以下是ls -l /dev/ | grep video
:
crw-rw---- 1 root video 29, 0 Apr 16 08:13 fb0
crw-rw---- 1 root video 243, 0 Apr 16 08:13 media0
crw-rw---- 1 root video 243, 1 Apr 16 14:06 media1
crw-rw----+ 1 root video 81, 0 Apr 16 08:13 video0
crw-rw----+ 1 root video 81, 1 Apr 16 08:13 video1
crw-rw----+ 1 root video 81, 2 Apr 16 14:06 video2
crw-rw----+ 1 root video 81, 3 Apr 16 14:06 video3
3 个新条目/dev/media1
:/dev/video2
和/dev/video3
。
我什至发现了一个索尼网络摄像头 (CEVCECM),它最多可以添加 4 个新设备。dmesg
日志:
[21927.665747] usb 2-2: new high-speed USB device number 23 using xhci_hcd
[21927.817330] usb 2-2: New USB device found, idVendor=05e3, idProduct=0608, bcdDevice= 9.01
[21927.817339] usb 2-2: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[21927.817343] usb 2-2: Product: USB2.0 Hub
[21927.824119] hub 2-2:1.0: USB hub found
[21927.824814] hub 2-2:1.0: 4 ports detected
[21928.113733] usb 2-2.4: new high-speed USB device number 24 using xhci_hcd
[21928.223184] usb 2-2.4: New USB device found, idVendor=054c, idProduct=097b, bcdDevice=21.12
[21928.223192] usb 2-2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[21928.223197] usb 2-2.4: Product: CEVCECM
[21928.223201] usb 2-2.4: Manufacturer: Sony
[21928.223206] usb 2-2.4: SerialNumber: DHZD10412EUHK1
[21928.227506] uvcvideo: Found UVC 1.00 device CEVCECM (054c:097b)
[21928.242592] uvcvideo: Unable to create debugfs 2-24 directory.
[21928.242780] uvcvideo 2-2.4:1.0: Entity type for entity Extension 7 was not initialized!
[21928.242783] uvcvideo 2-2.4:1.0: Entity type for entity Extension 3 was not initialized!
[21928.242785] uvcvideo 2-2.4:1.0: Entity type for entity Processing 2 was not initialized!
[21928.242787] uvcvideo 2-2.4:1.0: Entity type for entity Camera 1 was not initialized!
[21928.242877] input: CEVCECM: CEVCECM as /devices/pci0000:00/0000:00:1c.7/0000:25:00.0/usb2/2-2/2-2.4/2-2.4:1.0/input/input38
生成的设备文件包含ls -l /dev | grep video
:
crw-rw---- 1 root video 29, 0 Apr 16 08:13 fb0
crw-rw---- 1 root video 243, 0 Apr 16 08:13 media0
crw-rw---- 1 root video 243, 1 Apr 16 14:18 media1
crw-rw----+ 1 root video 81, 0 Apr 16 08:13 video0
crw-rw----+ 1 root video 81, 1 Apr 16 08:13 video1
crw-rw----+ 1 root video 81, 2 Apr 16 14:18 video2
crw-rw----+ 1 root video 81, 3 Apr 16 14:18 video3
crw-rw----+ 1 root video 81, 4 Apr 16 14:18 video4
crw-rw----+ 1 root video 81, 5 Apr 16 14:18 video5
5 个新条目:/dev/media1
和/dev/video2
到/dev/video5
.
我觉得要使用的文件是正确/dev/media[n]
的,但 Skype 和 guvcview 不知何故未能这样做并回退到/dev/video[n]
.
例如,我对 Webcamoid 没有这个问题。
如果有人有想法,我会接受。与此同时,我将继续调查......
--- 编辑了 2019-05-14 ---
得到了一些有趣的信息v4l2-ctl --device=/dev/video* --all
。对于群光惠普高清网络摄像头,其 2 个设备文件具有不同的设备功能:
# Devices capabilities for /dev/video0
Video Capture
Streaming
Extended Pix Format
# Devices capabilities for /dev/video1
Metadata Capture
Streaming
Extended Pix Format
对于 USB 网络摄像头,我得到了类似的结果。所以说到底,也许 Skype 和 guvcview 做不到的就是只列出支持Video Capture
设备功能的视频设备。
第二设备提供关于来自第一设备的视频数据的元数据。此补丁引入了新设备:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=088ead25524583e2200aa99111bea2f66a86545a
可以在此处找到有关 V4L 元数据接口的更多信息:
https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/dev-meta.html
对于普通的 USB 视频类设备,这主要只是提供更准确的时间戳信息。对于像英特尔的 RealSense 系列这样的相机,提供有关如何捕获图像的更广泛的数据。
据推测,这些数据被拆分到一个单独的设备节点中,因为它无法以兼容的方式轻松地传递到主设备节点上。但这有点痛苦,因为 (a) 不关心此元数据的应用程序现在需要过滤掉额外的设备,并且 (b) 关心元数据的应用程序需要一种将两个设备绑定在一起的方法.
真的很烦人,但刚刚找到了一个解决方案:让 udev 为设备节点分配符号链接,仅为“真实”摄像头,而不是元数据。它们与 udev 相同 (?),即
udevadm info -n /dev/video0
与 是“相同的”udevadm info -n /dev/video1
,但它们得到不同的 ATTR{index}。因此,对于我的 2 个摄像头,我得到了以下结果/etc/udev/rules.d/99-cam.rules
:之后,只需
/dev/cams/camX
在您的应用程序中使用,而不是/dev/videoY