How to transcode a directory of audio files to AAC with FFmpeg

I recently started to backup my CDs as lossless flac files on my home server. The problem is, my mobile phone cannot play back flac files, so I wrote a little bash script that transcodes a directory of audio files to high quality variable bitrate AAC files that I can play back on my mobile phone.

The script takes the directory I want to transcode as the first input argument and the file ending (in my case “flac”) as the second argument. It then changes into the given directory, creates a folder called “m4a”, transcodes all audio files with the given file ending into the m4a folder and changes back to the directory where it came from.

Copy the script code below and paste it into your favourite editor. Store the file as “makem4a” or whatever you like somewhere your system can find it, i.e. a folder that is in your $PATH. Don’t forget to make the file executable.

# encode all files in directory $1 of type $2 into VBR AAC

cd $1
mkdir m4a
for f in *.$2; do
ffmpeg -i "$f" -b:a 256k -q:a 1 -strict experimental -rtpflags latm "m4a/${f%.$2}.m4a"
cd $oldDir
echo "`basename $0`: INFO: Finished transcoding"

An example call:
$ makem4a ~/music/artist/album/ flac
The newly created AAC files reside in ~/music/artist/album/m4a/ and carry the same name and meta data as the original files.

About h0nk3ym0nk3y

h0nk3ym0nk3y is one of the three LinuxM0nk3ys from Linux M0nk3ys @ WordPress Linux M0nk3ys @ YouTube Linux M0nk3ys @ Twitter

Posted on October 3, 2012, in Audio / Video, Bash-Scripts, Command-Line and tagged , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: