===========================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的值設定為采樣率。在壓縮影片時,一定要注意聲音和視訊的這兩組值設定正确,否則會引起音視訊不正确。