[Gambas-user] Music.Length

Steven Drinnan steven at ...1545...
Sat Jun 28 05:23:32 CEST 2008


Just one more prog that can do the job

exiftool 

a python based tool that just spits all the info out to the command
line. 

example:

 exiftool  "/home/steven/Documents/My Music/Various Artists/Super Hits
1993-2003 Disc 1/2 Unlimited - No Limit.mp3" ExifTool Version
Number         : 7.25
File Name                       : 2 Unlimited - No Limit.mp3
Directory                       : /home/steven/Documents/My
Music/Various Artists/Super Hits 1993-2003 Disc 1
File Size                       : 4 MB
File Modification Date/Time     : 2005:06:04 10:23:06
File Type                       : MP3
MIME Type                       : audio/mpeg
MPEG Audio Version              : 1
Audio Layer                     : 3
Audio Bitrate                   : 160000
Sample Rate                     : 44100
Channel Mode                    : Joint Stereo
MS Stereo                       : Off
Intensity Stereo                : Off
Copyright Flag                  : False
Original Media                  : False
Emphasis                        : None
Length                          : 197.825 s
Picture                         : (Binary data 0 bytes, use -b option to
extract)
Title                           : No Limit
Track                           : 15
Artist                          : 2 Unlimited
Genre                           : Rock/Pop
Album                           : Super Hits 1993-2003 Disc 1
Year                            : 
Comment                         : 
Duration                        : 03:17 (approx)


Another one is 
id3v2 

which gives this

 id3v2 -R  "/home/steven/Documents/My Music/Various Artists/Super Hits
1993-2003 Disc 1/2 Unlimited - No Limit.mp3" 
id3v1 tag info for /home/steven/Documents/My Music/Various Artists/Super
Hits 1993-2003 Disc 1/2 Unlimited - No Limit.mp3:
Title  : No Limit                        Artist: 2
Unlimited                   
Album  : Super Hits 1993-2003 Disc 1     Year:     , Genre: Other (12)
Comment:                                 Track: 15
id3v2 tag info for /home/steven/Documents/My Music/Various Artists/Super
Hits 1993-2003 Disc 1/2 Unlimited - No Limit.mp3:
TLEN (Length): 197825
APIC (Attached picture): ()[, 0]: image/jpg, 0 bytes
TIT2 (Title/songname/content description): No Limit
TRCK (Track number/Position in set): 15
TPE1 (Lead performer(s)/Soloist(s)): 2 Unlimited
TCON (Content type): Rock/Pop (255)
TALB (Album/Movie/Show title): Super Hits 1993-2003 Disc 1

TLEN = 197825 gives the track length in milliseconds so that's 197.825s
or 3min and 18s approx.

I have not had a good look at it but both seem to do what you want.

Steven Drinnan


On Sat, 2008-06-21 at 10:27 +0200, Ron Onstenk wrote:
> 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
> 
> 
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 





More information about the User mailing list