Help - Search - Members - Calendar
Full Version: Calculate the playtime of a MP3-file
Hydrogenaudio Forums > Lossy Audio Compression > MP3 > MP3 - Tech
NBG
Hello,

i would like to calculate the playtime of a MP3-file (HH:MM:SS).

Actually i got the follow informations of a file:

MPEG 1
Layer3
128 KBIT
44100 KHz
Joint Stereo
3882423 bytes size
(and perhaps the number of frames by counting the frame syncs)

How get back the total seconds of the file on the basis of this datas?

I read somewhere the duration of a frame is always 0,26 seconds?!

So i just must count all frames, multiply them with 0,26 and divide by 10 to get the length?
rickio
QUOTE(NBG @ Jul 16 2006, 09:52) *

Hello,

i would like to calculate the playtime of a MP3-file (HH:MM:SS).

Actually i got the follow informations of a file:

MPEG 1
Layer3
128 KBIT
44100 KHz
Joint Stereo
3882423 bytes size
(and perhaps the number of frames by counting the frame syncs)

How get back the total seconds of the file on the basis of this datas?

I read somewhere the duration of a frame is always 0,26 seconds?!

So i just must count all frames, multiply them with 0,26 and divide by 10 to get the length?


well one little media player i have used which is xmplay, gives you that information in that mode. check it out. http://www.un4seen.com/xmplay.html


NBG
Sorry, need no external tool, i need basic informations to make a calculation by myself.
Jebus
QUOTE(NBG @ Jul 16 2006, 09:52) *

Hello,

i would like to calculate the playtime of a MP3-file (HH:MM:SS).

Actually i got the follow informations of a file:

MPEG 1
Layer3
128 KBIT
44100 KHz
Joint Stereo
3882423 bytes size
(and perhaps the number of frames by counting the frame syncs)

How get back the total seconds of the file on the basis of this datas?

I read somewhere the duration of a frame is always 0,26 seconds?!

So i just must count all frames, multiply them with 0,26 and divide by 10 to get the length?


size_in_bytes / bitrate = length_in_seconds.

3,882,423 bytes = 31,059,384 bits
128 kbit/s = 131,072 bits/s

31,059,384 / 131,072 = 237 seconds.

Yeah, tags and stuff could add extra info, but an ID3v2 tag is typically only 1kB, which would be far less than a single second. So if you're rounding to seconds, just use the bitrate like that - no need to seek frames.
NBG
Thanks for the info! But what about VBR (when the bitrate is not constant)?
boojum
I think you have answered your own question. cool.gif
Firon
VBR files (usually) have a VBRI or XING/LAME header, and you can use that to get the necessary info to calculate it.

http://gabriel.mp3-tech.org/mp3infotag.html
http://www.codeproject.com/audio/MPEGAudioInfo.asp
NBG
http://www.codeproject.com/audio/MPEGAudio....asp#XINGHeader

But how to calculate? Or have i first to read out the "normal" MP3-header BEFORE the Xing-tag?
sony666
The only reliable way is like Foobar does IMO, counting the number of samples and divide by samplerate (like 44100)
NBG
"the number of samples"

Means frame sync by frame sync and the samples are everything between them?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.