Last active
August 29, 2015 14:08
-
-
Save timtomch/65b3abae4734342f7298 to your computer and use it in GitHub Desktop.
Batch AAC to MP3 convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PATH=/usr/local/bin:$PATH | |
# for use within Automator, the path to usr/local/bin has to be added | |
# so that faad and lame can be used | |
# last argument is the output path - add a trailing slash | |
outputpath=${@:$#}"/" | |
# start numbering depending on the # of files already in that directory | |
count=$(ls -1 $outputpath | wc -l) | |
# all arguments but last are the files to be converted | |
for file in "${@:1:$#-1}"; do | |
let count++ | |
# get the original file name without its path | |
filebase=${file##*/} | |
# get the original file extension | |
fileext=${filebase##*.} | |
# remove the suffix (.m4a or whatever) | |
newprefix=${filebase%.*} | |
# make a new file name | |
newfilename=$(printf "%03d" $count)" "$newprefix".mp3" | |
# for some reason, trying to concatenate $newprefix within printf | |
# produces strange results | |
# debugging output | |
echo $filebase | |
# check the original format, trusting the extension (for now) | |
case $fileext in | |
"mp3") | |
echo "mp3 file, just copy" | |
cp "$file" "$outputpath$newfilename" | |
;; | |
"m4a") | |
echo "aac file, let's convert" | |
# do the actual conversion | |
# faad converts original file into wav, outputs to stdout | |
# lame encodes piped stdin into mp3, stores in new file | |
faad -q -o - "$file" | lame - "$outputpath$newfilename" | |
;; | |
*) | |
echo "unknown format :(" | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is meant to be used as part of an Automator workflow, see http://notes.timtom.ch/Coding/USBplaylist