v4l2-ctl 是 Linux 系统中用于控制 Video for Linux 2 (V4L2) 设备的命令行工具,主要用于管理摄像头、视频采集卡等多媒体设备的参数和功能。
安装v4l2-ctl:
apt install v4l-utils
查看设备节点:
ls /dev/video*
拍照:
v4l2-ctl -d /dev/video25 –set-fmt-video=width=2592,height=1944,pixelformat=MJPG –stream-mmap=3 –stream-skip=3 –stream-to=/userdata/media/T2025-test.jpg –stream-count=1 –stream-poll
录像:
v4l2-ctl –device /dev/video25 –set-fmt-video=width=960,height=540,pixelformat=MJPG –stream-mmap –stream-to=/userdata/media/T2025-test –stream-count=130
录像后的视频流封装为 mp4 格式:
/oem/usr/bin/ffmpeg -i /userdata/media/T2025-test -b:v 20M /userdata/media/T2025-test.mp4 -y
更多 v4l2-ctl 相关命令:
列出所有 V4L2 设备:v4l2-ctl –list-devices
查看摄像头支持的图像格式:v4l2-ctl -d /dev/video1 –list-formats
查看摄像头支持的格式和分辨率:v4l2-ctl -d /dev/video1 –list-formats-ext
查看摄像头所有参数:v4l2-ctl -d /dev/video1 –all
查看摄像头驱动信息:v4l2-ctl -d /dev/video1 -D
查看摄像头MJPG压缩格式所支持的分辨率(YUYV同样的方法,调整参数即可):
v4l2-ctl –list-framesizes=MJPG -d /dev/video1
设置参数: 将 /dev/video55 设备的图像格式设置为YUYV,分辨率为640×480:
v4l2-ctl -d /dev/video55 –set-fmt-video=width=640,height=480,pixelformat=NV12
查看配置是否成功:v4l2-ctl -d /dev/video55 –get-fmt-video
设置摄像头曝光参数:
v4l2-ctl -d /dev/video0 –set-ctrl=exposure_auto=1 # 1:使用非自动曝光,3:自动曝光
v4l2-ctl -d /dev/video0 –set-ctrl=exposure_absolute=1000
捕捉视频帧:设备捕获10帧视频数据,并保存为test_frame.yuv文件。 v4l2-ctl -d /dev/video55 –stream-mmap –stream-count=10 –stream-to=test_frame.yuv
更详细参数命令:
v4l2-ctl -d /dev/video55 –set-fmt-video=width=1920,height=1080,pixelformat=’NV12′ –stream-mmap=4 –stream-skip=3 –stream-to=/userdata/1080p60_nv12.rgb –stream-count=1 –stream-poll
参数说明:
-d /dev/video55 指定video设备
–set-fmt-video 指定宽高及pxielformat (pixelformat=NV12 格式 FourCC编码)
–stream-mmap 指定 buffer 的类型为 mmap
–stream-skip 指定丢弃(不保存到文件) 前 3 帧
–stream-to 指定帧数据保存的文件路径
–stream-count 指定抓取的帧数
–stream-poll 该选项指示 v4l2-ctl 采用异步 IO
media-ctl是 Linux 系统中用于配置和管理 V4L2(Video for Linux 2)子设备的命令行工具,它主要用于配置媒体控制器(Media Controller)框架下的复杂视频设备(如摄像头、图像传感器、CSI/DSI接口、图像处理单元等)的拓扑结构和数据流路径。
#!/bin/bash
# List all media entities and pads
echo “Listing all media entities and pads:”
media-ctl -p
# Set a specific link between two pads
# Example: Linking pad 0 of entity ‘ov5647 3-0036’ to pad 0 of entity ‘rkisp1-mainpath’:
echo “Setting link from ov5647 3-0036:0 to rkisp1-mainpath:0”
media-ctl –link “‘ov5647 3-0036′:0->’rkisp1-mainpath’:0″[1]
# Configure video formats
# Example: Setting format YUYV8_2X8 on pad 0 of entity ‘ov5647 3-0036’:
echo “Setting format YUYV8_2X8 on ov5647 3-0036:0″
media-ctl –set-v4l2 ‘”ov5647 3-0036”:0[fmt:=yuyv8_2x8/640×480]’
参考:https://blog.csdn.net/m0_49857167/article/details/145603913