AVI is a container from the late 1990s that refuses to die. Old camcorder clips, ripped DivX/Xvid movies, MJPEG captures, and screen recordings from legacy tools all still land on hard drives as .avi files — and modern phones, browsers, and editors rarely play them cleanly. Converting AVI to MP4 fixes that. In most cases the safest path is a re-encode to H.264 + AAC, but in a few lucky situations you can change only the container. This guide shows both, and how to tell them apart.
Tested with: FFmpeg 8.1
What You’ll Learn
- What’s actually inside an AVI (DivX/Xvid/MJPEG and friends)
- The one command that converts virtually any AVI to MP4
- When stream-copy works — and when it doesn’t
- Choosing a CRF value for quality vs. size
- Fixing old AVI audio (MP3, PCM, AC-3)
- Deinterlacing camcorder footage
- Troubleshooting
- FAQ
1. What’s Inside an AVI
AVI is just a container. The codecs inside vary wildly depending on the era and the tool that created the file:
| Common video codec | Era / source | MP4-compatible? |
|---|---|---|
| DivX / Xvid (MPEG-4 ASP) | Ripped movies, 2000s | Sometimes (needs care) |
| MJPEG | Old cameras, capture cards | No |
| Cinepak, Indeo, MS-MPEG4 | 1990s clips | No |
| H.264 in AVI (rare) | Some capture tools | Yes (copyable) |
| Common audio codec | MP4-compatible? |
|---|---|
| MP3 | Yes (copyable) |
| PCM (uncompressed) | No (re-encode) |
| AC-3 | Yes in MP4, but re-encode for safety |
Because the mix is unpredictable, re-encoding to H.264 + AAC is the reliable default — it produces a file that plays everywhere regardless of what the original AVI contained.
2. The One Command for (Almost) Any AVI
This re-encodes both video and audio and makes the file web-ready:
ffmpeg -i input.avi -c:v libx264 -crf 23 -c:a aac -b:a 192k -movflags +faststart output.mp4
-c:v libx264… encode video as H.264, the most compatible codec-crf 23… constant-quality target (lower = better quality, bigger file)-c:a aac -b:a 192k… re-encode audio to AAC; 192k suits the MP3 audio common in AVIs-movflags +faststart… move the moov atom to the front for instant streaming
This handles DivX, Xvid, MJPEG, PCM, and MP3 inputs alike.
3. When Stream-Copy Works (and When It Doesn’t)
If your AVI already contains MP4-compatible codecs — most reliably H.264 video + MP3 or AAC audio — you can change the container without re-encoding. This is instant and lossless:
ffmpeg -i input.avi -c:v copy -c:a copy -movflags +faststart output.mp4
When this works, the conversion finishes in a second or two and the quality is untouched.
It may fail, or produce a poorly compatible file, when:
- The video is DivX/Xvid (MPEG-4 ASP). FFmpeg can often stream-copy this into MP4 (stored as
mp4v), but many modern players and devices handle it poorly — re-encoding to H.264 is the more reliable choice. - The video is MJPEG, Cinepak, or Indeo — these don’t belong in MP4 reliably.
- The audio is PCM — MP4 doesn’t carry raw PCM cleanly.
To check what’s inside before deciding:
ffprobe -hide_banner input.avi
Look at the Video: and Audio: lines. Video: h264 + Audio: mp3/aac is the cleanest copy case. DivX/Xvid (mpeg4) can often be copied too (stored as mp4v), though re-encoding to H.264 is more compatible. For MJPEG, Cinepak, Indeo, or PCM audio, re-encode with Section 2.
A common middle ground: copy the video but re-encode only the audio.
ffmpeg -i input.avi -c:v copy -c:a aac -b:a 192k -movflags +faststart output.mp4
This works when the video is already H.264 but the audio is PCM or another incompatible format.
4. Choosing a CRF Value (Quality vs. Size)
CRF controls the quality/size balance during re-encoding:
| CRF | Visual quality | Typical use | File size |
|---|---|---|---|
| 18 | Visually lossless | Preserving rare footage | Large |
| 20 | Excellent | Family videos worth keeping | Medium-large |
| 23 | Very good (default) | General conversion | Medium |
| 26 | Good | Casual viewing | Small |
Old AVIs are often low-resolution (640×480 or smaller), so even a low CRF produces a small file. For cherished footage, prefer CRF 18–20:
ffmpeg -i input.avi -c:v libx264 -crf 18 -preset slow -c:a aac -b:a 192k -movflags +faststart output.mp4
Re-encoding a DivX/Xvid source to H.264 at CRF 20 usually keeps the same visual quality at a similar or smaller file size, because H.264 is more efficient than MPEG-4 ASP.
5. Fixing Old AVI Audio
AVI audio is frequently the source of trouble:
- MP3 audio is fine to copy (
-c:a copy) into MP4, but re-encoding to AAC at 192k maximizes player compatibility. - PCM audio must be re-encoded; it cannot stream-copy into MP4.
- AC-3 audio can stay, but re-encoding to stereo AAC avoids decode issues on phones.
A safe audio normalization that downmixes to stereo AAC:
ffmpeg -i input.avi -c:v libx264 -crf 20 -c:a aac -b:a 192k -ac 2 -movflags +faststart output.mp4
-ac 2 forces stereo output, which prevents “no sound” issues on devices that can’t handle surround tracks from old captures.
6. Deinterlacing Camcorder Footage
Many AVI files from MiniDV camcorders and analog capture cards are interlaced, which shows as comb-like horizontal lines on motion. Add the yadif filter to deinterlace:
ffmpeg -i input.avi -vf yadif -c:v libx264 -crf 20 -c:a aac -b:a 192k -movflags +faststart output.mp4
-vf yadif produces a clean progressive video. If motion still looks slightly soft, that’s normal — interlaced sources lose a little detail when deinterlaced.
7. Troubleshooting
Error 1: Could not find tag for codec ... in stream
Cause: You tried -c:v copy on a video codec the MP4 muxer doesn’t accept (such as MJPEG, Cinepak, or Indeo). DivX/Xvid can usually be copied, but other AVI codecs cannot.
Fix: Re-encode the video with -c:v libx264 (Section 2).
Error 2: Output has no sound
Cause: PCM or another incompatible audio track was copied with -c:a copy.
Fix: Re-encode audio: -c:a aac -b:a 192k.
Error 3: Video shows horizontal comb lines on motion
Cause: The source is interlaced.
Fix: Add -vf yadif to deinterlace (Section 6).
Error 4: Audio and video drift out of sync
Cause: Some old AVIs use variable frame rate or have a broken header. Fix: Force a constant frame rate during re-encode:
ffmpeg -i input.avi -r 30 -c:v libx264 -crf 20 -c:a aac -b:a 192k -movflags +faststart output.mp4
Error 5: File starts playing only after a long buffer online
Cause: Missing faststart.
Fix: Add -movflags +faststart (it’s in every command above).
FAQ
Q1. Will converting AVI to MP4 reduce quality? A. A re-encode is lossy, but at CRF 18–20 the loss is generally invisible — and because H.264 is more efficient than DivX/Xvid, you often get equal quality in a similar or smaller file. If your AVI already holds H.264 + MP3, stream-copy (Section 3) is lossless.
Q2. How do I know if I can use the fast copy method?
A. Run ffprobe input.avi. h264 + mp3/aac copies cleanly. DivX/Xvid (mpeg4) can usually be copied too (as mp4v), but H.264 re-encoding is more compatible. For other codecs (MJPEG, PCM, etc.), re-encode.
Q3. Why does my old AVI fail to play on my phone even after copying? A. The container changed but the codec didn’t. Phones don’t play DivX/Xvid/MJPEG. Re-encode to H.264.
Q4. What CRF is best for irreplaceable home videos?
A. Use CRF 18 with -preset slow to preserve as much detail as possible.
Q5. My AVI is tiny and low-resolution. Should I upscale? A. Generally no — upscaling can’t add detail. Just convert at a low CRF to preserve what’s there.
Q6. Can I batch-convert a folder of AVI files? A. Yes, with a shell loop calling FFmpeg once per file. Keep the per-file command identical to the Section 2 command.
Related Articles
- Complete Guide to Converting Video to MP4
- Complete Guide to Video Format Conversion
- Complete Guide to Compressing Video
- Remuxing MKV to MP4 Losslessly
Tested with FFmpeg 8.1 — verified with our command-check script Primary sources: ffmpeg.org/ffmpeg.html / ffmpeg.org/ffmpeg-codecs.html