https://blog.csdn.net/ai2000ai/article/details/77530741
Open look from the entire file, FLV is the header and Body composition.
1、Header
The Signature : The first three bytes of the file as a fixed FLV 'F''L''V', is used to identify the file format do flv format detection time.
If you find the first three bytes of "FLV", it is considered flv file.
Version: The first 4 bytes flv version number.
Flags: fifth byte in bits 0 and bit 2, respectively, in the presence of video and audio (1 indicates the presence and 0 indicates the absence).
DataOffset is : The last four bytes FLV header length.
2 FLV body = TagSize|Tag | TagSize | Tag... ...
After the FLV header, that is, FLV File Body.
FLV File Body is a series of back-pointers + tags configured .back-pointers is four bytes of data, the tag indicates the previous size.
3.FLV Tag
Data FLV file is composed of one TAG, TAG which data may be video, audio, scripts.
onMetaData contained in the scripts, containing important information, such as width and height, duration, filesize etc.
TAG is a structure of the table:
1.FLVTAG
Field | Type | Comment |
Reserved | UB [2] | Reserved for FMS, should be 0 |
Filter | UB [1] | Indicates if packets are filtered. 0 = No pre-processing required. 1 = Pre-processing (such as decryption) of the packet is required before it can be rendered. Shall be 0 in unencrypted files, and 1 for encrypted tags. See Annex F. FLV Encryption for the use of filters. |
Roof | UB [5] | Type of contents in this tag. The following types are |
data Size | UI24 | Length of the message. Number of bytes after StreamID to end of tag (Equal to length of the tag – 11) |
Timestamp | UI24 | Time in milliseconds at which the data in this tag applies. This value is relative to the first tag in the FLV file, which always has a timestamp of 0. |
TimestampExtended | UI8 | Extension of the Timestamp field to form a SI32 value. This field represents the upper 8 bits, while the previous Timestamp field represents the lower 24 bits of the time in milliseconds. |
StreamID | UI24 | Always 0. |
AudioTagHeader | IF TagType == 8 AudioTagHeader |
|
VideoTagHeader | IF TagType == 9 VideoTagHeader |
|
EncryptionHeader | IF Filter == 1 EncryptionTagHeader |
|
FilterParams | IF Filter == 1 FilterParams |
|
Data | IF TagType == 8 AUDIODATA IF TagType == 9 VIDEODATA IF TagType == 18 SCRIPTDATA |
Data specific for each media type. |
TagType: TAG中第1个字节中的前5位表示这个TAG中包含数据的类型,8 = audio,9 = video,18 = script data.
DataSize:StreamID之后的数据长度.
Timestamp和TimestampExtended组成了这个TAG包数据的PTS信息,记得刚开始做FVL demux的时候,并没有考虑TimestampExtended的值,直接就把Timestamp默认为是PTS,后来发生的现 象就是画面有跳帧的现象,后来才仔细看了一下文档发现真正数据的PTS是PTS= Timestamp | TimestampExtended<<24.
StreamID之后的数据就是每种格式的情况不一样了,接下格式进行详细的介绍.
Audio Tags
如果TAG包中的TagType==8时,就表示这个TAG是audio。
StreamID之后的数据就表示是AudioTagHeader,AudioTagHeader结构如下: