pi-libcamera-rtsp
Raspberry Pi Camera → RTSP/HLS with libcamera + GStreamer
arm64
Raspberry PiCameraRTSPHLSGStreamerarm64
Overview
Primary hardware
Raspberry Pi 4/5 & CM4/CM5 (arm64)
What it does
Captures from libcamera (Pi Cam v2/HQ/GS), encodes H.264/H.265 via V4L2, serves RTSP (optional HLS).
Why it saves time
No more libcamera/GStreamer incantations; healthcheck, env-config, and multi-cam ready out of the box.
Get access
Use StreamDeploy to manage OTA updates, versioned configs, and rollbacks across fleets.
Request accessDockerfile
ARG BASE_IMAGE
# Pi OS arm64 base with libcamera & gstreamer
FROM ${BASE_IMAGE:-"raspberrypi/libcamera:latest"}
ENV DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
RUN apt-get update && apt-get install -y --no-install-recommends \
gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad gstreamer1.0-libav libcamera-apps \
python3 python3-pip curl ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Minimal rtsp server helper
RUN pip3 install --no-cache-dir gst-rtsp-server
WORKDIR /app
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
ENV CAMERA_INDEX=0 \
WIDTH=1280 HEIGHT=720 FPS=30 \
CODEC=h264 \
RTSP_PORT=8554 \
RTSP_PATH=/cam \
EXTRA_PIPELINE=""
EXPOSE 8554
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s \
CMD bash -lc 'nc -z localhost $RTSP_PORT'
ENTRYPOINT ["/app/entrypoint.sh"]
entrypoint.sh
#!/usr/bin/env bash
set -euo pipefail
: "${CAMERA_INDEX:=0}"
: "${WIDTH:=1280}"; : "${HEIGHT:=720}"; : "${FPS:=30}"
: "${CODEC:=h264}"; : "${RTSP_PORT:=8554}"; : "${RTSP_PATH:=/cam}"
: "${EXTRA_PIPELINE:=}"
# Select encoder caps for Pi (v4l2 stateful)
if [[ "${CODEC}" == "h265" ]]; then
ENC="v4l2h265enc"
RTP="rtph265pay pt=96"
else
ENC="v4l2h264enc extra-controls="controls,video_gop_size=30""
RTP="rtph264pay pt=96 config-interval=1"
fi
# libcamera source via libcamerasrc (if present) else fallback to libcamera-vid piping
if gst-inspect-1.0 libcamerasrc >/dev/null 2>&1; then
PIPE="libcamerasrc camera-index=${CAMERA_INDEX} ! video/x-raw,width=${WIDTH},height=${HEIGHT},framerate=${FPS}/1"
else
echo "[warn] libcamerasrc not found; attempting v4l2src /dev/video0"
PIPE="v4l2src device=/dev/video0 ! video/x-raw,width=${WIDTH},height=${HEIGHT},framerate=${FPS}/1"
fi
# Run RTSP server using gst-launch (simple, robust)
exec gst-launch-1.0 -v ${PIPE} ! videoconvert ! ${ENC} ! ${RTP} name=pay0 ${EXTRA_PIPELINE} \
! rtspclientsink location=rtsp://127.0.0.1:${RTSP_PORT}${RTSP_PATH} || true