Skip to content

libcamera and libcamera-apps

Introduction


libcamera is a new software library aimed at supporting complex camera systems directly from the Linux operating system. In the case of the Raspberry Pi it enables us to drive the camera system directly from open source code running on ARM processors.

libcamera presents a C++ API to applications and works at the level of configuring the camera and then allowing an application to request image frames. These image buffers reside in system memory and can be passed directly to still image encoders (such as JPEG) or to video encoders (such as h.264), though such ancillary functions as encoding images or displaying them are strictly beyond the purview of libcamera itself.

At Arducam, we added more RPI camera support and improved the existing libcamera with extensive features like auto-focus, external trigger, strobe functions, auto-load camera calibration parameters with our Pivariety solution and modified version of libcamera.

Picamera2 is not supported on:

  • Images based on Buster or earlier releases.
  • Raspberry Pi OS Legacy images.
  • Bullseye (or later) images where the legacy camera stack has been re-enabled.

More about libcamera

You can get more information about libcamera for Raspberry Pi at the following link: Libcamera

libcamera is an open source Linux community project. More information is available at the libcamera website.

Getting Started


For Native cameras, please refer to the official Raspberry Pi documentation: Doc

Native Camera Board list:

Resolution Camera Module
5MP OV5647
8MP imx219
12MP imx477
16MP imx298
0.3MP OV7251
2MP OV2311
1.58MP imx296

For the imx519/hawkeye 64mp, you need to install the following steps:

imx519/hawkeye 64mp camera Board list:

Resolution Camera Module
16MP imx519
64MP hawkeye-64mp

Step 1. Download the bash scripts

wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh
chmod +x install_pivariety_pkgs.sh

Step 2. Install libcamera

./install_pivariety_pkgs.sh -p libcamera_dev

Step 3. Install libcamera-apps

./install_pivariety_pkgs.sh -p libcamera_apps

Troubleshooting

If you receive the following error when installing libcamera, you can use the command ./install_pivariety_pkgs.sh -l to update your package:

libcamera-error-1

You can use following command to update your package:

./install_pivariety_pkgs.sh -l

libcamera-hello


libcamera-hello is the equivalent of a "hello world" application for the camera. It starts the camera, displays a preview window, and does nothing else. For example

libcamera-hello

For more parameters, please use the --help parameter to see

libcamera-hello --help

libcamera-jpeg


libcamera-jpeg is a simple still image capture application. It deliberately avoids some of the additional features of libcamera-still which attempts to emulate raspistill more fully. As such the code is significantly easier to understand, and in practice still provides many of the same features.

To capture a full resolution JPEG image use

libcamera-jpeg -o test.jpg

For more parameters, please use the --help parameter to see

libcamera-jpeg --help

libcamera-still


libcamera-still is very similar to libcamera-jpeg but supports more of the legacy raspistill options. As before, a single image can be captured with

libcamera-still -o test.jpg

Continuous automatic photo taking, 1 shot per second within 5 seconds

libcamera-still -t 5000 --datetime -n --timelapse 1000

For more parameters, please use the --help parameter to see

libcamera-still --help

Autofocus/Manual Focus Function

Tip

For cameras with focus motors, we have added autofocus parameters to enable single autofocus and continuous autofocus functions.
Different cameras use their corresponding operation commands, please enter the camera content you need according to the index:

  • For Arducam 16MP/64MP Autofocus camera

Continuous Autofocus
libcamera-still -t 0 

libcamera-still -t 0 --autofocus-mode continuous
Single Autofocus
libcamera-still -t 0 --autofocus-mode auto
Manual Focus
libcamera-still -t 0 --autofocus-mode manual
# Use keyboard to control focus
# "f" trigger one-shot autofocus
# "a" add the lens position, "d" decrease the lens position, the minimum unit of step adjustment is 1
libcamera-still -t 0 --autofocus-mode manual -k
Adjust Lens Position
libcamera-still -t 0 --autofocus-mode manual --lens-position 5
Autofocus Before Capture Images
libcamera-still -t 0 --autofocus-on-capture
Set Focus Range
# Normal
libcamera-still -t 0 --autofocus-range normal

# Close Focus
libcamera-still -t 0 --autofocus-range macro
  • For OV5647/IMX219 and IMX477 Camera Module

Note

The IMX219, OV5647, IMX477 cameras will need to use a specific tuning data file to achieve autofocus function.

Please refer to the following corresponding docs to get more details and operation steps for above camera modules:

libcamera-vid


libcamera-vid is the video capture application. By default it uses the Raspberry Pi’s hardware H.264 encoder. It will display a preview window and write the encoded bitstream to the specified output. For example, to write a 10 second video to file use

libcamera-vid -t 10000 -o test.h264

For cameras with focus motors, we have added autofocus parameters to enable single autofocus and continuous autofocus functions

Single autofocus

libcamera-vid -t 0 --autofocus-mode auto

Continuous automatic photo taking, 1 shot per second within 5 seconds

libcamera-vid -t 5000 --datetime -n --timelapse 1000

For more parameters, please use the --help parameter to see

libcamera-vid --help

libcamera-raw


libcamera-raw is like a video recording application except that it records raw Bayer frames directly from the sensor. It does not show a preview window. For a 2 second raw clip use.

libcamera-raw -t 2000 -o test.raw

For more parameters, please use the --help parameter to see

libcamera-raw --help