1.headerThe header section records the type of FLV, version and other information, is the beginning of the FLV, generally similar, accounting for 9bytes. The specific format is as follows:
File type |
3 bytes |
"FLV" |
Version |
1 byte |
Typically 0x01 |
Flow information |
1 byte |
The last digit is 1 for the video, the penultimate digit is 1 for audio, the second to fourth digit must be 0. |
Header length |
4 bytes |
The length of the entire header, typically 9, is greater than 9 indicates that there is extended information below |
2.body body part by a tag, each tag has a 4bytes of space below, used to record the length of the tag, this post for reverse reading processing, their relationship is as follows: 2.1.Tag Each tag is also made up of two parts: tag header and tag Data. The tag header is the type of the current tag, data area (tag) length and other information, as follows:
name |
length |
Introduction |
Tag type |
1 bytes |
8: Audio 9: Video 18: Script Other: Reserved |
Data area length |
3 bytes |
The length of the data area |
Time stamp |
3 bytes |
An integer, in milliseconds. For script-type tags always 0 |
Time Stamp Extension |
1 bytes |
Expands the timestamp to 4bytes, which represents a high 8-bit. Rarely used |
Streamsid |
3 bytes |
Always 0 |
Data area |
Determined by data area length |
Data entity |
2.2.Tag DataThe data area can be divided into three kinds according to the tag type, audio data, video data and script data.
2.2.1. Audio data The first byte is the audio information, formatted as follows.
name |
length |
Introduction |
Audio format |
4 bits |
0 = Linear PCM, platform endian 1 = ADPCM 2 = MP3 3 = Linear PCM, little endian 4 = Nellymoser 16-khz Mono 5 = Nellymoser 8-khz Mono 6 = Nellymoser 7 = g.711 A-law logarithmic PCM 8 = g.711 Mu-law logarithmic PCM 9 = Reserved Ten = AAC one = Speex = MP3 8-khz = Device-specific Sound |
Sample Rate |
2 bits |
0 = 5.5-khz 1 = 11-khz 2 = 22-khz 3 = 44-khz For AAC always 3 |
Length of the sample |
1 bit |
0 = Snd8bit 1 = snd16bit The compressed audio is 16bit |
Audio type |
1 bit |
0 = Sndmono 1 = Sndstereo For AAC always 1 |
The audio stream data starts at 2byte.
2.2.2. Video dataAs with audio data, the first byte is a video message in the following format:
name |
length |
Introduction |
Frame type |
4 bits |
1:keyframe (for AVC, a seekable frame) 2:inter frame (for AVC, a non-seekable frame) 3:disposable Inter frame (h.263 only) 4:generated keyframe (reserved for server with only) 5:video Info/command Frame |
Encoding ID |
4 bits |
1:jpeg (currently unused) 2:sorenson H.263 3:screen Video 4:on2 VP6 5:on2 VP6 with alpha channel 6:screen Video Version 2 7:avc |
2.2.3 Script Data script tag generally only one, is the first tag of FLV, for storing FLV information, such as duration, Audiodatarate, creator, width and so on.
The data type of the script is described first. All data is in the form of data type + (data length) + data , the data type is 1byte, the data length depends on the existence of data type, the data is followed.
The types of data are: 0 = number Type 1 = Boolean Type 2 = String Type 3 = Object Type 4 = MovieClip Type 5 = Null type 6 = undefine D Type 7 = Reference type 8 = ECMA array type ten = Strict array type one = Date type = Long String type
If the type is string, the following 2bytes is the length of the string (long string is 4bytes), followed by the string data, and if it is number type, the following 8bytes is the data of type double, Boolean type, The back 1byte is of type bool.
Know this and then look at the script in FLV, the general beginning is 0x02, representing the string type, followed by the string length of 2bytes, generally 0x000a ("onmetadata" length), followed by the string "Onmetadata". It seems that files in FLV format have onmetadata tags, which are used when running ActionScript. followed by 0x08, which represents the ECMA array type, which is similar to map, with a key followed by a value. The keys are of type string, so the beginning of the 0x02 is omitted, followed directly by the length of the string, then the string, and then the type of the value, which is described above. 3. Summarize the format of the FLV is still relatively simple, the header part is very concise, the body part is by a Tag,tag words also on three kinds, script tag generally only one, I think this is also the reason that FLV can become the online video format. As long as we know the format, we can write a program to parse the FLV file, which is what I want to do next.