#!/bin/sh set -e HWACCEL="${HWACCEL:-none}" # Auto-detect the best available hardware accelerator by checking device nodes. # /dev/nvidia0 → NVENC (NVIDIA, requires NVIDIA Container Toolkit + deploy config) # /dev/dri/renderD128 → VAAPI (Intel/AMD, requires /dev/dri device passthrough) # falls back to software (mediamtx built-in recorder, no FFmpeg) detect_hwaccel() { if [ -e /dev/nvidia0 ] && [ -e /dev/nvidiactl ]; then echo "nvenc" elif [ -e /dev/dri/renderD128 ]; then echo "vaapi" else echo "none" fi } if [ "$HWACCEL" = "auto" ]; then HWACCEL=$(detect_hwaccel) echo "[start] auto-detected hardware acceleration: $HWACCEL" fi if [ "$HWACCEL" = "none" ]; then CONFIG=/app/mediamtx.yml else CONFIG=/app/mediamtx-hwaccel.yml echo "[start] hardware acceleration: $HWACCEL" fi # Export so on-ready-hw.sh inherits the resolved value export HWACCEL # Start mediamtx in the background; Express handles auth and serves HLS. mediamtx "$CONFIG" & # Exec Node.js as the foreground process so Docker tracks it for health/stop. exec node --max-old-space-size=384 dist/index.js