Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How are raw cuts in MP3 files rightly done? (Read 4365 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How are raw cuts in MP3 files rightly done?

How many frames before a frame do you have to include when making a raw cut in an MP3 file, in order to ensure that the frame will be played perfectly? The problem is the bit shunt, though, is there any specification on how many frames it could be spread over, its maximum size, or how many frames before a frame its constituent parts can be located?

Also, are bit shunts used in VBR files?

Regards
Mikael Möre

How are raw cuts in MP3 files rightly done?

Reply #1
You can try to repack your file using:

MP3Packer -z -b 320

to minimize the usage of bit reservoir, make your cut and then repack again using

MP3Packer -z

How are raw cuts in MP3 files rightly done?

Reply #2
You can try to repack your file using:

MP3Packer -z -b 320

to minimize the usage of bit reservoir, make your cut and then repack again using

MP3Packer -z

This is mostly right, but it will actually maximize the use of the bit-reservoir. However, doing what you suggest will ensure that the nth frame is contained entirely in the (n-1)th frame and the nth frame.

If you cut at the beginning of frame n-1, then run mp3packer again, it will throw out frame n-1 and you will be left with n being the first frame (after a warning saying the first frame will be thrown out)

The maximum number of frames to get in advance is:
48000: 511 byte reservoir, minimum 58 data bytes/frame -> 9 frames in advance
44100: 511 res, min 66 bytes/frame -> 8
32000: 511 res, min 106 bytes/frame -> 5
24000: 255 res, min 25 bytes/frame -> 11
22050: 255 res, min 29 bytes/frame -> 9
16000: 255 res, min 49 bytes/frame -> 6
12000: 255 res, min 73 bytes/frame -> 4
11025: 255 res, min 81 bytes/frame -> 4
8000: 255 res, min 121 bytes/frame -> 3
I think
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel, H2G2

 

How are raw cuts in MP3 files rightly done?

Reply #3
How many frames before a frame do you have to include when making a raw cut in an MP3 file, in order to ensure that the frame will be played perfectly?

It depends on the mpeg version, bitrate, channel count. The bitreservoir pointer is usually 9 bits long (mpeg1). Only maindata bits are adressed that way. So assuming an MPEG1 layer3 stereo stream you'll have
Code: [Select]
frame_size - (4 + (protection_bit==0 ? 2 : 0) + 30)
// 4 bytes frame header, 16 bit crc (optional), 30 bytes side info

bytes of main data within a frame of size frame_size bytes.
Example: 128 kbps CBR 44100 Hz, stereo stream:
frame_size = 417 or 418 bytes (depending on whether the padding flag is set)
This leaves room for at least 381 bytes of main data per frame.
The bit reservoir pointer (which is actually the first 8 (mpeg2) or 9 (mpeg1) bits of the side info data) can be no larger than 511. => In the worst case you need two preceeding frames to be able to decode the current one since 2 x 381 >= 511.

Also, are bit shunts used in VBR files?

Yes. But it's fairly safe to assume that only one preceeding frame is needed because the encoder is allowed to increase a frame size when the signal part is more demanding.

Cheers!
Sebastian