91 lines
3.3 KiB
Markdown
91 lines
3.3 KiB
Markdown
# 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.
|
||
|
||

|
||
|
||
## 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 | [Camera Module V1](https://link.amazon/B06pUz1hx) | Älterer Klassiker | `1296:972`, `1920:1080` |
|
||
| IMX219 | 8 MP | [Camera Module V2](https://link.amazon/B067tm0OG) | Bewährt, günstig (getestet) | `1640:1232`, `1920:1080` |
|
||
| IMX708 | 12 MP | [Camera Module 3](https://link.amazon/B06i4SJxj) | Autofokus, HDR | `2304:1296` |
|
||
| IMX477 | 12,3 MP | [HQ Camera](https://link.amazon/B0aSTdoui) | Größerer Sensor, Wechselobjektive | `2028:1520`, `2028:1080` |
|
||
| IMX296 | 1,6 MP | [Global Shutter](https://link.amazon/B03eIhcOQ) | Keine Rolling-Shutter-Verzerrung | `1456:1088` |
|
||
| IMX500 | 12,3 MP | [AI Camera](https://link.amazon/B0bzzySrw) | 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.
|