|
楼主 |
发表于 2008-1-11 16:29:32
|
显示全部楼层
ftyp Box定义:
{
/* ftyp Box 大小,单位byte */
unsigned int(32) size;
/* Box类型:‘ftyp’*/
unsigned int(32) type = ‘ftyp’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
/* 分支类型 */
unsigned int(32) major_brand;
/* 分支版本号 */
unsigned int(32) minor_version;
unsigned int(32) compatible_brands[];
}
说明:
整个文件只有一个ftyp Box;file type box
读取分支类型可以确定此文家是mp4文件还是3gp文件还是其它类型的文件;
moov Box定义:
{
/* moov Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘moov’*/
unsigned int(32) type = ‘moov’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
unsigned int(8)[] data;
}
说明:
整个文件只有一个moov Box;movie box
moov Box的data部分包含着表中所述的子Box;
mdat Box定义:
{
/* mdat Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘mdat’*/
unsigned int(32) type =‘mdat’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
/* 多媒体数据 */
unsigned int(8)[] data;
}
mvhd Box定义:
{
/* mvhd Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘mvhd’ */
unsigned int(32) type = ‘mvhd’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
unsigned int(8) version;
bit(24) flags = 0;
if (version==1) {
/* 创建时间单位s,从1904年1月1日0:0:0开始 */
unsigned int(64) creation_time;
/* 最近访问时间,同上 */
unsigned int(64) modification_time;
/* 时间单位(1秒 = timescale,类似播放器中90k)*/
unsigned int(32) timescale;
/* 文件播放时间(与播放时间最长流相同),单位是时间单位;
文件播放时间换算成秒就是:(duration / timescale)秒 */
unsigned int(64) duration;
} else { // version==0
unsigned int(32) creation_time;
unsigned int(32) modification_time;
unsigned int(32) timescale;
unsigned int(32) duration;
}
template int(32) rate = 0x00010000;
template int(16) volume = 0x0100;
const bit(16) reserved = 0;
const unsigned int(32)[2] reserved = 0;
template int(32)[9] matrix =
{ 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
// Unity matrix
bit(32)[6] pre_defined = 0;
unsigned int(32) next_track_ID;
}
说明:
只有一个mvhd Box;movie header box
template int(32) rate = 0x00010000;32位定点数: 16位整数,16位小数(1.0)
template int(16) volume = 0x0100; 16位定点数::8位整数,8位小数(1.0)
trak Box定义:
{
/* trak Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘trak’*/
unsigned int(32) type = ‘trak’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
unsigned int(8)[] data; /* 流具体定义 */
}
tkhd Box定义:
{
/* tkhd Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘tkhd’ */
unsigned int(32) type = ‘tkhd’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
unsigned int(8) version;
bit(24) flags;
if (version==1) {
/* 与mvhd定义相同 */
unsigned int(64) creation_time;
unsigned int(64) modification_time;
/* 流ID */
unsigned int(32) track_ID;
const unsigned int(32) reserved = 0;
/* 流播放时间,单位是时间单位,时间单位使用mvhd描述的时间单位 */
unsigned int(64) duration;
} else { // version==0
unsigned int(32) creation_time;
unsigned int(32) modification_time;
unsigned int(32) track_ID;
const unsigned int(32) reserved = 0;
unsigned int(32) duration;
}
const unsigned int(32)[2] reserved = 0;
template int(16) layer = 0;
template int(16) alternate_group = 0;
template int(16) volume;
const unsigned int(16) reserved = 0;
template int(32)[9] matrix=
{ 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
unsigned int(32) width;
unsigned int(32) height;
}
说明:
Track Header Box:每个Track Box一个Track Header Box;
Width和height是16.16的定点数
在这个Box中主要的信息就是:流ID(track_ID);
mdia Box定义:
{
/* mdia Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘mdia’*/
unsigned int(32) type =‘mdia’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
/* 子Box */
unsigned int(8)[] data;
}
mdhd Box定义:
{
/* mdhd Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘mdhd’ */
unsigned int(32) type = ‘mdhd’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
unsigned int(8) version;
bit(24) flags = 0;
if (version==1) {
unsigned int(64) creation_time;
unsigned int(64) modification_time;
/* 与mvhd含义相同 */
unsigned int(32) timescale;
unsigned int(64) duration;
} else { // version==0
unsigned int(32) creation_time;
unsigned int(32) modification_time;
unsigned int(32) timescale;
unsigned int(32) duration;
}
bit(1) pad = 0;
unsigned int(5)[3] language; // ISO-639-2/T language code
unsigned int(16) pre_defined = 0;
}
说明:
Media Header Box:每个Media Box一个Media Header Box;
在这个Box中主要的信息就是:流的时间单位(timescale)以及流的长度(duration)
hdlr Box定义:
{
/* hdlr Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘hdlr’ */
unsigned int(32) type = ‘hdlr’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
unsigned int(8) version = 0;
bit(24) flags = 0;
unsigned int(32) pre_defined = 0;
unsigned int(32) handler_type;
const unsigned int(32)[3] reserved = 0;
string name;
}
说明:
Handler Box,每个mdia Box一个hdlr Box;
handler_type:‘vide’说明是视频流
‘soun’说明是音频流
… 其它用处流
一个Trak Box可以根据hdlr Box里面的handler_type确定其流类型,也可以根据minf Box的子Box media info header Box确定其流类型。
minf Box定义:
{
/* minf Box的长度,单位byte */
unsigned int(32) size;
/* Box类型:‘minf’*/
unsigned int(32) type =‘minf’;
if (size==1){
unsigned int(64) largesize;
}else if (size==0) {
// box extends to end of file
}
/* 子Box */
unsigned int(8)[] data;
}
vmhd/smhd/nmhd Box:media info header Box
如果hdlr Box中指定的流类型为video流,那么此处media info header Box的类型应该为vmhd Box;同理,如果hdlr Box中指定的流类型为audio流,那么此处media info header Box的类型为smhd Box; |
|