当前位置:网站首页>Flv structure description

Flv structure description

2022-06-09 01:53:00 knowledgebao

1. flv

1.1. brief introduction

  • One flv file , Every type of tag All belong to one stream ( Or audio , Or video , Or information )
  • One flv The file has at most one audio stream , A video stream , There is no case of multiple independent audio and video streams in one file .(mp4 It supports multiple audio and video )
  • flv The file format uses the big endian .

1.2. structure

  • notes : The following data type in
    • UI Represents an unsigned integer , The numbers that follow indicate the number of digits in length . such as UI8, Represents an unsigned integer , The length is one byte .
    • UI24 It's three bytes .
    • UB Represents a bit field , such as UB5 Represents a byte of 5 position .

1.2.1. The overall structure

  • The overall structure is as follows , from Header And Tag form
  • Every Tag There is a piece under the 4bytes Space , Used to record this tag The length of ( Not included tagSize The amount of 4 Bytes ), Post can be used for reverse read processing (TagHeader Li Hui records Tag The length of , It can be used for forward reading data processing ).
  • body contain Tag0Size+Tag1(Tag1Size)+…+TagN(TagNSize)
  • tagSize = 11*8(tagHeaderSize)+tagDataSize(tagHeader Are there in )
Header
Tag0Size( No, Tag0 So here is 0)
Tag1
Tag1Size
Tag2
Tag2Size
TagN(lastTag)
TagNSize(lastTagSize)

1.2.2. Header structure

FieldtypeComment
Signature UI’F’(0X46)
Signature UI8‘L’(0X4C)
Signature UI8‘V’(0x56)
edition UI8FLV Version of .0x01 Express FLV The version is 1
Keep field UB5 The top five must be 0
Is there an audio stream UB1 Whether the audio stream has a flag
Keep field UB1 Must be 0
Is there a video stream UB1 Whether there is a flag in the video stream
File header size UI32FLV The size of the head (FLV Version is 1 Fixed as 9). The size of the file header here ( Including these four bytes )

1.2.3. tag structure

FieldtypeComment
TAG type UI88: audio,9: video,18: script data( Description information ).
data size UI24 The size of the data area , barring tag head . The total size of Baotou is 11 Bytes .
Time stamp UI24 Current frame timestamp , In milliseconds . be relative to FLV The first of the files TAG timestamp . first tag The timestamp of is always 0, the truth is that dts
Timestamp extension field UI8 If the timestamp is greater than 0xFFFFFF, This byte will be used . This byte is the high of the timestamp 8 position , The upper three bytes are low 24 position .
flow IDU24 Always 0
Data area UI8[n] Distinguish by type , Including video , Audio , Description information

1.2.4. Audio data structure

FieldtypeComment
Audio format UB40: 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;10:AAC;11:Speex;14:MP3 8-Khz;15:Device-specific sound;9,12,13:reserved;
Sampling rate UB20:5.5-kHz;1:11-kHz;2:22-kHz;3:44-kHz(For AAC: always 3)
Sample size UB10:snd8Bit;1:snd16Bit. Only uncompressed formats are valid , The compression format is in accordance with 16bit Sampling processing
channel UB10: Mono ;1: stereo , Two channel .Nellymoser Must be 0,AAC Must be 1
Voice data UI8[N] If it is PCM Linear data , Every time you store 16bit Small end storage , A signed . If the audio format is AAC, The stored data is AAC AUDIO DATA( See the following for the specific format ), Otherwise, it is a linear array .

AACAUDIODATA

FieldTypeComment
AACPacketTypeU80: AAC sequence header;1: AAC raw
DataUI8[n]AudioSpecificConfig(ISO 14496-3) or Raw AAC frame data

1.2.5. Video data structure

FieldtypeComment
The frame type UB41: keyframe (for AVC, a seekable frame)——h264 Of IDR, Keyframes , Reentrant frame ; 2: inter frame (for AVC, a non- seekable frame),h264 Normal frame ; 3: disposable inter frame (H.263 only);4: generated keyframe (reserved for server use only); 5: video info/command frame( For example, whether the logo is Seek etc. )
code IDUB41: 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
Video data UI[N] Different codes , The format is different ,H263VIDEOPACKET/SCREENVIDEOPACKET/VP6FLVVIDEOPACKET/VP6FLVALPHAVIDEOPACKET/SCREENV2VIDEOPACKET/AVCVIDEOPACKET One of the structures of , Refer to the standard for details

AVCVIDEOPACKET

FieldtypeComment
AVC packet type UI80:AVC Sequence header 1:AVC NALU unit 2:AVC End of sequence ( Low level avc Unwanted )
CTSSI24 If AVC packet The type is 1, Then for cts(Composition time offset) The offset , Otherwise 0, adopt CTS and tag Medium DTS You can get PTS
data UI8[n] If AVC packet The type is 0, Is the decoder configuration ,sps,pps. If it is 1, It is nalu unit ( It can be more than one )

1.3. Relevant concepts

  • pts(presentation time stamps),dts(decoder timestamps),cts(CompositionTime)
    • pts: Display time , That is, the time when the receiver displays this frame on the display . Unit is 1/90000 second .
    • dts: Decoding time , That is to say rtp The timestamp transmitted in the packet , Indicates the decoding order . The unit is 1/90000 second .
    • cts The offset :cts = (pts - dts) / 90 .cts In milliseconds .
    • flv In file Timestamp and TimestampExtended What you spell is dts. Unit is ms.
    • CompositionTime Express PTS be relative to DTS Offset value , Display time (pts) = Decoding time (tag Of the 5~8 byte ) + CompositionTime, The unit is also ms

1.4. Reference material

  1. FLV Detailed explanation of official specification of document format
  2. Official documents
  3. flv Medium time stamp
原网站

版权声明
本文为[knowledgebao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/159/202206081557239740.html