Help - Search - Members - Calendar
Full Version: Identify mp3 file as vbr
Hydrogenaudio Forums > Lossy Audio Compression > MP3 > MP3 - General
kirkm
I've written (if it can be so called!) a routine in MS Access's visual basic
to log mp3 and wav files into a table. Wanted fields include the duration and kbps.

The VBR files are giving a lot of trouble - I'm only reading 5 headers (thinking this should be enough) but sometimes
a CBR match is confirmed even when the file is VBR.

Is there a better way to determine if an mp3 is VBR, or not ?

2nd question - is there any way to calculate the duration of an mp3 file
without playing it? Even approximately ?

Thank you.
Kirk.
AgentMil
Hmmm... have you looked at the LAME tag that LAME encoded files have. Search the forum for information on them. Hope this help.

Laters

AgentMil
smack
QUOTE(kirkm @ Sep 5 2003, 02:28 AM)
The VBR files are giving a lot of trouble - I'm only reading 5 headers (thinking this should be enough) but sometimes
a CBR match is confirmed even when the file is VBR.
Is there a better way to determine if an mp3 is VBR, or not ?

If you want to know for sure if an MP3 file is VBR or CBR you have to look at ALL frames! When you find that all frames have the same size (bitrate indicator in the frame header) then the file can be called CBR, otherwise it is a VBR file.

A nice but inofficial and purely optional feature for VBR files is the so-called "Xing header". It contains some additional info about the file, including the total number of frames and a table of seek points. If you find such a Xing header at the beginning of an MP3 file you can be almost sure that it is VBR and use the info from it for calculation of the duration, for instance.
Note: although it is called "Xing header" (because it was introduced by the Xing encoder) it is widely supported - LAME also generates it for VBR files.

QUOTE
2nd question - is there any way to calculate the duration of an mp3 file
without playing it?  Even approximately ?

You have to find out the number of MPEG frames in the file. The most reliable way to do this is to count them all, seeking from one frame header to the next by using the frame sizes (bitrate indicators) until the end of file. If you have a CBR file then you can divide the file size by the frame size to calculate the number of frames.
Each MPEG audio frame will be decoded to a fixed number of samples (1152 for MPEG-1 or 576 for MPEG-2 files).
So the equation is:
duration[seconds] = number_of_frames * samples_per_frame / sampling_frequency[Hz]

Have fun! wink.gif
getID3()
A VBR MP3 is nothing more than a bunch of frames that may or may not have the same bitrate as the previous frame. There are two incompatible VBR header formats, "Xing" and "Fraunhofer", that may be present (although neither one is officially part of the MP3 design). The Xing version is used by LAME (and others) as well, whereas I believe the Fraunhofer (aka VBRI) version is I believe only created by Fraunhofer encoders. Note that LAME may optionally create a modified Xing-style header for CBR files, so the presence of this header frame is not neccesarily a guarantee that the file is VBR.

Brief links to basic documentation:
Xing: http://gabriel.mp3-tech.org/mp3infotag.html
VBRI: http://minnie.tuhs.org/pipermail/mp3encode...ary/001800.html

As I said before, a VBR file is not required to have either of the VBR headers (but it should never have both) so you may indeed need to walk through every frame of the file to get a frame size count/distribution and calculate the average bitrate. Playtime can be calculated as:
(filesize, not including tags, in bytes) * 8 / (bitrate in bps)

And naturally, there's also no guarantee that the VBR header is correct for the data it's attached to, so if you want to be absolutely sure, walk through all the frames.

And finally, free-format MP3s are always CBR. They're a pain, and fortunately rarely encountered, but the potential is there.

If it's any help, you can read through my MP3 scanning code:
http://www.getid3.org/getid3.mp3.phps
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.