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

Yeah, whatever, never mind

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

  1. Hi,

    You may want to check a tool i wrote: mussync-tools :

    It needs some tools to work properly:

    sudo apt-get install libav-tools eyed3 mediainfo vorbis-tools aac-enc atomicparsley \
    flac parallel vorbisgain vbrfix mp3val python-rgain fdkaac

    (Install guide in french available here: )

    It is capable of transcoding a music library from flac/mp3/ogg to ogg/m4a/mp3 while keeping files album art and metadata. I can also add replay gain to the created library.

    I wrote it to sync a lossless FLAC media library to a m4a version with the minimum hassle possible. I use it in sync with Musicbrainz Picard to keep my media library organized.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: