flv文件元信息(metadata)

转载 2011年01月13日 11:26:00

flv 元信息(metadata)

flv文件中的元信息,是一些描述flv文件各类属性的信息。这些信息以AMF格式保存在文件的起始部分。adobe官方的标准flv元信息项目如下(来源:http://help.adobe.com/en_US/FlashMediaLiveEncoder/3.0/Using/WS5b3ccc516d4fbf351e63e3d11c104ba878-7ff5.html):

  • audiochannels

  • audiocodecid

  • audiodatarate

  • audiodevice

  • audioinputvolume

  • audiosamplerate

  • creationdate

  • duration (media files only)

  • fmleversion (Flash Media Live Encoder version) (media files only)

  • framerate

  • height

  • lastkeyframetimestamp (media files only)

  • lasttimestamp (media files only)

  • presetname

  • videocodecid

  • videodatarate

  • videodevice

  • videokeyframe_frequency

  • width


每个元信息项目所表达的意思还是不难猜测。虽然现在网络流媒体中,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
- 623314
- 809714
- 983310
- 1182506
- 1353766
- 1524852
- 1707253
- 1898530
- 2116411
- 2306012
- 2476133
- 2671519
- 2841358
- 3009769
- 3163044
- 3340645
- 3502065
- 3663881
- 3867247
- 4050995
- 4251763
- 4411694
- 4587080
- 4766001
- 4967281
- 5162796
- 5345682
- 5523669
- 5672578
- 5867093
- 6086781
- 6257768
- 6453268
- 6656733
- 6854996
- 7023930
- 7188798
- 7362948
- 7560148
- 7778350
- 8007845
- 8265492
- 8453671
- 8678896
- 8892715
- 9084570
- 9281456
- 9584974
times:
- 0
- 4.933
- 10.933
- 16.933
- 22.933
- 28.933
- 34.933
- 40.933
- 46.933
- 52.933
- 58.933
- 64.933
- 70.933
- 76.933
- 82.933
- 88.933
- 94.933
- 100.933
- 106.933
- 112.933
- 118.933
- 124.933
- 130.933
- 136.933
- 142.933
- 148.933
- 154.933
- 160.933
- 166.933
- 172.933
- 178.933
- 184.933
- 190.933
- 196.933
- 202.933
- 208.933
- 214.933
- 220.933
- 226.933
- 232.933
- 238.933
- 244.933
- 250.933
- 256.933
- 262.933
- 268.933
- 274.933
- 280.933
- 286.933
- 292.933
- 298.933
lastkeyframelocation: 9584974
filesize: 9662773
height: 256
audiocodecid: 2
videodatarate: 201.133827405465
metadatacreator: modify by youku.com in 20090909
width: 320
...

下面重点讲述一下keyframes。keyframes几乎是一个非官方的标准。在网上已经很难看到flv文件格式,但是metadata里面不包含keyframes项目的视频。两个常用的操作metadata的工具是flvtool2和FLVMDI,都是把keyframes作为一个默认的元信息项目。关于keyframes,在FLVMDI的主页(http://www.buraks.com/flvmdi/)上有描述:
keyframes: (Object) This object is added only if youspecify the /k switch. 'keyframes' is known to FLVMDI and if /k switchis not specified, 'keyframes' object will be deleted.
'keyframes' object has 2 arrays: 'filepositions' and 'times'. Botharrays have the same number of elements, which is equal to the numberof key frames in the FLV. Values in times array are in 'seconds'. Eachcorrespond to the timestamp of the n'th key frame. Values infilepositions array are in 'bytes'. Each correspond to the filepositionof the nth key frame video tag (which starts with byte tag type 9).

简单来说,keyframes保存着关键帧的时间和文件偏移量的映射。在网络流媒体环境下,服务器能够以很小的代价保证发送给客户端的第一帧是可以显示出来的关键帧,从而提高用户体验。FLVMDI我没用过。用flvtool2来更新源信息的命令是:
flvtool2 -U youku.flv youku.flv.out
上面的那个youku的视频,我用flvtool2更新了元信息之后,元信息如下:
liruqi@Apollo:~/Videos$ flvtool2 -P youku.flv.out
---
/home/liruqi/Videos/youku.flv.out:
duration: 300.934
hasMetadata: true
hasKeyframes: true
framerate: 14
datasize: 9598746
audiodatarate: 44.5357982098402
audiosamplerate: 22000
cuePoints:
audiosamplesize: 16
hasVideo: true
lasttimestamp: 300.867
videocodecid: 2
canSeekToEnd: false
stereo: true
audiosize: 1801606
lastkeyframetimestamp: 298.933
videosize: 7795514
audiodelay: 0
hasAudio: true
filesize: 9662891
height: 256
keyframes:
filepositions:
- 1651
- 255153
- 432485
- 623394
- 809794
- 983390
- 1182586
- 1353846
- 1524932
- 1707333
- 1898610
- 2116491
- 2306092
- 2476213
- 2671599
- 2841438
- 3009849
- 3163124
- 3340725
- 3502145
- 3663961
- 3867327
- 4051075
- 4251843
- 4411774
- 4587160
- 4766081
- 4967361
- 5162876
- 5345762
- 5523749
- 5672658
- 5867173
- 6086861
- 6257848
- 6453348
- 6656813
- 6855076
- 7024010
- 7188878
- 7363028
- 7560228
- 7778430
- 8007925
- 8265572
- 8453751
- 8678976
- 8892795
- 9084650
- 9281536
- 9585054
times:
- 0
- 4.933
- 10.933
- 16.933
- 22.933
- 28.933
- 34.933
- 40.933
- 46.933
- 52.933
- 58.933
- 64.933
- 70.933
- 76.933
- 82.933
- 88.933
- 94.933
- 100.933
- 106.933
- 112.933
- 118.933
- 124.933
- 130.933
- 136.933
- 142.933
- 148.933
- 154.933
- 160.933
- 166.933
- 172.933
- 178.933
- 184.933
- 190.933
- 196.933
- 202.933
- 208.933
- 214.933
- 220.933
- 226.933
- 232.933
- 238.933
- 244.933
- 250.933
- 256.933
- 262.933
- 268.933
- 274.933
- 280.933
- 286.933
- 292.933
- 298.933
videodatarate: 205.961039263196
audiocodecid: 2
metadatacreator: inlet media FLVTool2 v1.0.6 - http://www.inlet-media.de/flvtool2
metadatadate: Mon Oct 26 00:32:57 GMT+0800 2009
width: 320
hasCuePoints: false
...

所谓的更新,就是flvtool2把元信息全部改写了。实际上跟youku原来的没差多少,只是把文件属性重新计算了一遍。
再看看FLVMDI所定义的metadata的标准,跟flvtool2的比较类似:

  • duration: (Number) Length of the FLV in seconds. FLVMDI computes this value.
  • lasttimestamp: (Number) TimeStamp of the last tag in the FLV file.
  • lastkeyframetimestamp: (Number) TimeStamp of the last video tag which is a key frame. This info might be needed because seeking a frame after this time usually does not work.
  • width: (Number) Width of the video in pixels. (Flash exporter 1.1 sets this to 0).
  • height: (Number) Height of the video in pixels. (Flash exporter 1.1 sets this to 0).
  • videodatarate: (Number) FLVMDI does not compute this value and imports it if present. (Defaults to 0).
  • audiodatarate: (Number) FLVMDI does not compute this value and imports it if present. (Defaults to 0).
  • framerate: (Number) FLVMDI computes this value, but uses imported value if not 0.
  • creationdate: (String) FLVMDI cannot compute this value and imports it if present. (Defaults to 'unknown').
  • filesize: (Number) Filesize in bytes (including the injected data).
  • videosize: (Number) Total size of video tags in the file in bytes.
  • audiosize: (Number) Total size of audio tags in the file in bytes.
  • datasize: (Number) Total size of data tags in the file in bytes.
  • metadatacreator: (String) Will be set to 'Manitu Group FLV MetaData Injector 2'.
  • metadatadate: (Date) Date and time metadata added. (Note that this is not of type string like 'creationdate').
  • xtradata: (string) Additional string data if specified.
  • videocodecid: (Number) Video codec ID number used in the FLV. (Sorenson H.263 =2, Screen Video =3, On2 VP6 = 4 and 5, Screen Video V2 = 6).
  • audiocodecid: (Number) Audio codec ID number used in the FLV. (Uncompressed = 0, ADPCM = 1, MP3 = 2, NellyMoser = 5 and 6).
  • audiodelay:(Number) Audio delay in seconds. Flash 8 encoder delays the video forbetter synch with audio (Audio and video does not start both at time 0,Video starts a bit later). This value is also important for Flash 8Video Encoder injected Cue Points, because logical time of the cuepoints does not correspond to physical time they are inserted in theFLV. (Cue points are injected before encoding, when the video isshifted by 'audio delay' seconds, cue points are also shifted and theirphysical time in the FLV changes).
  • canSeekToEnd: (Boolean) True if the last video tag is a key frame and hence can be 'seek'ed.
  • keyframes: (Object) 


很显然,优酷就是改了flvtool2的一些代码然后拿来用了,还谦卑地说"modify by youku.com"。这句话都有语法问题,真是够山寨的。

 

原文地址:http://hi.baidu.com/barnabas/blog/item/854b3523f28c234493580766.html

FLV视频封装格式详解

Overview Flash Video(简称FLV),是一种流行的网络格式。目前国内外大部分视频分享网站都是采用的这种格式. File Structure 从整...
  • BSPLover
  • BSPLover
  • 2012年04月04日 21:13
  • 16251

FLV容器分析1

借用了FlvParse这个工具和UI,结合官方文档分析出来的。 此工具挺好,就是不开源,而且对于Metadata Tag的数据也没有精确显示到每一个byte。实际使用当中还出现字段没有完全显示之类的...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

FLV科普12 FLV脚本数据解析-Metadata Tag解析

AMF(Action Message Format)是Flash与服务端通信的一种常见的二进制编码模式,其传输效率高,可以在HTTP层面上传输。现在很多Flash WebGame都采用这样的消息格式。...

也说FLV格式分析(C语言从0开始,详解,完整版)

也说FLV格式分析(C语言完整版) 最近想写一个在线视频播放软件,经研究得知某视频网站会将一个视频成很多段来投放从而方便在线缓冲,以及加Ad之类的目的。下载后大概如下图所示(星哥的九品芝麻官)...
  • spygg
  • spygg
  • 2016年12月27日 16:09
  • 1531

rtmp flv metadata

Metadata property name Data type Description lastkeyframetimestamp ...

FLV格式解析—写的很有条理,看懂了

转自:http://wuyuans.com/2012/08/flv-format/ 最近要用到flv,整理了一些flv格式的资料,供参考。 flv文件主要由两部分组成:header和body...
  • occupy8
  • occupy8
  • 2015年02月11日 11:14
  • 2482

关于音视频的一些知识(demux、filter等)

MUX和DEMUX Mux 是 Multiplex 的缩写,意为“多路传输”,其实就是“混流”、“封装”的意思,与“合成”的意思相似就是指把视频素材和音频素材封装到一个单独的文件中。 muxing...
  • HAOMCU
  • HAOMCU
  • 2011年12月15日 09:28
  • 11207

Qt5的插件机制(4)--Qt插件的元信息metaData

JSON 与Qt插件的元信息 MetaData Qt插件的源码中,基本都能见到一个 xxx.json 的文件,这个文件中通常只包含一句: {     "Keys": [ "yyy" ] } 我们...

ffmpeg生成带关键帧头信息的flv文件(一)

普通flv文件头信息中不带关键帧信息,在网页播放器中播放时,seek速度很慢,为了加快flv的seek速度,我们可以在flv的头信息中写入关键帧信息. 主要方法为;在写头信息时预留一定的位置用来写关...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:flv文件元信息(metadata)
举报原因:
原因补充:

(最多只允许输入30个字)