raspberrypi / libcamera

Other
218 stars 92 forks source link

64mp video recording #176

Closed mssc89 closed 4 days ago

mssc89 commented 1 week ago

I've recently bought Arducam Owlsight B0483 camera (not to be confused with previous hawkeye model) and hooked it up to my raspberry pi 5 4GB. Camera works perfectly when capturing photos at full resolution or videos up to 3840x2160, but when trying to capture full 9248x6944 at 2.6 fps, libcamera and/or picamera2 fails. When starting capture with: libcamera-vid --width 9248 --height 6944 -o output.mp4 -t 10000 it will inevitably throw errors like: [0:21:22.305850463] [1332] ERROR V4L2 v4l2_videodevice.cpp:1961 /dev/video20[20:out]: Failed to queue buffer 2: Invalid argument [0:21:22.305880741] [1332] ERROR RPISTREAM rpi_stream.cpp:276 Failed to queue buffer for ISP Input It will sometimes succeed to grab a few frames, but most of the time it just crashes with this error, requiring sigkill as ctrl+c doesn't seem to work in this state.

I've tried other formats, including yuv420, but it doesn't help. I also tried adding dtoverlay=vc4-kms-v3d,cma-512 to config.txt but error still persists.

As a last resort, I limited the buffers using --buffer-count and it fixed the issue, as now I'm able to capture full resolution video. The highest safe option seems to be --buffer-count 2 as increasing it any higher than that results in the same errors as above. I've monitored RAM usage during recording with various buffer counts and when set to 2, it uses about 2.9GB of RAM, but it is unable to keep 2.6fps, often dropping to half of that.

When using yuv420, I'm able to use --buffer-count 4 without issues.

As this seems to be a libcamera issue (despite using arducam hardware) I would like to know whether this is intended behaviour (dependence on the user to test buffer config)? How does libcamera determine number of buffers to use and why it fails to determine the right number for this resolution?

naushir commented 1 week ago

libcamera does not account for the actual size of the buffer when determine the default buffer count. There would be way too many variables to account for and we will almost certainly break other use cases that cannot be accounted for. So we only use the use case to select a default buffer count.

As to your dmesg error, I think this may be an issue similar to https://github.com/raspberrypi/picamera2/issues/1035#issuecomment-2122831389 - probably unrelated to libcamera. There is no fix yet for that.