Files
appRobotWebcam/docker-compose.yaml
2026-06-04 06:13:20 +02:00

110 lines
5.9 KiB
YAML
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.
name: approbotwebcam
# ════════════════════════════════════════════════════════════════════════════
# FINALER WebRTC-AUFBAU go2rtc (Streaming) + Node.js (Viewer/Proxy/API)
# ════════════════════════════════════════════════════════════════════════════
#
# Portainer: Stack → Web editor → dieses YAML einfügen → Deploy.
# Vorher in Portainer → "Environment variables":
# APP_PATH = /absoluter/pfad/zum/appRobotWebcam (Code muss dort liegen)
#
# WICHTIG: Vor jedem Redeploy sicherstellen, dass server.js / public/ / src/
# auf dem Server unter APP_PATH aktuell sind (Synology-Sync abwarten).
#
# Firewall (Internet): TCP 8444 (Viewer+API+Signaling) · UDP 8555 (WebRTC-Media)
# Port 1984 (go2rtc) NICHT nach aussen läuft nur intern via localhost.
#
# Zugriff:
# Viewer: http://<host>:8444/
# Snapshot (Homing) http://<host>:8444/api/snapshot/cam0
# go2rtc-Debug-UI http://<host>:1984/ (nur intern/LAN)
# ════════════════════════════════════════════════════════════════════════════
configs:
go2rtc_yaml:
# Komplette go2rtc-Config eingebettet keine separate Datei nötig.
content: |
streams:
# Option C — ffmpeg: mit expliziten Input-Flags, OHNE -re und OHNE -readrate_initial_burst.
# go2rtc ist on-demand: startet FFmpeg erst wenn ein Client verbindet (bestätigt: 0% CPU ohne Client).
# -input_format mjpeg → Kamera-natives MJPEG, kein Pixel-Decode nötig
# -fflags nobuffer → kein Input-Puffer
# -flags low_delay → minimaler Decoder-Delay
# -probesize 32 → keine lange Format-Analyse beim Start
# -analyzeduration 0 → sofortiger Start
# go2rtc übernimmt H.264-Encoding (-g 50 bleibt, aber ohne -re-Stau).
cam0: "ffmpeg:-f v4l2 -input_format mjpeg -video_size 640x480 -framerate 30 -fflags nobuffer -flags low_delay -probesize 32 -analyzeduration 0 -i /dev/video0#video=h264"
cam1: "ffmpeg:-f v4l2 -input_format mjpeg -video_size 640x480 -framerate 30 -fflags nobuffer -flags low_delay -probesize 32 -analyzeduration 0 -i /dev/video2#video=h264"
#
# Option B Hardware-Encoding (nächster Schritt falls CPU noch zu hoch):
# cam0: "ffmpeg:-f v4l2 -input_format mjpeg -video_size 640x480 -framerate 30 -fflags nobuffer -flags low_delay -i /dev/video0#video=h264#hardware"
# cam1: "ffmpeg:-f v4l2 -input_format mjpeg -video_size 640x480 -framerate 30 -fflags nobuffer -flags low_delay -i /dev/video2#video=h264#hardware"
webrtc:
listen: ":8555"
candidates:
# stun:8555 → go2rtc erkennt die öffentliche IP automatisch (für Internet).
# Falls das nicht klappt: feste IP/Domain eintragen, z.B.
# - robot.example.com:8555
- stun:8555
api:
listen: ":1984"
# origin "*" erlaubt das WebSocket-Signaling vom Viewer (Port 8444 = anderer Origin).
# Ohne diese Zeile blockt go2rtc den WS mit "request origin not allowed".
# LAN: unkritisch. Internet: Caddy davor schränkt den Zugriff wieder ein.
origin: "*"
log:
level: info
# TODO (on-demand Encoding): go2rtc hält den Encoder auch ohne Clients am Laufen.
# Das verbraucht unnötig ~35% CPU wenn niemand zuschaut.
# Lösung: v4l2:/dev/video0 ohne #video=h264 → go2rtc öffnet Kamera nur bei Bedarf?
# Oder: mediamtx als Zwischenstufe (hat explizites on-demand). Prüfen.
services:
# ── go2rtc: Kamera-Capture · H.264-Encoding · WebRTC ──────────────────────
go2rtc:
image: ghcr.io/alexxit/go2rtc
container_name: AppRobotGo2RTC
restart: unless-stopped
network_mode: host # echte Host-IP als WebRTC-ICE-Kandidat
devices:
- /dev/video0:/dev/video0
- /dev/video2:/dev/video2
group_add:
- video
configs:
- source: go2rtc_yaml
target: /config/go2rtc.yaml
# ── webcam: Node.js (Viewer · /api/ws-Proxy · Snapshot-API) ──────────────
webcam:
build:
context: /tmp # Leerer Build-Context Code kommt per Bind-Mount
dockerfile_inline: |
FROM node:lts-bookworm-slim
WORKDIR /usr/src/app
EXPOSE 8444
image: approbotwebcam:latest
container_name: AppRobotWebcam
restart: unless-stopped
network_mode: host # erreicht go2rtc via localhost:1984
command: sh -c "npm install --omit=dev && node server.js"
volumes:
- ${APP_PATH:-.}:/usr/src/app
environment:
- NODE_ENV=production
- PORT=8444
- GO2RTC_URL=http://localhost:1984
depends_on:
- go2rtc
# ── FALLBACK ──────────────────────────────────────────────────────────────────
# Meckert Portainer beim Deploy über "configs content" (sehr alte Compose-Version)?
# → den configs-Block oben löschen und stattdessen beim go2rtc-Service mounten:
# volumes:
# - ${APP_PATH:-.}/go2rtc.yaml:/config/go2rtc.yaml:ro
#
# Bleibt eine Kamera schwarz? → in der Config oben die Quelle ersetzen durch die
# simple, bestätigte Form (ohne Auflösung): "ffmpeg:/dev/video0#video=h264#video=mjpeg"
# ────────────────────────────────────────────────────────────────────────────────