Files
ocr_data/scripts/set_ffmpeg.sh
2026-09-28 16:09:31 +08:00

27 lines
1.2 KiB
Bash
Raw Permalink 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
# 一键切换项目 bin/ffmpeg 的版本(本机自用 cpu / 打 GPU 包 gpu)
# bash temp/set_ffmpeg.sh cpu # johnvansickle 全静态,任何 glibc 都能跑(本机自用)
# bash temp/set_ffmpeg.sh gpu # BtbN 含 cuda/nvdec,需 glibc>=2.28(给 GPU 机器)
set -euo pipefail
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # 项目根
V="${1:-cpu}"
BIN="$(pwd)/bin"; mkdir -p "$BIN"
have(){ command -v "$1" >/dev/null 2>&1; }
case "$V" in
cpu) URL="https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" ;;
gpu) URL="https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz" ;;
*) echo "用法: bash temp/set_ffmpeg.sh [cpu|gpu]"; exit 1 ;;
esac
echo "下载 $V 版 ffmpeg ..."
tmp="$(mktemp -d)"
if have curl; then curl -L "$URL" -o "$tmp/ff.tar.xz"; else wget -O "$tmp/ff.tar.xz" "$URL"; fi
tar xf "$tmp/ff.tar.xz" -C "$tmp"
ffb="$(find "$tmp" -type f -name ffmpeg | head -1)"
ffp="$(find "$tmp" -type f -name ffprobe | head -1)"
cp "$ffb" "$ffp" "$BIN/"
chmod +x "$BIN/ffmpeg" "$BIN/ffprobe"
rm -rf "$tmp"
echo "已切到 $V 版: $("$BIN/ffmpeg" -version 2>&1 | head -1 || echo '本机跑不了(若是 gpu 版+老 glibc,正常)')"