MP3 repair: fixing your corrupt MP3s

laptop and stethoscope

The contents of music files, such as MP3s, are arranged according to a strict specification. Sometimes music files can contain errors that means the specification is not necessarily 100% adhered to, and this can lead to undesirable characteristics such as undisplayable album artwork or skips and pops when playing-back.

How can you diagnose and fix these errors?

MP3 files (and other digital music files) seem fairly straightforward when you first start working with them. You download or create them from rips, you copy them around, maybe to your mobile music player, and you double click on them and play them. They seem pretty black box.

In reality, things are much more complicated. There are a set of clearly defined rules that determine how an MP3 file is structured internally. Add in tagging (which was always an after thought for MP3) and you have a complex data structure. Basically there are a lot of things to go wrong and you can be sure they will do at some point!

It turns out MP3 corruption, and the integrity of your music files generally, are something any music library organizer has to content with.

Back in April I exchanged a series of emails with a user of bliss who had added artwork but the artwork did not display. The reason was not initially clear, so I asked him to upload one file and I checked it out.

Interestingly, using bliss it was clear that the artwork was present inside the file. I tried it with some music players and some showed the artwork, some didn't. All of the music players played back an audible 'pop' when the track was started. It was clear something was wrong with the file.

Solving MP3 corruption

You guessed it: it turned out this file was suffering from MP3 corruption. While the file was generally correctly encoded, it was not 100% correct (purists will argue that means it simply isn't correctly encoded, which is true, but in reality music players often offer a level of tolerance).

The way I found this out was by running the file through a piece of software called MP3 Diags. This open-source project is an ingenious piece of software that checks your MP3s for adherence to the strict letter of the MP3 specification.

The interface of MP3 Diags is quite complicated and overall it is aimed at the technical user. Here's what the author of MP3 Diags himself has to say:

This program is not really meant for those who want to push a button and have everything fixed automatically, but rather for people who have some technical background, who are rather picky about what's in their MP3 files, and who are willing to spend some time to get them right.

(From the MP3 Diags home page).

So maybe not for the faint hearted, but I thought it a useful exercise to show how errors in MP3s can be corrected. In this example I use MP3 Diags against my own MP3 collection.

Using MP3 Diags to find MP3 corruption

I pointed MP3 Diags at my music collection on my NAS. Because it's a network-mounted collection it took a little while to run through, but once done MP3 Diags can be restarted without losing your work and the results of its assessments.

MP3 Diags only supports MP3s, by the way. This means the vast majority of my files, which are stored in FLAC, were not analysed. I do still own some MP3s without FLAC counterparts, for example on the odd occasion where I or the wife (most often the wife) have purchased some music online from Amazon or similar.

So I pointed MP3 Diags at my collection, and let it chug away. Upon completion, here's what I got:

MP3 Diags UI after scanning my entire collection of MP3s

The results are, on first glance, worrying! It seems that pretty much every file has something wrong with it. Each file is tabulated with markers for where a particular rule, represented with an abbreviation, is broken. For instance, in the above example, ab represents:

Low quality MPEG audio stream. (What is considered "low quality" can be changed in the configuration dialog, under "Quality thresholds".)

It turns out that errors flagged by MP3 Diags include such 'subjective' matters as where a file is lacking volume normalisation information, or where the bitrate of the MP3 is below a configurable quality threshold. It's possible to change these quality thresholds and also ignore certain assessments.

Scrolling through my collection, however, I was soon to find some more worrying findings.

An album that I swear is my wife's, Reflections - Carly Simon's Greatest Hits contained a number of more serious errors:

More serious corruption for Carly Simon's Greatest Hits including 'Invalue MPEG stream'

Here's a selection of the juicy errors contained within:

  • Invalid MPEG stream. Stream has fewer than 10 frames.
  • Broken stream found. Since other streams follow, it is possible that players and tools will have problems using the file. Removing the stream is recommended.
  • Unknown stream found. Since other streams follow, it is possible that players and tools will have problems using the file. Removing the stream is recommended.

Not pretty. So I thought how bad can it be? and played some of the music files. While the music files could still be played, an audible pop could be heard at the start of each track, which is pretty horrible to listen to and distracting when you are... tolerating... the album (sorry Carly Simon fans!).

Hammer time!

MP3 Diags offer a number of 'transformations' that are intended to fix a given MP3 file:

Fixing MP3 problems is achieved through clicking one of the 'hammer' icons

The first hammer gives a pull down menu of individual transformations to choose from. The numbered hammers batch together transformations. Unfortunately, it's not really clear which transformation corresponds to which problem, so you have to do a bit of educated guesswork (remember: take backups!).

First I selected Remove broken streams. This 'did something' and reduced the number of errors stored against these files. In particular, the ib rule appeared fixed. But when I played the music, the pop still occured.

I got luckier second time. I chose Remove unknown streams. This time, all problem markers were cleared (except for the volume normalisation one, but I can sort that later) and most importantly playing the music back worked without any audible artifacts.

The MP3s after MP3 Diags had worked its magic.

So there you have it... if you have weird sound artifacts or an MP3 file that won't do what it's told, maybe it's corrupted! Give MP3 Diags a try.

Thanks to jfcherry for the image above.
tags: mp3 corrupt mp3 diags

The Music Library Management blog

Dan Gravell

I'm Dan, the founder and programmer of bliss. I write bliss to solve my own problems with my digital music collection.