[MultiMedia] FLV format

Vince Huang
2 min readJun 27, 2017

--

The FLV header All FLV files begin with the following header:

  • Signature(UI8): Signature byte always ‘F’ (0x46)
  • Signature(UI8): Signature byte always ‘L’ (0x4C)
  • Signature(UI8): Signature byte always ‘V’ (0x56)
  • Version(UI8): File version (for example, 0x01 for FLV version 1)
  • TypeFlagsReserved(UB[5]): Must be 0
  • TypeFlagsAudio(UB[1]): Audio tags are present
  • TypeFlagsReserved(UB[1]): Must be 0
  • TypeFlagsVideo(UB[1]): Video tags are present
  • DataOffset(UI32): Offset in bytes from start of file to start of body (that is, size of header)

The DataOffset field usually has a value of 9 for FLV version 1. This field is present to accommodate larger headers in future versions.

Example: 
0x46 0x4C 0x56 0x01 0x05 0x00 0x00 0x00 0x09 means
TypeFlagsAudio = 1
TypeFlagsVideo = 1
DataOffset = 0x00 0x00 0x00 0x09

The FLV file body After the FLV header, the remainder of an FLV file consists of alternating back-pointers and tags. They interleave as shown in the following table:

  • PreviousTagSize0(UI32): Always 0
  • Tag1(FLVTAG): First tag
  • PreviousTagSize1(UI32): Size of previous tag, including its header. For FLV version 1, this value is 11 plus the DataSize of the previous tag.
  • Tag2(FLVTAG): Second tag
  • PreviousTagSizeN-1(UI32): Size of second-to-last tag
  • TagN(FLVTAG): Last tag
  • PreviousTagSizeN(UI32): Size of last tag

FLV tags FLV tags have the following format:

  • TagType(UI8): Type of this tag. Values are: 0x8: audio, 0x9: video, 0x12: script data and all others: reserved.
  • DataSize(UI24): Length of the data in the Data field
  • Timestamp(UI24): Time in milliseconds at which the data in this tag applies. This value is relative to the first tag in the FLV file, which always has a timestamp of 0.
  • TimestampExtended(UI8): Extension of the Timestamp field to form a SI32 value. This field represents the upper 8 bits, while the previous Timestamp field represents the lower 24 bits of the time in milliseconds.
  • StreamID(UI24): Always 0.
  • Data: If TagType == 0x08 for AUDIODATA; If TagType == 0x09 for VIDEODATA; If TagType == 0x12 for SCRIPTDATAOBJECT
Example: 
0x12 0x00 0x03 0x15 0x00 0x00 0x00 0x00 0x00 0x00 0x00 means
TagType = 0x12
DataSize = 0x00 0x03 0x15
TimeStamp = 0x00 0x00 0x00
TimeStampExtend = 0x00
StreamID = 0x00 0x00 0x00

Originally published at vincewiki.blogspot.com on June 27, 2017.

--

--

Vince Huang
Vince Huang

Written by Vince Huang

A Product Owner in software company, interests include agile/scrum, machine learning and mobile design. https://www.linkedin.com/in/kuoyuhuang/

No responses yet