Solved

Determining audio bitrate and length

Posted on 2009-07-03
3
928 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
[X]
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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
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…
Suggested Courses

739 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