How to Convert AVI to MP4
Convert AVI to MP4 by copying streams without quality loss or re-encoding to H.264 and AAC. Covers FFmpeg, HandBrake and VLC, plus how to check the output and fix common problems.
AVI and MP4 are both containers. Each one holds video and audio streams that were compressed with separate codecs, so converting an AVI file to MP4 can mean two different jobs. If the streams inside the AVI already use codecs that MP4 players handle well, such as H.264 video, you can copy them into a new MP4 container without re-encoding. This keeps the original quality and finishes quickly. If the AVI uses older or capture-oriented codecs, such as Xvid, DivX, Motion JPEG, DV or uncompressed video, the video usually needs re-encoding. That takes longer and loses some quality unless you choose your settings carefully.
Before you start
First decide where the conversion will run. Desktop tools such as FFmpeg, HandBrake and VLC media player work locally, so the file stays on your computer. An online converter uploads your file to someone else's server. Before you upload recordings of people, meetings or private spaces, read the service's own statements about storage, deletion and file size limits. You cannot verify those statements yourself, so treat them as claims rather than guarantees.
- Keep the original AVI file until you have checked the converted MP4.
- Make sure you have enough free disk space for a second file of similar or larger size.
- Choose a converter. FFmpeg is free and runs from the command line. HandBrake is free and graphical, and it always re-encodes video. VLC media player has a Convert/Save feature that can re-encode to MP4.
- Find out what is inside the AVI. Run ffprobe input.avi or open the file in MediaInfo, then note the video codec, audio codec, resolution and frame rate.
The codecs you find decide which method to use:
- H.264 video with MP3 or AAC audio: you can usually copy both streams into MP4 without re-encoding.
- H.264 video with PCM audio, or with audio your target player rejects: copy the video and convert only the audio to AAC.
- Xvid, DivX or other MPEG-4 Part 2 video: you can copy it into MP4, but re-encoding to H.264 plays on more devices.
- Motion JPEG, which many webcams and older cameras produce, DV, or uncompressed video: re-encode it.
Step-by-step instructions
Option 1: Change the container without re-encoding (FFmpeg)
- Open a terminal in the folder that contains the AVI file.
- Run: ffmpeg -i input.avi -c copy -movflags +faststart output.mp4
- If FFmpeg reports that it could not find a tag for the audio codec, the MP4 container does not support that audio. Copy the video and convert only the audio instead: ffmpeg -i input.avi -c:v copy -c:a aac -b:a 192k -movflags +faststart output.mp4
- If FFmpeg warns about packed B-frames, which is common in DivX and Xvid files, add -bsf:v mpeg4_unpack_bframes before the output file name. You can also switch to Option 2.
Copying streams changes only the container. The bitrate, resolution and frame rate stay the same, and the file size stays roughly the same. The -movflags +faststart option moves the file index to the beginning of the file, so the video can start playing in a browser before it has fully downloaded.
Option 2: Re-encode to H.264 and AAC (FFmpeg)
- Run: ffmpeg -i input.avi -c:v libx264 -crf 20 -preset medium -pix_fmt yuv420p -c:a aac -b:a 192k -movflags +faststart output.mp4
- -crf sets a target quality instead of a fixed bitrate. Lower numbers give higher quality and larger files. The libx264 default is 23, and values from about 18 to 23 are common for good-quality copies.
- -preset trades encoding speed for compression. Slower presets produce smaller files at the same quality setting.
- -pix_fmt yuv420p sets the colour format that most players and browsers support. This matters for Motion JPEG webcam recordings, which often use a colour format that leads to unplayable H.264 files if you leave it unchanged.
- If the source is interlaced, which is common with DV camcorder footage, add -vf yadif to deinterlace it.
- FFmpeg keeps the source frame rate by default. Change it only if your destination requires a specific rate.
Option 3: Use a graphical converter
In HandBrake, open the AVI file, pick a preset, set the container format to MP4, choose where to save the file and start the encode. HandBrake always re-encodes the video, so use it in the same situations as Option 2. VLC media player can also convert AVI to MP4 through its Convert/Save feature using an H.264 profile. It is convenient if VLC is already installed, but it gives you fewer quality controls, and menu labels differ between versions.
Check the output
- Run ffprobe output.mp4 or open the file in MediaInfo. Confirm that the video codec, audio codec, resolution and frame rate are what you intended.
- Compare the duration with the original. A noticeably shorter file means a stream was dropped or cut off.
- Play the start, middle and end of the file. Pay attention to audio sync near the end, where drift builds up.
- Test the file where it will actually be used, such as a browser, phone, video editor or upload platform. Whether an MP4 plays depends on the codecs inside it, not on the file extension.
- Compare file sizes. A stream copy stays about the same size. A re-encode can be larger or smaller depending on the quality setting and the source. Motion JPEG and uncompressed sources usually become much smaller.
Re-encoding cannot restore detail that the original recording lost. Converting a low-bitrate AVI with a high-quality setting only makes the file bigger.
Common problems and next steps
- The MP4 has no sound: the audio was probably PCM or another format your player does not support. Convert the audio with -c:a aac as shown in Option 1.
- The video plays in VLC but not in a browser or on a phone: VLC can play almost any codec, but other players cannot. Re-encode with Option 2 so the file uses H.264, yuv420p and AAC.
- The audio drifts out of sync: this often happens with AVI files from capture software that dropped frames. Re-encode instead of copying, and add -af aresample=async=1 to correct the audio timing.
- You see comb-like lines on moving objects: the source is interlaced. Add -vf yadif when you re-encode.
- The output is much larger than expected: raise the CRF value slightly or use a slower preset.
- You have many files to convert: on Linux or macOS, run a loop in the folder, for example: for f in *.avi; do ffmpeg -i "$f" -c copy "${f%.avi}.mp4"; done. Then check a few results before you delete any originals.
If you record AVI files regularly from a webcam, capture card or recording program, check whether it lets you choose MP4 as the recording format. Recording in the format you need from the start avoids the conversion step.