Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:AVI

From ReverseEngineering.wiki
Format
Developer Microsoft
Magic 52 49 46 46 xx xx xx xx 41 56 49 20 ("RIFF", size, "AVI ")
Extensions .avi
Endianness little
On this wiki Facts · Code · Notes · Topics

Microsoft's RIFF-based video container (.avi): RIFF form type 'AVI ' with an hdrl list (avih main header, one strl per stream), a movi list of numbered stream chunks such as 00dc and 01wb, and an idx1 index; OpenDML adds AVIX continuation RIFFs and a super index for files over 1 GiB.

Overview

AVI is a RIFF file whose form type is AVI (with a trailing space). Its top-level layout is:

  • LIST hdrl: avih (the 56-byte MainAVIHeader: microseconds per frame, max bytes per second, padding, flags, total frames, initial frames, streams, suggested buffer size, width, height, 4 reserved dwords), then one LIST strl per stream holding strh (stream header: type vids/auds/txts, handler FourCC, flags, scale, rate, start, length ...), strf (stream format: a BITMAPINFOHEADER for video, a WAVEFORMATEX for audio, see Format:RIFF WAVE#fmt chunk) and optionally strd, strn, indx; an OpenDML LIST odml with dmlh (true total frame count) may follow.
  • LIST movi: the data chunks. Chunk ids are two decimal digits of the stream number plus a two-letter type: 00dc compressed video frame, 00db uncompressed (DIB) video, 00pc palette change, 01wb audio data, 02tx text. LIST rec groups interleaved chunks.
  • idx1: an array of 16-byte entries (chunk id, flags, offset, size). Offsets are relative to the start of the movi list data in most files, but some writers use absolute file offsets, so players test both.

Flags

From FFmpeg libavformat/avi.h: main header flags AVIF_HASINDEX 0x10, AVIF_MUSTUSEINDEX 0x20, AVIF_ISINTERLEAVED 0x100, AVIF_TRUSTCKTYPE 0x800, AVIF_WASCAPTUREFILE 0x10000, AVIF_COPYRIGHTED 0x20000; stream flag AVISF_VIDEO_PALCHANGES 0x10000; index flags AVIIF_INDEX (keyframe) 0x10 and AVIIF_NO_TIME 0x100. FFmpeg limits an AVI to 100 streams and splits RIFF chunks at 0x40000000 bytes (AVI_MAX_RIFF_SIZE).

OpenDML (AVI 2.0)

Files over 1 GiB continue in additional top-level RIFF AVIX chunks, each holding another LIST movi. The stream's indx chunk is a super index pointing to per-segment standard indexes (ix00 for stream 0); idx1 then covers only the first RIFF. FFmpeg's avidec.c parses these (read_odml_index) with a recursion limit.

Codec identification

Video: the compression FourCC in strf (BITMAPINFOHEADER) and the handler in strh name the codec (DIB, MJPG, DIV3, DX50, XVID, cvid, IV50 ...). Audio: the wFormatTag of the WAVEFORMATEX. Game cutscenes in AVI frequently use an obscure FourCC for a proprietary codec; the FourCC is then the only lead.

Reversing notes

  • If idx1 is missing or damaged, scan movi for the NNxx chunk ids; pad bytes keep chunks word aligned.
  • JUNK chunks are normal: FFmpeg's AVI muxer writes a zero-filled JUNK chunk before LIST movi as padding for tag editing (default 1016 bytes when no padding is requested, avienc.c ~lines 584-590) and a JUNK placeholder for the OpenDML super index (indx) and odml list; its resync scan in avidec.c skips JUNK, idx1, indx and ix## chunks while searching for data. Unverified: that some other tools pad movi to a 2048-byte boundary (not found in FFmpeg); check offsets rather than assume.

Code & repositories

See Library:FFmpeg (libavformat/avidec.c, avi.h, riff.c).

  • https://github.com/FFmpeg/FFmpeg @ 7045cc9b8020ebaae156f4947baa752625056f90 · license: LGPL-2.1-or-later (declared by the contributor; GitHub's detector did not recognize LICENSE.md)
    FFmpeg libavformat demuxers: riff.c (wFormatTag and FourCC tables), wavdec.c, avidec.c/avi.h, matroska.h (element ids), id3v2.h, isom.h/mov.c.
    Tested on: source read, not run: Read riff.c tag table, wavdec.c probe, avi.h, matroska.h and id3v2.h at this commit (sparse checkout). Not built. · checked 2026-10-18