Solved

Determining audio bitrate and length

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
Can't install scipy on Python 2.7 in Win7 2 279
Python mysql Insert data error 3 106
Perl Write to Specific line in a file 15 112
Python 3.5.2 - I need help with a script 8 49
A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

713 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