Software & AppsOperating SystemLinux

How To Convert Xvid AVI to H264 MKV or MP4 Using FFmpeg or Avconv

Ubuntu 19

In the world of digital media, there are countless video formats and codecs. Two such popular formats are AVI and MKV/MP4, and two popular codecs are Xvid and H.264. In this article, we will guide you on how to convert Xvid AVI files to H.264 MKV or MP4 files using FFmpeg or Avconv.

Quick Answer

To convert Xvid AVI files to H.264 MKV or MP4 files, you can use FFmpeg or Avconv. Both tools offer efficient methods for converting the files. You can either remux the AVI file into an MKV container using MKVToolNix, or re-encode the AVI file to H.264 MP4 using FFmpeg with specific commands.

Understanding the Basics

Before we dive into the conversion process, let’s understand the basics. AVI (Audio Video Interleave) is a multimedia container format introduced by Microsoft. Xvid is a video codec library following the MPEG-4 standard, specifically MPEG-4 Part 2 Advanced Simple Profile (ASP).

On the other hand, MKV (Matroska Video) and MP4 (MPEG-4 Part 14) are multimedia container formats, and H.264 is a video compression standard known for providing good video quality at substantially lower bit rates than previous standards.

Installing FFmpeg or Avconv

Both FFmpeg and Avconv are powerful command-line tools used for manipulating and converting multimedia data. They are almost identical, with Avconv being a fork of FFmpeg. You can install FFmpeg on Ubuntu using the following command:

sudo apt-get update
sudo apt-get install ffmpeg

Converting Xvid AVI to H.264 MKV or MP4

Method 1: Remuxing into Matroska container (MKV)

Remuxing is a process of changing the ‘container’ or ‘wrapper’ of the video file without changing the video or audio streams. Here’s how you can do it:

  1. Install MKVToolNix: MKVToolNix is a set of tools to create, alter, and inspect Matroska files. You can install it using the following command:
sudo apt-get update
sudo apt-get install mkvtoolnix
  1. Open MKVToolNix GUI: Once installed, you can open the GUI and add the source AVI file.
  2. Start muxing: Set the output file name and location, then click on the “Start muxing” button. This will create an MKV file with the same video and audio streams as the original AVI file, but in a different container format.

Method 2: Re-encoding to H.264 codec (MP4)

Re-encoding is a process of converting the video or audio codec. Here’s how you can re-encode Xvid AVI to H.264 MP4:

ffmpeg -i input.avi -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4

Let’s break down the command:

  • -i input.avi: This specifies the input file, which is an AVI file in our case.
  • -c:v libx264: This sets the video codec to H.264 using the libx264 library.
  • -crf 23: This sets the Constant Rate Factor (CRF) for video quality. Lower values result in higher quality, but larger file sizes. A value of 23 is a good starting point.
  • -preset medium: This sets the encoding speed and compression efficiency. The “medium” preset provides a good balance between speed and quality.
  • -c:a aac -b:a 128k: This sets the audio codec to AAC with a bitrate of 128kbps.
  • output.mp4: This specifies the output file, which is an MP4 file in our case.

Conclusion

Converting Xvid AVI files to H.264 MKV or MP4 files can be done efficiently using FFmpeg or Avconv. While remuxing is a quick process that doesn’t affect the quality, re-encoding gives you more control over the output quality and file size. Choose the method that best suits your needs and follow the steps provided in this guide.

Remember, while working with command-line tools, always be cautious as incorrect commands can lead to data loss. It’s always a good idea to keep a backup of your original files before starting the conversion process.

What is the difference between AVI and MKV/MP4?

AVI is a multimedia container format introduced by Microsoft, while MKV and MP4 are also multimedia container formats. The main difference is that AVI is an older format and has more limited features compared to MKV and MP4. MKV and MP4 offer better support for various video and audio codecs, subtitles, and chapter markers.

What is Xvid?

Xvid is a video codec library that follows the MPEG-4 standard, specifically MPEG-4 Part 2 Advanced Simple Profile (ASP). It is designed to provide good video quality while maintaining reasonable file sizes.

What is H.264?

H.264, also known as AVC (Advanced Video Coding), is a video compression standard. It is widely used and known for providing good video quality at substantially lower bit rates than previous standards. H.264 is supported by most modern devices and platforms.

What is FFmpeg?

FFmpeg is a powerful command-line tool used for manipulating and converting multimedia data. It supports a wide range of audio and video formats, codecs, and filters.

What is Avconv?

Avconv is a fork of FFmpeg and is also a command-line tool used for manipulating and converting multimedia data. It shares many similarities with FFmpeg and can perform similar tasks.

Can I use FFmpeg or Avconv on Windows or macOS?

Yes, both FFmpeg and Avconv can be used on Windows and macOS, in addition to Linux. You can download the binaries or build them from source for your specific operating system.

What is remuxing?

Remuxing is a process of changing the ‘container’ or ‘wrapper’ of a video file without altering the video or audio streams. It simply repackages the existing streams into a different container format, such as converting an AVI file to an MKV file.

What is re-encoding?

Re-encoding is a process of converting the video or audio codec. It involves decoding the original streams and then encoding them using a different codec. In the context of converting Xvid AVI to H.264 MKV or MP4, re-encoding refers to converting the Xvid video codec to the H.264 video codec.

What is the Constant Rate Factor (CRF) in FFmpeg?

The Constant Rate Factor (CRF) is a parameter used in FFmpeg to control the video quality and file size of the output. A lower CRF value results in higher video quality but larger file sizes, while a higher CRF value reduces the video quality but produces smaller file sizes. A value of 23 is commonly used as a good starting point.

How can I backup my original files before starting the conversion process?

To backup your original files, you can simply make a copy of them in a separate directory or external storage device. This way, you can always revert back to the original files if needed. It’s always recommended to keep backups of important files before making any changes or conversions.

Leave a Comment

Your email address will not be published. Required fields are marked *