Convert MP4 to AVI Using FFmpeg on Linux
This guide provides a straightforward, step-by-step walkthrough on how to convert an MP4 video file to the AVI format using FFmpeg on a Linux system. You will learn the basic command for a quick conversion, how to preserve video quality, and how to batch-process multiple files at once. Whether you are a terminal beginner or looking for advanced optimization flags, these examples will help you handle your video conversions efficiently.
Installing FFmpeg on Linux
Before converting your files, you need to ensure FFmpeg is installed
on your system. You can verify this by opening your terminal and running
ffmpeg -version. If it is not installed, use the
appropriate package manager for your Linux distribution:
- Ubuntu/Debian:
sudo apt update && sudo apt install ffmpeg - Fedora:
sudo dnf install ffmpeg - Arch Linux:
sudo pacman -S ffmpeg
The Basic Conversion Command
The simplest way to convert an MP4 file to AVI is to let FFmpeg automatically select the default codecs based on the file extension. Open your terminal, navigate to the folder containing your video, and run the following command:
ffmpeg -i input.mp4 output.avi
In this command, -i specifies the input file
(input.mp4), and the final argument is the desired name of
your output file (output.avi). FFmpeg will read the
container and convert the streams automatically.
Converting with High Quality (Re-encoding)
The default conversion might sometimes compress the video too much,
resulting in a loss of quality. To maintain high visual quality, you can
use the H.264 video codec and the MP3 or PCM audio codec inside the AVI
container. The Constant Rate Factor (-crf) flag controls
the quality, where a lower number means better quality (18 to 23 is
usually the sweet spot).
ffmpeg -i input.mp4 -c:v libx264 -crf 20 -c:a libmp3lame -q:a 2 output.avi
-c:v libx264: Sets the video codec to H.264.-crf 20: Adjusts the video quality (lower equals better).-c:a libmp3lame: Sets the audio codec to MP3.-q:a 2: Sets a high variable bitrate for the audio.
Remuxing Without Re-encoding (Fast Method)
If your MP4 file already uses video and audio codecs that are compatible with the AVI container, you can copy the streams directly without re-encoding them. This process is incredibly fast because it skips the heavy math of compression and simply changes the “wrapper.”
ffmpeg -i input.mp4 -c copy output.avi
Using -c copy will complete the conversion in a matter
of seconds, saving both time and CPU power while preserving 100% of the
original quality.
Batch Converting Multiple MP4 Files
If you have a directory full of MP4 files, converting them one by one
is tedious. You can use a simple Bash for loop in your
Linux terminal to automate the process and convert every MP4 file in the
current directory to AVI format.
for f in *.mp4; do ffmpeg -i "$f" "${f%.mp4}.avi"; done
This loop takes every file ending in .mp4, strips the
extension using ${f%.mp4}, appends .avi to the
filename, and processes them sequentially without overwriting your
original files.