Solved

Determining audio bitrate and length

Posted on 2009-07-03
3
868 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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 …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now