V4l2-ctl

1 v4l-utils

v4l-utils是一种用于处理媒体设备的软件包,它主要包含两个常用工具1:

  1. media-ctl:用于配置拓扑结构中各节点的format、大小、链接;操作/dev/medio0节点;获取Camera支持数据格式等。
  2. v4l2-ctl:用于获取和设置v4l2设备的参数。

它托管在[ v4l-utils.git ]中,并打包在大多数发行版中。提供了一系列库和实用程序,可用于控制板

l-utils还包含其他一些实用程序和库,用于处理视频4 Linux(V4L)设备驱动程序和相关功能。用于排查V4L2设备问题的实用程序。它可以检查设备连接、功能和参数配置,并生成详细的错误报告。

以下是v4l-utils中一些常用工具的简要说明:

  1. v4l2-ctl:用于控制和配置V4L2设备的功能和参数。它可以设置图像分辨率、帧率、缩放、旋转等参数,以及控制摄像头的基本设置。
  2. v4l2-overlay:用于在屏幕上叠加图像或文本,以提供对图像的注释或标记。它可以将自定义的图像或文本叠加在视频流上,并支持透明度和位置调整。
  3. v4l2-format:用于查询和设置设备图像格式的实用程序。它可以列出设备支持的所有图像格式,并选择要使用的特定格式。
  4. v4l2-capture:用于捕获视频帧的实用程序。它可以读取设备缓存中的视频帧,并将其保存为图像文件或进行其他处理。
  5. v4l2-zoom:用于缩放视频图像的实用程序。它可以将图像放大或缩小,同时支持平滑的缩放效果。
  6. v4l2-exposure:用于控制摄像头曝光时间的实用程序。它可以设置曝光时间、曝光补偿、手动/自动曝光模式等参数。

这些工具可以单独使用,也可以与其他V4L2相关的库和应用程序一起使用,以实现更复杂的功能和操作。

这里只展开v4l2-ctl

2 v4l2-ctl

 v4l2-ctl --help 查询支持的所有命令

 v4l2-ctl --help

General/Common options:
  --all              display all information available
  -C, --get-ctrl=<ctrl>[,<ctrl>...]
                     get the value of the controls [VIDIOC_G_EXT_CTRLS]
  -c, --set-ctrl=<ctrl>=<val>[,<ctrl>=<val>...]
                     set the value of the controls [VIDIOC_S_EXT_CTRLS]
  -D, --info         show driver info [VIDIOC_QUERYCAP]
  -d, --device=<dev> use device <dev> instead of /dev/video0
                     if <dev> starts with a digit, then /dev/video<dev> is used
  -e, --out-device=<dev> use device <dev> for output streams instead of the
                     default device as set with --device
                     if <dev> starts with a digit, then /dev/video<dev> 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=<ctrl>[,<offset>,<size>]+
                     the subset of the N-dimensional array to get/set for control <ctrl>,
                     for every dimension an (<offset>, <size>) 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=<prio>
                     set the new access priority [VIDIOC_S_PRIORITY]
                     <prio> is 1 (background), 2 (interactive) or 3 (record)
  --silent           only set the result code, do not print any messages
  --sleep=<secs>     sleep <secs>, call QUERYCAP and close the file handle
  --verbose          turn on verbose ioctl status reporting
 

 2.1 常用命令

2.1.1 v4l2-ctl --list-devices  

列出系统中所有的V4L2设备

下图2路usb摄像头

 2.1.2  v4l2-ctl -d /dev/veoxx --all

查询相机的详细信息   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

2.1.3 查询指定格式下各种分辨率支持

v4l2-ctl --list-framesizes=MJPG -d /dev/video11

 2.1.4 查看usb摄像头所有可用的分辨率 

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)

 2.1.5 显示摄像头参数

 v4l2-ctl -d /dev/video11 --list-ctrls

2.2 设置相关命令

不是所有相机以下参数设置都支持,修改前先查询,在已知参数属性的基础上修改.

2.2.1 曝光模式

exposure_auto是v4l2-ctl命令中的一个参数,用于设置相机的曝光模式。

exposure_auto的取值可以是以下几种:

  1. Off:自动曝光时间调节处于禁用状态;
  2. Once:曝光时间会自动进行调整,以达到指定的目标值。当达到目标值时,自动功能将自动设为Off,并且新的参数值将应用到后续图像;
  3. Continuous:在采集图像时持续调整曝光时间。调整过程将持续,直到参数设为Once或Off为止。

v4l2-ctl -d /dev/video11 --set-ctrl exposure_auto=3

2.2.2 测试显示信息test_pattern

正常结果

 

2.2.3 增加图片亮度analogue_gain

 而此设备可能是这个参数

打开相机来试试

2.2.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

2.3 使用v4l2-ctl抓帧

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

 


 

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值