v4l2 fcntl.ioctl VIDIOC_S_PARM for setting fps and resolution of camera capture

本秂侑毒 提交于 2020-02-24 04:36:48

问题


I am trying to set fps and resolution of webcam and capture from it via v4l2 Python.

v4l2 Python documentation is limited to ;

>>> import v4l2
>>> import fcntl
>>> vd = open('/dev/video0', 'rw')
>>> cp = v4l2.v4l2_capability()
>>> fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
0
>>> cp.driver
'ov534'
>>> cp.card
'USB Camera-B4.09.24.1'

Looking at the videodev2.h ;

#define VIDIOC_S_PARM       _IOWR('V', 22, struct v4l2_streamparm)

VIDIOC_S_PARM is related to v4l2_streamparm that is ;

struct v4l2_streamparm {
    enum v4l2_buf_type type;
union {
    struct v4l2_captureparm capture;
    struct v4l2_outputparm  output;
    __u8    raw_data[200];  /* user-defined */
} parm;
};

And if I want to set the parameter ;

import v4l2
import fcntl
vd = open('/dev/video1', 'rw')
cp = v4l2.v4l2_streamparm()
fcntl.ioctl(vd, v4l2.v4l2_streamparm, cp)

this is as far as I could get.

How can I adjust fps rate and resolution of the camera using Python v4l2 and capture images from it ?


回答1:


From the V4L2 side, you need to:

  • use the VIDIOC_G_PARM ioctl and check the v4l2_streamparm.parm.capture.capability member to find out whether the driver allows V4L2_CAP_TIMEPERFRAME.
  • if so, use the VIDIOC_ENUM_FRAMEINTERVALS ioctl to get the list of possible frame intervals (inverse of framerates), in the form of v4l2_fract structures
  • use these values with the VIDIOC_S_PARM ioctl and fill in the v4l2_streamparm.parm.capture.timeperframe member.

That should allow setting the capture-side frame rate. It's your task to make sure you're reading fast enough not to get frame drops.



来源:https://stackoverflow.com/questions/13981933/v4l2-fcntl-ioctl-vidioc-s-parm-for-setting-fps-and-resolution-of-camera-capture

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!