Blog about my hardware and software projects.

Update from 12. November 2024: I updated the guide based on a fresh install of Arch Linux ARM on Raspberry Pi 4B (1GB RAM version). To do the fresh install, I followed the installation steps here: https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-4. Then I documented all steps I took to make the camera working.
I updated the dependencies, the meson command for rpicam-apps compilation, and added more detailed explanations.

Note: this guide was created using Raspberry Pi 4b. If you have Raspberry Pi 5, please let me know if it works!


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

The first step is to install libcamera on our system. I have tried to use the extra/libcamera package from the Arch Linux ARM repository and libcamera-git from AUR. Neither was compatible with the rpicam-apps that we want to install next. Therefore we need to compile and install libcamera manually from the source.

To compile libcamera, first install the dependencies:

$ sudo pacman -S boost cmake gcc git libdrm libexif libjpeg libpng libtiff meson pkgconf python-jinja python-ply python-yaml

(I also included the dependencies for rpicam-apps we will need next)

Then run the following commands:

$ git clone https://git.libcamera.org/libcamera/libcamera.git
$ cd libcamera
$ meson setup build
$ ninja -C build -j1 # -j1 added because of 1GB RAM limit
$ sudo ninja -C build install
$ cd .. # exit the libcamera directory

Building rpicam-apps on Arch linux ARM

I follow the official guide: https://www.raspberrypi.com/documentation/computers/camera_software.html#building-rpicam-apps
but I make adjustments for the 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=disabled -Denable_drm=enabled -Denable_egl=disabled -Denable_qt=disabled -Denable_opencv=disabled -Denable_tflite=disabled -Denable_hailo=disabled

$ meson compile -C build -j1 # -j 1 added because of 1GB RAM limit
$ sudo meson install -C build
$ sudo ldconfig # this is only necessary on the first build

Note that I run the export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig command because of the following meson error:

meson.build:37:16: ERROR: Dependency "libcamera" not found, tried pkgconfig and cmake

Also note that I configure a minimal build using meson. I only want the CLI tools to work and do not need anything else, you might want to enable different options based on your needs.

Fix error loading shared libraries

After running rpicam-still the error is:

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

The problem is that the rpicam_app.so library was installed into /usr/local/lib/, which is not a standard shared library path in Arch Linux. For rpicam-still to be able to find the shared library, we need to add it to LD_LIBRARY_PATH. To do this, (assuming your shell is bash), edit ~/.bash_profile (or ~/.bashrc) and add the following line:

export LD_LIBRARY_PATH=/usr/local/lib

After that, logout and login, or run source .bash_profile.

Fix privileges

source: https://raspberrypi.stackexchange.com/questions/141106/how-to-fix-the-libcamera-error-could-not-open-any-dmaheap-device

We are almost finished. Try running:

$ libcamera-hello --list-cameras

If it returns:

Could not open any dmaHeap device
No cameras available!

we can fix this by editing /etc/udev/rules.d/raspberrypi.rules and adding the following line:

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

Once that file has been updated either reboot or run:

$ sudo udevadm control --reload-rules && sudo udevadm trigger

Add the current user to the video group

$ sudo gpasswd -a $USER video

And now log off and log in.

Testing libcamera

Now we can try to run:

$ libcamera-hello --list-cameras

The output should show the connected camera!

You can also try taking a picture:

$ rpicam-still --output test.jpg --immediate

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:

On the video player side (NOT Raspberry):

$ ip addr # find the ip address of this machine (not raspberry, the other one)
$ netcat -l -p 5000 | mplayer -fs -cache 512 -

On the Raspberry:

$ rpicam-vid -t 0 --width 1# SnapFix Servis920 --height 1080 -o - | nc [video player machine IP] 5000

Resources I used

https://www.raspberrypi.com/documentation/computers/camera_software.html#getting-started


Leave a Reply

Your email address will not be published. Required fields are marked *