Files
gitlab-instance-0a899031_do…/scripts/linux/upgrade_ffmpeg_newer.sh
2026-03-28 18:38:41 -05:00

115 lines
3.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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 静态 ffmpegjohnvansickle…"
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/ffmpegPATH 中优先于 /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