This commit is contained in:
legop3
2025-11-14 05:52:52 -05:00
parent 2dc18da12d
commit 326ae16f6b
4 changed files with 97 additions and 48 deletions
+41 -21
View File
@@ -18,31 +18,51 @@ VIDEO_HEIGHT="${VIDEO_HEIGHT:-720}"
VIDEO_FPS="${VIDEO_FPS:-30}"
VIDEO_BITRATE="${VIDEO_BITRATE:-3000000}"
GST_BIN="${GST_BIN:-/usr/bin/gst-launch-1.0}"
if [[ -n "${LIBCAMERA_BIN:-}" ]]; then
LIBCAMERA_BIN_PATH="$LIBCAMERA_BIN"
elif command -v rpicam-vid >/dev/null 2>&1; then
LIBCAMERA_BIN_PATH="$(command -v rpicam-vid)"
elif command -v libcamera-vid >/dev/null 2>&1; then
LIBCAMERA_BIN_PATH="$(command -v libcamera-vid)"
else
echo "Neither rpicam-vid nor libcamera-vid found; install libcamera-apps." >&2
exit 1
fi
if [[ ! -x "$GST_BIN" ]]; then
if command -v gst-launch-1.0 >/dev/null 2>&1; then
GST_BIN="$(command -v gst-launch-1.0)"
else
echo "gst-launch-1.0 not found; install gstreamer1.0-tools and plugins." >&2
exit 1
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
exit 1
fi
run_pipeline() {
local bitrate_kbps=$((VIDEO_BITRATE / 1000))
if [[ "$bitrate_kbps" -le 0 ]]; then
bitrate_kbps=3000
fi
"${GST_BIN}" -e \
libcamerasrc \
! "video/x-raw,width=${VIDEO_WIDTH},height=${VIDEO_HEIGHT},framerate=${VIDEO_FPS}/1" \
! queue \
! videoconvert \
! x264enc speed-preset=ultrafast tune=zerolatency bitrate="${bitrate_kbps}" key-int-max="${VIDEO_FPS}" byte-stream=true \
! "video/x-h264,profile=baseline" \
! h264parse config-interval=1 \
! whipclientsink signaller::whip-endpoint="${WHIP_URL}"
"${LIBCAMERA_BIN_PATH}" \
--inline \
--timeout 0 \
--width "${VIDEO_WIDTH}" \
--height "${VIDEO_HEIGHT}" \
--framerate "${VIDEO_FPS}" \
--bitrate "${VIDEO_BITRATE}" \
--codec h264 \
--profile baseline \
--denoise cdn_off \
--nopreview \
--output - \
| "${FFMPEG_BIN_PATH}" \
-hide_banner \
-loglevel warning \
-fflags nobuffer \
-f h264 \
-i pipe:0 \
-c:v copy \
-an \
-f whip \
"${WHIP_URL}"
}
while true; do
+47 -16
View File
@@ -6,6 +6,10 @@ set -euo pipefail
BINARY_SRC="dist/roverd"
CONFIG_SRC="pi/roverd/roverd.sample.yaml"
FFMPEG_WHIP_VERSION="0.0.0"
FFMPEG_WHIP_BASE_URL="https://github.com/steel-dev/ffmpeg-whip/releases/download/v${FFMPEG_WHIP_VERSION}"
FFMPEG_WHIP_DIR="/usr/local/lib/ffmpeg-whip"
FFMPEG_WHIP_BIN="/usr/local/bin/ffmpeg-whip"
usage() {
cat <<'USAGE'
@@ -62,6 +66,11 @@ if [[ ! -f "$CONFIG_SRC" ]]; then
exit 1
fi
if ! command -v curl >/dev/null 2>&1; then
echo "curl is required by this installer" >&2
exit 1
fi
ensure_user() {
local user="$1"
local groups="${2:-}"
@@ -80,24 +89,44 @@ log() {
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*"
}
if ! command -v gst-launch-1.0 >/dev/null 2>&1; then
log "WARNING: gst-launch-1.0 not found; install GStreamer (sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libcamera)."
else
if command -v gst-inspect-1.0 >/dev/null 2>&1; then
if ! gst-inspect-1.0 whipclientsink >/dev/null 2>&1; then
log "WARNING: whipclientsink element missing; install gstreamer1.0-plugins-bad (1.22+)."
fi
if ! gst-inspect-1.0 libcamerasrc >/dev/null 2>&1; then
log "WARNING: libcamerasrc plugin missing; install gstreamer1.0-libcamera."
fi
if ! gst-inspect-1.0 x264enc >/dev/null 2>&1; then
log "WARNING: x264enc element missing; install gstreamer1.0-plugins-ugly."
fi
else
log "WARNING: gst-inspect-1.0 not found; unable to verify GStreamer plugins."
fi
if ! command -v rpicam-vid >/dev/null 2>&1 && ! command -v libcamera-vid >/dev/null 2>&1; then
log "WARNING: neither rpicam-vid nor libcamera-vid found in PATH; install libcamera-apps."
fi
install_ffmpeg_whip() {
local arch asset tmp
arch="$(uname -m)"
case "$arch" in
aarch64)
asset="ffmpeg-whip-linux-arm64.tar.gz"
;;
x86_64|amd64)
asset="ffmpeg-whip-linux-amd64.tar.gz"
;;
*)
log "WARNING: ffmpeg-whip binary not available for architecture ${arch}; ensure a WHIP-capable ffmpeg is installed manually."
return
esac
tmp="$(mktemp -d)"
log "Downloading ffmpeg-whip ${FFMPEG_WHIP_VERSION} (${asset})"
if ! curl -fsSL "${FFMPEG_WHIP_BASE_URL}/${asset}" -o "${tmp}/${asset}"; then
rm -rf "$tmp"
echo "Failed to download ffmpeg-whip from ${FFMPEG_WHIP_BASE_URL}/${asset}" >&2
exit 1
fi
rm -rf "${FFMPEG_WHIP_DIR}"
install -d "${FFMPEG_WHIP_DIR}"
tar -xzf "${tmp}/${asset}" -C "${FFMPEG_WHIP_DIR}" --strip-components=1
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_BIN}"
}
ensure_user roverd "dialout,gpio,video,render"
install -o roverd -g roverd -m 0755 "$BINARY_SRC" /usr/local/bin/roverd
log "Installed roverd binary"
@@ -115,6 +144,8 @@ fi
install -m 0644 pi/systemd/roverd.service /etc/systemd/system/roverd.service
log "Installed roverd systemd unit"
install_ffmpeg_whip
# 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