I am using RPi3B+ on 64bit Bookworm, libcamera latest compiled from source. Camera is IMX708 B0310 Arducam module.When using:I get this:which is representative of the performance I get using videodev2.h API library in C:I get 18.50fps at most, while when using libcamera-vid:I getwhich works out to just over 55.50fps (If I'm viewing this correctly. but thats worst case scenario).
I tried changing resolution, pixel format, buffer count and using this code:which all did nothing.
Does anyone know if/how I can improve V4L2 video capture FPS or am I bottlenecked by the libcamerify compatibility layer?
Code:
$ uname -aLinux user 6.6.31+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux
Code:
libcamerify v4l2-ctl -d /dev/video0 --set-fmt-video=width=1280,height=720,pixelformat=1 --stream-count=600 --stream-mmap
Code:
[1:04:34.437971071] [3259] INFO Camera camera_manager.cpp:313 libcamera v0.3.0+65-6ddd79b5[1:04:34.670279549] [3260] WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise[1:04:34.674612123] [3260] WARN RPiController controller.cpp:139 No algorithm found for "rpi.focus"[1:04:34.680398801] [3260] INFO RPI vc4.cpp:446 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media1 and ISP device /dev/media0[1:04:34.683401697] [3259] INFO Camera camera.cpp:1183 configuring streams: (0) 1280x720-YUV420[1:04:34.684777260] [3260] INFO RPI vc4.cpp:621 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected unicam format: 1536x864-pBAA[1:04:34.690009515] [3259] INFO Camera camera.cpp:1183 configuring streams: (0) 1280x720-YUV420[1:04:34.691042164] [3260] INFO RPI vc4.cpp:621 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected unicam format: 1536x864-pBAA<<<<<<<<<<<<<<<<<< 16.61 fps<<<<<<<<<<<<<<<<< 16.61 fps<<<<<<<<<<<<<<<< 16.61 fps<<<<<<<<<<<<<<<<< 16.61 fps<<<<<<<<<<<<<<<<< 16.61 fps...
Code:
#include <linux/videodev2.h>#define HEIGHT 1080#define WIDTH 1920typedef struct { void *start; size_t length;} buffer_t;buffer_t *camera_buffers;int camera_fd;struct v4l2_requestbuffers camera_req; ... camera_fd = open("/dev/video0", O_RDWR); if (camera_fd == -1) { perror("Opening camera device"); cleanup(2); } struct v4l2_format camera_fmt; memset(&camera_fmt, 0, sizeof(camera_fmt)); camera_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; camera_fmt.fmt.pix.width = WIDTH; camera_fmt.fmt.pix.height = HEIGHT; camera_fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; camera_fmt.fmt.pix.field = V4L2_FIELD_NONE; if (ioctl(camera_fd, VIDIOC_S_FMT, &camera_fmt) == -1) { perror("Setting Camera Pixel Format"); cleanup(2); } camera_req.count = 3; camera_req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; camera_req.memory = V4L2_MEMORY_MMAP; if (ioctl(camera_fd, VIDIOC_REQBUFS, &camera_req) == -1) { perror("Requesting Camera Buffer"); cleanup(2); } camera_buffers = calloc(camera_req.count, sizeof(*camera_buffers)); for (int i = 0; i < camera_req.count; i++) { struct v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = camera_req.type; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; if (ioctl(camera_fd, VIDIOC_QUERYBUF, &buf) == -1) { perror("Querying Camera Buffer"); cleanup(2); } camera_buffers[i].length = buf.length; camera_buffers[i].start = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, camera_fd, buf.m.offset); if (camera_buffers[i].start == MAP_FAILED) { perror("Mapping Camera Buffer"); cleanup(2); } } for (int i = 0; i < camera_req.count; i++) { struct v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = camera_req.type; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; if (ioctl(camera_fd, VIDIOC_QBUF, &buf) == -1) { perror("Queue Camera Buffer"); cleanup(2); } } enum v4l2_buf_type camera_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (ioctl(camera_fd, VIDIOC_STREAMON, &camera_type) == -1) { perror("Start Camera Capture"); cleanup(2); } pthread_t encoder_thread_id; int start = 1; while (--frames) { struct v4l2_buffer camera_buf; memset(&camera_buf, 0, sizeof(camera_buf)); camera_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; camera_buf.memory = V4L2_MEMORY_MMAP; if (ioctl(camera_fd, VIDIOC_DQBUF, &camera_buf) == -1) { perror("Dequeue Camera Buffer"); cleanup(2); } ... //calling frame procesing to a separate thread (performance is the same when all of this is commented out)... if (ioctl(camera_fd, VIDIOC_QBUF, &camera_buf) == -1) { perror("Queue Camera Buffer"); cleanup(2); } } if (ioctl(camera_fd, VIDIOC_STREAMOFF, &camera_type) == -1) { perror("Stop Camera Capture"); } ...
Code:
time libcamera-vid --frames 1000 --framerate 120 --mode 1920:1080:12:p --analoggain 29 --shutter 7000 --nopreview
Code:
[1:19:54.866263235] [3287] INFO Camera camera_manager.cpp:313 libcamera v0.3.0+65-6ddd79b5[1:19:55.094307487] [3288] WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise[1:19:55.098595782] [3288] WARN RPiController controller.cpp:139 No algorithm found for "rpi.focus"[1:19:55.103501936] [3288] INFO RPI vc4.cpp:446 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media1 and ISP device /dev/media0[1:19:55.103793392] [3288] INFO RPI pipeline_base.cpp:1104 Using configuration file '/usr/local/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'Mode selection for 1920:1080:12:P(120) SRGGB10_CSI2P,1536x864/120.135 - Score: 2200 SRGGB10_CSI2P,2304x1296/56.0255 - Score: 129099 SRGGB10_CSI2P,4608x2592/14.3536 - Score: 213343[1:19:55.120250223] [3287] INFO Camera camera.cpp:1183 configuring streams: (0) 640x480-YUV420 (1) 1536x864-SBGGR10_CSI2P[1:19:55.121283599] [3288] INFO RPI vc4.cpp:621 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected unicam format: 1536x864-pBAAreal0m17.998suser0m4.996ssys0m3.425s
I tried changing resolution, pixel format, buffer count and using this code:
Code:
struct v4l2_streamparm s; memset(&s, 0, sizeof(s)); s.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; s.parm.output.timeperframe.numerator = 1; s.parm.output.timeperframe.denominator = 60; ioctl(camera_fd, VIDIOC_S_PARM, &s);
Does anyone know if/how I can improve V4L2 video capture FPS or am I bottlenecked by the libcamerify compatibility layer?
Statistics: Posted by m4rkohr — Mon Jul 15, 2024 8:44 am