Is this a MP3 Frame header, MP3 Format |
![]() ![]() |
Is this a MP3 Frame header, MP3 Format |
Mar 31 2006, 22:23
Post
#1
|
|
|
Group: Members Posts: 96 Joined: 27-January 05 Member No.: 19366 |
I have some code that identifis the first MPEG frame header in an audio file, it works ok 99% of the time but is sometimes incorrectly indentifying ID3 tagging data incorrectly as audio data when the ID3 tag has not been unsynchronised.
The 4 bytes incorrectly identified as a frame header were FF FE C9 FF, is there anything that could be done to identify this as not being mpeg frame header, I check all the stuff I know off (Layer/version/bitrate/padding bits ...) . |
|
|
|
Mar 31 2006, 22:34
Post
#2
|
|
![]() foobar2000 developer Group: Admin Posts: 2806 Joined: 30-September 01 Member No.: 84 |
My solution is to accept the stream only when you see two valid frames one immediately after another, with no syncwords inbetween and same MPEG/layer/numberofchannels/samplerate info in both frame headers. Chance of random garbage spoofing that is essentially zero.
|
|
|
|
Mar 31 2006, 23:45
Post
#3
|
|
|
Group: Members Posts: 96 Joined: 27-January 05 Member No.: 19366 |
Thanks, I have tried to do just that but my method that calculates the frame size so I know where the next frame should start does not return integral numbers, I dont think it returns the correct number with the result that I was then rejecting valid headers because I was looking for the next header in the wrong place.
Psuedo Code shown below if anyone can see anything wrong with it. switch (layer) { case LAYER_I: return 12 * getBitRate() / getSamplingRate() + getPaddingLength()) * 4; case LAYER_II: return 144 * getBitRate() / getSamplingRate() + getPaddingLength() ; case LAYER_III: return 144 * getBitRate() / getSamplingRate() + getPaddingLength(); } |
|
|
|
Mar 31 2006, 23:52
Post
#4
|
|
|
Winamp Developer Group: Developer Posts: 415 Joined: 17-July 05 From: Ashburn, VA Member No.: 23375 |
Make sure you use 72* instead of 144* if it's MPEG-2 or MPEG-2.5 (See: http://minnie.tuhs.org/pipermail/mp3encode...ry/005598.html)
Also, you need to round down, and your integer math might be rounding up. This post has been edited by benski: Mar 31 2006, 23:58 |
|
|
|
Apr 1 2006, 09:07
Post
#5
|
|
|
Group: Members Posts: 96 Joined: 27-January 05 Member No.: 19366 |
thanks vmuch
|
|
|
|
Apr 2 2006, 15:42
Post
#6
|
|
|
Group: Members Posts: 96 Joined: 27-January 05 Member No.: 19366 |
Ok, Ive done all this and compared my results to that given by Winamp & Itunes, the caculation of frame length, and number of frames is now always correct and working properly.
But it has made another problem I was having worse, calculating the audio length worse. i have an audio file that lasts for 4mins 30 secs, however my program,Itunes and Winamp all report it as 8mins 6 secs, having changed my framelength calculation from 144 -> 72, I calculate the audio length as 16 mins 12 secs (double) Im calculating track length as numberOfFrames * noOfSamplesPerFrame / SamplingRate 18612 * 1152 / 22050 = 972 = 16 mins 12 secs The MPEG is MPEG Version2 Layer III, Im sure the framecount is correct. The sampling rate is also as reported by other tools but I wonder if i have to multiply it by two to compensate for the 144 - 72 change, I dont know if the number of frames per sample is correct. |
|
|
|
Apr 2 2006, 17:41
Post
#7
|
|
|
Winamp Developer Group: Developer Posts: 415 Joined: 17-July 05 From: Ashburn, VA Member No.: 23375 |
MPEG2 Layer 3 is 576 samples per frame
|
|
|
|
Apr 3 2006, 15:52
Post
#8
|
|
|
Group: Members Posts: 96 Joined: 27-January 05 Member No.: 19366 |
Ok, is that also true for:
MPEG version2, Layer II MPEG version2.5, Layer II MPEG version2.5, Layer III |
|
|
|
Apr 3 2006, 16:09
Post
#9
|
|
![]() Group: Members Posts: 3493 Joined: 14-May 03 From: Bad Herrenalb Member No.: 6613 |
Samples per frame:
MPEG 1 Layer 1 = 384 MPEG 1 Layer 2 = 1152 MPEG 1 Layer 3 = 1152 MPEG 2 Layer 1 = 384 MPEG 2 Layer 2 = 1152 MPEG 2 Layer 3 = 576 MPEG 2 and 2.5 are the same in this regard. This post has been edited by Sebastian Mares: Apr 3 2006, 16:09 |
|
|
|
Apr 3 2006, 16:11
Post
#10
|
|
![]() Group: Members Posts: 3493 Joined: 14-May 03 From: Bad Herrenalb Member No.: 6613 |
QUOTE (benski @ Apr 1 2006, 12:52 AM) Make sure you use 72* instead of 144* if it's MPEG-2 or MPEG-2.5 (See: http://minnie.tuhs.org/pipermail/mp3encode...ry/005598.html) Also, you need to round down, and your integer math might be rounding up. Layer I is always 48. So, to sum up, this is what I use (and according to multiple tests, it also works): Frame Number = Audio Size in Bytes / (Coefficient * Bit Rate in kbps * 1000 / Sampling Rate in Hz + Padding) Where Coefficient is: MPEG 1 Layer 1 = 48 MPEG 1 Layer 2 = 144 MPEG 1 Layer 3 = 144 MPEG 2 Layer 1 = 48 MPEG 2 Layer 2 = 144 MPEG 2 Layer 3 = 72 For Layer II and III, Padding is 1 when the padding bit is set and 0 when the padding bit is not set. For Layer I, Padding is 4 or 0. Then we have: Duration in s = Frame Number * Sample Size / Sampling Rate in Hz Where Sample Size is: MPEG 1 Layer 1 = 384 MPEG 1 Layer 2 = 1152 MPEG 1 Layer 3 = 1152 MPEG 2 Layer 1 = 384 MPEG 2 Layer 2 = 1152 MPEG 2 Layer 3 = 576 This post has been edited by Sebastian Mares: Apr 3 2006, 16:18 |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 22nd November 2009 - 06:19 |