Introduction
An .h264 or .264 file holds H.264 video exactly as an
encoder produced it, with no container around it. H.264, also called AVC or MPEG-4
Part 10, is defined by ITU-T H.264 and ISO/IEC 14496-10, and is the most widely used
video codec. The byte stream layout these files use is described in Annex B of the
standard, which is why they are often called Annex B streams.
The file has no audio, no index and usually no timestamps, so a player has to be told the frame rate. Raw streams are used to test encoders and decoders, and as an intermediate step before the video is put into an MP4 or MKV file.
Structure
The stream is a sequence of NAL units (network abstraction layer units). Each one is
preceded by a start code, the bytes 00 00 01 or 00 00 00 01.
To keep a start code from appearing inside a unit by accident, the encoder inserts an
emulation prevention byte 03 after any two zero bytes that would otherwise
be followed by a byte of 03 or less.
The first byte of each NAL unit is its header: one forbidden bit that is always zero,
two bits of nal_ref_idc giving its importance, and five bits of
nal_unit_type. The common types are 7, the sequence parameter set with
the profile, level and frame size; 8, the picture parameter set; 5, a slice of an IDR
frame, where decoding can start; 1, a slice of any other frame; 6, supplemental
enhancement information; and 9, an access unit delimiter that marks the start of each
frame.
000 00 00 01 start code, then SPS (type 7)varies…00 00 00 01 start code, then PPS (type 8)varies…00 00 01 start code, then an IDR slice (type 5)varies…00 00 01 start code, then a slice (type 1) for each following framerepeated
Reference
- Byte stream – start codes, emulation prevention and the bit syntax
- NAL units – the header, every type from 0 to 31 and the access unit delimiter
- Sequence parameter set – every field, scaling lists, picture size and the SPS extension
- VUI and HRD – timing, aspect ratio and colour codes, and the buffering model
- Picture parameter set – every field and slice groups
- Slice header – slice types, reference list changes, weights and reference marking
- Slice data – macroblock types, prediction, coded block pattern and residual coding
- CAVLC tables – coeff_token, level, total_zeros and run_before codes
- CABAC initial values – which contexts each element uses and the (m, n) pair of ctxIdx 0 to 459
- CABAC values for 4:4:4 – the Cb and Cr contexts, ctxIdx 460 to 1023
- CABAC binarisation and contexts – the decoding engine tables, every bin string and how each bin's context is chosen
- SEI messages – framing, every payload type and the main message fields
- SEI message fields – the syntax and codes of every other Annex D message
- H.274 SEI messages – annotated regions, phase indication, processing order, encoder optimisation, source picture timing, modality and AI usage restrictions
- Profiles and levels – every
profile_idc, the constraint flags and the level table - Scalable video (SVC) – Annex F: layer header extension, subset SPS extension, slice header, profiles and SVC SEI messages
- Multiview and depth (MVC, MVCD) – Annexes G and H: view header extension, SPS extensions, list modification, profiles, SEI messages and VUI
- 3D-AVC – Annex I: depth parameter sets, SPS extension, slice header, new macroblock flags and their CABAC contexts
Not described
The reference pages follow ITU-T H.264 (06/2026, version 16), which is free to read.
Known, not yet covered
- Reference: the decoding processes of clauses 8 and 9 (prediction, transforms, deblocking, reference picture handling) and of the multi-layer Annexes F, G, H and I (SVC, MVC and MVCD, 3D-AVC), and the hypothetical reference decoder of Annex C.
- Reference: the level limit tables of Annexes F to I (F.10.2, G.10.2, H.10.2, I.10.2) and the alternative SVC parsing clauses F.9.1 to F.9.3.
- Reference: the macroblock neighbour derivations of clause 6.4 that the CABAC context rules use.
- Reference: the H.274 messages not yet written: film grain characteristics (type 64), neural-network post-filter (210, 211), digitally signed content (220 to 222) and generative face video (223, 224), see H.274 SEI messages.
- Viewer: the Pictures tab draws one frame, chosen with the Frame option (display order, from 0), decoded in the browser from the nearest IDR picture. It decodes frame pictures, MBAFF frames (macroblock pairs coded as frame or field pairs, which is what x264 writes for interlaced video) and field pictures (PAFF), also mixed in one stream, of monochrome, 4:2:0, 4:2:2 and 4:4:4 streams, also 4:4:4 with separate colour planes, at 8 to 14 bits per sample, with the Baseline, Main, High, High 10, High 4:2:2 and High 4:4:4 Predictive tools: CAVLC and CABAC, I, P and B slices, Intra 4×4, 8×8 and 16×16 and I_PCM, quarter-sample motion compensation, several reference frames with list modification, the sliding window and memory management operations 1 to 6 with long-term reference pictures, spatial and temporal direct prediction, explicit and implicit weighted prediction, the 4×4 and 8×8 transforms with scaling matrices, lossless transform bypass (with its horizontal and vertical residual prediction), and the deblocking filter. Every frame of 295 test streams (x264 output, among it its MBAFF interlaced coding with frame and field pairs next to each other, the explorer's own samples, streams whose reference marking was rewritten to use the memory management operations, and hand-written streams of field pictures and MBAFF frames that x264 cannot make, and hand-written streams of residual data at 9 to 14 bits) matches ffmpeg byte for byte, except at 11 and 13 bits, which ffmpeg refuses and whose frames match a hand-computed reconstruction instead; the three separate-colour-plane streams are checked against ffmpeg's decoding of the three monochrome streams they were made from, because ffmpeg cannot decode separate colour planes. The Video tabs of the FLV, MP4 and MPEG-TS viewers and the FLA video view draw H.264 pictures with the same decoder.
- Viewer: not decoded to pixels, with the reason on the Pictures tab: field pictures with separate colour planes, slice groups (FMO), data partitioning (NAL unit types 2 to 4), SP and SI slices, and the pixels of the scalable, multiview and 3D layers (only the base layer is drawn). A gap in frame_num (gaps_in_frame_num_value_allowed_flag 1) makes "non-existing" reference frames through the sliding window, as 8.2.5.2 says; they are never output, and a picture that predicts from one stops the decoder with the reason (the check reports it as a problem); checked against ffmpeg on one hand-written stream. Bit depths 9 to 14: no encoder here writes them (x264 and this ffmpeg make 8 and 10 bits; the code takes the depth from the sequence parameter set and has no other special case), so hand-written streams were made with a bit writer: I_PCM pictures, Intra 16x16 pictures with a DC coefficient at a high quantiser, and P pictures with a vector in every macroblock and the deblocking filter, are byte-exact with ffmpeg at 9, 12 and 14 bits; ffmpeg refuses 11 and 13 bits, whose I_PCM and skipped pictures equal the samples written. The residual (transform) path at every depth from 9 to 14 bits, with CAVLC and with CABAC, in 4:2:0, 4:2:2 and 4:4:4, is checked by 50 more hand-written streams. Thirty-two have six pictures of one Intra_16x16 macroblock each (DC prediction, deblocking off) at quantisers from QP′Y 3 up to the largest the depth allows, with levels from 1 to over 1,000 (the CAVLC level_prefix escapes and the CABAC Exp-Golomb suffix), and a luma 11 bits with chroma 13 bits pair; each decoded picture equals a reconstruction computed by hand from the equations of clause 8.5 (scaling, the DC transforms of luma and of 4:2:0 and 4:2:2 chroma, the 4×4 inverse transform, the clipping), written separately from the decoder, which also checks every range the standard puts on the intermediate values; where ffmpeg decodes the depth (9, 12 and 14) it gives the same frames. The other eighteen streams (9, 12 and 14 bits) have two pictures of 4 × 3 macroblocks (every Intra_16x16 prediction mode the neighbours allow, random chroma modes, random levels, the neighbour contexts of nC and coded_block_flag), byte-exact with ffmpeg. What remains unchecked at these depths is every other tool (inter prediction with residual, Intra 4×4 and 8×8, 8×8 transforms, scaling matrices and lossless bypass above 10 bits, field pictures): the code takes the depth from the sequence parameter set and has no other special case, and the same paths are byte-exact against ffmpeg at 8 and 10 bits. Decoded but not checked against a reference decoder, because no encoder or sample here writes them: memory management operation 4 that lowers the maximum long-term index and so drops pictures (the test streams only raise it), temporal direct prediction when the colocated picture's reference is long-term, the residual coding of field pictures (the CABAC field contexts and the field scans also run for the field macroblocks of MBAFF frames, which are checked, but no sample has a field picture with residual data: x264 writes MBAFF only, and the hand-written field pictures have I_PCM intra macroblocks and inter macroblocks without residual), a frame picture whose reference list holds a frame of which only one field is still marked as a reference (the specification leaves such a frame out and FFmpeg lists it, so no stream was compared), and a first field whose second field never comes (it is output as a frame on its own).
- Viewer: the tree lists the macroblock layer field by field for CAVLC I slices only; the slice data of CABAC slices, P and B slices, MBAFF pictures, pictures with slice groups (FMO) and data partitions is shown as raw bytes after the slice header (the Pictures tab decodes the first two kinds to pixels). Data partitioned pictures are counted but not told apart.
- Viewer: NAL unit types 14, 15, 16, 20 and 21 (SVC, MVC, 3D-AVC) are read field by field: the NAL unit header extensions of Annexes F, G and I, the prefix NAL unit with its reference base picture marking, the subset sequence parameter set with the SVC, MVC, MVCD and 3D-AVC extensions and their VUI extensions (with HRD parameters), the depth parameter set, and the slice headers of the layers and views (scalable, MVC with its view-index list modifications, 3D-AVC). Only the headers: the macroblock layers and the pixels of the scalable, multiview and 3D layers are not decoded (the Pictures tab draws the base layer, which any AVC decoder reads), and the SEI messages of Annexes F to I (types 24 to 54 and the nesting messages) are shown as sized raw bytes. Checked against the JVT MVC conformance streams (single files, nine of them, every header reads to its last bit) and hand-written SVC, MVC (with MFC), MVCD and 3D-AVC streams made with a bit writer from the syntax tables (no public single-file SVC or 3D-AVC stream was found: the JVT SVC streams are zip archives). The 3D-AVC slice header with slice_header_prediction_flag is read as the syntax table prints it, whose braces are ambiguous in this edition, and the header groups it copies from another view component are not resolved.
- Viewer: SEI messages are named for every payload type, and buffering period, picture timing, user data (registered and unregistered), recovery point, mastering display colour volume and content light level are decoded field by field, and so are the two messages of the base specification between payload types 24 and 54: frame packing arrangement (45, every field of D.1.26, with the rules of D.2.26 checked as problems: the quincunx and flag rules per packing type, the reserved values and byte, the repetition period) and display orientation (47, D.1.27; the rotation is shown in degrees). They are checked against ffmpeg’s own trace of a hand-written stream carrying eight and four of them. The other messages of 24 to 54 are specified in Annexes F (24 to 35), G (36 to 44 and 46), H (48 to 53) and I (54): the viewer names each, reads its payload type and size, and shows the payload as sized raw bytes with the annex that specifies it; their bodies are not decoded, because they describe the scalable, multiview and 3D layers, whose scope (whether SVC, MVC and 3D-AVC layers belong in this format or in a format of their own) is still to be decided. The messages of types 2, 3, 7 to 23, 56 and the H.274 ones (SEI message fields) are named and shown as sized raw bytes too.
- Viewer: the checks cover what the headers settle: start codes and zero_byte, emulation prevention, forbidden_zero_bit, reserved NAL unit types, nal_ref_idc, parameter set ranges and references, slice header ranges, the order of NAL units in an access unit, IDR and frame_num rules and the delimiter and recovery rules. The Conformance tab adds three groups. Level limits (Annex A, Tables A-1 to A-5) per sequence parameter set: MaxFS and its square-root limits, MaxDpbMbs against max_num_ref_frames and max_dec_frame_buffering, MaxBR and MaxCPB from the HRD parameters (with the factors of Table A-2), the frame_mbs_only_flag and direct_8x8_inference_flag rules, the nominal macroblock rate (MaxMBPS) from the VUI timing, and per access unit (from the CPB removal times, or the nominal period of a fixed frame rate) the macroblock rate, MinCR and the slice rate of A.3.3; while it decodes, the vertical and horizontal motion vector range, MaxMvsPer2Mb, the bits of a macroblock_layer (CAVLC: its syntax; CABAC: the read_bits(1) calls of 9.3.3.2.2 and 9.3.3.2.3 while it is parsed, as A.3.1 n and A.3.2 j define them, and against max_bits_per_mb_denom of the VUI, E-80), the bin count of every CABAC picture against (32 ÷ 3) × NumBytesInVclNALunits + RawMbBits × PicSizeInMbs ÷ 32 (7.4.2.10; the decoder counts every DecodeBin call: decisions, bypass bins and terminating bins), the bytes of a picture against max_bytes_per_pic_denom (E-79; both VUI limits take the value the standard infers when the VUI does not say), MinLumaBiPredSize, MaxSubMbRectSize and the macroblocks in a slice. The counts are checked against the encoder that wrote 90 hand-written CABAC pictures (its bins, and its bits less the 9 the decoder reads to start, equal the decoder’s counts) and against 1,456 CABAC slices of x264 and hand-written streams, each read to its last bit (the count of read_bits(1) calls ends exactly at the end of the slice). For a separate-colour-plane picture the three planes count as one picture of three times the macroblocks (the standard does not say; the reading is the one that gives the same limit per macroblock). The hypothetical reference decoder (Annex C): with HRD parameters, timing information, a buffering period message and picture timing messages, the CPB model of C.1 and C.3 for every schedule (arrival and removal times, CPB overflow and underflow, the initial_cpb_removal_delay limits), and the DPB with output times (C.2); always, the output order DPB of C.4 with bumping, which finds a stream that cannot be output in order with the frame buffers it declares or that holds more reference frames than there are buffers (a field pair counts as one frame buffer, ordered by its first field). Reference lists, by running the decoder (without drawing: no prediction, motion compensation or inverse transform, so it reads every syntax element and vector at about 100,000 to 250,000 macroblocks per second in the test runs) over every picture of the stream or of a window of it: the Check option reads the whole stream (whatever its size) or one window of about 250,000 macroblocks, a run of IDR periods that the decoder can start at with the parameter sets that came before it; automatically a stream of up to 250,000 macroblocks is read whole and a larger one is read from window 1, and the Conformance tab says how many macroblocks were read of how many the stream has, the window, and the speed. A ref_idx past its list, an entry of the list with no picture that a macroblock selects, a modification naming a picture that is not there, a P or B slice with no reference picture, and a "non-existing" frame of a gap in frame_num used for prediction. Not checked: the limits and HRD of the scalable, multiview and 3D profiles (Annexes F to I), the references of layers and views other than the base layer, and, in a window, the part of the stream outside it (the Conformance tab says which window was read; a stream that is one single IDR period is one window, so it can only be read whole); the HRD runs on the first sequence parameter set's VUI.
Links
Software
- FFmpeg and ffplay – command-line tools that play, write and wrap raw H.264 streams (Windows, macOS, Linux)
- VLC media player – free media player that plays raw H.264 files (Windows, macOS, Linux)
- mpv – free, minimal media player (Windows, macOS, Linux)
- x264 – free H.264 encoder that can write raw streams (Windows, macOS, Linux)
- GPAC and MP4Box – tools that put raw streams into MP4 (Windows, macOS, Linux)
Developers
- libavcodec – FFmpeg’s codec library, which decodes and encodes H.264 (C)
- libx264 – the x264 encoder as a library (C)
- OpenH264 – Cisco’s open H.264 encoder and decoder (C++)
Reference
- ITU-T Recommendation H.264 – the standard, with the byte stream format in Annex B
- RFC 6184 – RTP payload format for H.264, with the NAL unit header and profile-level-id
- RFC 6190 – RTP payload format for SVC, with the NAL unit header extension
- cbs_h264_syntax_template.c – FFmpeg’s field-by-field syntax of the parameter sets and slice header