32

I have a number of songs in my Music library that display incorrect duration values, and so play only partially in Clementine. In Banshee and some other players they show different duration values and sometimes play the full song.

Is there a way to fix this without having to "re-encode" the song?

RolandiXor
  • 51,091
  • 31
  • 161
  • 256

4 Answers4

32

MP3 Diags can fix incorrect durations (and other errors). It is open source and in the repositories. It is a GUI Tool.

Installation

sudo apt-get install mp3diags mp3diags-doc

Another option is MP3val, which can be used either via commandline or via GUI:

Installation

sudo apt-get install mp3val

Usage example

mp3val damaged.mp3 -f -t

-f: fix errors, -t: keep original timestamp

TomRoche
  • 123
  • 4
phoibos
  • 21,016
  • 4
  • 48
  • 47
  • This worked for me. I use `cat` to combine audiobook parts into one file (`cat 1.mp3 2.mp3 > out.mp3`) and that works great for playback but almost every player gets wacky with the timestamps and even `mediainfo` shows the duration from the first file rather than the combined. – blockloop Nov 02 '13 at 19:48
  • 1
    `cat` is less than ideal for tasks like combining mp3s. A better way: [http://superuser.com/questions/314239/how-to-join-merge-many-mp3-files](http://superuser.com/questions/314239/how-to-join-merge-many-mp3-files) – phoibos Nov 02 '13 at 20:48
  • Why do you think that? MP3 files aren't much more than raw streams and they're *almost* the perfect candidate for `cat` aside from trivial side effects solved with a simple reassessment of Xing header data. Even without the mp3val the files still play in every player I've sent them through. `cat` is extremely efficient and MUCH faster than re-encoding with ffmpeg. Even with the added mp3val command. – blockloop Nov 03 '13 at 05:03
  • 2
    `ffmpeg` with `concat` and `-acodec copy` does _not_ re-encode - it just copies the streams (so it's fast), but creates a proper file in the first place (without useless header & tag data appearing multiple times in the resulting files). – phoibos Nov 03 '13 at 09:55
27

If you don't want to install anything new, try with ffmpeg:

ffmpeg -i file_orig.mp3 -acodec copy file_fixed.mp3
Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Alcaro
  • 403
  • 4
  • 5
  • 2
    Perfect solution, works also if the wrong mp3 file has been created by ffmpeg itself! – Pierpaolo Cira Feb 24 '18 at 18:28
  • This actually worked for me, when the `mp3val` and `mp3check` solutions didn't. (Just to be sure, it doesn't re-encode, right?) – Noldorin Feb 28 '18 at 01:35
  • 1
    With -acodec copy, it doesn't reencode. If you want to verify, try with and without it and check how fast it goes. – Alcaro Feb 28 '18 at 10:47
3

Aside from the VBR headers not matching the actual audio (which you would use mp3val to correct, as mentioned in the other answer), another reason this can be caused is by an MP3 file having ID3 tag that has an incorrect value for the TLEN tag. You can fix this using the mid3v2 tool from the mutagen package to remove the tag (apparently its optional):

$ mid3v2 --delete-frames=TLEN filename.mp3

The music player Quodlibet also has a convenient "Fix MP3 Duration" plugin you can use to do this.

(Taken from the Quodlibet FAQ: http://quodlibet.readthedocs.org/en/latest/guide/faq.html)

nedned
  • 401
  • 5
  • 14
0

mp3check worked perfect for me also with wildcards.

sudo apt-get install mp3check

mp3check {filename or wildcard} --cut-junk-start --cut-junk-end --fix-headers
  • helped when Windows media player showed wrong mp3 file duration – Mantas D Nov 07 '17 at 11:53
  • *WARNING* If you have id3v2 tags, cover art etc, be extremely aware of these issues (I learnt the hard way) https://bugs.launchpad.net/ubuntu/+source/mp3check/+bug/592775 https://bugs.launchpad.net/ubuntu/+source/mp3check/+bug/1348223 – digitaltoast Mar 30 '19 at 22:04