v4l2 fcntl.ioctl VIDIOC_S_PARM for setting fps and resolution of camera capture
python, v4l2, webcam
Solution
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.
Problem
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 ?