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:
@@ -1,27 +0,0 @@
|
||||
[Unit]
|
||||
Description=Room concrete camera SRT publisher (Pi)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
# PS3 Eye mic (card 2) exposes 4ch/16k; use plughw to avoid format errors.
|
||||
ExecStartPre=/usr/bin/sh -c "/usr/bin/amixer -q -c 2 sset 'Mic Capture Switch' cap || /usr/bin/true"
|
||||
ExecStartPre=/usr/bin/sh -c "/usr/bin/amixer -q -c 2 sset 'Mic Capture Volume' 100% || /usr/bin/amixer -q -c 2 sset 'Mic' 100% cap || /usr/bin/true"
|
||||
ExecStart=/usr/bin/ffmpeg \
|
||||
-fflags nobuffer -flags low_delay -rtbufsize 0 -thread_queue_size 256 \
|
||||
-f v4l2 -input_format yuyv422 -video_size 640x480 -framerate 30 -i /dev/video0 \
|
||||
-fflags nobuffer -thread_queue_size 256 -f alsa -ac 4 -ar 16000 -i plughw:2,0 \
|
||||
-map 0:v:0 -map 1:a:0 \
|
||||
-c:v h264_v4l2m2m -b:v 600k -maxrate 700k -bufsize 1400k -g 30 -bf 0 -pix_fmt yuv420p \
|
||||
-af "pan=mono|c0=FL+FR,volume=0.5" \
|
||||
-c:a libopus -b:a 64k -ar 16000 -ac 1 \
|
||||
-flush_packets 1 -f mpegts \
|
||||
srt://192.168.0.86:9000?streamid=#!::r=room/concrete,m=publish&latency=10&mode=caller&transtype=live&pkt_size=1316
|
||||
Restart=always
|
||||
RestartSec=2
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -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
|
||||
@@ -1,27 +0,0 @@
|
||||
[Unit]
|
||||
Description=Room camera SRT publisher (ensures mic capture unmuted)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
# Some USB mics only expose a single "Mic" control; don't fail if a control is missing.
|
||||
ExecStartPre=/usr/bin/sh -c "/usr/bin/amixer -q -c 0 sset 'Mic Capture Switch' cap || /usr/bin/true"
|
||||
ExecStartPre=/usr/bin/sh -c "/usr/bin/amixer -q -c 0 sset 'Mic Capture Volume' 100% || /usr/bin/amixer -q -c 0 sset 'Mic' 100% cap || /usr/bin/true"
|
||||
ExecStart=/usr/bin/ffmpeg \
|
||||
-fflags nobuffer -rtbufsize 0 -probesize 32 -analyzeduration 0 -use_wallclock_as_timestamps 1 \
|
||||
-thread_queue_size 256 -f v4l2 -input_format h264 -i /dev/video2 \
|
||||
-fflags nobuffer -thread_queue_size 256 -f alsa -ar 16000 -ac 2 -i hw:0,0 \
|
||||
-map 0:v:0 -map 1:a:0 \
|
||||
-c:v libx264 -preset ultrafast -tune zerolatency -flags +low_delay \
|
||||
-b:v 600k -maxrate 700k -bufsize 700k -g 30 -bf 0 -x264-params keyint=30:min-keyint=30:scenecut=0 \
|
||||
-c:a libopus -b:a 64k -ar 16000 -ac 1 \
|
||||
-flush_packets 1 -f mpegts \
|
||||
srt://192.168.0.86:9000?streamid=#!::r=room/carpet,m=publish&latency=10&mode=caller&transtype=live&pkt_size=1316
|
||||
Restart=always
|
||||
RestartSec=2
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user