Skip to content

Instantly share code, notes, and snippets.

@bradenbest
Last active December 11, 2016 04:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bradenbest/cfba10c9df4b4c0daaab to your computer and use it in GitHub Desktop.
Save bradenbest/cfba10c9df4b4c0daaab to your computer and use it in GitHub Desktop.
Easy batch-converter for audio formats
#!/bin/bash
# Converts audio formats in bulk
# requires avconv
fformat=m4a
tformat=mp3
c=0
t=0
files=*.$fformat
echo Scanning directory . . .
for file in $files; do
t=$[t+1]
echo "#$t: $file"
done
echo "Found $t file(s):"
read -p "Do you want to see avconv's output? (y/n) (default: n)" avcout
for file in $files; do
fname="${file%.*}"
c=$[c+1]
echo "Converting ($c/$t)"
echo "From: $fname.$fformat"
echo "To: $fname.$tformat"
if [ "$avcout" == "y" ]; then
avconv -i "$fname.$fformat" "$fname.$tformat"
else
avconv -i "$fname.$fformat" "$fname.$tformat" 2> /dev/null
fi
done
read -p "Do you want to keep all .$fformat files (0), remove them (1), or something else (2)? (default: 0)" choice
if [ "$choice" == "1" ]; then
rm *.$fformat
elif [ "$choice" == "2" ]; then
rm -i *.$fformat
fi
@An-Tax
Copy link

An-Tax commented Sep 14, 2015

Works very well but avconv default converts to 128kbit/s perhaps a bit rate option for people who prefer a higher bit rate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment