Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse MP3 data to extract numbered frames?

I am writing a streaming application for MP3 (CBR). It is all passthru, meaning I don't have to decode/encode, I just need to pass on the data as I see it come through. I want to be able to count the MP3 frames as they passthru (and some other stuff like throughput calculations).

According to the MP3 frame header spec, the sync word appears to be eleven (11) bits of 1s, however I notice (naturally) that the frame payload which I should safely assume to be binary and thus it is not odd at all to see eleven (11) 1s in sequence.

My questions:

  1. Is there a Unix|Linux|Perl MP3 parser utility (dd-style) that can pull numbered frames from an MP3 file/pipe?
  2. How does one delineate an MP3 header block from any other binary payload data? and lastly:
  3. Is a constant bitrate (CBR) MP3 defined by payload bytes or are the header bytes included in the aggregate # of bytes/bits per any given timeslice?

Thanks,

like image 311
Jé Queue Avatar asked Jan 04 '11 23:01

Jé Queue


1 Answers

I'll take a stab at #2.

It is my understanding that the common way to sync to the MP3 stream (and thus allow for your counting of the frames) is to do this:

  • Search for a sync word
  • When sync word is found, validate the rest of the header
  • If the frame header is valid, then you should know the position of the next header
  • If you hit 3 or 4 headers in a row, and they are valid, then chances are very high that you have found them.

I saw a page recently with documentation on this, but I can't find it at the moment. If I find it again, I will post it.

like image 134
Brad Avatar answered Sep 28 '22 08:09

Brad