3gp文件格式研究

来源:百度文库 编辑:神马文学网 时间:2024/04/27 15:19:14
需要看的文档
http://www.3gpp.org/ftp/Specs/archive/26_series/
3GPP TS 26.233
3GPP TS 26.243
3GPP TS 26.244
http://www.iec.ch/cgi-bin/getcorr.pl/isoiec14496-12-cor2%7Bed1.0%7Den.pdf?file=isoiec14496-12-cor2%7Bed1.0%7Den.pdf
http://www.iec.ch/cgi-bin/getcorr.pl/isoiec15444-12-cor2{ed2.0}en.pdf?file=isoiec15444-12-cor2{ed2.0}en.pdf
我做的一个辅助工具:http://www.sf.org.cn/Soft/app/sys/200609/1447.html
首先来说3gp文件相当于一个容器,本身没有什么具体的编码解码规则。
我们可以选择编码方式
- AMR narrow-band speech codec (see clause 7.2) RTP payload format according to [11]. A PSS client is not required to support multi-channel sessions;
- AMR wideband speech codec (see clause 7.2) RTP payload format according to [11]. A PSS client is not required to support multi-channel sessions;
- Extended AMR-WB codec (see clause 7.3) RTP payload format according to [85];
- Enhanced aacPlus and MPEG-4 AAC codec (see clause 7.3) RTP payload format according to [13];
- MPEG-4 video codec (see clause 7.4) RTP payload format according to RFC 3016 [13];
- H.263 video codec (see clause 7.4) RTP payload format according to RFC 2429 [14];
- H.264 (AVC) video codec (see clause 7.4) RTP payload format according to [92]. A PSS client is required to support all three packetization modes: single NAL unit mode, non-interleaved mode and interleaved mode. For the interleaved packetization mode, a PSS client shall support streams for which the value of the "sprop-deint-buf-req" MIME parameter is less than or equal to MaxCPB * 1000 / 8, inclusive, in which "MaxCPB" is the value for VCL parameters of the H.264 (AVC) profile and level in use, as specified in [90]. Parameter sets shall not be transmitted within the RTP payload, i.e., all parameter sets required for a session must be provided in the SDP;
- 3GPP timed text format (see clause 7.9) RTP payload format according to [80];
- DRM encrypted RTP payload format according to clause K.1 in Annex K;
- RTP retransmission payload format according to [81].
其中手机最普遍支持的格式是 amr(音频) +h263(视频)
3gp文件基于mpeg4由若干个box组成
一个3gp文件由若干个box组成常见的有:
文件格式:ftyp box
媒体数据:mdat box
剪辑数据: moov box

ftyp box 相当于文件头,说明了文件所使用的协议版本等信息
ftyp
+[4]-+[4]-+[4]-+[4]-+[4]-+
|size|ftyp|mjbr|mivs|cpbr|
+----+----+----+----+----+
mjbr:major_brand 版本分支
mivs:minor_version 版本号
cpbr:compatible_brands 兼容分支
mdat box 存放了音频视频和其他的数据,一般的文件至少有2个mdatbox,一个用于音频,一个用于视频,通常还会有一些文本信息也放在mdatbox中,各种信息的顺序不固定。
如果只是存放音乐一个mdat就够用了。
你可能会问这么多box 都叫mdat我怎么知道音频放哪里视频放哪里呢?别着急这些东西都放在moovbox里面
moovbox是一个3gp文件中最复杂最重要的文件。
看到这里你可能会问"moovbox里面的方框都分别代表什么含义呀?媒体描述信息是怎么存放的?",别着急咱们来慢慢分析一下。
mvhd 媒体信息头
首先剖析一下mvhd,顺便以此为例理解一下box的结构。
每一个box开头的4个字节都是一个整数存放了本box的长度。
接下来的4个字节是个字符串存放了本box的类型。如"moov","mvhd"。
基本上box都是这模样的:
+[4]-+[4]-+[size-8]-------------------+
|size|type|data                       |
+----+----+---------------------------+
在mvhd box中接下来的是版本标志等信息。
MVHD
+[4]-+[4]-+[4]-+[4]-+[4]-+[4]-+[4]-+[76]----...---------+[4]-+
|size|mvhd|vsfl|cttm|mdtm|tmsc|mxtl|reserved...         |ntid|
+----+----+----+----+----+----+----+--------...---------+----+
size:box长度
type:文件类型标识内容为"mvhd"
vsfl:版本号标志
cttm:creat time 文件创建时间
mdtm:modification time  文件修改时间
tmsc:timescale 时间缩放因数
mxtl:maxTrackLen duration of longest track 最长播放时间
reserved: 保留字段
ntid-next trak id  下一个频道标识
TKHD
有两个版本
v=0
+[4]-+[4]-+[4]-+[4]-+[4]-+[4]-+[4]-+[4]-+
|size|tkhd|vsfl|cttm|mdtm|tkid|resv|duat|
+----+----+----+----+----+----+----+----+
+[12]+----+----+2-+2-+[36]----...-+[4]-+[4]-+
|reserved      |ct|rs|reserved    |twvo|thvo|
+----+----+----+--+--+--------...-+----+----+
v=1
+[4]-+[4]-+[4]-+[8]-----+[8]-----+[4]-+[4]-+[8]-----+
|size|tkhd|vsfl|cttm    |mdtm    |tkid|resv|duat    |
+----+----+----+--------+--------+----+----+--------+
+[12]+----+----+2-+2-+[36]----...-+[4]-+[4]-+
|reserved      |ct|rs|reserved    |twvo|thvo|
+----+----+----+--+--+--------...-+----+----+
size:box长度
type:文件类型标识内容为"tkhd"
vsfl:版本号标志
cttm:creat time 文件创建时间
mdtm:modification time  文件修改时间
tkid:track-id
resv:reserved
duat:duration
reserved:
ct:codec_type {audio=0x0100; video=0}
rs:reserved
reserved:
twvo:Track width , for visual only
thvo:Track height, for visual only