SuperMan-Lfj / blog

Apache License 2.0
1 stars 0 forks source link

FLV seek #36

Open SuperMan-Lfj opened 3 years ago

SuperMan-Lfj commented 3 years ago

keyframes索引信息

官方的文档中并没有对keyframes index做描述, 但是,flv的这种结构每个tag又不像TS有同步头,如果没有keyframes index的话,seek及快进快退的效果会非常差,因为需要一个tag一个tag的顺序读取。后来在做flv文件合成的时候,发现网上有的flv文件将keyframes信息隐藏在 Tag中。keyframes几乎是一个非官方的标准, 也就是民间标准。

两个常用的操作metadata的工具是flvtool2和FLVMDI,都是把keyframes作为一个默认的元信息项目。在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’和‘times’分别指的是关键帧的文件位置和关键帧的PTS。通过keyframes可以建立起自己的Index,然后在seek和快进快退的操作中,快速有效地跳转到你想要找的关键帧位置进行处理。

yamdi:将flv转成带索引的flv,项目主页:http://sourceforge.net/projects/yamdi/

yamdi -i i.flv -o o.flv