Convert WAV to MP3 with FFmpeg in Linux

This article provides a quick overview and a straightforward guide on how to convert a WAV audio file to the MP3 format using the powerful FFmpeg command-line tool in Linux. You will learn the basic command for a quick conversion, as well as advanced options for adjusting audio quality, bitrate, and handling multiple files simultaneously.

The Basic Conversion Command

To convert a WAV file to an MP3 file using FFmpeg, you only need a simple command structure. Open your terminal and run the following:

ffmpeg -i input.wav output.mp3

In this command:

Controlling Audio Quality and Bitrate

By default, FFmpeg will choose a standard bitrate, but you can manually control the quality of your output MP3 file using either a Constant Bitrate (CBR) or a Variable Bitrate (VBR).

Constant Bitrate (CBR)

If you want to ensure a specific, consistent audio quality, use the -b:a flag followed by the desired bitrate (such as 128k, 192k, or 320k for the highest quality):

ffmpeg -i input.wav -b:a 320k output.mp3

Variable Bitrate (VBR)

For better compression efficiency, you can use VBR by using the -q:a flag. The scale ranges from 0 to 9, where 0 represents the highest quality and 9 represents the lowest:

ffmpeg -i input.wav -q:a 2 output.mp3

Note: A VBR setting of -q:a 2 generally results in a bitrate of around 170-210 kbps, which provides an excellent balance between file size and audio fidelity.

Batch Converting Multiple Files

If you have an entire directory of WAV files that you need to convert to MP3 at once, you can use a simple for loop in your Linux terminal:

for file in *.wav; do
    ffmpeg -i "$file" -b:a 192k "${file%.wav}.mp3"
done

This loop iterates through every file ending in .wav, converts it to a 192k bitrate MP3, and retains the original filename while replacing the extension.