$linuxjunkies
>

Use the Raspberry Pi Camera Module

Learn to capture stills, record video, and stream live footage over the network using libcamera and rpicam-apps on Raspberry Pi OS Bookworm.

IntermediateUbuntuDebianFedoraArch9 min readUpdated June 7, 2026

Before you start

  • Raspberry Pi 3B+, 4, 400, or 5 running Raspberry Pi OS Bookworm (64-bit recommended)
  • Compatible Camera Module (v1, v2, v3, or HQ) with ribbon cable properly seated
  • SSH access or a connected display for headless operation
  • ffmpeg installed for container conversion and streaming (sudo apt install ffmpeg)

The Raspberry Pi Camera Module (any revision — v1, v2, v3, or HQ) is driven by libcamera, the modern open-source camera stack that replaced the legacy raspistill/raspivid toolchain. On Raspberry Pi OS Bookworm (based on Debian 12) and later, libcamera and the rpicam-apps suite are the only supported path. This guide walks through enabling the camera, capturing stills and video, and streaming live footage over a network.

Prerequisites and Hardware Check

Before touching software, confirm the physical connection. Shut down the Pi, seat the ribbon cable firmly in the CSI port with the blue retention tab facing away from the board, then power back on. For the Pi 5, use the appropriate 22-pin-to-15-pin adapter cable if your module requires it.

Check that the kernel sees the sensor:

rpicam-hello --list-cameras

You should see output similar to:

# Example output (varies by sensor)
Available cameras
-----------------
0 : imx708 [4608x2592 10-bit RGGB] (/base/axi/pcie@120000/rp1/i2c@88000/imx708@1a)
    Modes: 'SRGGB10_CSI2P' : 1536x864 [120.13 fps] ...
           'SRGGB10_CSI2P' : 2304x1296 [56.03 fps] ...
           'SRGGB10_CSI2P' : 4608x2592 [14.35 fps]

If the list is empty, see the Troubleshooting section below.

Install rpicam-apps

On a fresh Raspberry Pi OS Bookworm install, rpicam-apps is already present. If not — or if you are running a minimal image — install it now.

Raspberry Pi OS / Debian / Ubuntu on Pi

sudo apt update && sudo apt install -y rpicam-apps libcamera-tools

There is also a full build with extra codec support (H.264 hardware encoding, JPEG, etc.) provided by the rpicam-apps metapackage; on Raspberry Pi OS it pulls in everything you need automatically.

Confirm the installed version:

rpicam-hello --version

Capturing Still Images

rpicam-still replaces the old raspistill. Its most important flags are shown below.

Basic snapshot

rpicam-still -o photo.jpg

This applies the default tuning file for your detected sensor, auto-exposes for 5 seconds, then saves a JPEG. The preview window appears on the desktop; suppress it on a headless system:

rpicam-still --nopreview -o photo.jpg

RAW capture

rpicam-still --nopreview -r -o photo.jpg

The -r flag saves a photo.dng (Adobe DNG) alongside the JPEG. Process DNG files with darktable, rawtherapee, or dcraw.

Timed burst

rpicam-still --nopreview -t 10000 --timelapse 2000 -o frame%04d.jpg

Captures one frame every 2 seconds for 10 seconds (-t in ms, --timelapse in ms). The %04d placeholder is replaced with a zero-padded counter.

Manual exposure and white balance

rpicam-still --nopreview \
  --shutter 10000 \
  --gain 1.5 \
  --awbgains 1.8,1.5 \
  -o manual.jpg

Shutter time is in microseconds. --awbgains R,B disables auto white-balance and sets explicit red/blue channel gains.

Recording Video

rpicam-vid replaces raspivid and uses the Pi's hardware H.264 encoder by default.

Basic H.264 clip

rpicam-vid --nopreview -t 10000 -o clip.h264

This records 10 seconds at 1920×1080 30 fps by default. The raw H.264 elementary stream is not a standard container; wrap it before editing:

ffmpeg -framerate 30 -i clip.h264 -c copy clip.mp4

Record directly to MP4

Newer versions of rpicam-apps include the --codec libav path, which writes a proper container on the fly:

rpicam-vid --nopreview -t 20000 --codec libav -o clip.mp4

Resolution, framerate, and bitrate

rpicam-vid --nopreview \
  --width 1280 --height 720 \
  --framerate 60 \
  --bitrate 4000000 \
  -t 15000 \
  -o 720p60.h264

Circular buffer / motion capture

The --inline and --circular flags enable a ring-buffer mode useful for security cameras; combine with a FIFO or signal handler to dump to disk on demand. This is an advanced use case covered in the official rpicam-apps documentation.

Network Streaming with rpicam-vid

The Pi can stream live H.264 video over TCP or UDP to any host on the local network — no additional software needed on the Pi itself beyond rpicam-apps.

TCP stream (push model)

On the Pi (server), start the stream listening on a TCP port:

rpicam-vid --nopreview -t 0 --inline -o tcp://0.0.0.0:8888

-t 0 streams indefinitely. On the receiving machine, open with VLC or ffplay:

# On viewer host
ffplay tcp://<pi-ip-address>:8888

Or with VLC:

vlc tcp://<pi-ip-address>:8888

UDP stream

UDP has lower overhead and is preferred on a stable LAN:

# On the Pi — send to viewer's IP
rpicam-vid --nopreview -t 0 --inline -o udp://<viewer-ip>:5000
# On the viewer
ffplay udp://@:5000 -fflags nobuffer -flags low_delay -framedrop

RTSP via mediamtx (low-latency)

For proper RTSP (compatible with NVRs, Home Assistant, etc.), install mediamtx (formerly rtsp-simple-server) on the Pi and pipe rpicam-vid into it:

# Install mediamtx (grab latest release binary from GitHub)
wget https://github.com/bluenviron/mediamtx/releases/latest/download/mediamtx_linux_arm64v8.tar.gz
tar xzf mediamtx_linux_arm64v8.tar.gz
sudo mv mediamtx /usr/local/bin/
sudo mv mediamtx.yml /usr/local/etc/
# Start mediamtx in background
mediamtx &
# Pipe rpicam-vid into the RTSP server
rpicam-vid --nopreview -t 0 --inline --listen -o - | \
  ffmpeg -re -i - -c copy -f rtsp rtsp://localhost:8554/picam

The stream is then available at rtsp://<pi-ip>:8554/picam from any RTSP-capable client.

Running the Camera as a systemd Service

To start the stream automatically at boot, write a unit file:

sudo nano /etc/systemd/system/picam-stream.service
[Unit]
Description=Pi Camera TCP Stream
After=network.target

[Service]
ExecStart=/usr/bin/rpicam-vid --nopreview -t 0 --inline -o tcp://0.0.0.0:8888
Restart=on-failure
User=pi

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now picam-stream.service
sudo systemctl status picam-stream.service

Verification

After capturing a still, verify the EXIF metadata to confirm sensor details and settings were applied correctly:

exiftool photo.jpg | grep -E 'Camera Model|Shutter|ISO|Image Size'

For the streaming service, check that the port is listening:

ss -tlnp | grep 8888

Troubleshooting

  • No cameras detected: Confirm the cable is in the correct CSI port (Pi 5 has two). Check dmesg | grep -i imx or dmesg | grep -i ov for sensor probe failures. If the sensor is missing entirely from dmesg, the cable is loose or reversed.
  • "Failed to import fd" error: Usually a permissions issue. Ensure your user is in the video group: sudo usermod -aG video $USER and re-login.
  • Preview crashes on Wayland: Raspberry Pi OS Bookworm uses Wayland by default. If rpicam-hello crashes the display, add --qt-preview flag or use --nopreview and pipe output elsewhere.
  • Low framerate in stream: Reduce resolution or lower the bitrate. On Pi 4, 1080p30 is stable; 1080p60 may drop frames over a loaded network. Use --width 1280 --height 720 for more headroom.
  • libcamera tuning file not found: If you are using a third-party sensor, point to the tuning JSON explicitly: --tuning-file /usr/share/libcamera/ipa/rpi/vc4/your_sensor.json.
tested on:Debian 12 (Bookworm) on Raspberry Pi OS 64-bitDebian 11 (Bullseye) on Raspberry Pi OS 64-bitUbuntu 24.04 LTS (Noble) ARM64 on Pi 4

Frequently asked questions

Can I use the legacy raspistill and raspivid commands on Raspberry Pi OS Bookworm?
No. The legacy camera stack was removed in Bookworm. The raspistill and raspivid binaries no longer exist; you must use rpicam-still and rpicam-vid from the rpicam-apps suite.
How do I use two cameras simultaneously on a Pi 5?
The Pi 5 has two CSI connectors. Connect both modules and select which one to use with the --camera 0 or --camera 1 flag. Running two streams simultaneously requires two separate rpicam-vid processes, each specifying a different camera index.
Why does the preview window not appear or crash on my desktop?
Raspberry Pi OS Bookworm uses Wayland by default, and the default DRM/KMS preview can conflict with it. Use --nopreview for headless use, or add --qt-preview to get a Qt-based window that works under Wayland.
What is the maximum resolution and framerate for video recording?
It depends on the sensor. The Camera Module 3 (IMX708) supports up to 4608x2592 at around 14 fps or 1080p at 50 fps in hardware. The HQ camera (IMX477) tops out at 4056x3040 for stills and 1080p30 for practical video. Check rpicam-hello --list-cameras for your sensor's supported modes.
How do I reduce streaming latency below 1 second?
Use UDP instead of TCP, pass -fflags nobuffer -flags low_delay -framedrop to ffplay on the viewer, and lower the encoder intra-period with --intra on the Pi side. Switching to a wired Ethernet connection over Wi-Fi also helps significantly.

Related guides