How to convert a wav to mp3 using ffmpeg

By | April 3, 2016
How to convert a wav to mp3 using ffmpeg

How to convert a wav to mp3 using ffmpeg

How to convert a wav to mp3 using ffmpeg

Todays post I will show you how to convert a wav to mp3 format. If you use Soundcloud you will often come across free downloads of tracks from up and coming producers who want to spread their music to more people, or from established artists who use a free track as some additional promotion for their future releases or events.

Most people these days would agree that mp3 is still the most accepted format for most audio players and devices, although there are many other formats available like aac, mp4 (stems), flac, and indeed wav which all have their place.

ffmpeg is a hugely useful media conversion tool which I have spoken about before, so today I will show you how easy it is to take your wav file and convert it to an mp3.

1) Follow my guide to install ffmpeg HERE. As you can see I use a static version as its totally simple to install, and has all the functionality I have ever needed.

2) I got this great track from Soundcloud HERE – https://soundcloud.com/abstractillusion/abstract-illusion-isolation-vip-free-download-mastered-wav and as you can see when you download it, it is a wav file. So upload it to your linux box (or ffmpeg works on windows). Anyway get it in a directory you can get to and get to your command prompt.

Bit of promo for Abstract Illusion here is his free download track –

3) ffmpeg has 100s of options but for this task it is simple. First we will look at the wav file we have downloaded –

ffmpeg -i "Abstract Illusion - Isolation VIP.wav"

Output –

ffmpeg version 2.0.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 24 2013 05:31:18 with gcc 4.8 (Debian 4.8.1-10)
configuration: --extra-cflags=-I../static/include --extra-ldflags='-L../static/lib -static' --enable-gpl --enable-version3 --enable-static --disable-shared --disable-debug --enable-runtime-cpudetect --enable-libmp3lame --enable-libx264 --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --disable-ffserver
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from 'Abstract Illusion - Isolation VIP.wav':
Duration: 00:06:14.81, bitrate: 2116 kb/s
Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s32, 2116 kb/s
At least one output file must be specified

The key things to note are the Hz and the kb/s highlighted above which show the quality the file was recorded in. If (for example) your file was recorded at 128 kb/s there would be no point in converting it to a 320 kb/s file (it will not make the file better quality)

Check out -  Identify a string of consecutive characters in bash script

4) ok so now to convert your wav to mp3. Here is how you do it –

ffmpeg -i "Abstract Illusion - Isolation VIP.wav" -acodec libmp3lame -ac 2 -ar 44100 -ab 320k -f mp3 "Abstract Illusion - Isolation VIP.mp3"

-ac 2 – audio channels 2 for stereo as it said the file was on previous step
-ar 44100 – audio rate 44100 or sometimes 48000 are most normal ones, just use what was in the output from previous step
-ab 320k – the wav file said it was 2116 kb/s which is most of the reason for the large file size of a wav file. 320k is DJ quality you will hear in a club, if you are going to listen on a mobile phone then 128k is perfectly acceptable and will save you a lot of space
-f mp3 – simply says that your output file will be in mp3 format

The output –

ffmpeg version 2.0.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 24 2013 05:31:18 with gcc 4.8 (Debian 4.8.1-10)
configuration: --extra-cflags=-I../static/include --extra-ldflags='-L../static/lib -static' --enable-gpl --enable-version3 --enable-static --disable-shared --disable-debug --enable-runtime-cpudetect --enable-libmp3lame --enable-libx264 --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --disable-ffserver
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from 'Abstract Illusion - Isolation VIP.wav':
Duration: 00:06:14.81, bitrate: 2116 kb/s
Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s32, 2116 kb/s
Output #0, mp3, to 'Abstract Illusion - Isolation VIP.mp3':
Metadata:
TSSE : Lavf55.12.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s32p, 320 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s24le -> libmp3lame)
Press [q] to stop, [?] for help
size= 14644kB time=00:06:14.83 bitrate= 320.0kbits/s
video:0kB audio:14643kB subtitle:0 global headers:0kB muxing overhead 0.007263%

You can see from the output above the input and output channels. This conversion was fast as the track is just over 6mins length (highlighted above), but it works whatever size of file you are using, just will take a bit longer!

Check out -  How to embed a tweet in a wordpress post

5) Check your output file like this –

ffmpeg -i "Abstract Illusion - Isolation VIP.mp3"

ffmpeg version 2.0.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 24 2013 05:31:18 with gcc 4.8 (Debian 4.8.1-10)
configuration: --extra-cflags=-I../static/include --extra-ldflags='-L../static/lib -static' --enable-gpl --enable-version3 --enable-static --disable-shared --disable-debug --enable-runtime-cpudetect --enable-libmp3lame --enable-libx264 --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --disable-ffserver
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
Input #0, mp3, from 'Abstract Illusion - Isolation VIP.mp3':
Metadata:
encoder : Lavf55.12.100
Duration: 00:06:14.86, start: 0.000000, bitrate: 320 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 320 kb/s
At least one output file must be specified

You can see that your newly converted file is now 320kb/s

And thats it. you now have an mp3 file converted from a wav that you can use on your devices. And while you are listening to your newly converted Abstract Illusion track, check out his other tracks on Soundcloud HERE

In future posts I will show you some of the other things you can do with ffmpeg with both audio and video so subscribe to the bashworkz.com website to be notified of new hints and tips I post up here.

Leave a Reply