Media-over-QUIC is a streaming protocol built upon cutting edge protocols (QUIC, HTTP3) and browser APIs (WebTransport, WebCodecs). It's slightly faster than WebRTC, has an advanced data recovery mechanism (placed at the frame level and not at the packet level), it supports additional codecs (FLAC) and is less complicated to route.
4.0 KiB
Raspberry Pi Cameras
MediaMTX natively supports most Raspberry Pi Camera models, enabling high-quality and low-latency video streaming from the camera to any user, for any purpose. There are some additional requirements:
-
The server must run on a Raspberry Pi, with one of the following operating systems:
- Raspberry Pi OS Trixie
- Raspberry Pi OS Bookworm
- Raspberry Pi OS Bullseye
Both 32-bit and 64-bit architectures are supported.
-
If you are using Raspberry Pi OS Bullseye, make sure that the legacy camera stack is disabled. Type
sudo raspi-config, then go toInterfacing options,enable/disable legacy camera support, chooseno. Reboot the system.
The setup procedure depends on whether you want to run the server outside or inside Docker:
-
If you want to run the standard (non-Dockerized) version of the server:
-
Download the server executable. If you're using 64-bit version of the operative system, make sure to pick the
arm64variant. -
Edit
mediamtx.ymland replace everything inside sectionpathswith the following content:
paths: cam: source: rpiCameraThe resulting stream will be available on path
/cam. -
-
If you want to run the server inside Docker, you need to use the
1-rpiimage and launch the container with some additional flags:docker run --rm -it \ --network=host \ --privileged \ --tmpfs /dev/shm:exec \ -v /run/udev:/run/udev:ro \ -e MTX_PATHS_CAM_SOURCE=rpiCamera \ bluenviron/mediamtx:1-rpi
The Raspberry Pi Camera can be controlled through a wide range of parameters, that are listed in the configuration file.
Custom libcamera
Some cameras, in particular ArduCam products, require a custom libcamera. These are not compatible with precompiled MediaMTX binaries and Docker images, since they embed a standard libcamera.
If you want to interact with these cameras, you need to compile MediaMTX from source.
Adding audio
In order to add audio from a USB microphone, install GStreamer and alsa-utils:
sudo apt install -y gstreamer1.0-tools gstreamer1.0-rtsp gstreamer1.0-alsa alsa-utils
list available audio cards with:
arecord -L
Sample output:
surround51:CARD=ICH5,DEV=0
Intel ICH5, Intel ICH5
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
default:CARD=U0x46d0x809
USB Device 0x46d:0x809, USB Audio
Default Audio Device
Find the audio card of the microphone and take note of its name, for instance default:CARD=U0x46d0x809. Then create a new path that takes the video stream from the camera and audio from the microphone:
paths:
cam:
source: rpiCamera
cam_with_audio:
runOnInit: >
gst-launch-1.0
rtspclientsink name=s location=rtsp://localhost:$RTSP_PORT/cam_with_audio
rtspsrc location=rtsp://127.0.0.1:$RTSP_PORT/cam latency=0 ! rtph264depay ! s.
alsasrc device=default:CARD=U0x46d0x809 ! opusenc bitrate=16000 ! s.
runOnInitRestart: yes
The resulting stream will be available on path /cam_with_audio.
Secondary stream
It is possible to enable a secondary stream from the same camera, with a different resolution, FPS and codec. Configuration is the same of a primary stream, with rpiCameraSecondary set to true and parameters adjusted accordingly:
paths:
# primary stream
rpi:
source: rpiCamera
# Width of frames.
rpiCameraWidth: 1920
# Height of frames.
rpiCameraHeight: 1080
# FPS.
rpiCameraFPS: 30
# secondary stream
secondary:
source: rpiCamera
# This is a secondary stream.
rpiCameraSecondary: true
# Width of frames.
rpiCameraWidth: 640
# Height of frames.
rpiCameraHeight: 480
# FPS.
rpiCameraFPS: 10
# Codec. in case of secondary streams, it defaults to M-JPEG.
rpiCameraCodec: auto
# JPEG quality.
rpiCameraMJPEGQuality: 60
The secondary stream will be available on path /secondary.