From 324fed478aebe61460adab5738105be343fc1fc7 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Sun, 29 Mar 2026 21:34:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20archrived-shells/ffmpeg.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archrived-shells/ffmpeg.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/archrived-shells/ffmpeg.sh b/archrived-shells/ffmpeg.sh index e20166f..9e714dc 100644 --- a/archrived-shells/ffmpeg.sh +++ b/archrived-shells/ffmpeg.sh @@ -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