[Gambas-user] Music.Length
Ron Onstenk
ronstk at ...239...
Sat Jun 21 10:27:07 CEST 2008
On Friday 20 June 2008, Benoit Minisini wrote:
> I don't know why apparently the length of the audio is not encoded in the file
> header...
>
It is, but not in the way you think.
In fact is the mp3 as we know nowadays a incomplete standard.
We need to split the parts out of it.
Mp3 is the encoding method only used as _data_.
mpeg the layout of a block containing _data_
The file containing blocks of _data_
Audio is encoded, mp3 in this case, in blocks and each block
has a header telling the rate used and block length.
The block information is following a mpeg standard.
Divide the bytes by rate and the time per block is known.
Add the time per block for each block and you have the
total play time.
Storage on disk in a file was simple put all blocks
after each other and without a file header descibing the
content of the file.
It was the inovation of mp3 encoding that triggers a group
of enthousiast to write encoders/decoders to store there
music that way and made it as a pseudo standard for the
audiophiles, the 1/10 of the *.wav size that time in use.
The early players read the rate from first block and used it
for the whole file play and position, not looking every block.
Just to win decoding time on the slow computers those days.
They where not able to use variable rates at all.
In the early 90's using 90% cpu time with win3.11
Later the mp3 encoding programs were changed to use variable
rates and it was posible by using those block headers.
To know the total time now you need to read the whole file and
add the time per block. For file on local disk not a problem
but what if it is on local network share or via internet?
And how about live streams that use mp3 _encoding_?
The total time is only known when the stream is ready.
If the file had also container layout and could describe the
content you can write the time into this container header
and that does not exist for the populair mp3 encoded files.
It is missing the file(container) that the mp3 encoding
it is a good available encoding for streaming.
Just jump somewhere in the stream and in short time it plays.
side note 1)
The real name of a file should be myaudio.mp3.mpeg just as
myfileachive.tar.gz for files in a tar and late gzipped.
I's just MS DOS (DiskOperatingSystem) did not allow more as
3 characters for the extension that made the *.mp3 naming scheme.
side note 2)
when you were able to write the total length in the header.
Aborting a recording and you do not have a length to
write and the mp3 duration is 0 or endless.
In Result is you can't trust this value.
Same problem why a *.avi file is not a good container for
streaming with the seek index on the end of the file
and the start of the file contains the amount of segments
in the file to be able to find the start of the index.
Aborting the write of a avi file with encoded (mp3, divx, cvid)
data block makes the avi file corrupt for play.
Remember the avi repair tools for this problem.
The index is need while the encoded data blocks do not have(always)
fixed lengths and decoding _must_ begin on a block start.
Ron the 1'st
More information about the User
mailing list