现在的位置: 首页 > 综合 > 正文

IOS 基础媒体文件格式语法描述和语意(MP4文件格式分析实例)

2013年08月15日 ⁄ 综合 ⁄ 共 1959字 ⁄ 字号 评论关闭
一、基本对象 Box

Boxes start with a header which gives both size and type. 

在最前面Box 包含 size和type,size和type都是占4个字节。


The header permits compact or extended size (32or 64 bits) and compact or extended types (32 bits or full Universal Unique IDentifiers, i.e. UUIDs). 

允许根据需要,将size 简化或者扩展,同样的,对于type 也可以根据需要进行简化或者扩展。

简化,即使用32位的 size 和type. 扩展,即使用64位的size 和type.


The standard boxes all use compact types (32-bit) and most boxes will use the compact (32-bit) size. 

标准的box 使用简化的type,即32位的,大多数box一般也都使用简化的 32位的 size。


Typicallyonly the Media Data Box(es) need the 64-bit size.

但是 Media Data Box 需要使用64位的size.


The size is the entire size of the box, including the size and type header, fields, and all contained boxes.  

size指的是整个Box的大小,包括头部的 size和type 的大小,以及后面的值和所有的包含的其他box .

 
aligned(8) class Box (unsigned int(32) boxtype,optional unsigned int(8)[16] extended_type) {
   unsigned int(32) size;
   unsigned int(32) type = boxtype;
   if (size==1) {
      unsigned int(64) largesize;
   } else if (size==0) {
      // box extends to end of file
   }
if (boxtype==‘uuid’) {unsigned int(8)[16] usertype = extended_type;
}}
  

二、扩展对象

扩展对象继承了 Box,并在此基础上增加了 version和 flages.

 
aligned(8) class FullBox(unsigned int(32) boxtype, unsigned int(8) v, bit(24) f) extends Box(boxtype) {
unsigned int(8) version = v;
bit(24) flags = f;
}
  

三、构建文件对象

1、File Type Box 

 
aligned(8) class FileTypeBox
    extends Box(‘ftyp’) {
    unsigned int(32) major_brand;
    unsigned int(32) minor_version;
    unsigned int(32) compatible_brands[]; // to end of the box
}
  

计算一下FileTypeBox的大小:

size占32位,4个字节;

type占32位,4个字节;

major_brand占32位,4个字节;

minor_version占32位,4个字节;

compatible_brands 每个brand占32位,4个字节;



2、Free Space Box 

 
aligned(8) class FreeSpaceBox extends Box('free') { 
    unsigned int(8) data[];
}
 

计算一下Free Space Box的大小:

size占32位,4个字节;

type占32位,4个字节;

每个 data 占8位,1个字节;

3、Media Data Box


aligned(8) class MediaDataBox extends Box(‘mdat’) { 

bit(8) data[];

}

计算一下Media Data Box的大小:

size占32位,4个字节;

type占32位,4个字节;

每个 data 占8位,1个字节;

4、Movie Box 

aligned(8) class MovieBox extends Box(‘moov’){


计算一下Movie Box 的大小:

size占32位,4个字节;

type占32位,4个字节;


5、uuid

以上分析了通过一个mp4文件,分析了mp4文件格式顶级box的大小 size 、类型 type 以及相邻box的定位。



下面说一下,uuid.
根据基本对象 Box 的定义,如果
boxtype==‘uuid’
那么在type后面要包含 16个字节的 扩展类型。
扩展类型之后才是数据。



关于顶级box内部的子box的情况还没有做出说明,在下一篇文章会继续。

<EOF>

抱歉!评论已关闭.