tags:

views:

914

answers:

2

I know of many utilities that can tell me the bitrate of an MP3 file, but I've never seen one that can tell me whether or not the MP3 file is VBR (variable bit rate - the bit rate fluctuates within the file) or a CBR (constant bit rate - the bit rate stays the same within the file). My guess is that most programs aren't interested in finding this out since it involves analyzing the file somewhat to see if the bitrate changes, which takes away from speed.

So, in lieu of finding a utility, I'd like to write one - so how could I programmatically determine whether or not an MP3 file is VBR or CBR? I have about 15,000 files to go through to find this out for, so I need to automate the process.

+2  A: 

Check this MP3Header Class, it has a method that tells you if the mp3 file is VBR, and all the mp3 header information...

...
boolVBitRate = LoadVBRHeader(bytVBitRate);
...
CMS
The method this class uses to determine if its a VBR file is quite limited. It just checks if it finds the string "Xing" after the (optional) ID3v2 header of the file, but this is not described by any standard and there are encoders which don't put "Xing" in even if it is a VBR file.
Simon Lehmann
+3  A: 

MP3 files are essentially build of so called frames. Each frame has a small header that stores information about the frame. The header also stores which bitrate was used for the frame. In CBR files, all frames use the same bitrate and therefore every header has the same bitrate information.

To detect if a file uses VBR, you have to go through every frame of the file, look at the header and check if the bitrate field changes. If it does, its an VBR MP3.

A full description of the MP3 format is here: http://www.mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm

Simon Lehmann