sourceExtension=$1 # e.g. "mp3"
targetExtension=$2 # e.g. "wav"
IFS=$'\n'; set -f
for sourceFile in $(find . -iname "*.$sourceExtension")
do
targetFile="${sourceFile%.*}.$targetExtension"
ffmpeg -i "$sourceFile" "$targetFile"
done
unset IFS; set +f
示例调用:
$ sh ffmpeg-batch-convert.sh mp3 wav
作为奖励,如果你想删除源文件,你可以像这样修改脚本:
sourceExtension=$1 # e.g. "mp3"
targetExtension=$2 # e.g. "wav"
deleteSourceFile=$3 # "delete" or omitted
IFS=$'\n'; set -f
for sourceFile in $(find . -iname "*.$sourceExtension")
do
targetFile="${sourceFile%.*}.$targetExtension"
ffmpeg -i "$sourceFile" "$targetFile"
if [ "$deleteSourceFile" == "delete" ]; then
if [ -f "$targetFile" ]; then
rm "$sourceFile"
fi
fi
done
unset IFS; set +f