Files
live/start.sh
T
adminandClaude Opus 4.8 4ee945ca0d feat: encode on the GPU and restart individual renditions
Hardware encoding
- Detect the best usable encoder at startup by encoding a test frame with each
  candidate in turn (nvenc, qsv, amf, then libx264). Being compiled into ffmpeg
  is not enough: h264_amf fails without amfrt64.dll and h264_qsv fails without an
  Intel iGPU, so the probe is the only reliable answer.
- Translate the quality target into the chosen encoder's own vocabulary. libx264's
  -crf and "ultrafast" mean nothing to h264_nvenc, which takes -cq and p1..p7, so
  passing the configured values straight through would have been silently wrong.
- On the reference GTX 1060 a 1080p->720p rendition costs ~62% of a core on NVENC
  versus ~109% on libx264 ultrafast.

Per-rendition supervision
- Track encoder processes per rendition, not per stream. is_running answered
  "any alive", so when the source ("原画") encoder died while 1080p and 720p kept
  running, the supervisor saw a healthy stream and never restarted it — the
  source URL then 404'd permanently. It now requires every rendition to be alive
  and reports which ones are down.
- Restart only the dead renditions, so a single failure no longer interrupts
  viewers on the renditions that were fine.

Production serving
- Serve the built frontend from FastAPI with SPA fallback, so production is one
  process and one port with no Node runtime. Node becomes a build-time dependency.
- start.ps1/start.sh build the frontend on first run instead of failing to a 503.

Cleanup
- Drop the duplicated top-left LIVE badge; the control strip already carries it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-09-27 18:56:21 +08:00

40 lines
1.5 KiB
Bash

#!/bin/bash
# StreamCore - Start the backend.
#
# The backend owns everything: it serves the built frontend, starts the media
# origin at boot, supervises ffmpeg, and restarts either if it dies. This script
# only has to bring up the process that owns all of that. Node is a build-time
# dependency only (see the frontend build below), never a runtime one.
set -e
BASE="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
export LS_HLS_RUNTIME_DIR="${LS_HLS_RUNTIME_DIR:-$BASE/runtime/hls}"
export LS_REPLAY_MEDIA_DIR="${LS_REPLAY_MEDIA_DIR:-$BASE/runtime/replay}"
mkdir -p "$LS_HLS_RUNTIME_DIR" "$LS_REPLAY_MEDIA_DIR" "$BASE/runtime/logs"
HOST="${LS_HOST:-0.0.0.0}"
PORT="${LS_PORT:-8080}"
# Build the frontend once, so a fresh checkout does not come up as a 503.
if [ ! -f "$BASE/frontend/dist/index.html" ]; then
if command -v npm >/dev/null 2>&1; then
echo "[StreamCore] Building frontend..."
cd "$BASE/frontend"
[ -d node_modules ] || npm install
npm run build
else
echo "[StreamCore] WARNING: npm not found and frontend/dist is missing; the site will return 503." >&2
echo "[StreamCore] WARNING: install Node.js and run: cd frontend && npm install && npm run build" >&2
fi
fi
cd "$BASE/backend"
PY="$BASE/backend/venv/bin/python"
[ -x "$PY" ] || PY="$BASE/backend/.venv/bin/python"
[ -x "$PY" ] || PY="python"
echo "[StreamCore] Starting backend on ${HOST}:${PORT}..."
echo "[StreamCore] Frontend, MediaMTX, transcoders and HLS are served by the backend."
exec "$PY" -m uvicorn main:app --host "$HOST" --port "$PORT"