Skip to content

Instantly share code, notes, and snippets.

@probil
Created September 7, 2015 13:23
Show Gist options
  • Save probil/314e56739d83aab0a63f to your computer and use it in GitHub Desktop.
Save probil/314e56739d83aab0a63f to your computer and use it in GitHub Desktop.
Normalize audio files in dir and subdir
#!/usr/bin/env bash
cd $1
find . type f | grep mp3$ > mp3-files.txt
readarray -t files < mp3-files.txt
INDEX=0
LENGTH=${#files[@]}
for file in "${files[@]}"; do
INDEX=$((INDEX+1))
percent=$(printf '%i %i' $INDEX $LENGTH | awk '{ pc=100*$1/$2; i=int(pc); print (pc-i<0.5)?i:i+1 }')
echo "Converting... [$percent%] $file"
ffmpeg -loglevel panic -i "$file" -vn -ar 44100 -ac 2 -q:a 5 temp.mp3;
rm "$file";
mv temp.mp3 "$file";
done
echo "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment