TECHNICAL BLOG

Deep Dives for Engineers

Detailed technical articles covering the real problems we solve in embedded systems, AI, and robotics engineering.

Camera Module Integration in Embedded Linux: CSI-2, V4L2, and GStreamer
RDK and Broadband

Camera Module Integration in Embedded Linux: CSI-2, V4L2, and GStreamer

Worksprout Team Jan 18, 2025 8 min read

How to integrate camera modules into embedded Linux systems — from CSI-2 hardware interface and V4L2 driver configuration to efficient GStreamer pipeline construction.

Camera Interfaces in Embedded Linux

Embedded camera integration typically uses one of two hardware interfaces: USB Video Class (UVC) for USB cameras, and MIPI CSI-2 for compact, high-bandwidth camera modules soldered or connected directly to the SoC. CSI-2 is the preferred interface for embedded products where latency, power, and form factor matter — it offers up to 4.5 Gbps per lane, low CPU overhead through DMA transfers, and zero-copy paths into SoC image signal processors.

The V4L2 Subsystem

Linux's Video4Linux2 (V4L2) subsystem provides the kernel abstraction layer between camera hardware and userspace applications. A camera driver exposes a /dev/videoN device node with a standardised ioctl interface for format negotiation, buffer management, and streaming control. Applications use V4L2 ioctls directly or through libraries like libv4l2.

Query a connected camera's capabilities:

v4l2-ctl --device=/dev/video0 --list-formats-ext
v4l2-ctl --device=/dev/video0 --all

Devicetree Camera Configuration

For CSI-2 cameras, the camera sensor driver and the SoC's MIPI CSI receiver are both described in the devicetree, with a media pipeline linking them. A simplified example for a Sony IMX219 (Raspberry Pi Camera Module 2):

&csi1 {
    status = "okay";
    port {
        csi1_ep: endpoint {
            remote-endpoint = &imx219_0;
            data-lanes = <1 2>;
            clock-lanes = <0>;
        };
    };
};

&i2c0 {
    imx219: camera@10 {
        compatible = "sony,imx219";
        reg = <0x10>;
        port {
            imx219_0: endpoint {
                remote-endpoint = &csi1_ep;
                link-frequencies = /bits/ 64 <456000000>;
                data-lanes = <1 2>;
            };
        };
    };
};

GStreamer Pipeline Design

GStreamer is the standard framework for camera pipeline construction in embedded Linux. Its plugin architecture cleanly separates capture, conversion, encoding, and output concerns. A basic capture-to-display pipeline:

gst-launch-1.0 v4l2src device=/dev/video0 !   video/x-raw,width=1280,height=720,framerate=30/1 !   videoconvert ! autovideosink

For inference integration, replace autovideosink with an appsink and process frames in Python:

import gi, cv2, numpy as np
gi.require_version("Gst", "1.0")
from gi.repository import Gst, GLib

Gst.init(None)
pipeline = Gst.parse_launch(
    "v4l2src device=/dev/video0 ! "
    "video/x-raw,width=640,height=480,framerate=30/1 ! "
    "videoconvert ! video/x-raw,format=BGR ! "
    "appsink name=sink emit-signals=true max-buffers=1 drop=true"
)
sink = pipeline.get_by_name("sink")
sink.connect("new-sample", on_frame)
pipeline.set_state(Gst.State.PLAYING)
GLib.MainLoop().run()

Image Signal Processing

Raw Bayer output from CMOS sensors requires ISP processing — debayering, white balance, noise reduction, tone mapping — before it is useful for display or machine vision. SoCs like the BCM2711 (Pi 4/5), Amlogic S905X3, and Rockchip RK3588 include hardware ISPs accessible through dedicated V4L2 subdevice drivers. Leverage the hardware ISP path rather than software processing wherever possible — it saves substantial CPU cycles and produces better image quality.

Conclusion

Camera integration in embedded Linux requires alignment across three layers: correct hardware devicetree description, a working V4L2 driver stack, and an efficient GStreamer pipeline. Invest time in understanding the media controller topology (via media-ctl -p) for CSI cameras — it reveals the complete pipeline graph and makes debugging format negotiation failures much faster.

Share

Worksprout Team

The Worksprout engineering team specialises in embedded Linux, RDK-B broadband platforms, edge AI, and robotics systems. Based in Rajshahi, Bangladesh, we design and deploy production embedded intelligence for clients across South Asia and beyond.

Related Posts

Continue reading — handpicked articles you might enjoy