Unlocking the full potential of your Raspberry Pi Camera Module 3 on Ubuntu 24.04 can be a bit of a puzzle. If you’ve tried to use it straight out of the box, you’ve likely encountered issues because the default libcamera package in Ubuntu doesn’t inherently support Raspberry Pi’s unique camera hardware. This comprehensive guide provides a meticulously tested solution to get your Camera Module 3 up and running seamlessly.
The Challenge: Ubuntu’s Camera Software Limitation
The core of the problem lies in Ubuntu 24.04’s stock libcamera implementation. It’s the generic upstream version, which, unfortunately, lacks the specific drivers and optimizations required for Raspberry Pi’s camera modules. To bridge this gap and enable your Camera Module 3, you’ll need to compile Raspberry Pi’s specialized fork of libcamera and its associated applications, rpicam-apps, directly from their source code.
What You’ll Need
- A Raspberry Pi 4 or 5 powered by Ubuntu 24.04.
- A Camera Module 3, correctly attached to your Raspberry Pi.
- An active internet connection.
- At least 2GB of available storage space.
Step 1: Remove Any Pre-existing Camera Software
Before installing the custom components, it’s crucial to clear out any potentially conflicting camera packages that might already be on your system:
# 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 Essential Development Tools and Libraries
Proceed to install all the necessary build tools and libraries required for compiling libcamera and rpicam-apps:
# 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: Compile Raspberry Pi’s libcamera Fork
Now, clone the Raspberry Pi-specific libcamera repository and begin the compilation process:
# 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 ~
Important for devices with limited memory (e.g., Pi Zero, Pi 3): To prevent compilation errors, add -j 1 to your ninja commands to restrict the process to a single CPU core:
ninja -C build -j 1
Step 4: Compile rpicam-apps
With libcamera built, the next step is to compile the associated 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: Activate Camera Hardware in Boot Configuration
Edit your Raspberry Pi’s boot configuration to properly enable the camera hardware. Open the config.txt file:
sudo nano /boot/firmware/config.txt
At the very end of the file, add the appropriate camera overlay for your module. For Camera Module 3, use dtoverlay=imx708. If you’re using a different camera, choose the corresponding overlay:
# For Camera Module 3
dtoverlay=imx708
# For other cameras, use:
# dtoverlay=imx477 # HQ Camera
# dtoverlay=imx296 # GS Camera
# dtoverlay=imx519 # 16MP Camera
Save your changes by pressing Ctrl+X, then Y, and finally Enter.
Step 6: Restart Your Raspberry Pi
For the changes to take effect, a reboot is essential:
sudo reboot
Step 7: Verify Camera Functionality
Once your Raspberry Pi has restarted, confirm that your camera is working correctly using the following commands:
# 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
Crucial Note: Video Recording Requires Specific Codec
⚠️ It’s vital to remember: When recording video with rpicam-vid, you must include the --codec yuv420 flag. This ensures that the Raspberry Pi’s hardware H.264 encoder is utilized. Omitting this flag will result in an encoder error and prevent video recording.
# 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: Create an Alias for `yuv420` Default
To avoid repeatedly typing --codec yuv420, you can create a convenient alias:
echo "alias rpicam-vid='rpicam-vid --codec yuv420'" >> ~/.bashrc
source ~/.bashrc
Reference: Common Camera Commands
Here’s a quick reference for common tasks using your newly configured camera:
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
Live Preview
# 10-second preview
rpicam-hello -t 10000
# Fullscreen preview
rpicam-hello -t 10000 --fullscreen
Troubleshooting Common Issues
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 listed, indicating the hardware encoder is recognized.
Compilation Failures on Low-Memory Devices?
If your compilation halts due to memory constraints on devices like the Raspberry Pi Zero or Pi 3, try compiling with a single core:
# Use single-core compilation
ninja -C build -j 1
meson compile -C build -j 1
Encountering Video Encoding Errors?
If you receive an error message like ERROR: *** Unable to find an appropriate H.264 codec ***, it typically means you forgot to include --codec yuv420 in your rpicam-vid command:
# Wrong (will fail)
rpicam-vid -t 10000 -o video.h264
# Correct (will work)
rpicam-vid -t 10000 -o video.h264 --codec yuv420
Facing Permission Denied Issues?
Add your user to the video group to grant necessary permissions:
sudo usermod -aG video $USER
# Log out and back in for changes to take effect
Understanding Why This Solution Works
The standard libcamera package provided by Ubuntu originates from the upstream project and lacks the specific drivers and features tailored for Raspberry Pi’s unique camera hardware. The Raspberry Pi Foundation maintains its own fork of libcamera, which includes:
- Dedicated support for Raspberry Pi camera modules.
- Integration with the Pi Signal Processor (PiSP).
- Finely tuned camera calibration and configuration files.
- Seamless integration of the hardware video encoder.
By compiling and installing this specialized fork, you enable comprehensive camera functionality on your Ubuntu-powered Raspberry Pi.
Performance Insights
-
Hardware Encoding: The
yuv420codec leverages the Raspberry Pi’s dedicated hardware H.264 encoder (rpivid), ensuring high performance with minimal CPU load. - Smooth Previews: The EGL preview system utilizes GPU acceleration, delivering fluid and responsive live camera feeds.
- Exceptional Quality: The hardware encoder produces video quality comparable to that achieved on Raspberry Pi OS.
Validated Environments
This guide has been thoroughly tested and confirmed to work on the following setups:
- ✅ Raspberry Pi 5 running Ubuntu 24.04 LTS
- ✅ Raspberry Pi 4 running Ubuntu 24.04 LTS
- ✅ With the Camera Module 3
- ✅ On both Desktop and Server editions of Ubuntu
In Summary
With these steps, your Raspberry Pi Camera Module 3 should now be fully operational on Ubuntu 24.04, allowing you to:
- ✅ Enjoy live previews using
rpicam-hello. - ✅ Capture high-quality photos with
rpicam-still. - ✅ Record videos efficiently with
rpicam-vid --codec yuv420. - ✅ Benefit from hardware-accelerated H.264 video encoding.
- ✅ Access all advanced camera features available.
Additional Resources
- Raspberry Pi libcamera GitHub Repository
- Official rpicam-apps Documentation
- Upstream libcamera Documentation
Attributions
This comprehensive guide is a distillation of information gathered from:
- Official Raspberry Pi documentation.
- Discussions within the Ubuntu community forums.
- Extensive personal testing and troubleshooting efforts.
Did you find this tutorial helpful? Please share your feedback or any improvements you might have in the comments below!
#RaspberryPi #Ubuntu #Linux #CameraModule3 #Tutorial #TechGuide #HardwareSetup