V4L2 timeperframe weird behaviours
I'm currently building a capture software using the V4L2 API. The thing
is, when I fetch a frame I'm experimenting weird timing behaviours.
Basically, I set up the timeperframe capability according to the specs of
my webcam :
echo% v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUV 4:2:2 (YUYV)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.133s (7.500 fps)
Interval: Discrete 0.200s (5.000 fps)
Here I choose to capture YUYV 640x480 frames at 30 fps, so I set the
timeperframe capability :
FAIL_ON_NEGATIVE(ioctl(fd, VIDIOC_G_PARM, &setfps))
if (!(setfps.parm.capture.capability & V4L2_CAP_TIMEPERFRAME))
errx(1, "%s does not support frame rate settings", device);
BZERO_STRUCT(setfps)
setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
setfps.parm.capture.timeperframe.numerator = 1;
setfps.parm.capture.timeperframe.denominator = 30;
FAIL_ON_NEGATIVE(ioctl(fd, VIDIOC_S_PARM, &setfps))
I also check that the driver didn't change the numerator/denominator.
I request a frame :
FAIL_ON_NEGATIVE(select(fd + 1, &fds, NULL, NULL, NULL))
FAIL_ON_NEGATIVE(ioctl(fd, VIDIOC_DQBUF, &buf))
Surprisingly, at this point I found that the average delta time between
frames is 160 ms using the V4L2 timestamp field.
I did the same using another webcam and here I got my 30 fps at first but
then it stabilized at 133ms (2/15):
33 | 33 | 34 | 33 | 34 | 33 | 34 | 33 | 42 | 41 | 42 | 42 | 41 | 42 | 50 |
50 | 50 | 50 | 50 | 75 | 75 | 100 | 100 | 125 | 125 | 134 | 132 | 134 |
133 | 134 | 133 | 133 | 134 | 133 | 133 | 134 | 133 | 134
Using ffmpeg I have the same issue (160ms) :
ffmpeg -f video4linux2 -vcodec rawvideo -pix_fmt yuyv422 -s 640x480 -r 30
-i /dev/video0 out.yuv
frame= 109 fps=6.3 q=0.0 Lsize= 65400kB time=00:00:03.63
bitrate=147456.0kbits/s
What's going on ? Am I doing something wrong ?
No comments:
Post a Comment