USB 摄像头

操作环境:

  • 纽曼USB摄像头 camera-NM13-4K

  • LPA3588

  • Ubuntu20.04

查找USB摄像头文件名

插入USB摄像头,内核有如下日志:

neardi@LPA3588:~$ dmesg
[ 2740.549384] usb 7-1.2: new high-speed USB device number 6 using xhci-hcd
[ 2740.705306] usb 7-1.2: New USB device found, idVendor=1bcf, idProduct=0215, bcdDevice=34.07
[ 2740.705328] usb 7-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2740.705341] usb 7-1.2: Product: 4K AutoFocus Webcam
[ 2740.705353] usb 7-1.2: Manufacturer: 4K AutoFocus Webcam
[ 2740.775878] uvcvideo: Found UVC 1.00 device 4K AutoFocus Webcam (1bcf:0215)
[ 2741.037436] usb 7-1.2: Warning! Unlikely big volume range (=4096), cval->res is probably wrong.
[ 2741.037459] usb 7-1.2: [7] FU [Mic Capture Volume] ch = 1, val = 0/4096/1

也可以使用lsusb命令,列出所有的usb设备:

neardi@LPA3588:~$ lsusb
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 003: ID 0bda:9210 Realtek Semiconductor Corp. Ugreen Storage Device
Bus 008 Device 002: ID 05e3:0620 Genesys Logic, Inc. USB3.2 Hub
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 005: ID 046d:c534 Logitech, Inc. Unifying Receiver
Bus 007 Device 006: ID 1bcf:0215 Sunplus Innovation Technology Inc. 4K AutoFocus Webcam
Bus 007 Device 002: ID 05e3:0610 Genesys Logic, Inc. 4-port hub

其中设备ID为1bcf:0215的设备即为4K纽曼USB摄像头。

使用v4l2-ctl命令,列出所有视频设备:

neardi@LPA3588:~$ v4l2-ctl --list-devices
......
4K AutoFocus Webcam: 4K AutoFoc (usb-xhci-hcd.6.auto-1.2):
	/dev/video23
	/dev/video24
	/dev/media2

则表示设备ID为1bcf:0215的usb摄像头的设备文件名为/dev/video23和/dev/video24。

打开摄像头

查看摄像头支持的格式、分辨率及帧率:

neardi@LPA3588:~/samba$ v4l2-ctl -d /dev/video23 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Type: Video Capture

	[0]: 'MJPG' (Motion-JPEG, compressed)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)
	......
	[1]: 'YUYV' (YUYV 4:2:2)
		Size: Discrete 1920x1080
			Interval: Discrete 0.200s (5.000 fps)
			Interval: Discrete 0.200s (5.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.100s (10.000 fps)
		Size: Discrete 1600x900
			Interval: Discrete 0.200s (5.000 fps)
		Size: Discrete 640x360
			Interval: Discrete 0.033s (30.000 fps)
	.....

Gstreamer(推荐)

neardi@LPA3588:~$ gst-launch-1.0 v4l2src device=/dev/video23 ! video/x-raw,width=640,height=480,framerate=30/1  ! mpph264enc ! queue ! h264parse ! mppvideodec ! rkximagesink

V4l2工具

neardi@LPA3588:~$ sudo apt update
neardi@LPA3588:~$ sudo apt install qv4l2
neardi@LPA3588:~$ qv4l2 -d /dev/video23

ffplay

neardi@LPA3588:~$ ffplay /dev/video23