Files
Linux-Shell/archrived-shells/ffmpeg.sh

42 lines
1.1 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.
#!/bin/bash
extensions=("mp4" "avi" "mov" "mkv" "flv" "wmv")
echo "开始批量转码H.264 MP4..."
echo
for ext in "${extensions[@]}"; do
for file in *."$ext"; do
[ -f "$file" ] || continue
# 👉 提取类似 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 copy \
"$output"
if [ $? -eq 0 ]; then
echo "完成: $file"
else
echo "转码失败: $file"
fi
echo
else
echo "跳过 $file,因为 $output 已存在。"
fi
done
done
echo "所有任务执行完毕。"