What Are the Advantages of FLV Format?
FLV is short for FLASH VIDEO. The FLV streaming format is a video format developed with the introduction of Flash MX. Due to the extremely small file size and fast loading speed, it makes it possible to watch video files on the Internet. Its appearance effectively solves the problem of the large size of the exported SWF file after the video file is imported into Flash. And other issues.
- Flv video files for online viewing are basically not available for download. Here are two download methods:
- FLV
- FLV is a binary file consisting of a FLV header and many tags. Tags can be divided into three categories: audio, video, and script, which represent audio streams, video streams, and script streams (keywords or file information).
- FLV file = FLV header file + tag1 + tag content 1 + tag2 + tag content 2 + ... + ... + tagN + tag content N.
FLV flv FLV header
- Generally simple, including global information such as file type
- File type 3bytes is always FLV (0x46 0x4C 0x56)
- Version 1byte is usually 0x01, which means FLV version 1
- 1 byte of the stream information is 1 to indicate that there is video, the 3rd to bottom is 1 to indicate that there is audio, others should be 0 (some software such as flvtool2 may cause the 4th to bottom bit to be 1, but nothing is wrong)
- The length of the header is 4 bytes. The length of the entire file header is usually 9 (3 + 1 + 1 + 4). Sometimes there is some other information later, not 9
- FLV header file: (9 bytes)
- 1-3: The first 3 bytes are the file format identifier (FLV 0x46 0x4C 0x56).
- 4-4: The 4th byte is the version (0x01)
- 5-5: The first 5 bits of the 5th byte are reserved and must be 0.
- 6-9: The four bytes of 6-9 are reserved. Its data is 00000009.
- The length of the entire file header, usually 9 (3 + 1 + 1 + 4)
flv file meta information
- Meta information in flv files is information describing various attributes of flv files. This information is saved in the AMF format at the beginning of the file. Adobe's official standard FLV meta-information items are as follows (Source: [1] ):
- audiochannels
- audiocodecid
- audiodatarate
- audiodevice
- audioinputvolume
- audiosamplerate
- creationdate
- duration (media files only)
- fmleversion (Flash Media Live Encoder version) (media files only)
- framerate
- height
- lastkeyframetimestamp (media files only)
- lasttimestamp (media files only)
- presetname
- videocodecid
- videodatarate
- videodevice
- videokeyframe_frequency
- width
- Two commonly used tools to manipulate metadata are flvtool2 and FLVMDI . Both use keyframes as a default meta-information item.
FLV Body flv FLV Body
- The FLV body is composed of many tags. A tag includes the following information:
- previoustagsize 4bytes The length of the previous tag, the first tag is 0
- tag type 1byte
- Three categories:
- * 8-audio tag
- * 9-video tag
- * 18-script tag
- The length of the data area is 3 bytes. The time stamp is 3 bytes. The unit is milliseconds. If it is a script tag, it is 0.
- Extended timestamp 1byte as the high bit of timestamp
- streamsID 3bytes is always 0 (don't know what to do)
- Data area
- There are different data areas according to different tag types
- Audio tag data area
- audio information 1byte
- FLV
- * 0-uncompressed
- * 1-ADPCM
- * 2-MP3
- * 5-Nellymoser 8kHz momo
- * 6-Nellymoser
- The following two bits represent samplerate:
- * 0-5.5kHz
- * 1-11kHz
- * 2-22kHz
- * 3-44kHz
- The following bit represents the length of each sample:
- * 0-snd8Bit
- * 1-snd16Bit
- The following bit indicates the type:
- * 0-sndMomo
- * 1-sndStereo
- audio data area
- indefinite
- video tag data area
- video information 1byte
- The first four bits indicate the type:
- * 1-keyframe
- * 2-inner frame
- * 3-disposable inner frame (H.263 only)
- The last four bits represent the encoder id:
- * 2-Seronson H.263
- * 3-Screen video
- * 4-On2 VP6
- * 5-On2 VP6 without channel
- * 6-Screen video version 2
- video data area
- indefinite
- ScriptTagData structure (control frame)
- This type of tag is also commonly called a metadata tag, and it will put some parameter information about FLV video and audio, such as duration, width, height, etc. Usually this type of tag will appear after the File Header as the first tag, and there will be only one.
- The first 11 bytes are the first AMF packet (13 bytes) of the Tag Header structure:
- The first byte indicates the AMF packet type, which is always always 0x02, indicating a string
- The 2-3 bytes are UI16 type values, which are always 0x000A ("onMetaData" length). The following bytes are always "onMetaData". (6F, 6E, 4D, 65, 74, 61, 44, 61, 74, 61) The second AMF package:
- The first byte indicates the AMF packet type, which is always always 0x08, which indicates an array. The 2-5th byte is a UI32 type value, which indicates the number of array elements.
- The following is the encapsulation of each array element, which is a pair of element name and value. The representation method is as follows: The first 1-2 bytes represent the length of the element name, assuming L. This is followed by a string of length L. The L + 3 byte indicates the type of element value.
- Followed by the corresponding value, the number of bytes taken depends on the type of value.
tag flv tag format
- Tag type information, fixed length is 15 bytes
- 1-4: previous tag length (4 bytes), the first tag is 0
- 5-5: tag type (1 byte); 0x8 audio; 0x9 video; 0x12 script data
- 6-8: tag content size (3 bytes)
- 9-11: Timestamp (3 bytes) (ms) (the first tag is always 0, if it is a script tag, it is 0)
- 12-12: Timestamp extension (1 byte) makes the timestamp into 4 bytes (to store the flv time information for a longer time), and this byte is used as the most significant bit of the timestamp.
- During the flv playback process, the playback order is played in the time stamp order of the tag. Any time setting data format added to the file will be ignored.
- 13-15: streamID (3 bytes) is always 0