Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically determine whether an MP3 file is CBR or VBR? (preferrably using c#)

Tags:

c#

mp3

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.

like image 789
Tom Kidd Avatar asked Oct 13 '08 00:10

Tom Kidd


2 Answers

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

like image 101
Simon Lehmann Avatar answered Oct 26 '22 13:10

Simon Lehmann


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);
...
like image 45
Christian C. Salvadó Avatar answered Oct 26 '22 15:10

Christian C. Salvadó