Cameras for Raspberry Pi

  1. Home
  2. Docs
  3. Cameras for Raspberry Pi
  4. Raspberry Pi libcamera Guide

Raspberry Pi libcamera Guide

What is libcamera?

what is libcamera and how you cana use it on Raspberry Pi

libcamera is an open source camera stack, which was used by Raspberry Pi to develop their latest camera software library. It offers users more lower-level access than the old raspistill and is fully open-sourced.

The libcamera-apps that are currently available for Raspberry Pi:

  1. libcamera-hello will give you a preview of the camera module.
  2. libcamera-jpeg will capture still images after showing you a preview window.
  3. libcamea-still offers all the features of raspistill.
  4. libcamera-vid offers all the features of raspivid.
  5. libcamera-raw will get raw frames from the image sensor.
  6. libcamera-detect will work with tensorflow lite to automatically capture JPEG images when certain objects appear in the frame, it needs to be built first.

For more information, please refer to:

Below are the options that’re available for both commands:

-h [ --help ]

Print out the help message.

--version

Displays the build version number.

-v [ --verbose ]

Output extra debug and diagnostics.

-c [ --config ]

Read the options from a file. If no filename is specified, default to config.txt. In case of duplicate options, the ones provided on the command line will be used. Note that the config file must only contain the long form options.

--info-text

Sets the information string on the titlebar. Available values:

%frame (frame number)

%fps (framerate)

%exp (shutter speed)

%ag (analogue gain)

%dg (digital gain)

%rg (red colour gain)

%bg (blue colour gain)

%focus (focus FoM value)

%aelock (AE locked status)

--width

Set the output image width.

--height

Set the output image height.

-t [ --timeout ]

Time (in ms) for which program runs. The default value is 5000.

-o [ --output ]

Set the output file name.

--post-process-file

Set the file name for configuring the post-processing.

--rawfull

Force use of full resolution raw frames.

-n [ --nopreview ]

Do not show a preview window.

-p [ --preview ]

Set the preview window dimensions, given as x,y,width,height. E.G. 0,0,640,480

-f [ --fullscreen ]

Use a fullscreen preview window.

--qt-preview

Use Qt-based preview window (WARNING: causes heavy CPU load, fullscreen not supported)

--hflip

Request a horizontal flip transform.

--vflip

Request a vertical flip transform.

--rotation

Request an image rotation, 0 or 180

--roi

Set region of interest (digital zoom) e.g. 0.25,0.25,0.5,0.5

--shutter

Set a fixed shutter speed.

--analoggain

Set a fixed gain value (synonym for ‘gain’ option).

--gain

Set a fixed gain value.

--metering

Set the metering mode (centre, spot, average, custom).

--exposure

Set the exposure mode (normal, sport).

--ev

Set the EV exposure compensation, where 0 = no change

--awb

Set the AWB mode (auto, incandescent, tungsten, fluorescent, indoor, daylight, cloudy, custom).

--awbgains

Flush output data as soon as possible.

--wrap
When writing multiple output files, reset the counter when it reaches this number.

--brightness
Adjust the brightness of the output images, in the range -1.0 to 1.0

--contrast
Adjust the contrast of the output image, where 1.0 = normal contrast.

--saturation
Adjust the colour saturation of the output, where 1.0 = normal and 0.0 = greyscale.

--sharpness
Adjust the sharpness of the output image, where 1.0 = normal sharpening.

--framerate
Set the fixed framerate for preview and video modes.

--denoise
Sets the Denoise operating mode: auto, off, cdn_off, cdn_fast, cdn_hq

--viewfinder-width
Width of viewfinder frames from the camera (distinct from the preview window size.

--viewfinder-height
Height of viewfinder frames from the camera (distinct from the preview window size).

--tuning-file
Name of camera tuning file to use, omit this option for libcamera default behaviour.

--lores-width
Width of low resolution frames (use 0 to omit low resolution stream.

--lores-height
Height of low resolution frames (use 0 to omit low resolution stream.

--autofocus
Flush output data as soon as possible.

-k [ --keypress ]
Perform capture when ENTER pressed.

Pause or resume video recording when ENTER pressed.

-s [ --signal ]

Perform capture when signal received.

Pause or resume video recording when signal received.

Options only available for libcamera-still

-q [ --quality ]

Set the JPEG quality parameter.

-x [ --exif ]

Add these extra EXIF tags to the output file.

--timelapse

Time interval (in ms) between timelapse captures.

--framestart

Initial frame counter value for timelapse captures.

--datetime

Use date format for output file names.

--timestamp

Use system timestamps for output file names.

--restart

Set JPEG restart interval.

--thumb

Set thumbnail parameters as width:height:quality

-e [ --encoding ]

Set the desired output encoding, either jpg, png, rgb, bmp or yuv420

-r [ --raw ]

Also save raw file in DNG format.

--latest

Create a symbolic link with this name to most recent saved file

--immediate

Perform first capture immediately, with no preview phase.

Options only available for libcamera-vid

-b [ --bitrate ]

Set the bitrate for encoding, in bits/second (h264 only).

--profile

Set the encoding profile (h264 only).

--level

Set the encoding level (h264 only).

-g [ --intra ]

Set the intra frame period (h264 only).

--inline

Force PPS/SPS header with every I frame (h264 only).

--codec

Set the codec to use, either h264, mjpeg or yuv420.

--save-pts

Save a timestamp file with this name.

-q [ --quality ]

Set the MJPEG quality parameter (mjpeg only).

-l [ --listen ]

Listen for an incoming client network connection before sending data to the client.

-i [ --initial ]

Use ‘pause’ to pause the recording at startup, otherwise ‘record’ (the default).

--split

Create a new output file every time recording is paused and then resumed.

--segment

Break the recording into files of approximately this many milliseconds.

--circular

Write output to a circular buffer which is saved on exit.

The libcamera-Compatible Camera Lists

Below is a complete list of camera modules that work perfectly well with libcamera-apps.

Camera VendorsCamera Models
Raspberry Pi
V1/V2/HQ
ArducamV2 Series / HQ Series / Pivariety Series / High-Resolution Autofocus Camera

Note

Please avoid using our 16MP autofocus camera module with the official PoE HAT or touchscreen.

Please make sure your Raspberry Pi OS is downloaded from these two official sources:

Raspberry Pi Buster >

Raspberry Pi Bullseye >

How to install libcamera?

If you are using the Arducam Autofocus Camera for the first time, please follow these steps:

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. update your Pi

sudo apt update 

Step 3. Install libcamra-dev

./install_pivariety_pkgs.sh -p libcamera_dev

Step 4. Install libcamera-apps

./install_pivariety_pkgs.sh -p libcamera_apps

Step 5. Install the kernel driver

./install_pivariety_pkgs.sh -p imx519_kernel_driver

Step 6. Install the focus adjustment software

git clone https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver.git

Step 7. Reboot your Pi

For models other than Raspberry Pi 4, please also:

1. Open /boot/config.txt
2. Add the following line under [all]:
dtoverlay=vc4-fkms-v3d
3. Save and reboot

For one-time autofocus, append –autofocus to your command line:

libcamera-still -t 5000 -o test.jpg --autofocus

If you want to manually adjust the focus, please follow these steps:

Step 1. Open a preview window

libcamera-still -t 0

Step 2. Use our focus adjustment tool

cd Arducam-Pivariety-V4L2-Driver/focus
python3 FocuserExample.py -d /dev/v4l-subdev1

Step 3. Press the Up/Down Arrow for focus adjustment, press “ctrl + c” to save, or “r” to

reset.

Advanced usages of libcamera & libcamera-apps

For full details on how to use the libcamera for project-bulding, please refer to this article.

Was this article helpful to you? Yes 2 No 1