接下來就是Metadata的具體數據,由兩個AMF包組成。
Metadata元素個數暫定爲12個 = 音頻5個 + 視頻5個 + 2個(duration和filesize)。 後面還可能會加入其它元素,因此會返回來修改此值。metadata元素的順序不固定,此處採用ffmpeg中的順序。
第二個AMF包中各數組元素封裝形式爲:前兩個字節是元素名稱的長度;後面跟着長度爲L的字符串;第L+3個字節表示元素值的類型;後面跟着是對應值,佔用的字節數取決於值的類型。
keyframes: (Object) This object is added only if you specify the /k switch. 'keyframes' is known to FLVMDI and if /k switch is not specified, 'keyframes' object will be deleted.
'keyframes' object has 2 arrays: 'filepositions' and 'times'. Both arrays have the same number of elements, which is equal to the number of key frames in the FLV. Values in times array are in 'seconds'. Each correspond to the timestamp of the n'th key frame. Values in filepositions array are in 'bytes'. Each correspond to the fileposition of the nth key frame video tag (which starts with byte tag type 9).
也就是說keyframes中包含着2個內容 'filepositions' and 'times'分別指的是關鍵幀的文件位置和關鍵幀的PTS。通過keyframes可以建立起自己的Index,然後再seek和快進快退的操作中,快速有效的跳轉到你想要找的關鍵幀位置進行處理。
到此爲止已經介紹完flv文件格式,flv格式還是比較簡單的,header部分很簡潔,body部分都是由一個個tag組成,tag的話也就三種,腳本tag一般只有一個。最後用一個簡單的圖來概括flv文件格式,以結束本文檔。