关闭

flv文件元信息(metadata)

标签: flvvideoaudioobjectstringflash
2615人阅读 评论(2) 收藏 举报
分类:

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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:204586次
    • 积分:2775
    • 等级:
    • 排名:第12949名
    • 原创:46篇
    • 转载:178篇
    • 译文:0篇
    • 评论:26条
    文章分类
    最新评论