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 Trott | Linux Tips and Tutorials | August 9, 2013
1,121 words, estimated reading time 4 minutes.

I've been recording some audio tracks as uncompressed WAV files, but they are too large for sending over the internet or storing 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." Among the most popular lossless formats stands WAV (Waveform Audio File Format), 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 all of it 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 iPod and iPhone.

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 out a new file which is 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 is:

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 and can also be used to convert from any media file to any other. Most of the time this is automatic, so to convert from WAV to FLAC we simply need to supply the filenames.

ffmpeg -i track01.wav track01.flac

Using ffmpg 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 of files. The Sample rate, given in hertz or kilohertz is a measure of 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 in a given area so you can get more details. 44.1khz is usually quoted as being "CD Quality" whilst 8khz is equivalent to a telephone phone system.

The bit depth is a measure of how much data is in each sample, and using the photo analogy 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 what sample rate and bit rate are, we can change these values using ffmpeg. But please keep in mind that you cannot create data where none exists. If you have a 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 to your liking there are many tools and utilities which offer a GUI (Graphical User Interface) which can be a lot easier to use. Here are my two preferred options, one for Linux and one for Windows, although technically Audacity can be used in both 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. We can use Audacity to batch convert WAV to MP3 or any other format using the GUI. You will need the LAME MP3 encoder for exporting 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 in turn and export it using the default settings.
  5. To Change the default settings, first open a WAV and then 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.
Was this article helpful to you?
 

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

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 comment(s). Why not join the discussion!

We respect your privacy, and will not make your email public. Learn how your comment data is processed.

  1. On Thursday 6th of May 2021, said

    Thank you!

  2. FA

    On Thursday 29th of October 2020, felipe a said

    thank you !!

  3. DH

    On Sunday 23rd of August 2020, Dan Hunter said

    Thank you so much - very helpful.

  4. AA

    On Thursday 12th of March 2020, Andre Andre said

    how to convert all the wav file to mp3 in one query?

    1. Tim Trott

      On Thursday 12th of March 2020, Tim Trott  Post Author replied

      for i in *.wav; do ffmpeg -i "$i" -acodec mp3 -ab 64k "$(basename "$i" .wav)".mp3 ; done

  5. TO

    On Tuesday 28th of January 2020, Tom said

    Thank you!