mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
new room cam service
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# Room camera snapshot service
|
||||
|
||||
Lightweight systemd service that serves a JPEG snapshot from any MJPEG-capable webcam (most USB webcams) at 4 fps. The server pulls `http://<host>:8080/snapshot.jpg` for room cams.
|
||||
|
||||
## Files
|
||||
- `room-cam-snapshot.sh` – ffmpeg + simple HTTP server wrapper
|
||||
- `room-cam.service` – systemd unit template
|
||||
|
||||
## Usage
|
||||
1) Copy the service into place (adjust path/env as needed):
|
||||
```bash
|
||||
sudo cp roomcam-service/room-cam.service /etc/systemd/system/room-cam.service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now room-cam.service
|
||||
```
|
||||
2) Override defaults via `Environment=` in the unit or drop-ins:
|
||||
- `DEVICE=/dev/video0`
|
||||
- `RESOLUTION=640x480`
|
||||
- `QUALITY=5` (ffmpeg MJPEG quality; lower is higher quality)
|
||||
- `PORT=8080`
|
||||
- `WORKDIR=/run/roomcam`
|
||||
3) Point the server `roomCameras[].url` to `http://<host>:8080/snapshot.jpg`.
|
||||
|
||||
Notes:
|
||||
- The camera runs at its native MJPEG frame rate; the server polls snapshots at ~4 fps, so no extra filtering is applied here.
|
||||
|
||||
To run outside systemd, just execute `./room-cam-snapshot.sh` with any overrides.
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Configurable via environment
|
||||
DEVICE="${DEVICE:-/dev/video0}"
|
||||
RESOLUTION="${RESOLUTION:-640x480}"
|
||||
QUALITY="${QUALITY:-5}" # ffmpeg MJPEG quality (lower is better)
|
||||
PORT="${PORT:-8088}"
|
||||
WORKDIR="${WORKDIR:-/run/roomcam}"
|
||||
|
||||
mkdir -p "${WORKDIR}"
|
||||
SNAPSHOT_PATH="${WORKDIR}/snapshot.jpg"
|
||||
|
||||
cleanup() {
|
||||
[[ -n "${FFMPEG_PID:-}" ]] && kill "${FFMPEG_PID}" 2>/dev/null || true
|
||||
[[ -n "${HTTP_PID:-}" ]] && kill "${HTTP_PID}" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
trap 'exit 0' SIGTERM INT
|
||||
|
||||
/usr/bin/ffmpeg \
|
||||
-loglevel warning -nostats \
|
||||
-f v4l2 -input_format mjpeg -video_size "${RESOLUTION}" -i "${DEVICE}" \
|
||||
-q:v "${QUALITY}" \
|
||||
-f image2 -update 1 "${SNAPSHOT_PATH}" &
|
||||
FFMPEG_PID=$!
|
||||
|
||||
/usr/bin/python3 -u -m http.server "${PORT}" --directory "${WORKDIR}" --bind 0.0.0.0 &
|
||||
HTTP_PID=$!
|
||||
|
||||
wait -n "${FFMPEG_PID}" "${HTTP_PID}"
|
||||
@@ -0,0 +1,22 @@
|
||||
[Unit]
|
||||
Description=Room camera snapshot server (MJPEG webcam)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Environment=DEVICE=/dev/video0
|
||||
Environment=RESOLUTION=640x480
|
||||
Environment=FPS=4
|
||||
Environment=QUALITY=5
|
||||
Environment=PORT=8080
|
||||
Environment=WORKDIR=/run/roomcam
|
||||
WorkingDirectory=/home/daniel/gits/MultiRoombaRover/roomcam-service
|
||||
ExecStart=/usr/bin/env bash /home/daniel/gits/MultiRoombaRover/roomcam-service/room-cam-snapshot.sh
|
||||
Restart=always
|
||||
RestartSec=2
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user