【GStreamer 】2-ubuntu v4l2-ctl 查看USB 相机基本参数

本文介绍Linux下的V4L2视频设备驱动,并详细解释如何使用v4l2-ctl工具来查看和调整USB摄像头的各项参数,包括分辨率、帧率、曝光、增益等。

        v4l2是Video4linux2的简称,是linux中关于视频设备的内核驱动,在Linux中,视频设备是设备文件,可以像访问普通文件一样对其进行读写,摄像头设备文件位置是/dev/video0。V4L2在设计时,是要支持很多广泛的设备的,它们之中只有一部分在本质上是真正的视频设备。

        因为我们这篇文章不涉及内核部分摄像头驱动的实现,大致可以简单说下,内核部分的实现分两部分:

1.我们要根据摄像头的种类,实现具体的摄像头传感器的驱动,这里可能有一些数据和控制的通信总线的协议。

2.然后这个具体的驱动需要适配这个v4l2这个框架,然后向用户层映射成一个字符设备文件。

        而我们的主题就是对这个设备文件进行操作,这就是应用层该做的事。

目录

1 v4l2-ctl 常用命令介绍:

2 查看系统识别的USB 相机设备:

3 显示测试----需要桌面终端的配合

4 ubuntu下使用v4l2-ctl查看USB摄像头参数

4.1 查看可被调用的设备

4.2 查看摄像头所支持的指定格式的分辨率

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

4.4 相机的曝光增益查询

4.5 修改增益参数

4.6 相机参数说明


1 v4l2-ctl 常用命令介绍:

#List all video devices:
v4l2-ctl --list-devices
​
#List supported video formats and resolutions of default video device 
v4l2-ctl --list-formats-ext
​
#List supported video formats and resolutions of a specific video device:
v4l2-ctl --list-formats-ext --device path/to/video_device
#eg:
v4l2-ctl --list-formats-ext --device /dev/video0
​
#Get all details of a video device:
v4l2-ctl --all --device path/to/video_device
#eg:
v4l2-ctl --all --device /dev/video0
​
#Capture a JPEG photo with a specific resolution from video device:
v4l2-ctl --device path/to/video_device --set-fmt-video=width=width,height=height,pixelformat=MJPG --stream-mmap --stream-to=path/to/output.jpg --stream-count=1
#eg:
v4l2-ctl --device /dev/video0 --set-fmt-video=width=1280,height=720,pixelformat=MJPG --stream-mmap --stream-to=/home/nvidia/Pictures/video0-output.jpg --stream-count=1
​
#Capture a raw video stream from video device:
v4l2-ctl --device path/to/video_device --set-fmt-video=width=width,height=height,pixelformat=format --stream-mmap --stream-to=path/to/output --stream-count=number_of_frames_to_capture
#eg:
v4l2-ctl --device /dev/video0 --set-fmt-video=width=1280,height=720,pixelformat=MJPG --stream-mmap --stream-to=/home/nvidia/Pictures --stream-count=10
​
#List all video device's controls and their values:
v4l2-ctl --list-ctrls --device /path/to/video_device
#eg:
v4l2-ctl --list-ctrls --device /dev/video0

2 查看系统识别的USB 相机设备:

ls /dev/video*

 
ls /dev/v*

 

 

3 显示测试----需要桌面终端的配合

cheese -d /dev/video0

 

4 ubuntu下使用v4l2-ctl查看USB摄像头参数

v4l2-ctl -d  /dev/video0 --all

如果没有相关命令,请安装

v4l2-ctl --all -d /dev/video0查看相机参数时报错:

v4l2-ctl :command not found

手动安装:

sudo apt-get install v4l-utils

相机详细信息(我自己的):

v4l2-ctl -d  /dev/video0 --all
v4l2-ctl --list-ctrls --device /dev/video0
                     brightness 0x00980900 (int)    : min=-64 max=64 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=64 step=1 default=32 value=32
                     saturation 0x00980902 (int)    : min=0 max=128 step=1 default=64 value=64
                 &
cp@cp:~$ sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav Reading package lists... Done Building dependency tree... Done Reading state information... Done gstreamer1.0-tools is already the newest version (1.24.2-1ubuntu0.1). gstreamer1.0-plugins-base is already the newest version (1.24.2-1ubuntu0.3). gstreamer1.0-plugins-good is already the newest version (1.24.2-1ubuntu1.2). gstreamer1.0-plugins-bad is already the newest version (1.24.2-1ubuntu4). gstreamer1.0-plugins-ugly is already the newest version (1.24.1-1build1). gstreamer1.0-libav is already the newest version (1.24.1-1build1). The following package was automatically installed and is no longer required: libllvm19 Use 'sudo apt autoremove' to remove it. 0 upgraded, 0 newly installed, 0 to remove and 43 not upgraded. cp@cp:~$ sudo apt install v4l-utils libgstreamer-plugins-bad1.0-0 gstreamer1.0-plugins-bad-videoparsers gstreamer1.0-plugins-bad-faad Reading package lists... Done Building dependency tree... Done Reading state information... Done Note, selecting 'gstreamer1.0-plugins-bad' instead of 'gstreamer1.0-plugins-bad-videoparsers' Note, selecting 'gstreamer1.0-plugins-bad' instead of 'gstreamer1.0-plugins-bad-faad' v4l-utils is already the newest version (1.26.1-4build3). libgstreamer-plugins-bad1.0-0 is already the newest version (1.24.2-1ubuntu4). libgstreamer-plugins-bad1.0-0 set to manually installed. gstreamer1.0-plugins-bad is already the newest version (1.24.2-1ubuntu4). The following package was automatically installed and is no longer required: libllvm19 Use 'sudo apt autoremove' to remove it. 0 upgraded, 0 newly installed, 0 to remove and 43 not upgraded. cp@cp:~$ sudo modprobe bcm2835-codec cp@cp:~$ echo "bcm2835-codec" | sudo tee -a /etc/modules bcm2835-codec cp@cp:~$ v4l2-ctl --list-devices pispbe (platform:1000880000.pisp_be): /dev/video20 /dev/video21 /dev/video22 /dev/video23 /dev/video24 /dev/video25 /dev/video26 /dev/video27 /dev/video28 /dev/video29 /dev/video30 /dev/video31 /dev/video32 /dev/video33 /dev/video34 /dev/video35 /dev/video36 /dev/video37 /dev/media2 /dev/media3 rp1-cfe (platform:1f00110000.csi): /dev/video0 /dev/video1 /dev/video2 /dev/video3 /dev/video4 /dev/video5 /dev/video6 /dev/video7 /dev/media0 rpivid (platform:rpivid): /dev/video19 /dev/media1
最新发布
12-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机器人虎哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值