最近在做通过 uvc/v4l2 控制相机的内容,是通过拓展单元来控制的,但是代码跑不通
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#define DEVICE_PATH "/dev/video0" // 替换为你的 UVC 设备路径
#define XU_CONTROL_ID 0x06 // 替换为控制内录的 XU 控制 ID
int main() {
int fd;
struct v4l2_ext_control ext_ctrl;
struct v4l2_ext_controls ext_ctrls;
int result;
fd = open(DEVICE_PATH, O_RDWR);
if (fd < 0) {
perror("打开设备失败");
return -1;
}
// 设置 UVC 扩展控制来开启 1080p60fps 内录
ext_ctrl.id = XU_CONTROL_ID;
ext_ctrl.size = 0x01;
ext_ctrl.value = 0x34; // 该值用于开启 1080p60fps 内录
ext_ctrls.ctrl_class = V4L2_CTRL_CLASS_USER;
ext_ctrls.count = 1;
ext_ctrls.controls = &ext_ctrl;
result = ioctl(fd, VIDIOC_S_EXT_CTRLS, &ext_ctrls);
if (result) {
perror("设置扩展控制失败");
close(fd);
return -1;
}
printf("成功开启 1080p60fps 内录\n");
close(fd);
return 0;
}
bLength : 0x19 (25 bytes)
bDescriptorType : 0x24 (Video Control Interface)
bDescriptorSubtype : 0x06 (Extension Unit)
bUnitID : 0x06 (ID 6)
guidExtensionCode :
{41769EA2-04DE-E347-8B2B-F4341AFF003B}
bNumControls : 0x02 (2 Controls)
bNrInPins : 0x00 (0 Input Pin)
bControlSize : 0x01 (1 bytes)
bmControls : 0x03
D0 字段 uint8_t value 说明
0 0x30 关闭内录
0x31 开启内录 1080p25fps
0x32 开启内录 1080p30fps
0x33 开启内录 1080p50fps
0x34 开启内录 1080p60fps
1~14 保留 默认为 0x00
15 length 默认为 0x0F
结果:
设置扩展控制失败: Invalid argument
Process finished with exit code 255
1
ysc3839 278 天前 via Android
先用 Guvcview 试试有没有问题?
|