's'
This commit is contained in:
@@ -18,6 +18,41 @@ class StreamEnded(Exception):
|
||||
pass
|
||||
|
||||
|
||||
_FFMPEG_STATS_PERIOD_OK: bool | None = None
|
||||
|
||||
|
||||
def _require_ffmpeg_stats_period() -> None:
|
||||
"""推流依赖 -stats_period(ffmpeg 约 4.4+);Debian 11 默认 4.3 需升级。"""
|
||||
global _FFMPEG_STATS_PERIOD_OK
|
||||
if _FFMPEG_STATS_PERIOD_OK is True:
|
||||
return
|
||||
if _FFMPEG_STATS_PERIOD_OK is False:
|
||||
raise RuntimeError(
|
||||
"ffmpeg 不支持 -stats_period。板端执行: sudo bash scripts/linux/upgrade_ffmpeg_newer.sh"
|
||||
)
|
||||
try:
|
||||
r = subprocess.run(
|
||||
["ffmpeg", "-hide_banner", "-h", "full"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
)
|
||||
blob = (r.stdout or "") + (r.stderr or "")
|
||||
if "-stats_period" in blob:
|
||||
_FFMPEG_STATS_PERIOD_OK = True
|
||||
return
|
||||
except FileNotFoundError:
|
||||
_FFMPEG_STATS_PERIOD_OK = False
|
||||
raise RuntimeError("未找到 ffmpeg,请先安装。") from None
|
||||
except Exception as e:
|
||||
print(f"[WARN] 无法检测 ffmpeg 是否支持 -stats_period: {e}")
|
||||
return
|
||||
_FFMPEG_STATS_PERIOD_OK = False
|
||||
raise RuntimeError(
|
||||
"ffmpeg 不支持 -stats_period(需约 4.4+)。板端执行: sudo bash scripts/linux/upgrade_ffmpeg_newer.sh"
|
||||
)
|
||||
|
||||
|
||||
def sanitize_title(text: str, max_len: int = 120) -> str:
|
||||
if not text:
|
||||
return ""
|
||||
@@ -307,6 +342,8 @@ def start_douyin_youtube_ffplay(
|
||||
"-f", "flv", youtube_rtmp
|
||||
]
|
||||
|
||||
_require_ffmpeg_stats_period()
|
||||
|
||||
proc = None
|
||||
stderr_q = None
|
||||
reader_t = None
|
||||
|
||||
114
scripts/linux/upgrade_ffmpeg_newer.sh
Normal file
114
scripts/linux/upgrade_ffmpeg_newer.sh
Normal file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env bash
|
||||
# 将 ffmpeg 升级到含 -stats_period(约 4.4+),供 douyin_youtube_ffplay / robust_relay 使用。
|
||||
# Debian 11 默认 4.3.x:先试强制从 bullseye-backports 安装;仍不行则用 arm64 静态包到 /usr/local/bin。
|
||||
set -euo pipefail
|
||||
|
||||
if [[ ${EUID:-0} -ne 0 ]]; then
|
||||
exec sudo bash "$0" "$@"
|
||||
fi
|
||||
|
||||
have_stats_period() {
|
||||
command -v ffmpeg >/dev/null 2>&1 || return 1
|
||||
# ffmpeg 把 -h full 打到 stderr,不能 2>/dev/null 否则永远匹配不到
|
||||
ffmpeg -hide_banner -h full 2>&1 | grep -qE 'stats_period'
|
||||
}
|
||||
|
||||
install_johnvansickle_arm64_static() {
|
||||
local url="https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-arm64-static.tar.xz"
|
||||
local td dir
|
||||
td=$(mktemp -d)
|
||||
trap 'rm -rf "$td"' EXIT
|
||||
echo "[INFO] 下载 arm64 静态 ffmpeg(johnvansickle)…"
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fsSL -o "$td/ff.tar.xz" "$url"
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -q -O "$td/ff.tar.xz" "$url"
|
||||
else
|
||||
echo "需要 curl 或 wget" >&2
|
||||
return 1
|
||||
fi
|
||||
tar -xJf "$td/ff.tar.xz" -C "$td"
|
||||
dir=$(find "$td" -maxdepth 1 -type d -name 'ffmpeg-*-arm64-static' | head -1)
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
echo "解压后未找到 ffmpeg-*-arm64-static" >&2
|
||||
return 1
|
||||
fi
|
||||
install -m 0755 "$dir/ffmpeg" /usr/local/bin/ffmpeg
|
||||
install -m 0755 "$dir/ffprobe" /usr/local/bin/ffprobe
|
||||
hash -r
|
||||
trap - EXIT
|
||||
rm -rf "$td"
|
||||
echo "[INFO] 已写入 /usr/local/bin/ffmpeg(PATH 中优先于 /usr/bin 时生效)"
|
||||
}
|
||||
|
||||
if have_stats_period; then
|
||||
echo "[OK] 当前 ffmpeg 已支持 -stats_period"
|
||||
command -v ffmpeg
|
||||
ffmpeg -version | head -1
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -r /etc/os-release ]]; then
|
||||
echo "无法读取 /etc/os-release" >&2
|
||||
if [[ "$(uname -m)" == aarch64 ]]; then
|
||||
install_johnvansickle_arm64_static || exit 1
|
||||
have_stats_period && exit 0
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
# shellcheck source=/dev/null
|
||||
. /etc/os-release
|
||||
|
||||
case "${ID:-}" in
|
||||
debian)
|
||||
case "${VERSION_CODENAME:-}" in
|
||||
bullseye)
|
||||
BP=/etc/apt/sources.list.d/bullseye-backports.list
|
||||
if ! grep -qE 'bullseye-backports' /etc/apt/sources.list /etc/apt/sources.list.d/*.list 2>/dev/null; then
|
||||
echo "deb http://deb.debian.org/debian bullseye-backports main" >"$BP"
|
||||
fi
|
||||
apt-get update -qq
|
||||
echo "[INFO] ffmpeg 可用版本(apt-cache madison,前几行):"
|
||||
apt-cache madison ffmpeg 2>/dev/null | head -12 || true
|
||||
# 显式指定发行版,避免仍选中 bullseye 主源的 4.3.9
|
||||
apt-get install -y ffmpeg/bullseye-backports || true
|
||||
;;
|
||||
bookworm|trixie|sid)
|
||||
apt-get update -qq
|
||||
apt-get install -y ffmpeg
|
||||
;;
|
||||
*)
|
||||
echo "未内置规则的 Debian 代号: ${VERSION_CODENAME}" >&2
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
ubuntu)
|
||||
apt-get update -qq
|
||||
apt-get install -y ffmpeg
|
||||
;;
|
||||
*)
|
||||
echo "发行版 ${ID:-unknown}:跳过 apt 规则" >&2
|
||||
;;
|
||||
esac
|
||||
|
||||
if have_stats_period; then
|
||||
echo "[OK] apt 升级后已支持 -stats_period"
|
||||
command -v ffmpeg
|
||||
ffmpeg -version | head -1
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$(uname -m)" == aarch64 ]]; then
|
||||
echo "[WARN] apt 仍未提供带 -stats_period 的 ffmpeg,改用静态包" >&2
|
||||
install_johnvansickle_arm64_static
|
||||
fi
|
||||
|
||||
ffmpeg -version | head -1 || true
|
||||
if have_stats_period; then
|
||||
echo "[OK] 当前 ffmpeg 已支持 -stats_period"
|
||||
command -v ffmpeg
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[FATAL] 仍无法使用 -stats_period,请检查网络或手动安装 ffmpeg 4.4+(aarch64)" >&2
|
||||
exit 1
|
||||
@@ -49,6 +49,7 @@ FILES = [
|
||||
"src/control_plane.py",
|
||||
"src/web_process_backend.py",
|
||||
"src/hub_routes.py",
|
||||
"src/initializer.py",
|
||||
"src/live_config/__init__.py",
|
||||
"src/live_config/loader.py",
|
||||
"web.py",
|
||||
@@ -56,12 +57,15 @@ FILES = [
|
||||
"tiktok.py",
|
||||
"main.py",
|
||||
"ffmpeg_install.py",
|
||||
"scripts/launch.py",
|
||||
"scripts/env_check.py",
|
||||
"scripts/hardware_probe.py",
|
||||
"config/hardware.env.example",
|
||||
"ecosystem.config.cjs",
|
||||
"docs/install-profiles.md",
|
||||
"douyin_youtube_ffplay.py",
|
||||
"scripts/linux/install_hub.sh",
|
||||
"scripts/linux/upgrade_ffmpeg_newer.sh",
|
||||
"scripts/linux/reinstall_live_edge.sh",
|
||||
"scripts/linux/service_ctl.sh",
|
||||
"scripts/linux/lib/common.sh",
|
||||
|
||||
Reference in New Issue
Block a user