Hi Chris,
File information is received from Demuxer object. It includes anything that 
header can carry. length, song info, etc
Individual stream info is read when you decode the frames from Decoder 
object.
Here is the code which may help you (pycar.audio.aplaylist). Please note 
that I assume that only 1 stream per file.

    f= open( file, 'rb' )
    s= f.read( HEADER_CHUNK_SIZE )
    dm= muxer.Demuxer( getExtension( file ) )
    fr= dm.parse( s )
    if not dm.hasHeader() and menu.cache.getExtension( file )== 'mp3':
      try:
        # IDv1 hack
        f.seek( -128, 2 )
        dm= muxer.Demuxer( 'mp3' )
        dm.parse( f.read( 128 ) )
      except:
        traceback.print_exc();

    dec= acodec.Decoder( dm.streams[ 0 ] )
    d= dec.decode( fr[ 0 ][ 1 ] )
    # Hardcoding for mp3
    if d and ( dm.hasHeader()> 0 or len( d.data )> 0 ):
      # Stream params
      print d.sample_rate, d.channels, d.bitrate / 1000, file_size / ( 
d.bitrate * 125 )

    if dm.hasHeader():
      # Meta information ( song, artist, album, etc )
      print dm.getHeaderInfo()

Dmitry/

----- Original Message ----- 
From: "Chris Melville" <[EMAIL PROTECTED]>
To: <[email protected]>
Cc: "Dmitry Borisov" <[EMAIL PROTECTED]>
Sent: Tuesday, May 15, 2007 7:17 PM
Subject: Re: [Pymedia-users] Simple question - getting song length in 
seconds


>H Dimitry,
>
> I dont understand what you mean by Xing headers. I havent been able to get 
> that stream information to look right for any file format I've tried, 
> including FLAC (which stores that type of audio info in a STREAMINFO 
> metadata block). The 'length' always comes back as negative, for example.
>
> I tried Mutagen (http://www.sacredchao.net/quodlibet/wiki/Download) as 
> well, and that works fine on all the same files, but that doesn't have any 
> actual media playing/transcoding capabilities like PyMedia/FFMPEG.
>
> I need accurate song lengths, or there will be large cumulative errors 
> over whole collections.
>
> I'm also a bit lost on what you mean by calculating the song length from 
> the file size - doesn't that depend on how compressed the audio is?
>
> - John
>
> Dmitry Borisov wrote:
>> PyMedia does not parse Xing headers as of now but if you use CBR encoding 
>> and you have only 1 stream you can calc the length of the file:
>>     file_size/ ( bit_rate * 125 )
>> It will give the length of the file in seconds roughly.
>> Dmitry/
>>
>> ----- Original Message ----- 
>> From: "NeBlackCat (lists)" <[EMAIL PROTECTED]>
>> To: <[email protected]>
>> Sent: Monday, May 14, 2007 4:27 AM
>> Subject: [Pymedia-users] Simple question - getting song length in seconds
>>
>>
>>
>>> I'm sure this is a stupidly trivial question, but could someone please
>>> tell me how you determine the length of an audio file in seconds
>>> (without actually playing the file)? I just can't seem to find it from
>>> the code & docs.
>>>
>>> The first 'stream' returned by a Demuxer's streams property (after it's
>>> "parse" method has been called with some data) contains a field called
>>> 'length', but it's always negative, eg (from a .MP3):
>>>
>>> Streams:
>>> ({'bitrate': 0,
>>>   'block_align': 0,
>>>   'channels': 0,
>>>   'frame_rate': 25,
>>>   'frame_rate_base': 1,
>>>   'height': 0,
>>>   'id': 86016,
>>>   'index': 0,
>>>   'length': -2077252342,
>>>   'sample_rate': 0,
>>>   'type': 1,
>>>   'width': 0},)
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------------------------
>>> This SF.net email is sponsored by DB2 Express
>>> Download DB2 Express C - the FREE version of DB2 express and take
>>> control of your XML. No limits. Just data. Click to get it now.
>>> http://sourceforge.net/powerbar/db2/
>>> _______________________________________________
>>> Pymedia-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/pymedia-users
>>>
>>>
>>
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by DB2 Express
>> Download DB2 Express C - the FREE version of DB2 express and take
>> control of your XML. No limits. Just data. Click to get it now.
>> http://sourceforge.net/powerbar/db2/
>> _______________________________________________
>> Pymedia-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/pymedia-users
>>
> 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Pymedia-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pymedia-users

Reply via email to