v4l-utils是一种用于处理媒体设备的软件包,它主要包含两个常用工具1:
它托管在[ v4l-utils.git ]中,并打包在大多数发行版中。提供了一系列库和实用程序,可用于控制板
l-utils还包含其他一些实用程序和库,用于处理视频4 Linux(V4L)设备驱动程序和相关功能。用于排查V4L2设备问题的实用程序。它可以检查设备连接、功能和参数配置,并生成详细的错误报告。
以下是v4l-utils中一些常用工具的简要说明:
这些工具可以单独使用,也可以与其他V4L2相关的库和应用程序一起使用,以实现更复杂的功能和操作。
这里只展开v4l2-ctl
v4l2-ctl --help 查询支持的所有命令
v4l2-ctl --help
General/Common options:
--all display all information available
-C, --get-ctrl=[, ...]
get the value of the controls [VIDIOC_G_EXT_CTRLS]
-c, --set-ctrl== [, = ...]
set the value of the controls [VIDIOC_S_EXT_CTRLS]
-D, --info show driver info [VIDIOC_QUERYCAP]
-d, --device=use device instead of /dev/video0
ifstarts with a digit, then /dev/video is used
-e, --out-device=use device for output streams instead of the
default device as set with --device
ifstarts with a digit, then /dev/video is used
-h, --help display this help message
--help-all all options
--help-io input/output options
--help-misc miscellaneous options
--help-overlay overlay format options
--help-sdr SDR format options
--help-selection crop/selection options
--help-stds standards and other video timings options
--help-streaming streaming options
--help-subdev sub-device options
--help-tuner tuner/modulator options
--help-vbi VBI format options
--help-vidcap video capture format options
--help-vidout vidout output format options
--help-edid edid handling options
-k, --concise be more concise if possible.
-l, --list-ctrls display all controls and their values [VIDIOC_QUERYCTRL]
-L, --list-ctrls-menus
display all controls and their menus [VIDIOC_QUERYMENU]
-r, --subset=[, , ]+
the subset of the N-dimensional array to get/set for control,
for every dimension an (, ) tuple is given.
--list-devices list all v4l devices
--log-status log the board status in the kernel log [VIDIOC_LOG_STATUS]
--get-priority query the current access priority [VIDIOC_G_PRIORITY]
--set-priority=
set the new access priority [VIDIOC_S_PRIORITY]
is 1 (background), 2 (interactive) or 3 (record)
--silent only set the result code, do not print any messages
--sleep=sleep , call QUERYCAP and close the file handle
--verbose turn on verbose ioctl status reporting
列出系统中所有的V4L2设备
下图2路usb摄像头
查询相机的详细信息 v4l2-ctl -d /dev/video11
rk3568_r:/ $ v4l2-ctl -d /dev/video11 --all
Driver Info:
Driver name : uvcvideo
Card type : USB2.0_ CAM2: USB2.0_ CAM2
Bus info : usb-fd800000.usb-1.1
Driver version : 4.19.219
Capabilities : 0x84a00001
Video Capture
Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV'
Field : None
Bytes per Line : 1280
Size Image : 614400
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Limited Range)
Flags :
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 640, Height 480
Default : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 640, Height 480, Flags:
Selection: crop_bounds, Left 0, Top 0, Width 640, Height 480, Flags:
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
//亮度
brightness 0x00980900 (int) : min=-64 max=64 step=1 default=0 value=0
//对比度
contrast 0x00980901 (int) : min=0 max=100 step=1 default=50 value=50
//饱和度
saturation 0x00980902 (int) : min=0 max=100 step=1 default=64 value=64
//色度
hue 0x00980903 (int) : min=-180 max=180 step=1 default=0 value=0
white_balance_temperature_auto 0x0098090c (bool) : default=1 value=1
gamma 0x00980910 (int) : min=100 max=500 step=1 default=300 value=300
power_line_frequency 0x00980918 (menu) : min=0 max=2 default=1 value=1
//白平衡
white_balance_temperature 0x0098091a (int) : min=2800 max=6500 step=10 default=4600 value=4600 flags=inactive
//锐度
sharpness 0x0098091b (int) : min=0 max=100 step=1 default=55 value=55
//背光补偿
backlight_compensation 0x0098091c (int) : min=0 max=2 step=1 default=0 value=0
//自动曝光
exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=3
exposure_absolute 0x009a0902 (int) : min=50 max=10000 step=1 default=166 value=166 flags=inactive
exposure_auto_priority 0x009a0903 (bool) : default=0 value=1
pan_absolute 0x009a0908 (int) : min=-57600 max=57600 step=3600 default=0 value=0
tilt_absolute 0x009a0909 (int) : min=-43200 max=43200 step=3600 default=0 value=0
//变焦
zoom_absolute 0x009a090d (int) : min=0 max=3 step=1 default=0 value=0
v4l2-ctl --list-framesizes=MJPG -d /dev/video11
v4l2-ctl --list-formats-ext --device /dev/video11
列出了 yuyv /mpeg 支持的多有分辨率 及帧率等
v4l2-ctl --list-formats-ext --device /dev/video11
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUYV 4:2:2
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 800x600
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1024x768
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1280x960
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1600x1304
Interval: Discrete 0.200s (5.000 fps)
Index : 1
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : Motion-JPEG
Size: Discrete 640x480
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 800x600
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1024x768
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1280x960
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1280x1024
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1600x1200
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 1600x1304
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
v4l2-ctl -d /dev/video11 --list-ctrls
不是所有相机以下参数设置都支持,修改前先查询,在已知参数属性的基础上修改.
exposure_auto是v4l2-ctl命令中的一个参数,用于设置相机的曝光模式。
exposure_auto的取值可以是以下几种:
v4l2-ctl -d /dev/video11 --set-ctrl exposure_auto=3
正常结果
而此设备可能是这个参数
打开相机来试试
linux可用cheese 显示设备
cheese -d /dev/video
或 GStreamer/ffmpeg。。
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
v4l2-ctl -d /dev/video1 --set-fmt-video=width=800,height=600,pixelformat=NV12 --stream-mmap=3 --stream-to=/sdcard/out.yuv --stream-skip=9 --stream-count=1 m-mmap=3 --stream-to=/sdcard/out.yuv --stream-skip=9 --stream-count=1
貌似不支持一次抓怕多张
for i in {1..10}; do
v4l2-ctl -d /dev/video0 --set-ctrl exposure_absolute=$(($i * 10)) --get-ctrl exposure_absolute --get-fmt-video width --get-fmt-video height --get-fmt-video pixfmt --get-fmt-video field --get-fmt-video timeperframe --get-fmt-video sizeimage --get-fmt-video planes --get-fmt-video depth --get-fmt-video fcc --get-fmt-video tvnorm --get-fmt-video width --get-fmt-video height --get-fmt-video pixfmt --get-fmt-video field --get-fmt-video timeperframe --get-fmt-video sizeimage --get-fmt-video planes --get-fmt-video depth --get-fmt-video fcc --get-fmt-video tvnorm --save /path/to/image-$i.jpg
done