Calculating MP3 time (under Linux)?

Posted by: kremer

Calculating MP3 time (under Linux)? - 28/11/1999 11:14

Is there any tool to calculate how much playing time is contained in a particular MP3 file?

I use grip 2.7+lame 3.13 (Debian Potato) with variable bit rate and 160 bits. I suspect that the variable bit rate means that one must actually read each MP3 "packet" (whatever the MP3 terminology might be) in order to accumulate the total play time contained in it. Is this true?

In any case, I'd be very interested to know how much playing time is contained in my RIP'ed CD's so far, preferably under Linux but Lose98 will do as well.


Unit 119, 6Gb, Blue
Posted by: Verement

Re: Calculating MP3 time (under Linux)? - 28/11/1999 17:31

The attached source code will compute the actual duration of one or more MPEG audio files. It works with any of the three standard layers (yes, MP3) at any sampling frequency and bitrate, including a variable bitrate.

To compile: gcc -O2 maduration.c -o maduration

To use: maduration [-s] file [...]
On a directory tree: find . -type f -print | xargs maduration

The hours:mins:secs displayed are rounded down to whole seconds, but full accuracy is maintained internally to compute the total. The -s flag shows only the sum total of all files.

It's not as fast as a direct computation from the file size since it reads all the audio frame headers, but it should be very accurate, especially with variable bitrate files.

I place this code under the GNU GPL. Share, modify, and enjoy.

Cheers,
-v


Posted by: kremer

Re: Calculating MP3 time (under Linux)? - 21/12/1999 10:04

Thanks for the code. It works great for me.
I found and fixed a small bug - it doesn't check for zero-size input files and bombs on mmap(2)
with that size. I'll mail you the patch if I had your e-mail.


Unit 119, 6Gb, Blue
Posted by: Verement

Re: Calculating MP3 time (under Linux)? - 21/12/1999 12:55

Thanks. You could post the patch here, or mail it to me.