v4l2 fcntl.ioctl VIDIOC_S_PARM 用于设置相机捕获的 fps 和分辨率 [英] v4l2 fcntl.ioctl VIDIOC_S_PARM for setting fps and resolution of camera capture
问题描述
我正在尝试设置网络摄像头的 fps 和分辨率,并通过 v4l2 Python 从中捕获.
v4l2 Python 文档仅限于 ;
<预><代码>>>>导入 v4l2>>>导入 fcntl>>>vd = open('/dev/video0', 'rw')>>>cp = v4l2.v4l2_capability()>>>fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)0>>>驱动程序'ov534'>>>卡'USB 摄像头-B4.09.24.1'查看videodev2.h ;
#define VIDIOC_S_PARM _IOWR('V', 22, struct v4l2_streamparm)
VIDIOC_S_PARM 与 v4l2_streamparm 相关,即;
struct v4l2_streamparm {枚举 v4l2_buf_type 类型;联合{struct v4l2_captureparm 捕获;struct v4l2_outputparm 输出;__u8 原始数据[200];/* 用户自定义 */} 参数;};
如果我想设置参数;
import v4l2导入 fcntlvd = open('/dev/video1', 'rw')cp = v4l2.v4l2_streamparm()fcntl.ioctl(vd, v4l2.v4l2_streamparm, cp)
这是我所能得到的.
如何使用 Python v4l2 调整相机的 fps 速率和分辨率并从中捕获图像?
从 V4L2 方面,您需要:
- 使用
VIDIOC_G_PARM
ioctl 并检查v4l2_streamparm.parm.capture.capability
成员以了解驱动程序是否允许V4L2_CAP_TIMEPERFRAME
. - 如果是这样,请使用
VIDIOC_ENUM_FRAMEINTERVALS
ioctl 以v4l2_fract
结构 - 将这些值与
VIDIOC_S_PARM
ioctl 并填写v4l2_streamparm.parm.capture.timeperframe
成员.
这应该允许设置捕获端的帧速率.您的任务是确保您的阅读速度足够快,以免掉帧.
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 ?
From the V4L2 side, you need to:
- use the
VIDIOC_G_PARM
ioctl and check thev4l2_streamparm.parm.capture.capability
member to find out whether the driver allowsV4L2_CAP_TIMEPERFRAME
. - if so, use the
VIDIOC_ENUM_FRAMEINTERVALS
ioctl to get the list of possible frame intervals (inverse of framerates), in the form ofv4l2_fract
structures - use these values with the
VIDIOC_S_PARM
ioctl and fill in thev4l2_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.
这篇关于v4l2 fcntl.ioctl VIDIOC_S_PARM 用于设置相机捕获的 fps 和分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!