> 
> For a small application I'm writing in PHP, I need to know the absolute 
> maximum length of
> an MPEG encoded frame (all layers, all versions, including padding if present).
> 


The number of bits/frame is:  frame_size*bit_rate/sample_rate.
For MPEG1, frame_size = 1152 samples/frame
For MPEG2, frame_size =  576 samples/frame

For example, 

320k bits/second) *  ( 1152 samples/frame )  /  (48k samples/second) =

1152*320/48  bits/frame

largest mpeg1 frame:  1152*320/32 = 1440 bytes/frame
largest mpeg2 frame:   576*160/16 =  720 bytes/frame

For some sample rates the bits/frame will not come out as a integer
number of bytes.  In those cases round down to the nearest byte,
unless the padding bit is set in which case round up.  The encoder is
supposed to use padding in selected frames to keep the average bitrate
as close as possible to the specified bitrate.


> 
> Also, is looking for the "Xing" signature in a VBR file a "proper" way for 
> detecting
> variable bitrate MPEGs? Is there a better way.
> 
A VBR stream is not required to have the Xing signature.  So the proper
way is to find a frame sync word, find the frame size from the
header, and that will tell you where to start looking for the 
next syncword.  You probably want some some error checking/recovery
in case the first syncword you find is not a syncword but
part of the data.  

If the stream is using the 'free' bitrate (anyone ever see one of
these?) you will need to parse the 'side_info' fields to figure out
where the frame ends and thus where to start looking for the next sync
word, and then compute the actual bitrate being used.

Mark



--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to