我正在使用V4L2 API从UVC设备中抓取帧。我想通过计算帧的时间戳和当前时钟时间之间的偏移量来测量曝光时间。这是我正在使用的代码:

/* Control code snipped */
struct v4l2_buffer buf = {0}
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
ioctl(fd, VIDIOC_DQBUF, &buf);

switch( buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK )
{
    case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC:
    {
        struct timespec uptime = {0};
        clock_gettime(CLOCK_MONOTONIC,&uptime);

        float const secs =
            (buf.timestamp.tv_sec - uptime.tv_sec) +
            (buf.timestamp.tv_usec - uptime.tv_nsec/1000.0f)/1000.0f;

        if( V4L2_BUF_FLAG_TSTAMP_SRC_SOE == (buf.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) )
            printf("%s: frame exposure started %.03f seconds ago\n",__FUNCTION__,-secs);
        else if( V4L2_BUF_FLAG_TSTAMP_SRC_EOF == (buf.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) )
            printf("%s: frame finished capturing %.03f seconds ago\n",__FUNCTION__,-secs);
        else printf("%s: unsupported timestamp in frame\n",__FUNCTION__);

        break;
    }

    case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN:
    case V4L2_BUF_FLAG_TIMESTAMP_COPY:
    default:
        printf("%s: no usable timestamp found in frame\n",__FUNCTION__);
}

对于使用VIDIOC_S_CTRL设置的1秒曝光时间返回的结果的示例:
read_frame: frame exposure started 28.892 seconds ago
read_frame: frame exposure started 28.944 seconds ago
read_frame: frame exposure started 28.895 seconds ago
read_frame: frame exposure started 29.037 seconds ago

我得到了SRC_SOE时间戳和单调时钟之间30秒钟的怪异偏移,其中包含1秒钟的暴露 Weld 。应该从ktime_get_ts()的结果计算出V4L2/UVC时间戳。知道我在做什么错吗?

它可以在Linux 4.4 Gentoo系统上运行。网络摄像头是DMK21AU04.AS,被认为是标准UVC设备。

最佳答案

事情是...
1秒= 1000毫秒,
1毫秒= 1000us,
1我们= 1000ns。

所以...

它应该像...

float const secs =
        (buf.timestamp.tv_sec - uptime.tv_sec) +
        (buf.timestamp.tv_usec - uptime.tv_nsec/1000.0f)/1000000.0f;

关于linux - V4L2框架上的系统偏移,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40334608/

10-11 09:18