64MP - Unable to capture still at full resolution for png encoding - failed to allocate buffer

  1. Where did you get the camera module(s)?
    Directly from ArduCam - preorder

  2. Model number of the product(s)?
    B0399

  3. What hardware/platform were you working on?
    Raspberry Pi 4B, Rev 1.4, 8GB
    Hardware: BCM2711
    Revision: d03114

  4. Instructions you have followed. (link/manual/etc.)
    docs on arducam site

  5. Problems you were having?
    I can successfully capture full resolution images using libcamera-still for jpg and for yuv420.
    However, when I attempt with png or rgb or bmp encoding, a “failed to allocate buffers error” occurs

  6. The dmesg log from your hardware?
    [ 609.267481] cma: cma_alloc: linux,cma: alloc failed, req-size: 19422 pages, ret: -16
    [ 609.267508] unicam fe801000.csi: dma_alloc_coherent of size 79552512 failed

  7. Troubleshooting attempts you’ve made?
    Tried lower GPU memory settings, tried using libcamera-dev and apps version 0.0.6
    I can capture png encoded images at 16MP resolution settings.

  8. What help do you need?
    Pi / memory configuration to allow png encoding at full resolution, i.e. no errors when:
    libcamera-still -e png -o testpng.png

Additional Info:
config.txt starting with first line that is not commented out:

Uncomment some or all of these to enable the optional hardware interfaces

dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

Uncomment this to enable infrared communication.

#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

Additional overlays and parameters are documented /boot/overlays/README

Enable audio (loads snd_bcm2835)

dtparam=audio=on

Automatically load overlays for detected cameras

camera_auto_detect=1

Automatically load overlays for detected DSI displays

display_auto_detect=1

Enable DRM VC4 V3D driver

max_framebuffers=2

Disable compensation for displays with overscan

disable_overscan=1

[cm4]

Enable host mode on the 2711 built-in XHCI USB controller.

This line should be removed if the legacy DWC2 controller is required

(e.g. for USB device mode) or if USB support is not required.

otg_mode=1

[all]

[pi4]

Run as fast as firmware / board allows

arm_boost=1
dtoverlay=vc4-kms-v3d,cma-512

[all]
dtoverlay=dwc2

dtoverlay=arducam_64mp

Mem Info:
MemTotal: 8088108 kB
MemFree: 7351584 kB
MemAvailable: 7548504 kB
Buffers: 31816 kB
Cached: 456360 kB
SwapCached: 0 kB
Active: 94972 kB
Inactive: 440548 kB
Active(anon): 1112 kB
Inactive(anon): 130104 kB
Active(file): 93860 kB
Inactive(file): 310444 kB
Unevictable: 72136 kB
Mlocked: 16 kB
HighTotal: 7458816 kB
HighFree: 6848220 kB
LowTotal: 629292 kB
LowFree: 503364 kB
SwapTotal: 102396 kB
SwapFree: 102396 kB
Dirty: 48 kB
Writeback: 0 kB
AnonPages: 119492 kB
Mapped: 152260 kB
Shmem: 83872 kB
KReclaimable: 27208 kB
Slab: 47988 kB
SReclaimable: 27208 kB
SUnreclaim: 20780 kB
KernelStack: 2008 kB
PageTables: 4924 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 4146448 kB
Committed_AS: 1216372 kB
VmallocTotal: 245760 kB
VmallocUsed: 6316 kB
VmallocChunk: 0 kB
Percpu: 448 kB
CmaTotal: 524288 kB
CmaFree: 478580 kB

libcamera dpkg installed:
ii libcamera-apps 0.0.7 armhf libcamera-apps
ii libcamera-dev 0.0.7 armhf libcamera

os info:
PRETTY_NAME=“Raspbian GNU/Linux 11 (bullseye)”
Linux raspberrypi 5.15.32-v7l+ #1538 SMP Thu Mar 31 19:39:41 BST 2022 armv7l GNU/Linux

libcamera-still output:
$ libcamera-still -e png -o t1-4.png --autofocus
Made X/EGL preview window
[0:08:36.110274955] [3216] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3572-e13ccdd5
[0:08:36.189661589] [3220] WARN CameraSensorProperties camera_sensor_properties.cpp:163 No static properties available for ‘arducam_64mp’
[0:08:36.189722607] [3220] WARN CameraSensorProperties camera_sensor_properties.cpp:165 Please consider updating the camera sensor properties database
[0:08:36.190115067] [3220] ERROR CameraSensor camera_sensor.cpp:591 ‘arducam_64mp 10-001a’: Camera sensor does not support test pattern modes.
[0:08:36.215876024] [3220] WARN RPI raspberrypi.cpp:1263 Mismatch between Unicam and CamHelper for embedded data usage!
[0:08:36.216654334] [3220] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/v4l-subdev0
[0:08:36.216932350] [3220] INFO RPI raspberrypi.cpp:1386 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media3 and ISP device /dev/media0
[0:08:36.217913251] [3216] INFO Camera camera.cpp:1029 configuring streams: (0) 4096x3074-YUV420
[0:08:36.218563636] [3220] INFO RPI raspberrypi.cpp:764 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 4624x3472-SBGGR10_1X10 - Selected unicam format: 4624x3472-pBAA
[0:08:41.937125337] [3216] INFO Camera camera.cpp:1029 configuring streams: (0) 9152x6944-BGR888 (1) 9152x6944-SBGGR10_CSI2P
[0:08:41.938507067] [3220] INFO RPI raspberrypi.cpp:764 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected sensor format: 9152x6944-SBGGR10_1X10 - Selected unicam format: 9152x6944-pBAA
[0:08:42.297268091] [3220] ERROR V4L2 v4l2_videodevice.cpp:1211 /dev/video0[18:cap]: Unable to request 1 buffers: Cannot allocate memory
[0:08:42.297383997] [3220] ERROR RPI raspberrypi.cpp:1012 Failed to allocate buffers
ERROR: *** failed to start camera ***

I’m having the same issue here: Arducam 64mp random *** failed to allocate capture buffers *** with added cma-512

Hi, @JBG

Sorry, reply to you so late. Because the default timeout is too short, this problem is caused, you need to set up a long timeout time in the command.

As follows:

libcamera-still -t 10000 -e png -o t1-4.png --autofocus

Hi, @itsskin

Your problem also needs to set up a long timeout in the command.

Hello @yang
Thanks for reply. Unfortunately your suggestion doesn’t fix the problem and has no effect. I tried various timeouts from -t 10000 to -t 30000. I keep getting the same failure to allocate the memory. I’ve also tried different settings for the GPU memory from 32 through 76 with no change. There appears to be plenty of memory available:
/proc/meminfo says
CmaTotal: 524288 kB
CmaFree: 470684 kB
and dmesg:
[ 312.130289] cma: cma_alloc: linux,cma: alloc failed, req-size: 19422 pages, ret: -12
[ 312.130310] unicam fe801000.csi: dma_alloc_coherent of size 79552512 failed

I’ve also tried with no preview : -n
same result - failure to allocate buffer

I’m also seeing the random failures to capture a jpeg as @itsskin is seeing. Looks like the same thing is happening, but by repeatedly trying to capture, I eventually am able to capture a jpeg, including the dng, and yuv420. There just seems to a hangup preventing the buffer from being allocated even though the memory is available.

Added timeouts, but still the same. Exactly the same behaviour.

Hi, @JBG

You can try saving the image in jpg format.

Hello @yang
Thanks for response, but please see above: I can capture jpg (with random failures) .
However, I need a lossless encoding - png or bmp or rgb.
Capturing jpg doesn’t solve the issue.

Hello, I am also experiencing the same problem. I can take jpg pictures fine at all resolutions but I cannot capture a png file at all.

What’s being done to fix this?

It’s impossible to use the product you sold. What’s the updates on this?

@itsskin

For this issue, we are also currently communicating with the Raspberry Pi official.
https://forums.raspberrypi.com/viewtopic.php?t=339182

If you can, can you post your dmesg information as well.

What’s ETA? You said this a month ago.

@itsskin

Raspberry Pi official gave a very professional reply, you can refer to it. We will also test it in parallel.
https://forums.raspberrypi.com/viewtopic.php?t=339182

No practical solution there for me. Can you fix the bug with info they given you? What’s the ETA?

Hi, I am also experiencing this problem. I would like to output images from the raw Bayer information but I am getting the same error messages related to memory and buffers on the Raspberry Pi 4GB. This is a big issue as it means the camera is not useable for the purpose I wish to use it for.

@itsskin @bigollie93

I’m sorry for your bad experience.

Have you tried this?

Adding "alloc_in_cma_threshold=16" in /boot/cmdline.txt seems to solve that,

We do not have a better solution to the cma problem for now.

We will try to solve it anyway. But there is no exact deadline for this.

Hi there,
Thank you for this.

By adding the line stated above to the end of /boot/cmdline.txt I can now capture jpeg images with the raw flag to get a DNG image for the full sensor. This appears to be in 10bit format.

libcamera-still --width 9152 --height 6944 -r -o test.jpeg -q 100

Weirdly I can capture PNG images up to 9000x6000 pixels using the command below, but if I specify 9152x6144 I get the same error as before. This is on a 2GB pi 4 - I will test on a 4GB pi4 later on hopefully. This produces 9000x6000 png images - this seems to be in the full sensor format but I haven’t checked this fully.

libcamera-still --width 9000 --height 6000 -e png -o test.png

@bigollie93

It sounds like this does work, although not to your maximum expectations.

Hi there. Same problem on a 4GB RPI 4

After testing the new cmdline patch, the capture improves slighty and with simple commands.
Using other options such -k or -q=100, seems to leak memory never freed, although CMA reports on /proc/meminfo are fine.
Each time used, have to reduce capture resolution in order not to get “cannot allocate buffers”.
Setting resolution about 40Mp lets me get half dozen captures.