Flash视频流的cue points and metadata

2013-02-17 16:02:50

<p><strong>补充: 转自 </strong><a href="http://hi.baidu.com/barnabas/item/d1f0e5dd0e46b34edcf9be2d" rel="noopener noreferrer" target="_blank"><strong>http://hi.baidu.com/barnabas/item/d1f0e5dd0e46b34edcf9be2d</strong></a></p><p> </p><p>每个元信息项目所表达的意思还是不难猜测。虽然现在网络流媒体中,flv格式占据主导地位,但是标准的元信息项目中,经常被用到的只有不到一半。我们拿youku的flv文件中所包含的元信息项目做个比较。 liruqi@Apollo:~/Videos$ flvtool2 -P youku.flv --- /home/liruqi/Videos/youku.flv: duration: 300.867 hasMetadata: true hasKeyframes: true audiodatarate: 43.4919904392971 audiosamplerate: 22050 framerate: 15.0033071091213 datasize: 9661244 audiosamplesize: 16 hasVideo: true lasttimestamp: 300.867 stereo: true videocodecid: 2 canSeekToEnd: false lastkeyframetimestamp: 298.933 audiosize: 1801606 videosize: 7795514 hasAudio: true keyframes: filepositions: - 1571 - 255073 - 432405</p><p> </p><p>... (省略几十行数据) </p><p>- 9084570 </p><p>- 9281456 </p><p>- 9584974 </p><p>times: - 0</p><p>- 4.933</p><p>- 10.933</p><p>...</p><p>- 286.933</p><p>- 292.933</p><p>- 298.933</p><p>lastkeyframelocation: 9584974 </p><p>filesize: 9662773 </p><p>height: 256 </p><p>audiocodecid: 2 </p><p>videodatarate: 201.133827405465 </p><p>metadatacreator: modify by youku.com in 20090909 </p><p>width: 320 </p><p>...</p><p> </p><p>下 面重点讲述一下keyframes。keyframes几乎是一个非官方的标准。在网上已经很难看到flv文件格式,但是metadata里面不包含 keyframes项目的视频。两个常用的操作metadata的工具是flvtool2和FLVMDI,都是把keyframes作为一个默认的元信息 项目。关于keyframes,在FLVMDI的主页(http://www.buraks.com/flvmdi/)上有描述:</p><p><strong>keyframes</strong> </p><p>: (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.</p><p> </p><p>'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).</p><p> </p><p>简单来说,keyframes保存着关键帧的时间和文件偏移量的映射。在网络流媒体环境下,服务器能够以很小的代价保证发送给客户端的第一帧是可以显示出来的关键帧,从而提高用户体验。FLVMDI我没用过。用flvtool2来更新源信息的命令是: </p><p>flvtool2 -U youku.flv youku.flv.out</p><p> </p><p>上面的那个youku的视频,我用flvtool2更新了元信息之后,元信息如下: </p><p>liruqi@Apollo:~/Videos$ flvtool2 -P youku.flv.out </p><p>--- </p><p>/home/liruqi/Videos/youku.flv.out: </p><p>duration: 300.934 </p><p>hasMetadata: true </p><p>hasKeyframes: true </p><p>framerate: 14 </p><p>datasize: 9598746 </p><p>audiodatarate: 44.5357982098402 </p><p>audiosamplerate: 22000 </p><p>cuePoints: </p><p>audiosamplesize: 16 </p><p>hasVideo: true </p><p>lasttimestamp: 300.867 </p><p>videocodecid: 2 </p><p>canSeekToEnd: false </p><p>stereo: true </p><p>audiosize: 1801606 </p><p>lastkeyframetimestamp: 298.933 </p><p>videosize: 7795514 </p><p>audiodelay: 0 </p><p>hasAudio: true </p><p>filesize: 9662891 </p><p>height: 256 </p><p>keyframes: </p><p>filepositions: </p><p>- 1651 </p><p>- 255153 </p><p>- 432485 </p><p>...</p><p>- 9084650 </p><p>- 9281536 </p><p>- 9585054 </p><p>times: </p><p>- 0 </p><p>- 4.933 </p><p>- 10.933</p><p>... </p><p>- 286.933</p><p> </p><p>- 292.933 </p><p>- 298.933 </p><p>videodatarate: 205.961039263196 </p><p>audiocodecid: 2 </p><p>metadatacreator: inlet media FLVTool2 v1.0.6 - http://www.inlet-media.de/flvtool2 </p><p>metadatadate: Mon Oct 26 00:32:57 GMT+0800 2009 </p><p>width: 320 </p><p>hasCuePoints: false </p><p>...</p><p> </p><p>所谓的更新,就是flvtool2把元信息全部改写了。实际上跟youku原来的没差多少,只是把文件属性重新计算了一遍。 </p><p>再看看FLVMDI所定义的metadata的标准,跟flvtool2的比较类似: </p>