Using ffmpeg to convert to MP3

  • November 2, 2007
  • Avatar for peter
    Peter
    Upfold

Now we all know we should be using free and open formats like Vorbis for our audio, right? Yeah. Unfortunately, sometimes we are restricted by what some devices will support.

If you've got some tracks in Vorbis, WAV or another format and you want to convert it to MP3 format. Now you can use the open source MP3 library LAME, but it doesn't support quite as many input formats as ffmpeg does.

ffmpeg, for the uninitiated, is a piece of software (and software library) designed for converting all sorts of audio and video from one format to another. Most distributions don't ship it manually and many don't support it, so you may need to enable extra software repositories before installing the ffmpeg package.

Once you've got that, converting an audio file should be pretty easy and works as follows. Remember ffmpeg does take quite a lot as input files, and will detect the input format automatically. In a similar vain, the output format will be automatically determined by the file extension you give, so it makes light work of conversion and avoids lots of confusing command line switches.

A simple audio convert might be:

$ ffmpeg -i file file.mp3

Substitute in your filename, make sure the .mp3 extension is intact in the output filename and a convert should happen. Obviously, doing like this does have the disadvantage of using default settings.

The simplest of these settings to alter would be the bitrate, which determines the output quality. For MP3, a really quick guide would be that 128 kbps is fair quality, 160 kbps is good quality and 192 or above is very good quality.

Setting the bitrate of the output file is also simple, so let's add it to the command:

$ ffmpeg -b 192k -i file file.mp3

Here I set for 192 kbps quality.

This is only a very basic quick starter, but it does show you how easy it is to start converting audio with ffmpeg. If you need more flexibility in your conversion, you may want to switch to a solution like LAME, but for the ease of use and wealth of input formats a well-configured ffmpeg installation can give you, it's well worth a try for your converting needs too.

Avatar for peter Peter Upfold

Home » Articles »