Files

91 lines
3.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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](pictures/Raspi-Cam-MJPEG-Streaming.png)
## Voraussetzungen
- Raspberry Pi mit angeschlossener Kamera
- `rpicam-vid` (rpicam-apps)
- Python 3 mit venv (`sudo apt install python3-venv`)
## Installation
```bash
python3 -m venv venv
venv/bin/pip install -r requirements.txt
```
## Start
```bash
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) |
| `http://<host>:8080/snapshot.jpg` | Einzelbild (siehe unten) |
## Snapshot
`/snapshot.jpg` liefert den aktuellen Frame als einzelnes JPEG, ohne zusätzliche Kameralast. Kurz nach dem Start, solange noch kein Frame da ist, antwortet der Endpoint mit HTTP 503.
```bash
curl -o pictures/foto.jpg http://<host>:8080/snapshot.jpg
```
## Autostart mit systemd
In `raspi-cam.service` ggf. `User` und die Pfade anpassen. Der User muss Mitglied der Gruppe `video` sein.
```bash
sudo cp raspi-cam.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now raspi-cam
```
Status und Logs:
```bash
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` oder `180`) | leer |
Eine kommentierte Vorlage liegt in `.env.example` (`cp .env.example .env`). Die Sensor-Modi der angeschlossenen Kamera zeigt `rpicam-hello --list-cameras`.
## Kompatible Kameras
Alle offiziellen Raspberry-Pi-Kameras laufen mit `rpicam-vid`.
| Sensor | Auflösung | Kamera | Besonderheit | Passende `CAM_MODE` |
|---|---|---|---|---|
| OV5647 | 5 MP | <a href="https://link.amazon/B0iK3Ao79" target="_blank" rel="noopener sponsored">Camera Module V1</a> | Älterer Klassiker | `1296:972`, `1920:1080` |
| IMX219 | 8 MP | <a href="https://link.amazon/B07Z4ZNQ4" target="_blank" rel="noopener sponsored">Camera Module V2</a> | Bewährt, günstig (getestet) | `1640:1232`, `1920:1080` |
| IMX708 | 12 MP | <a href="https://link.amazon/B05vUbiip" target="_blank" rel="noopener sponsored">Camera Module 3</a> | Autofokus, HDR | `2304:1296` |
| IMX477 | 12,3 MP | <a href="https://link.amazon/B0e6OllYf" target="_blank" rel="noopener sponsored">HQ Camera</a> | Größerer Sensor, Wechselobjektive | `2028:1520`, `2028:1080` |
| IMX296 | 1,6 MP | <a href="https://link.amazon/B01uK3Cuf" target="_blank" rel="noopener sponsored">Global Shutter</a> | Keine Rolling-Shutter-Verzerrung | `1456:1088` |
| IMX500 | 12,3 MP | <a href="https://link.amazon/B0fjD4vcA" target="_blank" rel="noopener sponsored">AI Camera</a> | KI-Beschleuniger direkt im Sensor | `2028:1520` |
Die Kamera-Links sind Affiliate-Links (Werbung): Als Amazon-Partner verdiene ich an qualifizierten Verkäufen. Die Modi sind Richtwerte, die tatsächlichen können abweichen. NoIR-Varianten (ohne Infrarotfilter) gibt es für V1, V2, Module 3 und HQ. Sie nutzen denselben Sensor und dieselben Modi.