leosongwei / mutagen

Automatically exported from code.google.com/p/mutagen
GNU General Public License v2.0
0 stars 0 forks source link

MP3: MPEG-2/2.5 Layer III frame headers parsed incorrectly #46

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Given VBR MP3s made with LAME as follows:

flac -d -c silence-44-s.flac | lame --resample 24 -V9 --vbr-old - 
silence-44-s-mpeg2.mp3
flac -d -c silence-44-s.flac | lame --resample 12 -V9 --vbr-old - 
silence-44-s-mpeg25.mp3

Mutagen fails to extract correct header information from the resulting MP3:

>>> import mutagen, os
>>> a1 = mutagen.File(os.path.join('tests', 'data', 'silence-44-s-mpeg2.mp3'))
>>> a2 = mutagen.File(os.path.join('tests', 'data', 'silence-44-s-mpeg25.mp3'))
>>> vars(a1.info)
{'bitrate': 288000, 'layer': 1, 'length': 0.23799999999999999, 'mode': 1, 
'padding': False, 'protected': True, 
'sample_rate': 48000, 'version': 1}
>>> vars(a2.info)
{'bitrate': 5101, 'layer': 3, 'length': 7, 'mode': 1, 'padding': False, 
'protected': False, 'sample_rate': 12000, 'sketchy': 
False, 'version': 2.5}

Because it calculates the frame lengths incorrectly, it's essentially pulling 
out random header-like data when it can't 
find a second frame.

Going on the documentation about frame length calculation here[1], I'm able to 
get the headers correctly:

>>> import mutagen, os
>>> a1 = mutagen.File(os.path.join('tests', 'data', 'silence-44-s-mpeg2.mp3'))
>>> a2 = mutagen.File(os.path.join('tests', 'data', 'silence-44-s-mpeg25.mp3'))
>>> vars(a1.info)
{'bitrate': 18191, 'layer': 3, 'length': 3.7679999999999998, 'mode': 1, 
'padding': False, 'protected': False, 
'sample_rate': 24000, 'sketchy': False, 'version': 2}
>>> vars(a2.info)
{'bitrate': 9300, 'layer': 3, 'length': 3.8399999999999999, 'mode': 1, 
'padding': False, 'protected': False, 
'sample_rate': 12000, 'sketchy': False, 'version': 2.5}

I'm also including a prerequisite patch that fixes integer division being used 
to calculate MP3 lengths for VBR files.

[1] http://www.codeproject.com/KB/audio-video/mpegaudioinfo.aspx

Original issue reported on code.google.com by brodie....@gmail.com on 28 Dec 2009 at 12:58

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r72.

Original comment by joe.wreschnig@gmail.com on 6 Jan 2010 at 7:27

GoogleCodeExporter commented 9 years ago
Thanks for merging my patch!

The MP3s seem to have been missed during the commit though.

Original comment by brodie....@gmail.com on 6 Jan 2010 at 7:31

GoogleCodeExporter commented 9 years ago
Sorry about that, fixed in r73. Another reason for me to finish setting up an
automatic run-tests-on-server-on-commit script...

Original comment by joe.wreschnig@gmail.com on 7 Jan 2010 at 3:23

GoogleCodeExporter commented 9 years ago
in svn 84 this still isnt working properly:
mutagen calculates the length of mp3 files _slightly_ too long. Example:

A mp3 file is shown in vlc, mplayer and gstreamer having a length of 6:09 so 
around
369 seconds
mutagen gives its length as  370.378 seconds - too long. Picard (which also uses
mutagen) also shows 6:10 as duration.

This occurs with every mp3 i checked, vbr and cbr.

Original comment by kilian.l...@gmail.com on 26 Feb 2010 at 12:45

GoogleCodeExporter commented 9 years ago
If you want 100% accurate length calculation, use a sane format.

Original comment by joe.wreschnig@gmail.com on 26 Feb 2010 at 12:58