How to Setup Raspberry Pi Camera Module 3 on Ubuntu 24.04
If you’ve tried using the Raspberry Pi Camera Module 3 with Ubuntu 24.04, you’ve probably discovered it doesn’t work out of the box. The standard libcamera package from Ubuntu’s repositories doesn’t support Raspberry Pi cameras. Here’s the complete, tested solution.
The Problem
Ubuntu 24.04’s default libcamera is the upstream version, which lacks support for Raspberry Pi’s camera hardware. To get your Camera Module 3 working, you need to build Raspberry Pi’s fork of libcamera and rpicam-apps from source.
Prerequisites
- Raspberry Pi 4 or 5 running Ubuntu 24.04
- Camera Module 3 properly connected
- Internet connection
- At least 2GB free disk space
Step 1: Remove Conflicting Packages
First, remove any pre-installed camera packages:
# Remove existing rpicam-apps
sudo apt remove --purge rpicam-apps
# Remove standard libcamera (if installed)
sudo apt remove --purge libcamera-dev libcamera0
Step 2: Install Build Dependencies
Install all required development tools and libraries:
# Essential build tools
sudo apt install -y git python3-pip python3-jinja2 meson cmake ninja-build
# libcamera dependencies
sudo apt install -y libboost-dev libgnutls28-dev openssl libtiff5-dev pybind11-dev
sudo apt install -y python3-yaml python3-ply libglib2.0-dev libgstreamer-plugins-base1.0-dev
# rpicam-apps dependencies
sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev
sudo apt install -y libepoxy-dev libjpeg-dev libtiff5-dev libpng-dev
# For desktop Ubuntu (with GUI preview)
sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5
# Hardware encoder support
sudo apt install -y v4l-utils
Step 3: Build libcamera (Raspberry Pi Fork)
Clone and build Raspberry Pi’s libcamera fork:
# Clone the Raspberry Pi fork
git clone https://github.com/raspberrypi/libcamera.git
cd libcamera
# Configure the build
meson setup build --buildtype=release \
-Dpipelines=rpi/vc4,rpi/pisp \
-Dipas=rpi/vc4,rpi/pisp \
-Dv4l2=true \
-Dgstreamer=enabled \
-Dtest=false \
-Dlc-compliance=disabled \
-Dcam=disabled \
-Dqcam=disabled \
-Ddocumentation=disabled \
-Dpycamera=enabled
# Build (this takes 10-15 minutes)
ninja -C build
# Install
sudo ninja -C build install
# Return to home directory
cd ~
Note for low-memory devices (Pi Zero, Pi 3): Add -j 1 to ninja commands to limit to single-core compilation:
ninja -C build -j 1
Step 4: Build rpicam-apps
Now build the camera applications:
# Clone rpicam-apps
git clone https://github.com/raspberrypi/rpicam-apps.git
cd rpicam-apps
# Configure for desktop Ubuntu
meson setup build \
-Denable_libav=disabled \
-Denable_drm=enabled \
-Denable_egl=enabled \
-Denable_qt=enabled \
-Denable_opencv=disabled \
-Denable_tflite=disabled \
-Denable_hailo=disabled
# For Ubuntu Server (headless), use this instead:
# meson setup build \
# -Denable_libav=disabled \
# -Denable_drm=enabled \
# -Denable_egl=disabled \
# -Denable_qt=disabled \
# -Denable_opencv=disabled \
# -Denable_tflite=disabled \
# -Denable_hailo=disabled
# Build
meson compile -C build
# Install
sudo meson install -C build
# Update library cache
sudo ldconfig
cd ~
Step 5: Enable the Camera Hardware
Edit the boot configuration:
sudo nano /boot/firmware/config.txt
Add this line at the end (choose the correct overlay for your camera):
# For Camera Module 3
dtoverlay=imx708
# For other cameras, use:
# dtoverlay=imx477 # HQ Camera
# dtoverlay=imx296 # GS Camera
# dtoverlay=imx519 # 16MP Camera
Save with Ctrl+X, then Y, then Enter.
Step 6: Reboot
sudo reboot
Step 7: Test Your Camera
After reboot, verify everything works:
# Check version
rpicam-hello --version
# List detected cameras
rpicam-hello --list-cameras
# Preview for 5 seconds
rpicam-hello -t 5000
# Take a photo
rpicam-still -o test.jpg
# Record 10 seconds of video (IMPORTANT: use --codec yuv420)
rpicam-vid -t 10000 -o test.h264 --codec yuv420
Important: Video Recording Fix
⚠️ Critical: When recording video, you must specify --codec yuv420 to use the hardware H.264 encoder. Without this flag, rpicam-vid will fail with an encoder error.
# Correct way to record video
rpicam-vid -t 10000 -o video.h264 --codec yuv420
# Record at 1080p
rpicam-vid -t 10000 -o video.h264 --codec yuv420 --width 1920 --height 1080
# Record with 10 Mbps bitrate
rpicam-vid -t 10000 -o video.h264 --codec yuv420 -b 10000000
# Continuous recording (Ctrl+C to stop)
rpicam-vid -t 0 -o video.h264 --codec yuv420
Optional: Make yuv420 Default
To avoid typing --codec yuv420 every time, create an alias:
echo "alias rpicam-vid='rpicam-vid --codec yuv420'" >> ~/.bashrc
source ~/.bashrc
Common Commands Reference
Photo Capture
# Basic photo
rpicam-still -o photo.jpg
# Full resolution photo
rpicam-still -o photo.jpg -r
# Photo with 5-second preview
rpicam-still -o photo.jpg -t 5000
# Photo at specific resolution
rpicam-still -o photo.jpg --width 1920 --height 1080
Video Recording
# 30-second video
rpicam-vid -t 30000 -o video.h264 --codec yuv420
# 4K video
rpicam-vid -t 10000 -o video.h264 --codec yuv420 --width 3840 --height 2160
# High quality video (20 Mbps)
rpicam-vid -t 10000 -o video.h264 --codec yuv420 -b 20000000
Preview
# 10-second preview
rpicam-hello -t 10000
# Fullscreen preview
rpicam-hello -t 10000 --fullscreen
Troubleshooting
Camera Not Detected
# Check camera connection
vcgencmd get_camera
# Check kernel messages
dmesg | grep -i camera
# Verify video devices exist
ls -l /dev/video*
# List available video devices
v4l2-ctl --list-devices
You should see rpivid in the output, which is the hardware encoder.
Build Fails on Low Memory Devices
If compilation fails with memory errors on devices like Raspberry Pi Zero or Pi 3:
# Use single-core compilation
ninja -C build -j 1
meson compile -C build -j 1
Video Encoding Error
If you see ERROR: *** Unable to find an appropriate H.264 codec ***, you forgot to add --codec yuv420:
# Wrong (will fail)
rpicam-vid -t 10000 -o video.h264
# Correct (will work)
rpicam-vid -t 10000 -o video.h264 --codec yuv420
Permission Denied
Add your user to the video group:
sudo usermod -aG video $USER
# Log out and back in for changes to take effect
Why This Works
Ubuntu’s libcamera comes from the upstream repository and doesn’t include Raspberry Pi-specific drivers. Raspberry Pi maintains a fork with:
- Support for Raspberry Pi camera hardware
- PiSP (Pi Signal Processor) integration
- Optimized camera tuning files
- Hardware encoder integration
By building from Raspberry Pi’s fork, you get full camera functionality on Ubuntu.
Performance Notes
-
Hardware encoding: The
yuv420codec uses the Raspberry Pi’s hardware H.264 encoder (rpivid), which provides excellent performance with minimal CPU usage - Preview: The EGL preview uses GPU acceleration for smooth display
- Quality: The hardware encoder produces high-quality video comparable to Raspberry Pi OS
Tested On
- ✅ Raspberry Pi 5 + Ubuntu 24.04 LTS
- ✅ Raspberry Pi 4 + Ubuntu 24.04 LTS
- ✅ Camera Module 3
- ✅ Desktop and Server editions
Summary
Your Raspberry Pi Camera Module 3 is now fully functional on Ubuntu 24.04:
- ✅ Live preview with
rpicam-hello - ✅ Photo capture with
rpicam-still - ✅ Video recording with
rpicam-vid --codec yuv420 - ✅ Hardware-accelerated H.264 encoding
- ✅ All advanced camera features available
Additional Resources
Credits
This guide synthesizes information from:
- Raspberry Pi official documentation
- Ubuntu community forums
- Personal testing and troubleshooting
Found this helpful? Leave a comment below if you run into any issues or have improvements to suggest!
