我有如下文件:
- 01——A.wav
- 02——AB.wav
- 03 - C.wav ... 等等直到 15 - BLA.wav
我有一些类似这样的命令行:
dirinwav="/home/akrogun/Videos/CD1" && \
diringraphics="/home/akrogun/Videos/graphics/" && \
dirout="/home/akrogun/Videos/ffmpegout/" && \
file01="01 - A" && \
file02="02 - AB" && \
file03="03 - C" && \ and so on until file15="15 - BLA"
\
echo "Encoding " $file01..... && \
file_n=$file01 && \
number=01 && \
ffmpeg -y -i "$dirinwav/$file_n.wav" -acodec libfdk_aac -b 128k out-aac.aac && \
ffmpeg -y -i "$diringraphics/background.jpg" -i "$diringraphics/$number.png" -filter_complex "overlay" out-background.png && \
ffmpeg -y -loop 1 -i out-background.png -i out-aac.aac -vcodec mpeg4 -b:v 800k -acodec copy -shortest "$dirout/$file_n.mp4" && \
\
echo "Encoding " $file02..... && \
file_n=$file02 && \
number=02 && \
ffmpeg -y -i "$dirinwav/$file_n.WAV" -acodec libfdk_aac -b 128k out-aac.aac && \
ffmpeg -y -i "$diringraphics/background.jpg" -i "$diringraphics/$number.png" -filter_complex "overlay" out-background.png && \
ffmpeg -y -loop 1 -i out-background.png -i out-aac.aac -vcodec mpeg4 -b:v 800k -acodec copy -shortest "$dirout/$file_n.mp4" && \
\
echo "Encoding " $file03..... && \
file_n=$file03 && \
number=03 && \
ffmpeg -y -i "$dirinwav/$file_n.WAV" -acodec libfdk_aac -b 128k out-aac.aac && \
ffmpeg -y -i "$diringraphics/background.jpg" -i "$diringraphics/$number.png" -filter_complex "overlay" out-background.png && \
ffmpeg -y -loop 1 -i out-background.png -i out-aac.aac -vcodec mpeg4 -b:v 800k -acodec copy -shortest "$dirout/$file_n.mp4"
and so on until file15
这些命令行运行正常。我只是想知道如何让这些行循环工作?也许使用 for; do; done?或者其他什么?
提前致谢
答案1
下面是我的最终的 shell 脚本:
#! /bin/bash
#working directory
workdir="/home/akrogun/Videos/Faith + Hope + Love (2009)"
#input directory where WAV files are stored
dirinwav=""$workdir"/01-wav"
#input directory where bakground image are stored
diringraphics=""$workdir"/03-graphics"
#output directory
dirout=""$workdir"/04-ffmpeg"
# $1-WAVfile $2-background.jpg $3-tracknumber
function ffmpeg_stuff () {
echo "> executing ffmpeg -y -i "$1" -acodec libfdk_aac -b:a 128k out-aac.aac..."
ffmpeg -y -i "$1" -acodec libfdk_aac -b:a 128k out-aac.aac
printf "\n"
echo "> executing ffmpeg -y -i "$2" -i "$diringraphics"/"$3".png -filter_complex \"overlay\" out-background.png..."
ffmpeg -y -i "$2" -i "$diringraphics"/"$3".png -filter_complex "overlay" out-background.png
printf "\n"
echo "> executing ffmpeg -y -loop 1 -i out-background.png -i out-aac.aac -vcodec mpeg4 -b:v 800k -acodec copy -shortest "$dirout"/"$filenameWithoutExt".mp4..."
ffmpeg -y -loop 1 -i out-background.png -i out-aac.aac -vcodec mpeg4 -b:v 800k -acodec copy -shortest "$dirout"/"$filenameWithoutExt".mp4
printf "\n"
}
counter=1
files=("$dirinwav"/*.WAV)
for file in "${files[@]}"
do
if [ $counter -eq 1 ]
then
echo "Start processing ${#files[@]} files"
else
echo ""
fi
echo "================================"
echo "Processing "$file"....."
if [ $counter -lt 10 ]
then
track="0$counter"
else
track="$counter"
fi
filename="${file##*/}"
filenameWithoutExt="${filename%.*}"
ffmpeg_stuff "$dirinwav"/"$filename" "$diringraphics"/background.jpg "$track"
printf "\n\n\n"
if [ $counter -eq ${#files[@]} ]
then
echo "End..."
fi
counter=$(($counter+1))
done