mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 09:31:20 -04:00
new new new
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ENV_FILE="${WHIP_ENV_FILE:-/var/lib/roverd/whip.env}"
|
||||
ENV_FILE="${VIDEO_ENV_FILE:-/var/lib/roverd/video.env}"
|
||||
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "Environment file ${ENV_FILE} missing; cannot publish" >&2
|
||||
@@ -11,7 +11,7 @@ fi
|
||||
# shellcheck disable=SC1090
|
||||
source "$ENV_FILE"
|
||||
|
||||
: "${WHIP_URL:?WHIP_URL not set in ${ENV_FILE}}"
|
||||
: "${PUBLISH_URL:?PUBLISH_URL not set in ${ENV_FILE}}"
|
||||
|
||||
VIDEO_WIDTH="${VIDEO_WIDTH:-1280}"
|
||||
VIDEO_HEIGHT="${VIDEO_HEIGHT:-720}"
|
||||
@@ -31,12 +31,10 @@ fi
|
||||
|
||||
if [[ -n "${FFMPEG_BIN:-}" ]]; then
|
||||
FFMPEG_BIN_PATH="$FFMPEG_BIN"
|
||||
elif command -v ffmpeg-whip >/dev/null 2>&1; then
|
||||
FFMPEG_BIN_PATH="$(command -v ffmpeg-whip)"
|
||||
elif command -v ffmpeg >/dev/null 2>&1; then
|
||||
FFMPEG_BIN_PATH="$(command -v ffmpeg)"
|
||||
else
|
||||
echo "ffmpeg not found; install it or run the installer to fetch ffmpeg-whip." >&2
|
||||
echo "ffmpeg not found; install it via apt install ffmpeg." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -57,18 +55,20 @@ run_pipeline() {
|
||||
-hide_banner \
|
||||
-loglevel warning \
|
||||
-fflags nobuffer \
|
||||
-use_wallclock_as_timestamps 1 \
|
||||
-f h264 \
|
||||
-i pipe:0 \
|
||||
-c:v copy \
|
||||
-an \
|
||||
-f whip \
|
||||
"${WHIP_URL}"
|
||||
-flush_packets 1 \
|
||||
-f mpegts \
|
||||
"${PUBLISH_URL}"
|
||||
}
|
||||
|
||||
while true; do
|
||||
if run_pipeline; then
|
||||
exit 0
|
||||
fi
|
||||
echo "WHIP publisher exited, restarting in 2s..." >&2
|
||||
echo "Video publisher exited, restarting in 2s..." >&2
|
||||
sleep 2
|
||||
done
|
||||
+21
-62
@@ -6,9 +6,6 @@ set -euo pipefail
|
||||
|
||||
BINARY_SRC="dist/roverd"
|
||||
CONFIG_SRC="pi/roverd/roverd.sample.yaml"
|
||||
FFMPEG_SRC_REF="master"
|
||||
FFMPEG_WHIP_DIR="/usr/local/lib/ffmpeg-whip"
|
||||
FFMPEG_WHIP_BIN="/usr/local/bin/ffmpeg-whip"
|
||||
|
||||
usage() {
|
||||
cat <<'USAGE'
|
||||
@@ -23,8 +20,8 @@ Options:
|
||||
The script must run from the repository root and as root (sudo). It will:
|
||||
* create system users/groups if needed
|
||||
* install /usr/local/bin/roverd and /etc/roverd.yaml
|
||||
* install /usr/local/bin/whip-publisher and its systemd unit
|
||||
* enable roverd.service and whip-publisher.service
|
||||
* install /usr/local/bin/video-publisher and its systemd unit
|
||||
* enable roverd.service and video-publisher.service
|
||||
USAGE
|
||||
}
|
||||
|
||||
@@ -87,52 +84,14 @@ if ! command -v rpicam-vid >/dev/null 2>&1 && ! command -v libcamera-vid >/dev/n
|
||||
log "WARNING: neither rpicam-vid nor libcamera-vid found in PATH; install libcamera-apps."
|
||||
fi
|
||||
|
||||
ensure_ffmpeg_build_deps() {
|
||||
log "Installing FFmpeg build dependencies (this may take a while)..."
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends \
|
||||
git curl ca-certificates build-essential pkg-config yasm nasm \
|
||||
libssl-dev libx264-dev libopus-dev \
|
||||
libx11-dev libxext-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev libxcb-shape0-dev
|
||||
}
|
||||
|
||||
install_ffmpeg_whip() {
|
||||
if [[ -x "$FFMPEG_WHIP_BIN" && -f "$FFMPEG_WHIP_DIR/bin/ffmpeg" && -d "$FFMPEG_WHIP_DIR/lib" ]]; then
|
||||
log "ffmpeg-whip already present; skipping build"
|
||||
install_video_deps() {
|
||||
if command -v ffmpeg >/dev/null 2>&1 && (command -v rpicam-vid >/dev/null 2>&1 || command -v libcamera-vid >/dev/null 2>&1); then
|
||||
log "Video dependencies already installed; skipping apt install"
|
||||
return
|
||||
}
|
||||
ensure_ffmpeg_build_deps
|
||||
log "Building ffmpeg with WHIP muxer (this can take several minutes)..."
|
||||
rm -rf "$FFMPEG_WHIP_DIR"
|
||||
mkdir -p "$FFMPEG_WHIP_DIR"
|
||||
tmp="$(mktemp -d)"
|
||||
git clone --depth 1 --branch "$FFMPEG_SRC_REF" https://git.ffmpeg.org/ffmpeg.git "$tmp/ffmpeg"
|
||||
pushd "$tmp/ffmpeg" >/dev/null
|
||||
./configure \
|
||||
--prefix="$FFMPEG_WHIP_DIR" \
|
||||
--disable-debug --disable-doc --disable-ffplay --disable-ffprobe \
|
||||
--enable-shared --disable-static \
|
||||
--enable-openssl \
|
||||
--enable-protocol=http,https,tcp,udp,dtls,file,pipe \
|
||||
--enable-muxer=whip \
|
||||
--enable-gpl --enable-version3 \
|
||||
--enable-libx264 --enable-libopus \
|
||||
--enable-encoder=libx264,libopus \
|
||||
--enable-parser=h264 \
|
||||
--enable-bsf=h264_mp4toannexb \
|
||||
--enable-filter=scale,fps,format,aresample \
|
||||
--enable-indev=x11grab,xcbgrab
|
||||
make -j"$(nproc)"
|
||||
make install
|
||||
popd >/dev/null
|
||||
rm -rf "$tmp"
|
||||
cat > "${FFMPEG_WHIP_BIN}" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
export LD_LIBRARY_PATH=/usr/local/lib/ffmpeg-whip/lib:${LD_LIBRARY_PATH}
|
||||
exec /usr/local/lib/ffmpeg-whip/bin/ffmpeg "$@"
|
||||
EOF
|
||||
chmod 0755 "${FFMPEG_WHIP_BIN}"
|
||||
log "Installed ffmpeg-whip ($(${FFMPEG_WHIP_BIN} -version | head -n1))"
|
||||
log "Installing video dependencies (libcamera-apps, ffmpeg)..."
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends libcamera-apps ffmpeg
|
||||
}
|
||||
|
||||
ensure_user roverd "dialout,gpio,video,render"
|
||||
@@ -152,34 +111,34 @@ fi
|
||||
install -m 0644 pi/systemd/roverd.service /etc/systemd/system/roverd.service
|
||||
log "Installed roverd systemd unit"
|
||||
|
||||
install_ffmpeg_whip
|
||||
install_video_deps
|
||||
|
||||
# Install WHIP publisher assets
|
||||
install -D -o root -g root -m 0755 pi/bin/whip-publisher.sh /usr/local/bin/whip-publisher
|
||||
install -m 0644 pi/systemd/whip-publisher.service /etc/systemd/system/whip-publisher.service
|
||||
# Install video publisher assets
|
||||
install -D -o root -g root -m 0755 pi/bin/video-publisher.sh /usr/local/bin/video-publisher
|
||||
install -m 0644 pi/systemd/video-publisher.service /etc/systemd/system/video-publisher.service
|
||||
install -d -o roverd -g roverd /var/lib/roverd
|
||||
if [[ ! -f /var/lib/roverd/whip.env ]]; then
|
||||
cat > /var/lib/roverd/whip.env <<'ENV'
|
||||
if [[ ! -f /var/lib/roverd/video.env ]]; then
|
||||
cat > /var/lib/roverd/video.env <<'ENV'
|
||||
# Managed by roverd; placeholder values will be overwritten at runtime.
|
||||
WHIP_URL=http://192.168.0.86:8889/whip/CHANGE_ME
|
||||
PUBLISH_URL=srt://192.168.0.86:9000?streamid=#!::r=CHANGE_ME,m=publish&latency=20&mode=caller&transtype=live&pkt_size=1316
|
||||
VIDEO_WIDTH=1280
|
||||
VIDEO_HEIGHT=720
|
||||
VIDEO_FPS=30
|
||||
VIDEO_BITRATE=3000000
|
||||
ENV
|
||||
chown roverd:roverd /var/lib/roverd/whip.env
|
||||
chmod 0640 /var/lib/roverd/whip.env
|
||||
chown roverd:roverd /var/lib/roverd/video.env
|
||||
chmod 0640 /var/lib/roverd/video.env
|
||||
fi
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable roverd.service
|
||||
systemctl enable whip-publisher.service
|
||||
systemctl enable video-publisher.service
|
||||
if [[ $CONFIG_EXISTS -eq 1 ]]; then
|
||||
systemctl restart roverd.service
|
||||
systemctl restart whip-publisher.service
|
||||
log "Restarted roverd + WHIP publisher"
|
||||
systemctl restart video-publisher.service
|
||||
log "Restarted roverd + video publisher"
|
||||
else
|
||||
log "Skipped auto-start because config is the sample; edit $CONFIG_DEST then run: sudo systemctl restart roverd whip-publisher"
|
||||
log "Skipped auto-start because config is the sample; edit $CONFIG_DEST then run: sudo systemctl restart roverd video-publisher"
|
||||
fi
|
||||
|
||||
log "Install complete"
|
||||
|
||||
+5
-8
@@ -94,7 +94,7 @@ func LoadConfig(path string) (*Config, error) {
|
||||
},
|
||||
},
|
||||
Media: MediaConfig{
|
||||
PublishPort: 8889,
|
||||
PublishPort: 9000,
|
||||
HealthInterval: Duration{Duration: 30 * time.Second},
|
||||
VideoWidth: 1280,
|
||||
VideoHeight: 720,
|
||||
@@ -142,7 +142,7 @@ func LoadConfig(path string) (*Config, error) {
|
||||
cfg.Media.VideoBitrate = 3000000
|
||||
}
|
||||
if cfg.Media.PublishPort <= 0 {
|
||||
cfg.Media.PublishPort = 8889
|
||||
cfg.Media.PublishPort = 9000
|
||||
}
|
||||
if cfg.Media.PublishURL == "" {
|
||||
derived, err := derivePublishURL(cfg.ServerURL, cfg.Name, cfg.Media.PublishPort)
|
||||
@@ -166,12 +166,9 @@ func derivePublishURL(serverURL, roverName string, port int) (string, error) {
|
||||
if host == "" {
|
||||
return "", errors.New("serverUrl missing host")
|
||||
}
|
||||
scheme := "http"
|
||||
if parsed.Scheme == "wss" || parsed.Scheme == "https" {
|
||||
scheme = "https"
|
||||
}
|
||||
if port <= 0 {
|
||||
port = 8889
|
||||
port = 9000
|
||||
}
|
||||
return fmt.Sprintf("%s://%s:%d/whip/%s", scheme, host, port, url.PathEscape(roverName)), nil
|
||||
streamName := url.PathEscape(roverName)
|
||||
return fmt.Sprintf("srt://%s:%d?streamid=#!::r=%s,m=publish&latency=20&mode=caller&transtype=live&pkt_size=1316", host, port, streamName), nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const publisherEnvPath = "/var/lib/roverd/whip.env"
|
||||
const publisherEnvPath = "/var/lib/roverd/video.env"
|
||||
|
||||
func UpdatePublisherEnv(cfg MediaConfig) error {
|
||||
if cfg.PublishURL == "" {
|
||||
@@ -20,7 +20,7 @@ func UpdatePublisherEnv(cfg MediaConfig) error {
|
||||
return err
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintf(&buf, "WHIP_URL=%s\n", cfg.PublishURL)
|
||||
fmt.Fprintf(&buf, "PUBLISH_URL=%s\n", cfg.PublishURL)
|
||||
fmt.Fprintf(&buf, "VIDEO_WIDTH=%d\n", cfg.VideoWidth)
|
||||
fmt.Fprintf(&buf, "VIDEO_HEIGHT=%d\n", cfg.VideoHeight)
|
||||
fmt.Fprintf(&buf, "VIDEO_FPS=%d\n", cfg.VideoFPS)
|
||||
|
||||
@@ -15,13 +15,13 @@ battery:
|
||||
urgent: 1650
|
||||
maxWheelSpeed: 350
|
||||
media:
|
||||
publishUrl: http://192.168.0.86:8889/whip/roomba-alpha
|
||||
publishPort: 8889
|
||||
publishUrl: srt://192.168.0.86:9000?streamid=#!::r=roomba-alpha,m=publish&latency=20&mode=caller&transtype=live&pkt_size=1316
|
||||
publishPort: 9000
|
||||
videoWidth: 1280
|
||||
videoHeight: 720
|
||||
videoFps: 30
|
||||
videoBitrate: 3000000
|
||||
manage: true
|
||||
service: whip-publisher.service
|
||||
service: video-publisher.service
|
||||
healthUrl: ""
|
||||
healthInterval: 30s
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[Unit]
|
||||
Description=Rover WHIP Publisher
|
||||
Description=Rover Video Publisher (libcamera -> SRT)
|
||||
After=network-online.target roverd.service
|
||||
Wants=network-online.target
|
||||
|
||||
@@ -8,8 +8,8 @@ Type=simple
|
||||
User=roverd
|
||||
Group=roverd
|
||||
WorkingDirectory=/var/lib/roverd
|
||||
EnvironmentFile=/var/lib/roverd/whip.env
|
||||
ExecStart=/usr/local/bin/whip-publisher
|
||||
EnvironmentFile=/var/lib/roverd/video.env
|
||||
ExecStart=/usr/local/bin/video-publisher
|
||||
Restart=always
|
||||
RestartSec=2
|
||||
|
||||
Reference in New Issue
Block a user