“I want to play an avi video format file in browsers using HTML5 video code. Since the avi format file doesn't play in browsers i have to convert it into mp4 format file. For conversion i am using the ffmpeg code in Windows, and the command I used is ‘ffmpeg -i input.avi OUTPUT.mp4’. The conversion of video is completed but the video codec and audio codec isn't valid thus it fails to play to play using video tag in html5. what’s wrong with this command? Please help me with this.”

Many people have tried to use FFmpeg to convert video files files. If you are trying to use FFmpeg to convert AVI to MP4 but unluckily failed, this guide would be helpful to you. Here we would like to show you how to convert AVI to MP4 for various uses in different ways.

Part 1: AVI vs. MP4: Why convert AVI to MP4?

Why should we convert AVI files to MP4 format? AVI stands for Audio Video Interleave file, a multimedia container developed by Microsoft in 1992. This format enjoys full compatibility with Windows-based players, and other programs with related codecs. AVI files carry both audio and video data, saved with the .avi extension.

avi to mp4

MP4 is short for MPEG-4 Part 14. MP4 is a multimedia container format developed by Moving Picture Experts Group. You can see that MP4 videos are compatible with all mobile phones, including iPhone, iPad, Android phones and tablets. Most MP4 files are saved with .mp4. But you can also see some MP4 videos in .m4a and .m4p extensions.

The below table would show you the differences between AVI and MP4 file format:

File type AVI MP4

Pros

High-quality audio fidelity; can be used to make playable DVDs; does not need special hardware or software to run; supported by many codecs

Works across multiple platforms; can contain metadata and Extensible Meta Data Platform, including subtitles; can integrate with 3D graphics and menus; versatile

Cons

Can be quite large if uncompressed; compression beyond certain limits may lead to decline in quality; does not support user interactivity; not reliable for supporting softsubs

Codec compatibility issues may result in audio drifting out of sync with video; editing requires lots of computing power since both audio and video in this format are in a single file; lossy format

Video formats supported

H.263, VC-1, MPEG-1, MPEG-2, MPEG-4, others

MPEG-2, MPEG-4, H.264

Audio formats supported

AAC, WMA, MP3, FLAC, AMR, others

AAC, ALAC

Supported codecs

DivX, XviD

MPEG-1, MPEG-2, MPEG-4, H.264/AVC, H.265/HEVC, WMV/VC-1, Real Video, Theora, MVC, VP8, and VP9

Compatible devices

Microsoft devices, Mac OS X (with extra software)

Windows, Mac, Android, iPhone, iPad, etc.

Supported media players

Windows-based media players

Almost all media players

Best for

TV, master files

Social media platforms and browsers

AVI and MP4 have their strengths and weaknesses, and they could be a deal breaker. While AVI seems to be the better media container for quality, it uses very large file sizes, hence, may require compression to smaller file formats. MP4, on the other hand, uses smaller file sizes and works with almost all media players, but has an inferior video output quality compared to AVI. However, use AVI file format for TV production and a bit of YouTube, and MP4 for everything else since MP4 is accepted by more players and devices.

Part 2: How to convert AVI to MP4 using FFmpeg for Windows

Then, how can you convert AVI to MP4 using FFmpeg? FFmpeg is a free and open-source software project that is able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. At its core is the FFmpeg program itself, designed for command-line-based processing of video and audio files. It is widely used for format transcoding, basic editing (trimming and concatenation), video scaling, video post-production effects and standards compliance (SMPTE, ITU). FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc.

To convert AVI to MP4 files using FFmpeg on Windows computer, you have to make use of the right command lines. You could follow the below steps to learn how to convert AVI to MP4 using FFmpeg in detail:

  • Step 1. Download and install the latest FFmpeg from its official website.
  • Step 2. Use libvo_aacenc instead of libfaac.
  • Step 3. Try this command line in FFmpeg for converting AVI to MP4 files: ‘ffmpeg -i input.avi -c:v libx264 -preset slow -crf 19 -c:a libvo_aacenc -b:a 128k’

When the conversion completes, you should have changed your AVI files to MP4 files without quality loss.

Part 3: How to convert AVI to MP4 using FFmpeg for Mac

As a powerful command-line tool, FFmpeg allows you to convert/stream/record video and audio file. Its advanced codec library - libavcodec ensures high portability and codec quality.

To use this open source AVI to MP4 converter for Mac, you must know some basic coding techniques. Otherwise, you won't be able to start. The installation of FFmpeg is already very complicated for technical novices.

The below steps would show you how to convert AVI to MP4 using FFmpeg on Mac:

1. Follow the tutorial to install FFmpeg on Mac.
2. Find Terminal app and initiate it.
3. Drag and drop FFmpeg to the Terminal.

avi to mp4

4. Type the command –i. Add the original AVI video into terminal. Then enter xxx(the output file name).mp4.

avi to mp4

Individual AVI file conversion: -i input.flv xxx.mp4

Batch processing multiple AVI files: for i in *.avi; do name=`echo "$i" | cut -d'.' -f1` echo "$name" ffmpeg -i "$i" "${name}.mp4" done or for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done.

5. Press the “Enter” key to transcode AVI videos to MP4 on Mac using FFmpeg.

Part 4: How to convert AVI to MP4 using FFmpeg for Linux

As mentioned above, FFmpeg is an open-source command liner tool that is available for Windows, Mac and Linux. What if you are using a Linux system? How can you convert AVI to MP4 using FFmpeg on Linux?

If you are using a Linux system, you could try the below command line to convert AVI files to MP4 on Linux:

“ffmpeg -i infile.avi youroutput.mp4”

In such case ffmpeg re-encodes elementary streams within input.avi (cahnge containers and re-encode is the default mode of ffmpeg). It's worth noticing that re-encoding might deteriorate visual and/or hearing quality. Therefore, it's recommended to disable re-encoding by "c:v copy c:a copy" codec options:

“ffmpeg -i input.avi -c:v copy -c:a copy -y output.mp4”

In this way, you could convert AVI to MP4 files using FFmpeg on Linux with merely quality loss.

Part 5: Conclusion

You could see from the above information that FFmpeg could help you convert AVI files to MP4 files on Windows, Mac, and Linux without quality loss. However, it’s quite obvious that it requires command lining knowledge for you to make full use of FFmpeg to convert AVI to MP4 or others. If you are just a regular netizen, you may find it quite complicated to use FFmpeg to convert video files. Therefore, we would like to recommend you another way to help you convert AVI file to MP4 file. That’s to make use of video converter.

Among all these video converters, Leawo Prof. Media provides you comprehensive media converter solutions to help you handle media conversions between various media types, including Blu-ray, 4K Blu-ray, DVD, video, audio, picture, and even online videos.

  • Leawo Prof. Media
  • Leawo Prof. Media 11

    An 11-in-1 All-inclusive Total Media Converter Ultimate Solution
    Convert All Media files of Video, Audio, 4K UHD Blu-ray and DVD
    Download Videos and Audios from 1000+ Sites
    Professional Photo Slideshow Maker and Burner
    Greatly Enhance Blu-ray/DVD/Video Output Effects

With Leawo Prof. Media, you could not only convert AVI to MP4 file, but also handle other media file tasks including convert 4K Blu-ray , Blu-ray, DVD, online video, up to 4K video, audio, and picture files. This powerful software can also download video from YouTube, Facebook, Veoh, VEVO, and 1000+ other video sites. No doubt it will improve your digital entertainment.