Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Determining audio bitrate and length

Posted on 2009-07-03
3
909 Views
Last Modified: 2012-05-07
Hey experts,
I'm looking for either assistance with determining bitrate and track length using the Mutagen module or any other method of obtaining the info.
I'd like to be able to support these formats: FLAC, OggVorbis, MP3, WMA, and possibly ASF/M4A.  I've used a module called Mutagen for previous tag reading purposes. The project is hosted here: http://code.google.com/p/mutagen/ but unfortunately the documentation is nearly non-existent.
Does anyone know (preferably) how to use Mutagen to determine bitrate and track length or of another way to determine these?
Thanks.
0
Comment
Question by:khsater
  • 2
3 Comments
 
LVL 4

Author Comment

by:khsater
ID: 24774153
Geez!  I forgot a crucial detail.  I'm running Python for cgi use on Windows as an apache module.  So, I'd prefer a pre-compiled extension for python or even just a .py script.
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24779895
It can be found in the info.length and info.bitrate properties.

An example for mp3 can be found here:

http://svn.sacredchao.net/svn/quodlibet/trunk/mutagen/TUTORIAL

    from mutagen.mp3 import MP3
    audio = MP3("example.mp3")
    print audio.info.length, audio.info.bitrate

FLAC example here, no "bitrate" in this case:

http://code.google.com/p/quodlibet/wiki/Development/Mutagen

audio = FLAC(fname)
print "Sample rate:         ", audio.info.sample_rate
print "Nr. of channels:     ", audio.info.channels
print "Bits per sample:     ", audio.info.bits_per_sample
print "Total nr. of samples:", audio.info.total_samples
print "Length in secs:      ", audio.info.length

OggVorbis and WMA:

>>> from mutagen.oggvorbis import OggVorbis
>>> a=OggVorbis('tests\\data\\empty.ogg')
>>> a.info.bitrate
112000
>>> a.info.length
3.684716553287982

>>> from mutagen.asf import ASF
>>> a=ASF('tests\\data\\silence-1.wma')
>>> a.info.bitrate
64008
>>> a.info.length
3.7120000000000002
0
 
LVL 4

Author Closing Comment

by:khsater
ID: 31599659
Thanks, that's exactly what I was looking for.
I'll just calculate the average bitrate for FLAC files.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question