Reputation: 4221
how can i get bitrate
of a MP3 File ?
Upvotes: 7
Views: 4344
Reputation: 2453
Have a look at TAudioFile.GetMp3Info
in Read MP3 info (just ignore the german description)
Upvotes: 4
Reputation: 1593
MP3 Bitrate is stored in the 3rd byte of frame header so an option would be to search for the first byte with a value 255 (in theory there's should be no other bytes with all bits set to 1 before that) and bitrate should be stored two bytes after that. Following code does this:
program Project1;
{$APPTYPE CONSOLE}
uses
Classes, SysUtils;
const
BIT_RATE_TABLE: array [0..15] of Integer =
(0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0);
var
B: Byte;
begin
with TFileStream.Create(ParamStr(1), fmOpenRead) do begin
try
Position := 0;
repeat
Read(B, 1);
until B = 255;
Position := Position + 1;
Read(B, 1);
Writeln(BIT_RATE_TABLE[B shr 4]);
finally
Free;
end;
end;
end.
Note that this only finds bitrate of the first frame.
You can find more detailed info from here
Upvotes: 5
Reputation: 17138
You'll have to create a Delphi structure to read the MP3 file format.
That format is defined here:
http://en.wikipedia.org/wiki/MP3#File_structure
This link: http://www.3delite.hu/Object%20Pascal%20Developer%20Resources/id3v2library.html
appears to contain Delphi code for reading the format as well.
More basically, every file has a format, and generally you need to create a data structure to map that format. You then use file reading code to map the data in the file on top of structure that defines the file format.
Upvotes: 3