Hi,
After getting my mail nicely rejected ;) I tried the nice advice of using the TLEN frame. However very few (actually in my collection, none) mp3 files have such a frame.
Would anybody have some code snippet that I could use to get the nominative bitrate of a file, by using the id3_tag ?
Cheers
On Sat, 2002-01-26 at 05:06, mad-dev-admin@lists.mars.org wrote: <snip>
To answer your question, "bitrate detection" would not be an appropriate feature to add to libid3tag. However, you may be able to approximate the average bitrate using the file size and the TLEN frame from the ID3 tag.
Calculating the actual bitrate requires decoding MPEG audio frames, which is done by libmad (not libid3tag.)"
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.
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. :-)
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