For better or for worse, I use iTunes to manage the music on my iPhone. And since I have to have iTunes installed on my computer, I might as well also use it to rip my audio CDs into music files. Traditionally, the file format of choice was MP3, also known as MPEG-1 Audio Layer 3. However, a few years ago I heard about a new file format called AAC (Advanced Audio Coding) promising better sound quality than MP3s at similar bitrates, which iTunes also supports. So I went ahead with a project to re-rip all of my CDs from MP3 into AAC files, which by the way, have the file extension .m4a.

The problem I encountered was that I really disliked the file/folder structure that iTunes automatically uses when it rips your CDs. There seems to be no way to customize this file/folder structure in iTunes, so if you really care about what your files are named and in what directories they are placed, as I do, you’re stuck renaming all of your music files by hand, which is a major pain.

Therefore RenameM4A was born. This simple C# program allows you to select a set of M4A files and rename them according to a rename rule.

Rename Rules: Using RenameM4A

A rename rule is a simple way of enforcing a particular file/folder structure for any M4A file that is to be renamed. Because this is a very simple project, right now the rename rules support the following tags:

As you can see, the tags are surrounded by brackets which denote some kind of information contained within the file. All AAC files have metadata embedded in them which tells you information about the track and where it came from. When RenameM4A processes each file, it looks at the rename rule and replaces any tags encountered with information gathered from the file itself. This step takes place when you press the Preview button, which generates a list of files to be renamed, giving their original file locations and the new file location.

Then, you can hit either the Rename button or the Copy button to move or copy the file according to the destination paths given in the GridView. In fact, if you want to you can edit the GridView in order to fix any discrepancies that may have occurred when running the rule. For example, you might have a track from a particular band’s album where another artist is featured. Since you want the entire album contained within the same folder, you might edit the line for that track to remove the name of the other artist from the directory name.

If you take a look at the rename rule combo box, you can also see that there are a number of pre-loaded rename rules that may appeal to you.

How is AAC better than MP3?

In short, AAC files have superior sound quality and transparency than MP3s do, for the same bitrate. Put another way, you can encode your music at a lower bitrate than an MP3 for the same sound quality. Of course, there are a lot of other improvements, including:

  • More sample frequencies
  • Up to 48 channels of audio
  • Better handling of audio frequencies above 16 kHz
  • More flexibility in designing codecs

Advanced Audio Coding File Format

A SourceForge project called Atomic Parsley appears to have a lot of good information on the MPEG-4 file format, especially as it relates to M4A files. As it turns out, the AAC data is actually just a section within an MPEG-4 file, which can actually contain all kinds of nested data. Each nested section in an MPEG-4 file is called an atom (or sometimes a box); the first four bytes of each box defines its length in bytes, the next four is the name of the box, and the rest is either data or other nested boxes. In a way, that’s pretty similar to how XML works.

Since the only thing that RenameM4A really cares about is the album, artist, year, title, and track number, it simply scans the file for the five atoms it’s interested in and grabs the data. It’s also worth noting that text data appears to be stored in UTF-8 format, so you can’t simply assume that it will be straight-up ASCII.

Recent Improvements

This blog post actually took me a ridiculously long time to write. Mainly that’s because I was a bit embarrassed to release my source code; it was written several years ago and the way it was parsing M4A files was extremely naive. Recently, I rewrote most of the parsing code to make the following improvements:

  • More intelligent parsing; use atom information to jump to the sub-atoms of interest instead of scanning the entire file for “udta” and then each meta tag.
  • Reading only part of the file; since all metadata is under the “moov” atom, RenameM4A only needs to load the portion of the file under moov. The vast majority of a music file’s size is its music data, which is under the separate mdat atom, so we can avoid loading the entire file into memory when we don’t need to.

I did a simple benchmark test of the new and old parsing algorithms by trying to parse 14 half-hour audio files ten times each. The old parser takes about 36 seconds; the new one takes 0.14 seconds; an improvement of around 270 times faster. Not bad.

Download RenameM4A Source + Executable

[RenameM4A Source + Executable]
Note: Requires .NET Framework 2.0 or later.


MPEG-1 Audio Layer 3

Advanced Audio Coding

MPEG-4 Part 14

Atomic Parsley

Atoms, Boxes, Parents, Children & hex (oh my)

Subject: Dissection of m4a format – msg#00046

Published by


Seattleite. Climber. Snowboarder. Traveler. Party rocker. Technologist. Spanish enthusiast. Fun-seeker.

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 )

Facebook photo

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

Connecting to %s