ioctl failed

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
1,070件の閲覧回数
OlivierG
Contributor III

Hi 

On an IMX93evk card with Yocto
I tested the code below intended to do an image acquisition on the /dev/video device connected to a RPI-CAM-MIPI camera
https://docs.nxp.com/bundle/UM11933/page/topics/rpi-cam-mipi_overview.html

The calls to the ioctl function fail.
Curiously OpenCv makes the same calls and they do not fail
What did I miss?

int main() {
const char *device = "/dev/video0";
int fd = open(device, O_RDWR);
if (fd == -1) {
   perror("Opening video device");
   return 1;
}


struct v4l2_format format;
format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
format.fmt.pix.width = 640;
format.fmt.pix.height = 480;
format.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
format.fmt.pix.field = V4L2_FIELD_INTERLACED;

if (ioctl(fd, VIDIOC_S_FMT, &format) < 0) {
perror("Setting Pixel Format");
return 1;
}

struct v4l2_requestbuffers req;
memset(&req, 0, sizeof(req));
req.count = 1;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;

if (ioctl(fd, VIDIOC_REQBUFS, &req) < 0) {
perror("Requesting Buffer");
return 1;
}

struct v4l2_buffer buf;
memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = 0;

if (ioctl(fd, VIDIOC_QUERYBUF, &buf) < 0) {
perror("Querying Buffer");
return 1;
}

0 件の賞賛
返信
1 解決策
997件の閲覧回数
OlivierG
Contributor III
0 件の賞賛
返信
3 返答(返信)
1,064件の閲覧回数
JosephAtNXP
NXP TechSupport
NXP TechSupport

Hi,

Thank you for your interest in NXP Semiconductor products,

Are you able to replicate the camera preview in your setup?

$ media-ctl -p

$ v4l2-ctl --list-devices

List the supported pixel formats:

$ v4l2-ctl -d0 --list-formats
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture Multiplanar
...

List the supported image resolutions:

$ v4l2-ctl -d0 --list-framesizes YUYV
ioctl: VIDIOC_ENUM_FRAMESIZES
Size: Discrete 1920x1080
...

Capture the camera data and save them to a file using the "v4l2-ctl" command. The supported pixel formats and resolutions are listed above. Here is an example to capture the 1280x800 YUYV camera data:

$ v4l2-ctl -d0 --set-fmt-video=width=1280,height=800,pixelformat=YUYV --stream-mmap=4 --stream-count=10 --stream-to=test.yuv

Capture the camera data, preview them on screen or save them to a file using the "gstreamer" commands:

# preview on screen
$ gst-launch-1.0 -v v4l2src device=/dev/video0 ! "video/x-raw,format=YUY2,width=1280,height=800" ! queue ! waylandsink

Regards

0 件の賞賛
返信
1,022件の閲覧回数
OlivierG
Contributor III
Hi 
 
I have done the followings commands
 
# media-ctl -p
Media controller API version 6.6.23
 
Media device information
------------------------
driver          mxc-md
model           FSL Capture Media Device
serial          
bus info        platform:42800000.bus:camera
hw revision     0x0
driver version  6.6.23
 
Device topology
- entity 1: mxc_isi.0 (16 pads, 2 links, 0 routes)
            type V4L2 subdev subtype Unknown flags 0
pad0: Sink
<- "mxc-mipi-csi2.0":4 [ENABLED]
pad1: Sink
pad2: Sink
pad3: Sink
pad4: Sink
pad5: Sink
pad6: Sink
pad7: Sink
pad8: Sink
pad9: Sink
pad10: Sink
pad11: Sink
pad12: Source
-> "mxc_isi.0.capture":0 [ENABLED]
pad13: Source
pad14: Source
pad15: Sink
 
- entity 18: mxc_isi.0.capture (1 pad, 1 link)
             type Node subtype V4L flags 0
             device node name /dev/video0
pad0: Sink
<- "mxc_isi.0":12 [ENABLED]
 
- entity 22: mxc-mipi-csi2.0 (8 pads, 2 links)
             type Node subtype V4L flags 0
             device node name /dev/v4l-subdev0
pad0: Sink
<- "ap1302_mipi 2-003c":0 [ENABLED,IMMUTABLE]
pad1: Sink
pad2: Sink
pad3: Sink
pad4: Source
-> "mxc_isi.0":0 [ENABLED]
pad5: Source
pad6: Source
pad7: Source
 
- entity 31: ap1302_mipi 2-003c (1 pad, 1 link, 0 routes)
             type V4L2 subdev subtype Unknown flags 0
pad0: Source
-> "mxc-mipi-csi2.0":0 [ENABLED,IMMUTABLE]
 
# v4l2-ctl --list-devices
FSL Capture Media Device (platform:42800000.bus:camera):
/dev/media0
 
mxc-isi-cap_v1 (platform:4ae40000.isi:cap_devic):
/dev/video0
 
# v4l2-ctl -d0 --list-formats
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture Multiplanar
 
[0]: 'RGBP' (16-bit RGB 5-6-5)
[1]: 'RGB3' (24-bit RGB 8-8-8)
[2]: 'BGR3' (24-bit BGR 8-8-8)
[3]: 'YUYV' (YUYV 4:2:2)
[4]: 'YUV4' (32-bit A/XYUV 8-8-8-8)
[5]: 'NV12' (Y/UV 4:2:0)
[6]: 'NM12' (Y/UV 4:2:0 (N-C))
[7]: 'YM24' (Planar YUV 4:4:4 (N-C))
[8]: 'XR24' (32-bit BGRX 8-8-8-8)
[9]: 'AR24' (32-bit BGRA 8-8-8-8)
 
# v4l2-ctl -d0 --list-framesizes YUYV
ioctl: VIDIOC_ENUM_FRAMESIZES
Size: Discrete 1920x1080
Size: Discrete 1280x800
Size: Discrete 1280x720
Size: Discrete 640x480
 
# v4l2-ctl -d0 --set-fmt-video=width=1280,height=800,pixelformat=YUYV --stream-mmap=4 --stream-count=10 --stream-to=test.yuv
 
# ls -l test.yuv
-rw-r--r-- 1 root root 20480000 Feb 25 02:55 test.yuv
 
#gst-launch-1.0 -v v4l2src device=/dev/video0 ! "video/x-raw,format=YUY2,width=1280,height=800" ! queue ! waylandsink
i have a display on xwindows
 
 
When i launch code with the OpenCV video capture function with log debug level
 
 cv::VideoCapture camera(0, cv::CAP_V4L2);
I get
 
[DEBUG:0@0.030] global cap_v4l.cpp:1005 open VIDEOIO(V4L2:/dev/video0): opening...
[DEBUG:0@0.030] global cap_v4l.cpp:1021 open VIDEOIO(V4L2:/dev/video0): deviceHandle=14
[DEBUG:0@0.031] global cap_v4l.cpp:1089 tryIoctl VIDEOIO(V4L2:/dev/video0): tryIoctl(14, VIDIOC_QUERYCAP(2154321408), failIfBusy=1)
[DEBUG:0@0.031] global cap_v4l.cpp:1097 tryIoctl VIDEOIO(V4L2:/dev/video0): call ioctl(14, VIDIOC_QUERYCAP(2154321408), ...) => 0    errno=0 (Success)
[DEBUG:0@0.031] global cap_v4l.cpp:1089 tryIoctl VIDEOIO(V4L2:/dev/video0): tryIoctl(14, VIDIOC_G_FMT(3234878980), failIfBusy=1)
[DEBUG:0@0.031] global cap_v4l.cpp:1097 tryIoctl VIDEOIO(V4L2:/dev/video0): call ioctl(14, VIDIOC_G_FMT(3234878980), ...) => 0    errno=0 (Success)
[DEBUG:0@0.031] global cap_v4l.cpp:1089 tryIoctl VIDEOIO(V4L2:/dev/video0): tryIoctl(14, VIDIOC_S_FMT(3234878981), failIfBusy=1)
[DEBUG:0@0.031] global cap_v4l.cpp:1097 tryIoctl VIDEOIO(V4L2:/dev/video0): call ioctl(14, VIDIOC_S_FMT(3234878981), ...) => 0    errno=0 (Success)
[DEBUG:0@0.031] global cap_v4l.cpp:1089 tryIoctl VIDEOIO(V4L2:/dev/video0): tryIoctl(14, VIDIOC_S_PARM(3234616854), failIfBusy=1)
[DEBUG:0@0.031] global cap_v4l.cpp:1097 tryIoctl VIDEOIO(V4L2:/dev/video0): call ioctl(14, VIDIOC_S_PARM(3234616854), ...) => 0    errno=0 (Success)
[DEBUG:0@0.031] global cap_v4l.cpp:1089 tryIoctl VIDEOIO(V4L2:/dev/video0): tryIoctl(14, VIDIOC_G_PARM(3234616853), failIfBusy=1)
[DEBUG:0@0.031] global cap_v4l.cpp:1097 tryIoctl VIDEOIO(V4L2:/dev/video0): call ioctl(14, VIDIOC_G_PARM(3234616853), ...) => 0    errno=0 (Success)
 
ioctl with VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_S_PARM, VIDIOC_G_PARM work

 

0 件の賞賛
返信
998件の閲覧回数
OlivierG
Contributor III
0 件の賞賛
返信