FLV 文件格式简析

FLV

Flash Video is a container file format used to deliver digital video content (e.g., TV shows, movies, etc.) over the Internet using Adobe Flash Player version 6 and newer.
Flash Video content may also be embedded within SWF files.
There are two different video file formats known as Flash Video: FLV and F4V.
The audio and video data within FLV files are encoded in the same manner as they are within SWF files.
The F4V file format is based on the ISO base media file format and is starting with Flash Player 9 update 3.[1]

FLV是一种视频封装格式.

FLV 文件格式

FLV格式主要包括: FLV HeaderFLV Body两部分.

  • Header
    Header包括文件类型,流信息(是否包含视频音频),header长度等信息.
  • Body
    Body由一个个Tag组成.
    Tag包含的信息主要为: 视频、音频或脚本信息.
    Body中一般第一个Tag为脚本信息(meta data, 包含视频音频的编码格式,视频的宽高信息等,该类型的Tag一般有且仅有一个),其后的TagVideoAudioTag.
    FLV 文件格式简析_第1张图片
    **FLV 文件格式**
FLV Header

FLV Header一般为9个字节.
FLV Header`主要有四部分组成: 文件类型、版本信息、流信息、头长度.

FLV 文件格式简析_第2张图片
**The FLV header in Adobe Flash Video File Format Specification Version 10.1 **
  • 文件类型(3字节)
    固定为16进制的0x46 0x4c 0x56,即字符F L V的ASCII值.

  • 版本信息(1字节)
    一般为0x01

  • 流信息(1字节)

倒数第一位是1表示有视频,倒数第三位是1表示有音频,倒数第二、四位必须为0.

比如:
00 00 01 01表明该文件中包含视频和音频;
00 00 00 01表明该文件中仅包含视频.

  • 头长度(4字节)
    一般为9.
FLV 文件格式简析_第3张图片
**FLV Header 在文件中的示例**
FLV Body
FLV 文件格式简析_第4张图片
**FLV File Body Part 1 in Adobe Flash Video File Format Specification Version 10.1 **
**FLV File Body Part 2 in Adobe Flash Video File Format Specification Version 10.1 **

PreviousTagSizeNTagN的大小, 包括Tag Header(一般为11字节)和Tag Data的大小之和.

FLV Tag Header
FLV 文件格式简析_第5张图片
FLV Tag Header

可见第一个字节的后5位用于表示Tag的类型:
8 -- 音频
9 -- 视频
18 -- script data 也就是 metadata
第2字节到第4字节为DataSize,也就是Tag Data的大小(单位是字节,不包含这11字节的头)。也就是说Tag Data的最大值为2的24次方-1(0也算是一个数),
也就是16777216 - 1 = 16777215字节(即0xFFFFFF),也就是16M -1 - 11字节。

References

Adobe Flash Video File Format Specification Version 10.1
https://wuyuans.com/2012/08/flv-format/
http://blog.csdn.net/leixiaohua1020/article/details/50535082

你可能感兴趣的:(FLV 文件格式简析)