Is there a tool that can detect (and if possible, fix) glitches in MP3 files?

32

6

My collection contains some MP3s which have some glitches like:

  • displaying the wrong duration on loading
  • minor jumps
  • suddenly ending despite the duration claims another minute remaining
  • noise

I'm looking for a tool that can detect as many of these glitches as possible and fix those that can be fixed (obviously e.g. noise can not simply be eliminated in most cases).

Tobias Kienzler

Posted 2011-08-24T12:46:11.110

Reputation: 3 262

Question was closed 2019-03-16T06:29:42.593

Those sound like player issues. Are you sure those are caused by your MP3 files? – digitxp – 2011-08-24T14:59:26.483

@digitxp the sudden ending is probably due to missing parts of the file, but the wrongly displayed time might be caused by VLC. But still that means there is something wrong with the file since other files show the correct time. Noise and jumps might be due to a bad CD read, I digitalized my collection without doing double-checks :-/ – Tobias Kienzler – 2011-08-24T15:02:57.337

hm, the wrong duration could stem from VBR vs CBR... so the remaining problems are incompleteness and CD reading errors – Tobias Kienzler – 2011-08-24T15:17:53.957

Answers

35

The command-line tool mp3val makes quick work of scanning for, and optionally repairing, structural defects in mp3 files. I try to run it over pretty much every file in my collection, on the "can't hurt" principle. It identifies amazing numbers of ostensibly-good files with defects ranging from inconsequential to severe.

mp3val is especially good at recognizing and correcting header deficiencies, such as lack of VBR headers in a VBR file (the source of most wrong-duration and seeking issues). But it will also clear out garbage/corrupted audio frame data, unusable cruft that some players may handle less than elegantly if it's left in the file.

It can even be told to run over an entire directory of mp3's, repairing only those files it finds problems with, keeping backups (or optionally not), preserving timestamps (optionally), and logging the session to a text file (optionally).

And it's free and open source! (The link is to its sourceforge project.)

EDIT: One last thing I forgot to mention. "But mp3val hasn't been updated since 2009!!", I hear you cry. That's very true! It's been working just fine since 2009, and hasn't needed an update. (After all, it's not like the MP3 file format has changed any in the past 2 years!)

FeRD

Posted 2011-08-24T12:46:11.110

Reputation: 989

@Marecky That's very strange. I just tried mp3val on Fedora 28, and it's still running fine. The most esoteric library dependency it has is either libm.so.6 or libstdc++.so.6, so it's not like an incompatible ABI breakage is likely. Just to check, though: in its default mode mp3val won't touch any files, it'll only make modifications if it's run with the -f flag — and even then, only files where the scan mode logged a WARNING: or ERROR: would be modified. If it doesn't detect any fixable issues, it'll leave your files untouched. – FeRD – 2018-11-02T23:40:18.527

1@FeRD - You are right, I don't remember now which program was it (Audacious, Gnome MPV or Rhythmbox Music Player) but after ripping a cd with the last one I put new files into playlist of one of these programs and saw wrong track times - that is why I thought that mp3's have wrong indexes (or whatever that have inside) and run on them mp3val - but the files were correct - that is why mp3val never displayed any warning and didn't correct files. I don't know why player showed wrong track times, I will delete my previous comment. – Marecky – 2018-11-07T12:28:31.023

@Marecky If the audio CD was standard tracked content (with silences between each track, IOW not continuously-mixed audio), then depending how you ripped it, your audio files might've ended up with the track gaps encoded into each file. Then every file except the last will be slightly longer than that track's CD runtime, to account for the 2-second gap (silence) tacked on to the end. – FeRD – 2018-11-07T12:46:38.053

also +1 a second time for you edit :-) though there seem to be some valid bugs still open...

– Tobias Kienzler – 2011-08-26T15:04:08.747

1Yeah, it seems mp3val has some real problems under Windows 7 with some esoteric filenames. That's unfortunate. (First rule of modern computing: any sufficiently large MP3 collection will contain a file with any given form of esoteric filename.) It could use some luv from a Windows programmer, if anyone's up to it!

[OffTopic: It was surreal looking into the mp3val svn and finding out that the most recent patch had come from ME — especially since I'd totally forgotten about doing it! ;-)] – FeRD – 2011-12-20T20:40:07.010

1Unfortunately mp3val failed to fix some of my files :(. But MP3Diags was able to fix them (Xing header on VBR files which lead to a wrong duration being displayed). – scai – 2013-10-29T16:50:43.517

10

I assumed you already tried the first option on google ...? Also a perl script, mp3checker, that might be useful.

Edit:

As for repairing your tracks might give MP3 Diags(links to a lifehacker article) a look.

John

Posted 2011-08-24T12:46:11.110

Reputation: 1 101

thanks, checkmate is a nice tool to identify problem files (that still leaves the task of fixing things if possible though) – Tobias Kienzler – 2011-08-24T15:14:57.627

1Thumbs up for MP3 Diags. I had problems with my mp3 player not reporting the duration correctly. MP3 Diags found and fixed the problem. – David L – 2013-01-23T04:54:48.747

4

mpck works on Windows and GNU / Linux.

Home page: http://checkmate.gissen.nl/

It detects bad frames and generates optional reports.
There is a GUI frontend for windows too.

mpck 0.19 - checks a MP3 file for errors

Usage: mpck [OPTION]... [FILE]...

Verbosity:
   -v, --verbose        print some extra info
   -q, --quiet          print only Ok or Bad per file
   -B, --badonly        only report bad files
Other options:
   -R, --recursive      check directories recursively
   -e, --extention=EXT  only check files ending on .EXT
   -r                   short for -R -e mp3
   -m, --maxname=NUM    report bad for filenames which exceed NUM characters
   -n, --namecheck      check for strange characters in the filename
   -x, --xmloutput      output results in XML
   -h, --help           print this help, then exit
   -V, --version        print version information

Update:

This program seems to be fully capable of handling utf-8 file names, although I haven't tried japanese, chinese or more exotic glyphs.

Gentoo (UTF-8)

$ mpck -r 2000\ -\ Завтрак\ на\ траве\ \(USA\)/  | grep SUM
SUMMARY: 2000 - Завтрак на траве (USA)//04-ja-sbrasyvaju-kozhu.mp3
SUMMARY: 2000 - Завтрак на траве (USA)//07-tak-vot-kakaja-ty-demo.mp3
SUMMARY: 2000 - Завтрак на траве (USA)//09-evrej-i-goj.mp3
SUMMARY: 2000 - Завтрак на траве (USA)//06-teplyj-dozhd'-demo.mp3
SUMMARY: 2000 - Завтрак на траве (USA)//01-vse-napominaet-o-tebe.mp3
SUMMARY: 2000 - Завтрак на траве (USA)//02-marsh-novoselov--sf-unplugged.mp3
SUMMARY: 2000 - Завтрак на траве (USA)//05-rubaha.mp3
SUMMARY: 2000 - Завтрак на траве (USA)//03-kalifornia-love.mp3

Cygwin with UTF-8 locale (japanese locale in windows)
The native windows binary is not aware of cygwin so I had to convert the output.

$ mpck.exe -r "2000 - Завтрак на траве (USA)" | grep 'SUM' | 
       iconv -f CP932 -t UTF-8
SUMMARY: 2000 - Завтрак на траве (USA)\04-ja-sbrasyvaju-kozhu.mp3          
SUMMARY: 2000 - Завтрак на траве (USA)\07-tak-vot-kakaja-ty-demo.mp3       
SUMMARY: 2000 - Завтрак на траве (USA)\09-evrej-i-goj.mp3                  
SUMMARY: 2000 - Завтрак на траве (USA)\06-teplyj-dozhd'-demo.mp3          
SUMMARY: 2000 - Завтрак на траве (USA)\01-vse-napominaet-o-tebe.mp3        
SUMMARY: 2000 - Завтрак на траве (USA)\02-marsh-novoselov--sf-unplugged.mp3
SUMMARY: 2000 - Завтрак на траве (USA)\05-rubaha.mp3                     
SUMMARY: 2000 - Завтрак на траве (USA)\03-kalifornia-love.mp3            

Ярослав Рахматуллин

Posted 2011-08-24T12:46:11.110

Reputation: 9 076

Thanks, though that's already been mentioned in this answer

– Tobias Kienzler – 2013-07-24T06:57:26.100

mpck != mp3check. Am I wrong? – Ярослав Рахматуллин – 2013-07-24T07:11:47.243

No, it's the link labelled "the first option on google". But +1 nonetheless since you elaborate a bit on it's functions – Tobias Kienzler – 2013-07-24T07:12:41.913

Oh, right. I ignored that. I'll be checking out mp3val, but so far mpck has been able to to all that I need from an mp3-checker. – Ярослав Рахматуллин – 2013-07-24T07:14:45.507

How does it cope with unicode filenames? mp3val has this open bug and I don't assume anyone will ever fix it...

– Tobias Kienzler – 2013-07-24T07:16:33.807

Hm, that sucks big time :\ – Ярослав Рахматуллин – 2013-07-24T07:57:09.423

I guess this could be circumvented on Linux by writing a FUSE translates filenames into punycode and back...

– Tobias Kienzler – 2013-07-24T08:01:08.807

Probably better to just fix the original code... – Ярослав Рахматуллин – 2013-07-24T08:02:10.967

True, though that way all programs not handling unicode filenames correctly would "suddenly" work – Tobias Kienzler – 2013-07-24T08:03:44.553

2On Linux, it doesn't strike me as necessary to apply any workarounds for mp3val — AFAICT the referenced bug is a Windows-only problem. (Whatever functions it uses for parsing the command line or handling filenames must not be Unicode-safe.) Under Linux, I just hand-damaged (by zeroing out random blocks with ghex) mp3 files renamed as follows: Tësting 1.mp3 Testíng ®eally hµrd.mp3 ☭They don't get much weirder☭.mp3 ...mp3val had no trouble correctly processing all of them. – FeRD – 2013-10-08T09:47:53.357

Having been into the mp3val source for a different reason recently (don't even remember what), I can now say with certainty that the mp3val source is not Unicode filename safe on Windows. WOW is it not! It does all sorts of early-1990s-style pointer math with the file path s̶t̶r̶i̶n̶g̶s char[] arrays. That works OK on Linux, where you can generally assume that even Unicode filenames are UTF-8 (though anywhere that's not true, it surely will break). It breaks on Windows, though, because assuming pathnames always use one-byte-wide characters doesn't fly in the land of UTF-16. – FeRD – 2014-03-22T14:09:59.420

0

Simpler is to use ffmpeg to copy the file from the one with the faulty duration in its ID3 tag. This causes it to write the correct information.

ffmpeg -i "audio.mp3" -acodec copy "audio_fixed.mp3"

Because it uses copy it takes a fraction of the time the original encoding takes. This is hardly noticeable with a song, but you really appreciate it with a 7 hour audiobook. After re-encoding, the ID3 tags now have the correct information.

Miriam English

Posted 2011-08-24T12:46:11.110

Reputation: 1