V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
SageKwun
V2EX  ›  问与答

请教各位大佬 uvc v4l2 的问题

  •  
  •   SageKwun · 67 天前 · 446 次点击
    这是一个创建于 67 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在做通过 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

    2 条回复    2024-02-23 16:16:10 +08:00
    ysc3839
        1
    ysc3839  
       67 天前 via Android
    先用 Guvcview 试试有没有问题?
    SageKwun
        2
    SageKwun  
    OP
       67 天前
    @ysc3839 纯命令行,没有图形界面。。采集画面和控制之前通过别的软件试过了,是可以的,主要是这个拓展的部分需要自己编码实现,跑不通(之前没有做过这方面的)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1136 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 18:01 · PVG 02:01 · LAX 11:01 · JFK 14:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.