Solved

Determining audio bitrate and length

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python - passing two arguments to two different pages using url get method 4 66
Python script with password security? 15 105
Copy Files - Python 7 83
python sqlite question 11 46
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
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…
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 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…

773 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