更新 archrived-shells/ffmpeg.sh

This commit is contained in:
2026-03-29 21:34:13 +08:00
parent a85f18a089
commit 324fed478a

View File

@@ -2,18 +2,31 @@
extensions=("mp4" "avi" "mov" "mkv" "flv" "wmv")
echo "开始批量转码,输出格式为 AVC/H.264 编码的 MP4..."
echo "开始批量转码H.264 MP4..."
echo
for ext in "${extensions[@]}"; do
for file in *."$ext"; do
# 检查文件是否存在(避免没有匹配文件时报错)
[ -f "$file" ] || continue
output="${file%.*}.mp4"
# 👉 提取类似 1 (12).mp4 → 12
base=$(echo "$file" | sed -E 's/^1 \(([0-9]+)\)\.[^.]+$/\1/')
# 👉 如果匹配成功,就用纯数字,否则用原文件名
if [[ "$base" =~ ^[0-9]+$ ]]; then
output="${base}-h264.mp4"
else
output="${file%.*}-h264.mp4"
fi
if [ ! -f "$output" ]; then
echo "正在转码: $file --> $output"
ffmpeg -i "$file" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k "$output"
ffmpeg -i "$file" \
-c:v libx264 -preset medium -crf 23 \
-c:a copy \
"$output"
if [ $? -eq 0 ]; then
echo "完成: $file"
else