On Jul 28, 2005, at 3:48 PM, Langley, Adam wrote:
I have written a Managed C++ wrapper for the libMad decoder, and I would like to know…. How can I get EITHER, the _decoded_ length in bytes, or the duration in seconds of the whole file, without decoding the whole file?
I need to just evaluate a set of mp3 files, and obtain their lengths (preferably in bytes, then I can calculate the length in seconds by the bytes-per-second)
There is no official decoded length in bytes, as the number of output bits per sample is unspecified. Rather, you can determine the length in samples -- although it is often simpler to determine the length directly in units of time.
There are four possible methods for determining the length of an entire file:
1. Read the length from a 'TLEN' frame of an ID3v2 tag. If present, this is supposed to contain the length of the audio file in milliseconds (as a numeric string).
2. Read a Xing tag from the ancillary data of the first decoded frame. Multiply the playing time of one frame (given by frame-
header.duration) by the number of frames in the file as given by
the tag.
3. Assuming the file has a constant bitrate (not VBR), divide the file size in bytes (less any ID3 tags) by (125 * kbps) to obtain the playing time in seconds.
4. Scan every frame header of the file and accumulate the playing time of each to arrive at a total. This does not require a full decode of each frame, so it can be done relatively quickly.