Help - Search - Members - Calendar
Full Version: simple script for calculating average bitrates
Hydrogenaudio Forums > Hydrogenaudio Forum > General Audio
ff123
The following is a simple python script for calculating the bitrates of a group of encoded files. It relies upon having the original wavfiles around to get the duration of the files.

The user creates two text listfiles. The first listfile contains the names of the WAV files. The second listfile contains the names of the compressed files. Both lists must be ordered in the same way because the script pulls the file durations out of the WAV list and the file sizes out of the compressed list.

Then the program is invoked by:

python bitrate.py [wavlist] [compressedlist]

It outputs the bitrates (kbit/s) of each file in the list, and the overall average bitrate.

I envision this utility being used to help Roberto when he's verifying VBR bitrates in his next test.

Here is the script itself, which is named "bitrate.py"

CODE

# python script to calculate average bitrates
# invoked as follows:
# python bitrate.py [wavlist] [compressedlist]
#   wavlist is a text file which contains a list of WAV filenames
#   compressedlist is a text file which contains a list of the corresponding
#     compressed filenames.  The ordering of the filenames must be the same
#     as in wavlist.

import sys
import os
import wave
import string

duration = []
inf1 = file(sys.argv[1], 'r')
for line in inf1.readlines():
   sline = string.strip(line)
   inw = wave.open(sline, 'rb')
   duration.append(1.0 * inw.getnframes() / inw.getframerate())
   inw.close()
inf1.close()


fsize = []
inf2 = file(sys.argv[2], 'r')
for line in inf2.readlines():
   sline = string.strip(line)
   st = os.stat(sline)
   fsize.append(st.st_size)
inf2.close()


bitrate = []
i = 0
sumduration = 0
sumsize = 0
for fs in fsize:
   sumduration = sumduration + duration[i]
   sumsize = sumsize + fsize[i]
   bitrate.append(fsize[i]/duration[i] * 8.0 / 1000)
   i = i + 1
print bitrate
average_bitrate = sumsize/sumduration * 8.0 / 1000
print average_bitrate
rjamorim
QUOTE(ff123 @ Jun 28 2003 - 02:56 AM)
I envision this utility being used to help Roberto when he's verifying VBR bitrates in his next test.

It will surely be of much use. Thanks a lot. smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.