MPEG4 笔记(FTYP,MOOV,MVHD)

来源:互联网 发布:高级java工程师速成班 编辑:程序博客网 时间:2024/05/19 23:00

===========================ATOM介 绍============================


FTYP:
4Byte:size = 0x1C                                                    (0x00--0x03)
4Byte:type = 0x66 74 79 70                                    (0x04--0x07)
4Byte:MajorBrand = 0x6D 70 34 32                      (0x08--0x0B)
4Byte:MinorVersion                                                  (0x0C--0x0F)
size -= 16;
while(size)
{
4Byte:compatible_brand
size -= 4;
}


MOOV(Movie Atom)(容器)

4Byte:size = 0x00 00 0F 6C                                           (0x1C--0x1F)
4Byte:type = 0x66 74 79 70                                           (0x20--0x23)



MVHD(Movie header atom)

字段          长度(字节)         描述       
尺寸----------4--------------------这个movie header atom的字节数       
类型----------4--------------------Mvhd       
版本----------1--------------------这个movie header atom的版本       
标志----------3--------------------扩展的movie header标志,这里为0       
生成时间----4--------------------Movie atom的起始时间。基准时间是1904-1-1 0:00 AM       
修订时间----4--------------------Movie atom的修订时间。基准时间是1904-1-1 0:00 AM       
Timescale-- 4--------------------A time value that indicates the time scale for this movie—that is, the number of time units that pass per second in its time coordinate system. A time coordinate system that measures time in sixtieths of a second, for example, has a time scale of 60.    
相当于定义了标准的1秒在这部电影里面的刻度是多少.
Duration--4--A time value that indicates the duration of the movie in time scale units.Note that this property is derived from the movie’s tracks. The value of this field corresponds to the duration of the longest track in the movie.

播放速度----4--------------------播放此movie的速度。1.0为正常播放速度       
播放音量----2--------------------播放此movie的音量。1.0为最大音量       保留--10    这里为0       
矩阵结构----36------------------该矩阵定义了此movie中两个坐标空间的映射关系       
预览时间----4--------------------开始预览此movie的时间       
预览duration--4-----------------以movie的time scale为单位,预览的duration       
Poster time--4 ------------------The time value of the time of the movie poster.       
Selection time--4----------------The time value for the start time of the current selection.       
Selection duration--4 ----------The duration of the current selection in movie time scale units.       
当前时间----4--------------------当前时间       
下一个track ID--4--------------下一个待添加track的ID值。0不是一个有效的ID值。     


4Byte:size = 0x00 00 00 6C                                           (0x24--0x27)
4Byte:type = 1836476516                                              (0x28--0x2B)
1Byte:Version = 0x00
3Byte:Flags = 0x00 00 00 
if(Version == 0) //默认
{
4Byte:CreationTime = 0xC6 D3 A0 F9                          (0x30--0x33)
4Byte:ModificationTime = 0xC6 D3 A0 F9    
4Byte:TimeScale = 0x00 00 02 58(600)                       (0x38--0x3B)
4Byte:Duration = 0x00 00 14 28(5160)                         (0x3C--0x3F)
}
else if(Version == 1)
{
8Byte:CreationTime = 
8Byte:ModificationTime = 
4Byte:TimeScale = 
8Byte:Duration =
}
else
{
//todo
}
4Byte:Rate = 0x00 01 00 00                                    (0x40--0x43)      
2Byte:Volume= 0x01 00                                           (0x44--0x45)
10Byte:Reserved =                                                   (0x46--0x4F)

for (int i=0; i<9; i++)                                                  (0x50--0x73)
{
4Byte:Matrix[i]     
}

4Byte:Preview time = 0                                              (0x74--0x77)
4Byte:Preview duration = 0                                      (0x78--0x7B)
4Byte:Poster time = 0                                               (0x7C--0x7F)
4Byte:Selection time = 0                                           (0x80--0x83)
4Byte:Selection duration = 0                                    (0x84--0x87)
4Byte:Current time = 0                                              (0x88--0x8B)
4Byte:Next Track Id = 5                                             (0x8C--0x8F)

计算电影长度 = Duration/TimeScale= 5160/600 = 8.6 = 8秒 600ms 

TimeScale: 是指衡量影片时间的单位尺度,以毫秒为单位;
Duration: 是指某段影片的播放时间,以TimeScale所指示的时间尺度为单位。
譬如 TimeScale = 1000, 某个AU(Access Unit)的Duration = 23, 则表示该AU的播放时间为23毫秒。
再譬如某部影片以30 fps的速率播放,若TimeScale = 1000, 则各AU的duration为33或34(交替出现以使误差最小)。
一般情况下一个AU可以理解成为一个Frame,常见的TimeScale设置为1000以获取直观和计算方便,音频也常将TimeScale的值设置为采样率。在压缩影片时,一定要注意声音和视频的这两组值设置正确,否则会引起音视频不正确。