A video tag is a tag of type 9. After the 11-byte tag header comes the VideoTagHeader, then (in an encrypted tag) the encryption header, then the video data. If the top bit of the VideoTagHeader’s first byte is set, the tag is in the Enhanced FLV layout instead. Video tags are like SWF’s VideoFrame tag, and for the codecs SWF also has, the packets are the same as in SWF files (VP6 apart: FLV adds a byte of crop adjustments).
VideoTagHeader
| Field | Type | Meaning |
|---|---|---|
| FrameType | UB[4] | Bits 7 to 4: the kind of frame (below). |
| CodecID | UB[4] | Bits 3 to 0: the codec (below). |
| AVCPacketType | UI8 | Only when CodecID is 7: see AVC. |
| CompositionTime | SI24 | Only when CodecID is 7: see AVC. |
| FrameType | Meaning |
|---|---|
| 1 | Key frame (for AVC, a seekable frame) |
| 2 | Inter frame (for AVC, a non-seekable frame) |
| 3 | Disposable inter frame (H.263 only) |
| 4 | Generated key frame (reserved for server use only) |
| 5 | Video info/command frame (below) |
| 0, 6 to 15 | Not defined |
CodecID
| CodecID | Codec | Packet |
|---|---|---|
| 2 | Sorenson H.263 (Sorenson Spark) | H263VIDEOPACKET |
| 3 | Screen video | SCREENVIDEOPACKET |
| 4 | On2 VP6 | VP6FLVVIDEOPACKET |
| 5 | On2 VP6 with alpha channel | VP6FLVALPHAVIDEOPACKET |
| 6 | Screen video version 2 | SCREENV2VIDEOPACKET |
| 7 | AVC (H.264) | AVCVIDEOPACKET |
Adobe defines no other values. Software outside the specification uses some:
- 8: FFmpeg writes ITU-T H.263 video (with its standard picture header) here, when told to step outside the specification.
- 9: FFmpeg writes MPEG-4 Part 2 video here in the same way, with the AVCPacketType and CompositionTime bytes of AVC in front (packet type 0 for the decoder configuration, 1 for a frame).
- 12: used for HEVC by some streaming software, with AVC’s packet layout and an HEVCDecoderConfigurationRecord; FFmpeg reads it and calls it a non-standard extension that is in use. Enhanced FLV carries HEVC the registered way, by FourCC.
VIDEODATA
The video data is the VideoTagBody, or, in an encrypted tag, the EncryptedBody (the VideoTagBody encrypted; see Encryption). The VideoTagBody is the codec’s packet, chosen by CodecID, except in a video info/command frame.
Video info/command frames
When FrameType is 5, the VideoTagBody is one UI8 instead of a picture:
| Value | Meaning |
|---|---|
| 0 | Start of a client-side seeking video frame sequence |
| 1 | End of a client-side seeking video frame sequence |
Sorenson H.263 (CodecID 2)
Sorenson Spark is ITU-T H.263 with a shorter picture header, no group of blocks layer, and, in version 1, a different escape coding of coefficients. The packet, from the SWF specification:
| Field | Type | Meaning |
|---|---|---|
| PictureStartCode | UB[17] | 0000 0000 0000 0000 1, like H.263’s picture start code. |
| Version | UB[5] | 0 or 1. In version 1, after the escape code 0000 011 a format bit chooses a 7-bit (0) or 11-bit (1) LEVEL, after 1 bit of LAST and 6 bits of RUN; version 0 escapes as H.263 does. |
| TemporalReference | UB[8] | The picture number, as in H.263. |
| PictureSize | UB[3] | 0: custom size in 8 bits; 1: custom size in 16 bits; 2: 352 × 288 (CIF); 3: 176 × 144 (QCIF); 4: 128 × 96 (SQCIF); 5: 320 × 240; 6: 160 × 120; 7: reserved. |
| CustomWidth | UB[8] or UB[16] | When PictureSize is 0 or 1: the width in pixels. |
| CustomHeight | UB[8] or UB[16] | When PictureSize is 0 or 1: the height in pixels. |
| PictureType | UB[2] | 0: intra frame; 1: inter frame; 2: disposable inter frame; 3: reserved. |
| DeblockingFlag | UB[1] | Asks for the deblocking filter; advisory only. |
| Quantizer | UB[5] | The quantiser, as in H.263. |
| ExtraInformationFlag | UB[1] | 1 when a byte of extra information follows; the flag and byte repeat until a flag of 0. |
| ExtraInformation | UB[8] | When the flag is 1. |
| Macroblock | MACROBLOCK[] | The macroblocks, as in H.263 section 5.3: CodedMacroblockFlag, MacroblockType, BlockPattern, QuantizerInformation (UB[2]: −1, −2, +1, +2), MotionVectorData, three more motion vectors for INTER4V, and six blocks of coefficients (four luma, two chroma). |
| PictureStuffing | varies | As in H.263. |
Screen video (CodecID 3 and 6)
A lossless format for screen recordings. The picture is cut into a grid of blocks, 16 to 256 pixels a side in steps of 16, counted from the bottom left in rows; the last block of a row or column is partial when the image size is not a multiple of the block size. Each block’s pixels are compressed with zlib, as B, G, R bytes from the bottom row up. In an inter frame, an unchanged block is sent with a DataSize of 0.
| SCREENVIDEOPACKET field | Type | Meaning |
|---|---|---|
| BlockWidth | UB[4] | The block width: (this + 1) × 16 pixels. |
| ImageWidth | UB[12] | The image width in pixels. |
| BlockHeight | UB[4] | The block height: (this + 1) × 16 pixels. |
| ImageHeight | UB[12] | The image height in pixels. |
| ImageBlocks | IMAGEBLOCK[n] | One for each block of the grid. |
| IMAGEBLOCK field | Type | Meaning |
|---|---|---|
| DataSize | UB[16] | The size of the compressed data that follows; 0 when the block has not changed. |
| Data | UI8[DataSize] | The zlib-compressed pixels. |
Screen video version 2 (CodecID 6, Flash Player 8) adds key blocks and inter blocks, and a 15/7-bit hybrid colour space: in a decoded hybrid block, a byte with its top bit set and the next byte form a 15-bit RGB colour, and a byte with it clear indexes a 128-colour palette (sent as an IMAGEBLOCK, or else Adobe’s default palette).
| SCREENV2VIDEOPACKET field | Type | Meaning |
|---|---|---|
| BlockWidth, ImageWidth, BlockHeight, ImageHeight | UB[4], UB[12], UB[4], UB[12] | As in version 1. |
| Reserved | UB[6] | 0. |
| HasIFrameImage | UB[1] | 1 when IFrameImage follows. |
| HasPaletteInfo | UB[1] | 1 when PaletteInfo follows. |
| PaletteInfo | IMAGEBLOCK | When HasPaletteInfo: one block describing the palette. |
| ImageBlocks | IMAGEBLOCKV2[n] | Key blocks and inter blocks, from the bottom left. |
| IFrameImage | IMAGEBLOCKV2[n] | When HasIFrameImage: inter blocks to combine with the previous key blocks. |
| IMAGEBLOCKV2 field | Type | Meaning |
|---|---|---|
| DataSize | UB[16] | The size of what follows (Format, ImageBlockHeader and Data); 0 when the block has not changed. |
| Format | IMAGEFORMAT | Reserved UB[3] (0); ColorDepth UB[2] (0: 24-bit RGB, 2: 15/7-bit hybrid); HasDiffBlocks UB[1] (the data covers only some rows); ZlibPrimeCompressCurrent UB[1]; ZlibPrimeCompressPrevious UB[1] (zlib priming). |
| ImageBlockHeader | IMAGEDIFFPOSITION, IMAGEPRIMEPOSITION | When HasDiffBlocks: RowStart UI8 and Height UI8, the rows the data covers. When ZlibPrimeCompressCurrent: Block column UI8 and Block row UI8, the block that primes the zlib stream. |
| Data | UI8[] | The zlib-compressed pixels. |
Adobe does not give the layout of the palette inside PaletteInfo, nor how IFrameImage blocks are combined with the key blocks; those two parts of version 2 cannot be decoded from the published description.
On2 VP6 (CodecID 4 and 5)
VP6 frames, described by On2’s VP6 bitstream guide. In FLV each frame has a byte of crop adjustments in front; SWF files do not have it. The colour data is YUV (ITU-R BT.601). The alpha version sends a second VP6 stream, luma only, holding the alpha channel, and the colours are premultiplied by it.
| VP6FLVVIDEOPACKET field | Type | Meaning |
|---|---|---|
| HorizontalAdjustment | UB[4] | Pixels to take off the coded width; the picture shown is cropped. |
| VerticalAdjustment | UB[4] | Pixels to take off the coded height. |
| Data | UI8[n] | The VP6 frame. |
| VP6FLVALPHAVIDEOPACKET field | Type | Meaning |
|---|---|---|
| HorizontalAdjustment | UB[4] | As above. |
| VerticalAdjustment | UB[4] | As above. |
| OffsetToAlpha | UI24 | The length of the colour frame: where the alpha frame starts. |
| Data | UI8[OffsetToAlpha] | The VP6 frame of the colour channels. |
| AlphaData | UI8[n] | The VP6 frame of the alpha channel. |
A VP6 frame starts with a frame header: a bit for the frame type (0 key, 1 inter), a 6-bit quantiser and a bit saying a second partition follows; a key frame then has a 5-bit version, a 2-bit profile and an interlace bit, the second partition’s offset (UI16) when there is one or the profile is 0, and the coded and displayed size in macroblocks (four UI8: rows, columns, display rows, display columns). The rest is range-coded.
AVC (CodecID 7)
The VideoTagHeader has two more fields, and the body is an AVCVIDEOPACKET.
| Field | Type | Meaning |
|---|---|---|
| AVCPacketType | UI8 | 0: AVC sequence header. 1: AVC NALU. 2: AVC end of sequence (the lower-level end of sequence NAL unit is neither required nor supported). |
| CompositionTime | SI24 | When AVCPacketType is 1, the composition time offset in milliseconds (see ISO/IEC 14496-12, 8.15.3): the picture is shown this long after the tag’s time. Otherwise 0. |
| AVCPacketType | AVCVIDEOPACKET Data |
|---|---|
| 0 | An AVCDecoderConfigurationRecord (ISO/IEC 14496-15, 5.2.4.1): the same as the contents of an avcC box in an MP4 file. |
| 1 | One or more NAL units, each after its length; full frames are required. |
| 2 | Nothing. |
| AVCDecoderConfigurationRecord field | Type | Meaning |
|---|---|---|
| configurationVersion | UI8 | 1. |
| AVCProfileIndication | UI8 | profile_idc of the sequence parameter sets (66 Baseline, 77 Main, 88 Extended, 100 High, and so on). |
| profile_compatibility | UI8 | The constraint flags between profile_idc and level_idc in the sequence parameter sets. |
| AVCLevelIndication | UI8 | level_idc: the level times ten. |
| reserved, lengthSizeMinusOne | UB[6], UB[2] | Six 1 bits; then the size of each NAL unit’s length field, less 1 (0, 1 or 3). |
| reserved, numOfSequenceParameterSets | UB[3], UB[5] | Three 1 bits; then the number of sequence parameter sets. |
| sequenceParameterSetLength, sequenceParameterSetNALUnit | UI16, bytes | For each sequence parameter set. |
| numOfPictureParameterSets | UI8 | The number of picture parameter sets. |
| pictureParameterSetLength, pictureParameterSetNALUnit | UI16, bytes | For each picture parameter set. |
| chroma_format, bit_depth_luma_minus8, bit_depth_chroma_minus8 | UB[2], UB[3], UB[3] | For the High profiles (100, 110, 122 and 144), each after its reserved 1 bits. |
| numOfSequenceParameterSetExt, then each length and NAL unit | UI8, UI16, bytes | For the High profiles: sequence parameter set extensions. |
Each NAL unit in a packet of type 1 follows its length, which is lengthSizeMinusOne + 1 bytes long. A NAL unit’s first byte holds forbidden_zero_bit, nal_ref_idc (2 bits) and nal_unit_type (5 bits): 1 a slice, 5 an IDR slice, 6 SEI, 7 a sequence parameter set, 8 a picture parameter set, 9 an access unit delimiter and so on (see H.264).
What the viewer reads of each codec
The viewer decodes the pictures of Sorenson H.263, Screen video, Screen video 2 and On2 VP6. For the codecs below it reads the headers of every packet field by field, names each field, and lays the fields over the packet’s bytes, so that each byte belongs to one node of the tree. The headers are read by decoders shared by every format that carries these codecs; the parts they do not read are shown as labelled bytes with the reason.
| Codec | Read | Shown as bytes |
|---|---|---|
| AVC (H.264) | The configuration record and its parameter sets; every NAL unit header, sequence and picture parameter set (with VUI and HRD), slice header and SEI message; and, in I slices coded with CAVLC, the macroblock layer: mb_type, the intra prediction modes, the coded block pattern, mb_qp_delta and every residual block (the first few macroblocks of a slice are listed, the rest are read and counted). | CABAC slice data, P and B slices, MBAFF, slice groups, data partitions, SVC and MVC extensions. |
| HEVC (H.265) | The configuration record; NAL unit headers, video, sequence (with profile, tier and level, VUI, HRD, scaling lists and reference picture sets) and picture parameter sets, slice segment headers (reference picture sets, weights, entry points) and SEI messages. | The slice segment data, multilayer and 3D extensions. |
| AV1 | The configuration record; every OBU header; the sequence header; frame headers (frame size, tiles, quantisation, segmentation, loop filter, CDEF, restoration, global motion, film grain) with the reference state they need; tile group headers and tile sizes; metadata OBUs. | The tile data, the tile list OBU. |
| VP9 | Superframes and their index; the uncompressed header of every frame (colour, size, references, loop filter, quantisation, segmentation, tiles); the size of the compressed header and the tile sizes. | The compressed header and the tiles. |
| VP8 | The frame tag, the key frame start code and size, the boolean coded header of the first partition up to the token probability updates (segmentation, loop filter, partition count, quantiser indices, reference refresh flags), and the layout of the DCT partitions. | The rest of the first partition and the DCT tokens. |
| MPEG-4 Part 2 (CodecID 9) | Visual object sequence, visual object and video object layer headers (in the configuration packet and in key frames), group of VOP headers and every VOP header to the motion vector f_codes. FFmpeg writes frames into FLV as units after a 4-byte length, without the 00 00 01 prefix; the viewer reads that and plain start code streams. | The macroblock data, complexity estimation headers, sprites’ trajectories. |
| ITU H.263 (CodecID 8) | The picture header: start code, temporal reference, PTYPE (or PLUSPTYPE with OPPTYPE and MPPTYPE), custom picture format, quantiser and the extra insertion bytes. | Group of blocks and macroblock data; PB, B and enhancement picture fields. |