On Sat, 2002-01-26 at 08:12, Rob Leslie wrote:
Bastien Nocera wrote:
Would anybody have some code snippet that I could use to get the nominative bitrate of a file, by using the id3_tag ?
Simply put, I don't think this information can be learned from the ID3 tag. Unless (as I suggested) the tag has a TLEN frame -- then you can calculate the average bitrate by dividing the file size (less the size of the ID3 tag) by the playing time indicated by the TLEN frame.
OK
Failing this, you'd have to decode at least one frame of the actual audio using libmad. If the frame contains a Xing VBR header, you can calculate the total playing time and average bitrate very quickly. Otherwise you can either assume the file has a constant bitrate or you can scan the frame headers of the entire file to be more precise. A benefit of the latter option is you can then authoritatively add a TLEN frame to the ID3 tag. :-)
Fair enough. The main reason I thought it would be nice to have bitrate inside libid3tag was that libid3tag is for handling of metadata concerning a stream/file. Bitrate for me was metadata to the stream at the same level as the title or such.
My application doesn't link directly to libmad, only to libid3tag, and libmad is used through a plugin (I use gstreamer as my multimedia framework). I find having to link to libmad just to find the bitrate of the file a bit overkill, but then again, that's just my 2 pence worth.
Cheers