****************求mp3格式和解码算法*****************************

dreameasy 2003-12-03 10:05:21
小弟最近正在研究Linux下的mp3解码代码mpg123.无奈对mp3格式不盛了解,看着其源码中的各种变化一头雾水.请各位大瞎来帮帮我,我希望得到一份mp3格式的详细说明,最好有算法解析。(嘿嘿,是不是很贪心啊?)
分不是问题,小弟可以分次给的.
...全文
89 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
WvW 2003-12-06
  • 打赏
  • 举报
回复
好多现成的解码保, 都有源代码, 如楼上说说的
dreameasy 2003-12-05
  • 打赏
  • 举报
回复
谢谢 zachary7833() ,不过这个文挡我已经有了!

另外,liuwan(菜菜) :

你可以去找mpg123的源代码,这是很好的mp3解码源程序. (http://www.mpg123.org/)
还可以找lame mp3.
最简单的是http://www.wotsit.org/download.asp?f=mpeg3src
这是mp3的官方示范encode/decode,简单,但是效率低些!
HUNTON 2003-12-04
  • 打赏
  • 举报
回复
上次好象在哪见到的,一时没找到
zachary7833 2003-12-04
  • 打赏
  • 举报
回复
MPEG Audio Frame Header

An MPEG audio file is separated in smaller parts called frames. Each frame is independent. It has its own header and audio informations. There is no file header. Therefore, you can cut any part of MPEG file and play it correctly.

When you want to read info about an MPEG file, it is usually enough to find the first frame, read its header and assume that the other frames are the same (which may not be always the case).

The frame header is constituated by the very first four bytes (32bits) in a frame. The first eleven bits of a frame header are always set and they are called "frame sync". Therefore, you can search through the file for the first occurence of eleven bits set (meaning that you have to find a byte with a value of 255, and followed by a byte with its three most significant bits set). Then you read the whole header and check if the values are correct. You will see in next table the exact meaning of each bits in the header, and which values may be checked for validity. Each value that is specified as reserved, invalid, bad, or not allowed should indicate an invalid header.

Frames may have a CRC check, but it's pretty rare. The CRC is 16 bits long and, if it exists, it follows the frame header. After the CRC comes the audio data. You may calculate the length of the frame and use it if you need to read other headers too or just want to calculate the CRC of the frame, to compare it with the one you read from the file. This is actually a very good method to check the MPEG header validity.

Here is "graphical" presentation of the header content. The letters are used to indicate the different fields. In the table, you can see the details about the content of each field.

AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM


Sign Length
(bits) Position
(bits) Description
A 11 (31-21) Frame sync (all bits set)
B 2 (20,19) MPEG Audio version
00 - MPEG Version 2.5
01 - reserved
10 - MPEG Version 2
11 - MPEG Version 1
C 2 (18,17) Layer description
00 - reserved
01 - Layer III
10 - Layer II
11 - Layer I
D 1 (16) Protection bit
0 - Protected by CRC (16bit crc follows header)
1 - Not protected
E 4 (15,12) Bitrate index
bits V1,L1 V1,L2 V1,L3 V2,L1 V2,L2 V2,L3
0000 free free free free free free
0001 32 32 32 32 32 8 (8)
0010 64 48 40 64 48 16 (16)
0011 96 56 48 96 56 24 (24)
0100 128 64 56 128 64 32 (32)
0101 160 80 64 160 80 64 (40)
0110 192 96 80 192 96 80 (48)
0111 224 112 96 224 112 56 (56)
1000 256 128 112 256 128 64 (64)
1001 288 160 128 288 160 128 (80)
1010 320 192 160 320 192 160 (96)
1011 352 224 192 352 224 112 (112)
1100 384 256 224 384 256 128 (128)
1101 416 320 256 416 320 256 (144)
1110 448 384 320 448 384 320 (160)
1111 bad bad bad bad bad bad

NOTES: All values are in kbps
V1 - MPEG Version 1
V2 - MPEG Version 2 and Version 2.5
L1 - Layer I
L2 - Layer II
L3 - Layer III
"free" means variable bitrate.
"bad" means that this is not an allowed value

The values in parentheses are from different sources which claim that those values are valid for V2,L2 and V2,L3. If anyone can confirm please let me know.

F 2 (11,10) Sampling rate frequency index (values are in Hz) bits MPEG1 MPEG2 MPEG2.5
00 44100 22050 11025
01 48000 24000 12000
10 32000 16000 8000
11 reserv. reserv. reserv.

G 1 (9) Padding bit
0 - frame is not padded
1 - frame is padded with one extra bit
H 1 (8) Private bit (unknown purpose)
I 2 (7,6) Channel Mode
00 - Stereo
01 - Joint stereo (Stereo)
10 - Dual channel (Stereo)
11 - Single channel (Mono)
J 2 (5,4) Mode extension (Only if Joint stereo)
value Intensity stereo MS stereo
00 off off
01 on off
10 off on
11 on on

K 1 (3) Copyright
0 - Audio is not copyrighted
1 - Audio is copyrighted
L 1 (2) Original
0 - Copy of original media
1 - Original media
M 2 (1,0) Emphasis
00 - none
01 - 50/15 ms
10 - reserved
11 - CCIT J.17

How to calculate frame size

Read the BitRate, SampleRate and Padding (as value of one or zero) of the frame header and use the formula:

FrameSize = 144 * BitRate / SampleRate + Padding

Example: BitRate = 128000, SampleRate=441000, Padding=0 ==> FrameSize=417 bytes

MPEG Audio Tag MP3v1

The TAG is used to describe the MPEG Audio file. It contains information about artist, title, album, publishing year and genre. There is some extra space for comments. It is exactly 128 bytes long and is located at very end of the audio data. You can get it by reading the last 128 bytes of the MPEG audio file.

AAABBBBB BBBBBBBB BBBBBBBB BBBBBBBB
BCCCCCCC CCCCCCCC CCCCCCCC CCCCCCCD
DDDDDDDD DDDDDDDD DDDDDDDD DDDDDEEE
EFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFG


Sign Length
(bytes) Position
(bytes) Description
A 3 (0-2) Tag identification. Must contain 'TAG' if tag exists and is correct.
B 30 (3-32) Title
C 30 (33-62) Artist
D 30 (63-92) Album
E 4 (93-96) Year
F 30 (97-126) Comment
G 1 (127) Genre

The specification asks for all fields to be padded with null character (ASCII 0). However, not all applications respect this (an example is WinAmp which pads fields with <space>, ASCII 32).

There is a small change proposed in MP3v1.1 structure. The last byte of the Comment field may be used to specify the track number of a song in an album. It should contain a null character (ASCII 0) if the information is unknown.

Genre is a numeric field which may have one of the following values:

0 'Blues' 20 'Alternative' 40 'AlternRock' 60 'Top 40'
1 'Classic Rock' 21 'Ska' 41 'Bass' 61 'Christian Rap'
2 'Country' 22 'Death Metal' 42 'Soul' 62 'Pop/Funk'
3 'Dance' 23 'Pranks' 43 'Punk' 63 'Jungle'
4 'Disco' 24 'Soundtrack' 44 'Space' 64 'Native American'
5 'Funk' 25 'Euro-Techno' 45 'Meditative' 65 'Cabaret'
6 'Grunge' 26 'Ambient' 46 'Instrumental Pop' 66 'New Wave'
7 'Hip-Hop' 27 'Trip-Hop' 47 'Instrumental Rock' 67 'Psychadelic'
8 'Jazz' 28 'Vocal' 48 'Ethnic' 68 'Rave'
9 'Metal' 29 'Jazz+Funk' 49 'Gothic' 69 'Showtunes'
10 'New Age' 30 'Fusion' 50 'Darkwave' 70 'Trailer'
11 'Oldies' 31 'Trance' 51 'Techno-Industrial' 71 'Lo-Fi'
12 'Other' 32 'Classical' 52 'Electronic' 72 'Tribal'
13 'Pop' 33 'Instrumental' 53 'Pop-Folk' 73 'Acid Punk'
14 'R&B' 34 'Acid' 54 'Eurodance' 74 'Acid Jazz'
15 'Rap' 35 'House' 55 'Dream' 75 'Polka'
16 'Reggae' 36 'Game' 56 'Southern Rock' 76 'Retro'
17 'Rock' 37 'Sound Clip' 57 'Comedy' 77 'Musical'
18 'Techno' 38 'Gospel' 58 'Cult' 78 'Rock & Roll'
19 'Industrial' 39 'Noise' 59 'Gangsta' 79 'Hard Rock'
Any other value should be considered as 'Unknown'


MPEG Audio Tag MP3v2

This is new proposed TAG format which is different than MP3v1 and MP3v1.1. Complete tech specs for it may be found at http://www.id3.com/.

zachary7833 2003-12-04
  • 打赏
  • 举报
回复


Mpeg 1.0/2.0 LayersI, II and III header and trailer formats
-----------------------------------------------------------

Laurent.Clevy@alcatel.fr



* HEADER


bits name comments
--------------------------------------------------
12 sync 0xFFF
1 version 1=mpeg1.0, 0=mpeg2.0
2 lay 4-lay = layerI, II or III
1 error protection 0=yes, 1=no
4 bitrate_index see table below
2 sampling_freq see table below
1 padding
1 extension see table below
2 mode see table below
2 mode_ext used with "joint stereo" mode
1 copyright 0=no 1=yes
1 original 0=no 1=yes
2 emphasis see table below
--------------------------------------------------

- bitrate_index

. mpeg1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14
layer1 32 64 96 128 160 192 224 256 288 320 352 384 416 448
layer2 32 48 56 64 80 96 112 128 160 192 224 256 320 384
layer3 32 40 48 56 64 80 96 112 128 160 192 224 256 320

. mpeg2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14
layer1 32 48 56 64 80 96 112 128 144 160 176 192 224 256
layer2 8 16 24 32 40 48 56 64 80 96 112 128 144 160
layer3 8 16 24 32 40 48 56 64 80 96 112 128 144 160


- sampling_freq

. mpeg1.0

0 1 2

44100 48000 32000

. mpeg2.0

0 1 2

22050 24000 16000


- mode:

0 "stereo"
1 "joint stereo"
2 "dual channel"
3 "single channel"


- mode extension:

0 MPG_MD_LR_LR
1 MPG_MD_LR_I
2 MPG_MD_MS_LR
3 MPG_MD_MS_I

jsbound :

mode_ext 0 1 2 3
layer
1 4 8 12 16
2 4 8 12 16
3 0 4 8 16


- emphasis:

0 "none"
1 "50/15 microsecs"
2 "reserved" must not be used !
3 "CCITT J 17"




* TRAILER

at end of file - 128 bytes

offset type len name
--------------------------------------------
0 char 3 "TAG"
3 char 30 title
33 char 30 artist
63 char 30 album
93 char 4 year
97 char 30 comments
127 byte 1 genre
--------------------------------------------

- genre :

0 "Blues"
1 "Classic Rock"
2 "Country"
3 "Dance"
4 "Disco"
5 "Funk"
6 "Grunge"
7 "Hip-Hop"
8 "Jazz"
9 "Metal"
10 "New Age"
11 "Oldies"
12 "Other"
13 "Pop"
14 "R&B"
15 "Rap"
16 "Reggae"
17 "Rock"
18 "Techno"
19 "Industrial"
20 "Alternative"
21 "Ska"
22 "Death Metal"
23 "Pranks"
24 "Soundtrack"
25 "Euro-Techno"
26 "Ambient"
27 "Trip-Hop"
28 "Vocal"
29 "Jazz+Funk"
30 "Fusion"
31 "Trance"
32 "Classical"
33 "Instrumental"
34 "Acid"
35 "House"
36 "Game"
37 "Sound Clip"
38 "Gospel"
39 "Noise"
40 "AlternRock"
41 "Bass"
42 "Soul"
43 "Punk"
44 "Space"
45 "Meditative"
46 "Instrumental Pop"
47 "Instrumental Rock"
48 "Ethnic"
49 "Gothic"
50 "Darkwave"
51 "Techno-Industrial"
52 "Electronic"
53 "Pop-Folk"
54 "Eurodance"
55 "Dream"
56 "Southern Rock"
57 "Comedy"
58 "Cult"
59 "Gangsta"
60 "Top 40"
61 "Christian Rap"
62 "Pop/Funk"
63 "Jungle"
64 "Native American"
65 "Cabaret"
66 "New Wave"
67 "Psychadelic"
68 "Rave"
69 "Showtunes"
70 "Trailer"
71 "Lo-Fi"
72 "Tribal"
73 "Acid Punk"
74 "Acid Jazz"
75 "Polka"
76 "Retro"
77 "Musical"
78 "Rock & Roll"
79 "Hard Rock"
80 "Unknown"



- frame length :

. mpeg1.0

layer1 :
(48000*bitrate)/sampling_freq + padding
layer2&3:
(144000*bitrate)/sampling_freq + padding

. mpeg2.0

layer1 :
(24000*bitrate)/sampling_freq + padding
layer2&3 :
(72000*bitrate)/sampling_freq + padding


This is a brief and informal document targeted to those who want to deal with the MPEG format. If you are one of them, you probably already know what is MPEG audio. If not, jump to http://www.mp3.com/ or http://www.layer3.org/ where you will find more details and also more links.

NOTE: You cannot just search the Internet and find the MPEG audio specs. It is copyrighted and you will have to pay quite a bit to get the Paper. That's why I made this. Informations I got are gathered from the internet, and mostly originate from sources I found available. Despite my custom to always specify the sources, I am not able to do it this time. Sorry, I did not maintain the list. :(

This is not decoding specs, it just informs you how to read the MPEG headers and the MPEG TAG. MPEG Version 1, 2 and 2.5 and Layer I, II and III are supported, the MP3 TAG (MP3v1 and MP3v1.1) also.. Those of you who use Delphi may find my MPGTools Delphi unit useful, it is where I implemented this stuff.

gxqcdit 2003-12-04
  • 打赏
  • 举报
回复
MARK一下.
liuwan 2003-12-04
  • 打赏
  • 举报
回复
楼主,你好。我和你一样,也正着手开始研究Linux下的MP3软件解码算法。不过我还没有找到网上的开放源代码,你所说的那个Linux下的mp3解码代码mpg123能够发一份给我吗?至于你说的MP3格式的文档和算法解析的文档,我刚刚找到一份(还没来得及看),标题是《MPEG Layer3 Bitstream Syntax andDecoding》,请留下你的EMAIL,我们交流交流,我的EMAIL:
zhangcl@i-net.com.cn。 希望能共同进步!
thisisyjs 2003-12-04
  • 打赏
  • 举报
回复
你搜一下 "Layers.zip"我找到过。
dreameasy 2003-12-03
  • 打赏
  • 举报
回复
不盛了解,应为不甚了解,特此更正.
首先,FFDSHOW消耗CPU功率比原来的DivX编码方式少,甚至最高的后处理。同时后处理似乎给优良的品质效果,并允许超过原有的DivX编解码器的配置。它甚至可以全自动减少后处理,如果你的CPU是挤破头。噪音过滤器增加了一个rasterising效果图片 - 可能在某些情况下非常有用。 alpha版本还包括MPEG - 1和MPEG - 2文件(如VCD和SVCD影片),其中作品相当该死的实验播放。唯一的问题是,MPEG - 2播放可以直接从CD SVCD的剪辑,但需要使用VCDGear首先要提取的视频到硬盘。 FFDSHOW MPEG - 4视频解码器的特点: - 各种压缩方法: MPEG - 4兼容(XVID,DIVX,DIVX 6的DivX 4,DivX的5 7 8,DIVX)使用libavcodec的或XviD DIVX 3兼容,MSMPEG4v2,MSMPEG4v1 WMV2 WMV1 / 7 / 8 H263,H263 ,H264 HuffYUV YV12色彩 MJPEG MPEG - 1 MPEG - 2,使用MJPEGtools项目mpeg2enc代码 MP3,AC3,DTS,E - AC3,AAC格式 SVQ3 Vorbis格式 Theora格式(不经常使用,格式是没有稳定尚未) 所有的Windows Media Video 9的支持编码器输出​​到ASF / WMV文件或AVI - 所有常用的编码模式:恒定比特率,固定量化,定质量,二阶段编码(取决于压缩机的功能) - libavcodec的和XviD的运动估计方法的详细选择 - 最小和最大I帧间隔 - 最小和最大的量化选择,量化型和格子libavcodec的量化选择 - 自适应量化(亦称屏蔽)使用libavcodec和XviD,消除单一系数 - 可选择的压缩开始和结束学分 - 两个曲线的第二个阶段二阶段编码压缩算法 - XVID开发 - 第二遍模拟:虽然不是很精确,还有助于调整先进的曲线压缩参数 - 能够使用libavcodec的内部传递代码 - 图像预处理与FFDSHOW的图像过滤器(必须安装最新的FFDSHOW版本) - 图在编码过程中:如果你的编码方案未提供 - B帧支持:从一到8个连续的B帧 - 支持MPEG - 4 quarterpel和GMC - 可选择的隔行编码 - 减压 FFDSHOW的转换3943,3900 FFDSHOW转换: - 腾出空间用于添加更多的色彩FFDSHOW - 更新Libav - 更新pthreads的(CVS 20110710) - 修正了另一个DXVA的回归 - 更新Swscale - 64位的pthread库 - ffdshow的音频解码器的QT PCM变种(如三三两两)创建新格式“选项。他们以前如果未压缩的音频选项的一部分。 - 修正了一些色彩空间转换问题 - 更新了俄语翻译 - 在XP上安装的MANIFEST文件 - ICL12工程:清理和移动common_icl12.props所有共同属性 - VS2010的项目:清理 - 更新线程工具提示 - VS2010的项目: *清理额外的库 *修复makeAVIS文件,libfaad2 ff_wmv9项目 *重命名libmpeg2_ff一致性的项目文件 - 更新构建脚本 - 修正H.264 4:4:4 - 哈克,以防止与H.264 4:4:4的崩溃。色彩尚不支持。 - 更新黑名单 重要注意事项: - 一些杀毒软件一样的AVG“检测”在FFDSHOW木马之上。这是一个假阳性,有FFDSHOW建立无木马!
您可以使用本系统保护您的多媒体文件、课件等,支持所有的多媒体文件加密:
*.RM;*.RMVB;*.AVI;*.WMV;*.WMA;*.ASF;*.WMS;*.WAV;*.MP3;*.MPG;*.Dat;*.Mpeg;*.Vob等等;加密后的文件,商家可以离线向客户授权; 本系统特色:
1、加密时可以选择是否不同机器播放需要不同的播放密码-您可以为不同用户设置不同的播放密码,密码与用户的电脑硬件绑定,用户无法传播您的文件 
2、您可以指定是否可以提供免费试看试听(hot!)
3、可以指定产品编号,以便用户可以管理多个文件,以免混乱
4、您可以设置提示语,以便告知用户通过何种途径与您联系获得播放密码
5、本系统也可以结合网络应用,通过网络向客户发放播放密码、会员验证等方式(hot!)
6、支持所有多媒体格式文件加密(默认支持20多种格式,通过扩展解码器,可以支持所有格式
7、加密后的文件只能在您授权的机器上播放,通过此功能防止重要资料被带出公司或者单位使用。
8、加密后的文件支持各种方式分发给用户:网上下载、刻盘分发等,但用户必须得到您给他的播放密码才可以播放,您也可以限定用户在限定的机器上播放

最新更新:
一、用户可以选择记住播放密码,不用每次观看都需要密码
二、可以保存提示语设置,商家可以设置更灵活和个性化的提示语
三、用户提示框增加了滚动功能,商家可以设置更多的提示信息
四、增加了播放窗口的朦板功能,多重保护
五、播放密码采用更高强度的算法与验证方法
六、加密后的加密文件采用更美观和友好的图标,增强了亲合力
七、改进了线程启动播放方式,用户打开文件速度更快
八、修正了以前版本全屏播放的Bug
九、修正了跳过播放密码验证漏洞
十、修正了AVI,RM等文件播放时提示找不到解码器的问题
十一、新增防止屏幕翻录和防拷屏功能
十二、解决了提示语超长漏洞
十三、修正了以前老版本软件的各种其他问题...
十四、新增了离线控制播放次数和时间
十五、新增了播放时断开网络版防止远程翻录功能
十六、新增了 水印功能

更多扩展功能可以实现:
一、在线密码发放,用户可以通过您指定的网站,经过认证后获得播放密码,无须人工参与。
二、可以设置文件在某个时间段有效,或者在某个时间点后失效等等

2,542

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧