mp3 file length in time

Tim Heaney theaney at gmail.com
Sun Sep 17 11:59:01 EDT 2006


"Jay" <jaysherby at gmail.com> writes:
> Paul Rubin wrote:
>> "Jay" <jaysherby at gmail.com> writes:
>> > In python, I know there are a couple of modules for getting id3 info,
>> > but what about the length of an mp3 file in time?  Is there a way to
>> > aquire that info?  Most of my MP3s don't have id3 tags.  I don't care
>> > for them.  But I need to use python to get their file lengths.  How?
>>
>> You have to count the frames.  Lots of mp3 files use variable bit
>> rates, so you can't go by the file length.
>
> Any tips on how to do that?

Just as there are modules to help you read ID3 tags, there are modules
to help you read the data. For example, MAD

  http://www.underbit.com/products/mad/

can be used from Python

  http://spacepants.org/src/pymad/

so that you could get the length of a track in milliseconds with
something like

  import mad
  print mad.MadFile("a_track.mp3").total_time()

There are other modules for other libraries as well.

I hope this helps,

Tim



More information about the Python-list mailing list