
MP3 file format analysis

1. Summary of MP3 and MPEG files

An MP3 file is made up of frames, and a frame is the smallest unit of an MP3 file. The full name of MP3 must be MPEG1 Layer-3 audio file.
MPEG (MovingPictureExperts Group), MPGE audio layer refers to the sound part of the MPGE file, which is divided into three layers based on the quality and complexity of the encoding, namely Layer-1, Layer2 and Layer3, corresponding to MP1, MP2 and MP3 format files.
2. Structure of MP3 files
MP3 files are divided into 3 parts : TAG_V2(ID3V2 ) , Frame, TAG_V1(ID3V1) .
( 1 ) Frame format
The frame header is 4 bytes and its structure is as follows
typedef FrameHeader
{
unsigned intsync: 11; // synchronization information
unsigned intversion: 2; // version
unsigned intlayer: 2; // layer
unsigned intprotection: 1; // CRC check
unsigned intbitrate: 4; // Bit rate
unsigned intfrequency: 2; // sample rate
unsigned intpadding: 1; // adjust frame length
unsigned intprivate: 1; // reserved word
unsigned intmode: 2; // channel mode
unsigned int mode extension: 2; // extended mode
unsigned intcopyright: 1; // Copyright
unsigned original: 1; // original logo
unsigned inemphasis: 2; // emphasis mode
}
HEADER, *LPHEADER;
Each frame takes 26 ms to play, regardless of the length of the frame. The length of MAIN_DATA is
Length(MAIN_DATA) = ((version == MPEG1)?144:72) * bitrate/frequency + padding;
( 2 ) ID3V1 format
ID3V1 is stored at the end of the MP3 file, a total of 128 Bytes, all information is stored sequentially and the insufficient part is filled with ‘\0’, which can be opened and viewed with UltraEdit.
typedef tagID3V1 structure
{
char header[3];
char Title[30];
artist char[30];
album char[30];
char Year[4];
char Comment[28];
coal reserve;
character track;;
charGenus;
}
ID3V1,*pID3V1;
( 3 ) ID3V2 format
ID3V2 is stored in the header of the MP3 file and consists of a tag header and several tag frames.
The tag header is 10 bytes,
char header[3];
char see;
character review;
char Flag;
character size [4];
Each tag frame consists of a 10-byte frame header and at least one byte of variable-length content. The frame header is defined as follows:
char frame ID[4];
character size [4];
char Flags[2];



