raspi-cam

MJPEG-Stream-Server für die Raspberry-Pi-Kamera. Startet rpicam-vid einmalig als Singleton-Prozess und verteilt die Frames per Flask an beliebig viele Viewer. Bei einem Absturz von rpicam-vid erfolgt ein automatischer Neustart.

Raspi-Cam MJPEG Streaming

Voraussetzungen

  • Raspberry Pi mit angeschlossener Kamera
  • rpicam-vid (rpicam-apps)
  • Python 3 mit venv (sudo apt install python3-venv)

Installation

python3 -m venv venv
venv/bin/pip install -r requirements.txt

Start

venv/bin/python app.py

Danach erreichbar unter:

URL Beschreibung
http://<host>:8080/ HTML-Seite mit Live-Stream
http://<host>:8080/stream MJPEG-Stream
http://<host>:8080/stream.mjpg MJPEG-Stream (vehicle-counter kompatibel)

Autostart mit systemd

Die Unit nutzt den Interpreter aus dem venv (venv/bin/python), das Projekt muss also vorher wie oben installiert sein. In raspi-cam.service ggf. User und die Pfade anpassen. Der User muss Mitglied der Gruppe video sein.

sudo cp raspi-cam.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now raspi-cam

Status und Logs:

systemctl status raspi-cam
journalctl -u raspi-cam -f

Konfiguration

Die Konfiguration erfolgt über Umgebungsvariablen oder eine .env-Datei im Projektverzeichnis.

Variable Beschreibung Default
APP_HOST Bind-Adresse 0.0.0.0
APP_PORT HTTP-Port 8080
CAM_MODE Sensor-Modus 1640:1232
CAM_WIDTH Ausgabebreite 640
CAM_HEIGHT Ausgabehöhe 480
CAM_FRAMERATE Ziel-FPS 20
CAM_QUALITY JPEG-Qualität (1–100) 30
CAM_ROTATION Rotation (0/90/180/270) leer

Beispiel .env:

CAM_MODE=1640:1232
CAM_WIDTH=820
CAM_HEIGHT=616
CAM_FRAMERATE=20
CAM_QUALITY=50
CAM_ROTATION=
APP_PORT=8080
S
Description
Python Script für Raspberry Pi Kameras
Readme
558 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 100%