Raspberry camera on Archlinux ARM in 2024

I run Arch Linux ARM on my Raspberry Pi 4b. In past I have used commands raspistill and raspivid to shoot photos and videos using the Raspberry Pi Camera Module V2. Few months back, I wanted to use the camera again but found that the original commands are missing from the system.

The reason for this is that the tools raspistill and raspivid are discontinued and they have been replaced with new tools rpicam-still and rpicam-vid based on the libcamera library. As far as I know, these are not shipped with Archlinux ARM anymore and are not included in the official repositories. This post documents how to get the newer tool set running on Archlinux ARM. In other words, I present solution for raspistill command not found.

Preliminaries

Ensure that /boot/config.txt contains:

camera_auto_detect=1

Power off Raspberry, connect the camera and connect power.
Now compile libcamera and the tools:

Building libcamera

source: https://www.raspberrypi.com/documentation/computers/camera_software.html#building-libcamera
I have tried to use the extra/libcamera package from the repository and libcamera-git from AUR but neither is compatible with the rpicam-apps we will compile in the next step. Therefore we need to compile libcamera as well.
First install the dependencies:

# pacman -S boost gcc git gnutls meson gtest openssl libexif python3 python-jinja python-ply python-yaml pybind11 gst-plugins-base

To compile libcamera I ran:

$ git clone https://git.libcamera.org/libcamera/libcamera.git
$ cd libcamera
$ meson setup build
$ sudo ninja -C build install

Building rpicam-apps on Arch linux ARM

I follow the official guide: https://www.raspberrypi.com/documentation/computers/camera_software.html#building-rpicam-apps-without-rebuilding-libcamera
but make adjustments in case of Arch linux ARM running on Raspberry Pi 4 B

The commands are:

$ git clone https://github.com/raspberrypi/rpicam-apps.git
$ cd rpicam-apps

$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

$ meson setup build -Denable_libav=true -Denable_drm=true -Denable_egl=false -Denable_qt=false -Denable_opencv=false -Denable_tflite=false

$ meson compile -C build # use -j1 on Raspberry Pi 3 or earlier devices
$ sudo meson install -C build
$ sudo ldconfig # this is only necessary on the first build

Fix error loading shared libraries

After running rpicam-still the error is:

$ rpicam-still 
rpicam-still: error while loading shared libraries: rpicam_app.so.1.4.2: cannot open shared object file: No such file or directory

We need to edit .bash_profile (or .bashrc) and add:

export LD_LIBRARY_PATH=/usr/local/lib

After that logout and login or run source .bash_profile.

Testing libcamera

Now we can try to run:

libcamera-hello --list-cameras

The output should show the connected camera!

Fix priviledges

Could not open any dmaHeap device
No cameras available!

one can fix this by editing /etc/udev/rules.d/raspberrypi.rules:

SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660"

Once that file has been created either reboot or run:-

udevadm control --reload-rules && udevadm trigger

Add the user to the video group

gpasswd -a [your_username] video

Low-latency Raspberry camera stream with Netcat

I often want to view the camera stream with lowest latency possible to adjust the image. I found that using netcat to pipe the video stream into mplayer on the client gives me the lowest latency of all methods I tried.
Install the gnu-netcat package on Raspberry and mplayer on the monitor.
Then run following commands:
monitor:

ip addr # find the ip of this machine
netcat -l -p 5000 | mplayer -fs -cache 512 -

camera:

rpicam-vid -t 0 --width 1920 --height 1080 -o - | nc [machine IP] 5000