FLV file format (z)

Source: Internet
Author: User
Tags flv file

I was just reading some things about Demux. When I was dealing with files in the FLV format, I had no idea about the format of the FLV file, so I compared cloud head-to-head, I saw an article about the FLV file format. I wrote it quite clearly, so I turned around. O (distinct _ distinct) O ~
The FLV header file is simple and consists of nine bytes.

0-3: The first three bytes are the file format identifier (FLV 464c56 ).
4-4: 4th bytes (0x01)
5-5: The first five bits of the 5th bytes are reserved and must be 0.
5th bits of 6th bytes (typeflagsaudio)
The 5th bits of the 7th bytes are also reserved and must be 0.
5th-byte 8th-bit video type mark (typeflagsvideo)
6-9: The four bytes from 6 to 9 are retained. The data is 00000009.

The file content starts from 4 bytes of 0 and marks the size of the previous tag (because the previous tag is empty, the size is 0 ). then there are 1st tags in the FLV file. The tag type is 1 byte, including 8 audio, 9 video, 18 (0x12) script data, and others are retained. Each tag has its own type.
1: for example, data tag

Data tags is called by netstream in Flash Player. the content of a meta package consists of two AMF packages. the first one (AMF Type 0x02) is basically composed of 2 bytes with String Length + string, and the second one (AMF Type 0x08) is composed of an array, each element in the array is composed of different types. (The SWF file format uses 8-bit, 16-bit, 32-bit, 64-bit, signed, and unsigned integer types. all integer values are stored in the SWF file by using little-Endian byte order. FLV files, unlike SWF files, store multibyte integers in big-Endian byte order .)
Basic data tags format:
/*---------------------------
Tag Type 0x12
Tag size 3 bytes
Timestamp 3 bytes
Timestamp is extended by 1 byte
The three bytes of streamid are always 0.
DATA tag data
---------------------*/

DATA tag data composition (name + data ):
/*--------------------------------------
Object Name: 2 bytes name size
Object Data:
Data Type 1 byte
0 = Number Type
1 = Boolean Type
2 = string type
3 = Object Type
4 = movieclip type
5 = NULL type
6 = undefined type
7 = reference type
8 = ECMA array type
10 = strict array type
11 = date type
12 = long string type

Array Length
If type = 8, 4 bytes of data size

Data Value: If type = 0, double (8 bytes of double data)
If type = 1, ui8
If type = 2, 2-byte string
If type = 3, object data [N]
If type = 4, scriptdatastring defines the movieclip path
If type = 7, ui16
If type = 8, the end mark of the Data variable [ecmaarraylength] Is 000009.
If type = 10, data variable [N]
If type = 11, date type
If type = 12, 4-byte string

Data end if type = 3, object data end mark object and array End mark
If type = 10, array End mark

The date type is composed of the following: the datetime type of the time value starts from Jan 1, 1970 UTC in 8 bytes in milliseconds.
Time Offset local time zone and standard time minute offset
--------------------------------------------------*/
The data analysis in is as follows:
0x12 data tag type flag.
000152 data tag length
000000 Timestamp
00 timestamp Extension
000000 Stream ID

0x02 Data Object Type flag
Length of 000a Object Name
6f6e4d65746144617461 Object Name (onmetadata)
08 type flag of the second AMF. Data Array
Length of the 000e Array
Length of 000d Object Name
617564696f6461746172617465 Object Name (audiodatarate)
00 double type data mark
404c354dda204355 double data value

2: for example Video tag
Basic video tags format:
/*---------------------------
Tag data size three bytes of video data size
Tag timestamp 3-byte tag data application time (MS)
The tag timestamp expands the timestamp of 1 byte to 4 bytes, and the current byte is used as the high timestamp.
3-byte streamid class ID, always 0
Video tags data
--------------------------------------------*/

Video tags data:
/*----------------------------

Frame Type 4bit
1: Key Frame keyframe (the key frame in the video stores the complete data of the entire image and can be extracted to generate images)
2: inter frame of the intermediate frame (the State between key frames and incomplete image data must be generated based on the data of the previous frame)
3: any intermediate frame disposable inter frame (H.263 only)

Video Encoding ID 4bit
2: Sorenson H.263 (the video encoding used for mencoder conversion)
3: screen video
4: on2 VP6
5: on2 VP6 with alpha channel
6: screen video version 2

Video data
If codecid = 2
H263videopacket
If codecid = 3
Screenvideopacket
If codecid = 4
Vp6flvvideopacket
If codecid = 5
Vp6flvalphavideopac
Ket
If codecid = 6
Screenv2videopacket

3: for exampleAudio tag
Basic audio tags format:
/*---------------------------
Tag data size 3 bytes audio data size
Tag timestamp 3-byte tag data application time (MS)
The tag timestamp expands the timestamp of 1 byte to 4 bytes, and the current byte is used as the high timestamp.
3-byte streamid class ID, always 0
// Configure //-----------------------------------------------------------------------------------------------------------
Audio tags data:
The composition of audio format data is as follows:
The 4-Bit 0 audio format is uncompressed. 1 is ADPCM, 2 is MP3, 5 is nellymoser 8 kHz, and 6 is nellymoser.
Audio rate 2bit 0 = 5.5 kHz
1 = 11 kHz
2 = 22 kHz
3 = 44 kHz
Audio size 1bit 0 = snd8bit
1 = snd16bit
Audio type 1bit 0 = sndmono
1 = sndstereo
The size of the audio data in 1 byte. Different audio data formats

Nellymoser 8 kHz is a special type-8 KHz sampling rate is not supported in other formats. when the audio format is nellymoser 8 kHz mono, the sound rate and sound type are ignored. for other nellymoser sampling rates, the audio format and audio frequency are as usual.
References:
Explanation of the FLV File Format: www.roading.net/blog/post_102.html
FLV resources: blog.csdn.net/everlastinging/archive/2007/12/15/1939117.aspx
SWF and FLV file format specification License Agreement (FLV format document download): www.adobe.com/licensing/#/fileformat/license/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.