How to Convert WAV to MP3 with FFmpeg in Windows and Linux

How to convert WAV to MP3 in Linux using the ffmpeg command which is an audio conversion tool to compress the audio and make it more usable.

By Tim TrottLinux Tips and Tutorials • August 9, 2013
1,040 words, estimated reading time 4 minutes.
How to Convert WAV to MP3 with FFmpeg in Windows and Linux

I've been recording some audio tracks as uncompressed WAV files, but they are too large to send over the internet or store on mobile devices. Here's how to convert WAV to MP3, which will compress the audio and make them more usable.

As with photo compression, there are two types of audio media file formats - "lossy" and "lossless." WAV (Waveform Audio File Format) stands among the most popular lossless formats, while MP3 is the most common lossy format.

Lossy files are called so because they lose some data after compression to make their size smaller. WAV file is a completely uncompressed media file and takes up quite a bit of space.

ALAC and FLAC are both lossless formats of audio files that contain the same data as a WAV, but they use compression to produce smaller files. FLAC and ALAC formats don't lose any data - they keep and compress it brilliantly, as ZIP files do. ALAC and FLAC player support is much less than MP3, so you may have difficulty finding something that will play these files, and they are not supported on iPods and iPhones.

How to Convert WAV to MP3 on the Command Line

These commands do not alter the original, which you can back up to CD-ROM or similar. Instead, they write a new file, typically 70-80% smaller than the original.

You can install ffmpeg using this command:

sudo apt-get install ffmpeg

Update: Some of the newer distros do not have this package, so you may need to add the repository if the above command does not work.

sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
sudo apt-get update
sudo apt-get install ffmpeg

Windows users can simply download the installer from the website.

The commands to Convert WAV to MP3 using ffmpeg are:

ffmpeg -i track01.wav -acodec mp3 track01.mp3

You can also specify the bitrate of the MP3 with the -ab flag.

ffmpeg -i track01.wav -acodec mp3 -ab 64k track01.mp3

That is all you need to do to convert WAV to MP3 in the Linux shell or command prompt. You can also specify wildcards to process multiple files at the same time.

How to Convert WAV to FLAC (Or Any Other Format)

Ffmpeg is a great tool that can convert any media file to any other. This is usually automatic, so we need to supply the filenames to convert from WAV to FLAC.

ffmpeg -i track01.wav track01.flac

Using FFmpeg to Change Bit Depth or Sample Rate

Bit depth and sample rate are two properties of audio files that affect the quality and file size. The Sample rate, given in hertz or kilohertz, measures how often an audio wave is sampled; the more samples you have per second, the higher the quality. Think of it like the resolution or dots per inch of a photograph. The higher the DPI, the more pixels are in a given area so that you can get more details. 44.1khz is usually quoted as "CD Quality", while 8khz is equivalent to a telephone phone system.

Bit depth is a measure of how much data is in each sample, and using the photo analogy, it would be the number of colours or colour depth. A 16-bit audio file has 65,536 possible values for each sample, whilst an 8-bit audio file has only 256 possible values. As with photos, 256 colours is a limited colour palette, and photos won't look too good. 16-bit is better, and 24-bit is regarded as "photo quality".

Now you know the sample and bit rates, we can change these values using FFmpeg. But please remember that you cannot create data where none exists. If you have an 8khz, 8-bit audio file, you can convert it to 44.1khz 24-bit, but you won't make it sound like a CD-quality recording. All you are doing is changing the way the original data is stored. If you go the other way and convert a 44.1khz audio to 8khz, you will lose a lot of quality in the converted file because it does not have enough "space" to store all the data.

Changing the sample rate and bit depth is as easy as adding a few parameters to the command.

ffmpeg -i track01.wav -af aformat=s16:44100 track01.flac

This will give a bit depth of 16 bits and a sample rate of 44.1khz. To convert to 8-bit and 8 khz, use this.

ffmpeg -i track01.wav -af aformat=s8:8000 track01.flac

Convert WAV to MP3 with a GUI

If the command line isn't your liking, many tools and utilities offer a GUI (Graphical User Interface), which can be easier to use. Here are my two preferred options, one for Linux and one for Windows, although technically, Audacity can be used in Windows and Linux.

How to Batch Convert WAV to MP3 Using SoundConverter on Linux

SoundConverter is the leading audio file converter for the GNOME Desktop. It reads anything GStreamer can read (Ogg Vorbis, AAC, MP3, FLAC, WAV, AVI, MPEG, MOV, M4A, AC3, DTS, ALAC, MPC, Shorten, APE, SID, MOD, XM, S3M, etc...), and writes to Opus, Ogg Vorbis, FLAC, WAV, AAC, and MP3 files, or use any GNOME Audio Profile.

SoundConverter aims to be simple to use and very fast. Thanks to its multithreaded design, it will use as many cores as possible to speed up the conversion. It can also extract the audio from videos.

SoundConverter for Linux to convert wav to mp3
SoundConverter for Linux to convert wav to mp3

How to Batch Convert WAV to MP3 Using Audacity in Windows

Audacity is one of the top free software for editing audio files under Windows. Audacity can batch convert WAV to MP3 or any other format using the GUI. You will need the LAME MP3 encoder to export MP3 files. Here is how to batch convert WAV to MP3 in Audacity using Macros.

  1. Click on the Tools menu, then select Apply Macro, then Palette.
  2. In the Macro Palette select MP3 Conversion.
  3. Click the Files button and select the WAV files you want to convert.
  4. When you select the files and click Open, Audacity will open each file and export it using the default settings.
  5. To Change the default settings, open a WAV and export it. In the save dialogue, you can change the bit rate and quality. These will then be saved as the new default for batch conversion.

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

My website and its content are free to use without the clutter of adverts, popups, marketing messages or anything else like that. If you enjoyed reading this article, or it helped you in some way, all I ask in return is you leave a comment below or share this page with your friends. Thank you.

This post has 6 comments. Why not join the discussion!

New comments for this post are currently closed.