获得v4l2视频设备的最高分辨率

时间:2013-03-12 10:38:20

标签: linux resolution video-capture v4l2

如何才能检测连接的视频设备能够提供的最大分辨率?

我不想捕获任何内容,只需从v4l2中检索此信息。

谢谢!

1 个答案:

答案 0 :(得分:7)

使用VIDIOC_ENUM_FRAMESIZES ioctl:

    enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    struct v4l2_fmtdesc fmt;
    struct v4l2_frmsizeenum frmsize;
    struct v4l2_frmivalenum frmival;

    fmt.index = 0;
    fmt.type = type;
    while (ioctl(fd, VIDIOC_ENUM_FMT, &fmt) >= 0) {
        frmsize.pixel_format = fmt.pixelformat;
        frmsize.index = 0;
        while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0) {
            if (frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
                printf("%dx%d\n", 
                                  frmsize.discrete.width,
                                  frmsize.discrete.height);
            } else if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
                printf("%dx%d\n", 
                                  frmsize.stepwise.max_width,
                                  frmsize.stepwise.max_height);
            }
                frmsize.index++;
            }
            fmt.index++;
    }

afaik,VIDIOC_ENUM_FRAMESIZES在linux-2.6.29中引入

相关问题