SCRIPTDATA
如果TAG包中的TagType==18时,就表示这个TAG是SCRIPT.
SCRIPTDATA 结构十分复杂,定义了很多格式类型,每个类型对应一种结构.
Field |
Type |
Comment |
Type |
UI8 |
Type of the ScriptDataValue.
The following types are defined:
0 = Number
1 = Boolean
2 = String
3 = Object
4 = MovieClip (reserved, not supported)
5 = Null
6 = Undefined
7 = Reference
8 = ECMA array
9 = Object end marker
10 = Strict array
11 = Date
12 = Long string |
ScriptDataValue |
IF Type == 0
DOUBLE
IF Type == 1
UI8
IF Type == 2
SCRIPTDATASTRING
IF Type == 3
SCRIPTDATAOBJECT
IF Type == 7
UI16
IF Type == 8
SCRIPTDATAECMAARRAY
IF Type == 10
SCRIPTDATASTRICTARRAY
IF Type == 11
SCRIPTDATADATE
IF Type == 12
SCRIPTDATALONGSTRING |
Script data value.
The Boolean value is (ScriptDataValue ≠ 0). |
类型在FLV的官方文档中都有详细介绍.
onMetaData
onMetaData 是SCRIPTDATA中对我们来说十分重要的信息,结构如下表:
Property Name |
Type |
Comment |
audiocodecid |
Number |
Audio codec ID used in the file (see E.4.2.1 for available SoundFormat values) |
audiodatarate |
Number |
Audio bit rate in kilobits per second |
audiodelay |
Number |
Delay introduced by the audio codec in seconds |
audiosamplerate |
Number |
Frequency at which the audio stream is replayed |
audiosamplesize |
Number |
Resolution of a single audio sample |
canSeekToEnd |
Boolean |
Indicating the last video frame is a key frame |
creationdate |
String |
Creation date and time |
duration |
Number |
Total duration of the file in seconds |
filesize |
Number |
Total size of the file in bytes |
framerate |
Number |
Number of frames per second |
height |
Number |
Height of the video in pixels |
stereo |
Boolean |
Indicating stereo audio |
videocodecid |
Number |
Video codec ID used in the file (see E.4.3.1 for available CodecID values) |
videodatarate |
Number |
Video bit rate in kilobits per second |
width |
Number |
Width of the video in pixels |
这里面的duration、filesize、视频的width、height等这些信息对我们来说很有用.
keyframes
当时在做flv demux的时候,发现官方的文档中并没有对keyframes index做描述,但是flv的这种结构每个tag又不像TS有同步头,如果没有keyframes index 的话,seek及快进快退的效果会非常差,因为需要一个tag一个tag的顺序读取。后来通过网络查一些资料,发现了一个keyframes的信息藏在SCRIPTDATA中。
keyframes几乎是一个非官方的标准,也就是民间标准.在网上已经很难看到 flv文件格式,但是metadata里面不包含 keyframes项目的视频 . 两个常用的操作metadata的工具是flvtool2和FLVMDI,都是把keyframes作为一个默认的元信息项目.在FLVMDI的主页 (http://www.buraks.com/flvmdi/)上有描述:
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和快进快退的操作中,快速有效的跳转到你想要找的关键帧的位置进行处理。