当前位置:网站首页>Detailed explanation of FLV format

Detailed explanation of FLV format

2022-07-06 16:41:00 Dog egg L

FLV Format Overview :

FLV(Flash Video) yes Adobe A popular streaming media format designed and developed by the company , Because of its lightweight video file size 、 Simple package and so on , Make it very suitable for application on the Internet . Besides ,FLV have access to Flash Player Play it , and Flash Player Plug ins have been installed in most browsers around the world , This makes it possible to play through the web FLV The video is very easy .

Flv File format

Flv By file header (File Header) and The file body (File Body) form .

Flv Body By a series of Tag form , Every Tag Another one preTagSize Field , Mark the front one Tag Size .
 Insert picture description here

Flv Header

The file header consists of the following parts :

Signature(3 Byte)+Version(1 Byte)+Flags(1 Bypte)+DataOffset(4 Byte)

Signature Occupy 3 Bytes :
Fix FLV Three characters as a symbol . It is generally found that the first three characters are FLV I thought he was flv file .
Version Occupy 1 Bytes :
Mark FLV Version number of . Here we see 1
Flags Occupy 1 Bytes :
Content label . The first 0 Position and number 2 position , respectively video And audio Existing situation .(1 Indicates presence ,0 Does not exist ). notice 0x05, That is to say 00000101, Represents an existing video , There is also audio .
DataOffset Occupy 4 Bytes :
Express FLV Of header length .

The picture below is Flv Header The content of ,(UI8 Indicates no sign 8 position , That's one byte ;UB[5] Represents... In a byte 5 position )
 Insert picture description here

Flv Body

Flv Body One by one Tag form , Every Tag There is one. preTagSize Field , Mark the front one Tag Size .
 Insert picture description here
Tag There are three types ,Audio Tag( Audio Tag),Video Tag( video Tag),script Tag( also called Metadata Tag)

Every Tag from “Tag Header” and “Tag Data” form , For different types of Tag,“Tag Header” The format of is the same ,“Tag Body” The format of is different .
 Insert picture description here
The following figure summarizes the above content , After watching it, right flv There should be an overall understanding .
 Insert picture description here
Generally one flv The file consists of a header message , One script Tag, And several video Tag and audio Tag form .
 Insert picture description here
Let's explain each type of Tag Data
 Insert picture description here

Tag Data

Flv There are three kinds of tag:“Audio Tag Data”、“Video Tag Data”、“Script Tag Data”
 Insert picture description here

Aideo tag By tag Header + Tag Data form :

tag Header:
TagType: 8 (1 byte)
TagType The meaning of the representative is as follows :

  • 8: audio

  • 9 : video

  • 18 : script data

DataSize: 7 (3 bytes)
tag Data size
tag Header size = Previous Tag Size - DataSize
TimeStamp: 0 (3 bytes) Time stamp
TimestampExtended: 0 (1 byte) Extended timestamp
StreamId: 0 (3 bytes) flow ID

Audio Tag Data:
 Insert picture description here

Video tag analysis :

video tag By tag Header + Tag Data form :
 Insert picture description here
tag Header:

TagType: 9 (1 byte)
TagType The meaning of the representative is as follows :

  • 8: audio
  • 9 : video
  • 18 : script data

DataSize: 50 (3 bytes)

  • tag Data size

  • tag Header size = Previous Tag Size - DataSize

TimeStamp: 0 (3 bytes) Time stamp
TimestampExtended: 0 (1 byte) Extended timestamp
StreamId: 0 (3 bytes) flow ID

Video Tag Data
 Insert picture description here

scripts tag analysis :

This type of Tag Also commonly known as MetadataTag, Will put some about FLV Metadata information of video and audio, such as :duration、width、height etc. . Usually this type Tag Will follow FileHeader Later as the first Tag appear , And there's only one .
 Insert picture description here
tag Header:

TagType: 18 (1 byte)
TagType The meaning of the representative is as follows :

  • 8: audio

  • 9 : video

  • 18 : script data

DataSize: 293 (3 bytes)

  • tag Data size

  • tag Header size = Previous Tag Size - DataSize

TimeStamp: 0 (3 bytes) Time stamp
TimestampExtended: 0 (1 byte) Extended timestamp
StreamId: 0 (3 bytes) flow ID

tag Data:

AMF package : The first byte indicates AMF Packet type
 Insert picture description here
first AMF package :
The first byte is generally 0x02, Representation string , The first 2-3 Bytes represents the length of the string , It's usually 0x000A, Followed by a string , It's usually "onMetaData".

second AMF package :
The first byte is 0x08, Represents an array , The first 2-5 Bytes represent the number of array elements , Followed by the elements of the array , The format is : Element name length (UI16) + Element name (UI8[n]) + The value of the element (double), Finally “009” ending .
 Insert picture description here

原网站

版权声明
本文为[Dog egg L]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060920335630.html