Files
raspi-camera/README.md
T

104 lines
3.1 KiB
Markdown
Raw 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 |
|---|---|---|---|
| OV5647 | 5 MP | Camera Module V1 | Älterer Klassiker |
| IMX219 | 8 MP | Camera Module V2 | Bewährt, günstig |
| IMX708 | 12 MP | Camera Module 3 | Autofokus, HDR |
| IMX477 | 12,3 MP | HQ Camera | Größerer Sensor, Wechselobjektive |
| IMX296 | 1,6 MP | Global Shutter | Keine Rolling-Shutter-Verzerrung |
| IMX500 | 12,3 MP | AI Camera | KI-Beschleuniger direkt im Sensor |
NoIR-Varianten (ohne Infrarotfilter) gibt es für V1, V2, Module 3 und HQ. Sie nutzen denselben Sensor und dieselben Modi.
### Passende `CAM_MODE`
Richtwerte, die tatsächlichen Modi können abweichen.
| Sensor | `CAM_MODE` |
|---|---|
| OV5647 | `1296:972`, `1920:1080` |
| IMX219 (getestet) | `1640:1232`, `1920:1080` |
| IMX708 | `2304:1296` |
| IMX477 | `2028:1520`, `2028:1080` |
| IMX296 | `1456:1088` |
| IMX500 | `2028:1520` |