0

I have files, like these:

  • 01 - A.wav
  • 02 - AB.wav
  • 03 - C.wav ... and so on until 15 - BLA.wav

and I have some command line like these:

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

Those command lines are working just fine. I'm just wondering how to make those lines work in loop? Perhaps using for; do; done? Or something else?

Thanks in advance

1
  • If you have a list of wav files and a list of image files and they should match each other in pairs, I think you might want to consider arrays.
    – Rajib
    Apr 22, 2022 at 10:52

1 Answer 1

0

Here is my final shell script:

#! /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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .