# AVI

Canonical URL: https://encode.wiki/containers/avi/
Content version: ca42e61ede0a24f789d7287a0001244ad22f4abf
Status: current
License: CC BY-SA 4.0
Checksum (SHA-256): be7ab6d988b5ff764a297aaebc6b3d3fc16812939572fa1c77450c3dd4d18baf

AVI (Audio Video Interleave) is a RIFF-based container Microsoft introduced in 1992. It was the standard for DivX/Xvid files and old camcorders, and a great deal of legacy material is still stored in it. It works for playback of those files, but it is a poor target for anything new: use [MKV](/containers/matroska/) or [MP4](/containers/mp4/).

## What AVI cannot do well

- **No timestamps.** AVI stores a fixed frame rate in the stream header and each chunk is just "the next frame". There is no presentation time per frame.
- **Variable frame rate** therefore has to be faked by inserting empty "dropped frame" chunks, or it is lost. Footage from phones and screen recorders often breaks, drifts, or gets retimed when put in AVI.
- **B-frames** are a problem for the same reason: a decoder cannot derive presentation order from timestamps that are not there. MPEG-4 ASP (DivX/Xvid) used a "packed bitstream" workaround, which can confuse some remuxers; H.264 in AVI is non-standard, and many players mishandle it. Avoid B-frames in AVI-bound encodes, or better, do not use AVI.
- **Limited codecs and features.** AVI has no standard place for modern codecs, multiple audio languages, subtitles (beyond non-portable hacks), chapters, or HDR/colour metadata. AAC and Opus audio are not reliably supported, and the format predates VBR audio, so VBR MP3 in AVI often seeks badly.
- **Size.** Original AVI files are limited to 2 GB. The OpenDML extension (also called AVI 2.0) lifts that limit and is written by current tools, but very old players do not read it.

## Convert AVI to MKV or MP4

If the streams are acceptable to the target, copy them:

```sh
ffmpeg -i input.avi -c copy output.mkv
ffmpeg -i input.avi -c copy output.mp4
```

Old AVI files commonly contain MPEG-4 ASP (DivX/Xvid), MP3 or AC-3, which can be stream-copied to either container. Two things go wrong with B-frame files:

- FFmpeg stops with "Can't write packet with unknown timestamp" because the AVI has no presentation times. Add `-fflags +genpts` before `-i` so FFmpeg generates them: `ffmpeg -fflags +genpts -i input.avi -c copy output.mkv`. `mkvmerge -o output.mkv input.avi` handles these files without extra options.
- If FFmpeg warns about "packed B-frames" (the DivX/Xvid packed bitstream), add `-bsf:v mpeg4_unpack_bframes` to store them normally.

If the remux shows A/V desync or stuttering, the timing was damaged in the AVI; re-encoding the video usually fixes it:

```sh
ffmpeg -i input.avi -c:v libx264 -crf 20 -c:a aac -b:a 192k output.mp4
```

Re-encoding lossy sources such as DivX adds a generation of loss, so use a low CRF and only when you have to. Do not use AVI to hold new H.264/HEVC/AV1 content. The one place AVI is still reasonable is uncompressed or lossless intermediates (for example Lagarith or UT Video from old Windows tools), but those fit just as well in MKV.
