You are here: osflash » flv

FLV File Format

A Flash Video file (.FLV) consists of a short header, and then interleaved audio, video, and metadata packets. The audio and video packets are stored very similarly to those in SWF, and the metadata packets consist of AMF data.

FLV Header

Field Data Type Example Description
Signature byte[3] “FLV” Always “FLV”
Version uint8 “\x01” (1) Currently 1 for known FLV files
Flags uint8 bitmask “\x05” (5, audio+video) Bitmask: 4 is audio, 1 is video
Offset uint32_be “\x00\x00\x00\x09” (9) Total size of header (always 9 for known FLV files)

FLV Stream

Following the header is a stream of tags until EOF.

Field Data Type Example Description
PreviousTagSize uint32_be “\x00\x00\x00\x00” (0) Total size of previous tag, or 0 for first tag
Type uint8 “\x12” (0×12, META) Determines the layout of Body, see below for tag types
BodyLength uint24_be “\x00\x00\xe0” (224) Size of Body (total tag size - 11)
Timestamp uint24_be “\x00\x00\x00” (0) Timestamp of tag (in milliseconds)
Padding byte[4] “\x00\x00\x00\x00” Reserved?
Body byte[BodyLength] ... Dependent on the value of Type

FLV Tag Types

Tag code Name Description
0×08 AUDIO Contains an audio packet similar to a SWF SoundStreamBlock plus codec information
0×09 VIDEO Contains a video packet similar to a SWF VideoFrame plus codec information
0×12 META Contains two AMF packets, the name of the event and the data to go with it

FLV Tag 0x08: AUDIO

The first byte of an audio packet contains bitflags that describe the codec used, with the following layout:

Name Expression Description
soundType (byte & 0×01) » 0 0: mono, 1: stereo
soundSize (byte & 0×02) » 1 0: 8-bit, 2: 16-bit
soundRate (byte & 0x0C) » 2 0: 5.5 kHz, 1: 11 kHz, 2: 22 kHz, 3: 44 kHz
soundFormat (byte & 0xf0) » 4 0: Uncompressed, 1: ADPCM, 2: MP3, 5: Nellymoser 8kHz mono, 6: Nellymoser

The rest of the audio packet is simply the relevant data for that format, as per a SWF SoundStreamBlock

FLV Tag 0x09: VIDEO

The first byte of a video packet describes contains bitflags that describe the codec used, and the type of frame

Name Expression Description
codecID (byte & 0x0f) » 0 2: Sorensen H.263, 3: Screen video, 4: On2 VP6
frameType (byte & 0xf0) » 4 1: keyframe, 2: inter frame, 3: disposable inter frame

In some cases it is also useful to decode some of the body of the video packet, such as to acquire its resolution (if the initial onMetaData META tag is missing, for example).

TODO: Describe the techniques for acquiring this information. Until then, you can consult the flashticle sources.

FLV Tag 0x12: META

The contents of a meta packet are two AMF packets. The first is almost always a short uint16_be length-prefixed UTF-8 string (AMF type 0×02), and the second is typically a mixed array (AMF type 0×08). However, the second chunk typically contains a variety of types, so a full AMF parser should be used.

HTTP Streaming

It is possible to semi-stream flv over http using a trick which sends the normal headers then skips forward to a desired point in the file and moves the timestamps forward accordingly.

The FLV Metadata injector is a free closed-source tool which can inject this information into a FLV file. A sample php script and fla is available at FlashComGuru

Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
About - Site design by Aral Balkan, based on the original design by Nicolas Coevoet. OSFlash © 2005 Aral Balkan.
OSFlash, the OSFlash logo and mascot are trademarks of Ariaware Limited.

You are here: osflash » flv OSFlash footer graphic (graffiti).