Using ffmpeg to convert to MP3

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 - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Using ffmpeg to convert to MP3

  1. Marcos (guest)

    # Posted on 02 November 2007 at 10:49 PM

    Or just use PyTube as GUI ;)

    http://www.bashterritory.com/pytube



  2. Xiong Chiamiov (guest)

    # Posted on 15 May 2008 at 06:35 PM

    Actually, the command goes more something like this: $ ffmpeg -i [input] -ab 192k [output.mp3] Not only is the -b flag only for video, but you have to put the output options inbetween the input file and the output file.



  3. youtube downloader (guest)

    # Posted on 02 July 2008 at 05:07 PM

    when converting an FLV to MP3, the FLV is 4 mins long but the mp3 is 20 mins long, do you know the solution?



  4. Drew (guest)

    # Posted on 10 November 2008 at 02:41 AM

    Thanks to the help I got here and from other blogs, I've made the conversion command accessible from the context menu. So I can right-click an m4a and convert it to mp3. It comes out like Joe - His Song.m4a.mp3 but that's ok with me. This is for Windows XP.

    Go to tools>folder options>file types> and find the m4a extension. Go down to advanced and make a new action. I call mine "convert to mp3" . . . uh yeah.

    For the "application used to blah blah blah" paste in "C:\Program Files\WinFF\ffmpeg.exe" -i "%1" -ab 160k "%1".mp3

    I bet there's a way to strip out the m4a part of the filename, but it'll be good down the road when I can look at the name and say, "Oh yeah, these are all the files I scammed off so and so."

    Have fun.



  5. Shankar Prasad (guest)

    # Posted on 16 June 2009 at 07:41 AM

    Is it possible to convert .rm(real media) files to mp3 using ffmpeg? If yes, how can I do that?



  6. davandg (guest)

    # Posted on 17 June 2009 at 12:27 PM

    ffmpeg - formats to know formats that support your ffmpeg.

    ffmpeg is very easy to use, just do : ffmpeg -i inputFile.rm outputFile.mp3 and its done. You can add many options, use : ffmpeg -h to know all of these.



  7. sandeep (guest)

    # Posted on 25 November 2009 at 05:03 AM

    hello sir ,

    can ffmpeg.exe can convert .vqf to .mp3 file which parameters are need.



  8. # Posted on 25 November 2009 at 09:44 AM

    Sandeep,

    Try:

    ffmpeg -i inputfile.vqf outputfile.mp3

    If it works, then the answer is yes and if not, you may have to look somewhere other than ffmpeg.



  9. Paul (guest)

    # Posted on 06 January 2010 at 07:00 PM

    ffmpeg is great and can be used to convert pretty much any piece of media.. If ffmpeg cannot do it, you just missing the encoder/decoder for the particular type of media you are working with.



  10. don perry (guest)

    # Posted on 29 January 2010 at 04:35 PM

    Please know that -b192k is different from -ab192k

    -ab is audio bitrate, so use -ab192k



  11. CommonUser (guest)

    # Posted on 01 March 2010 at 11:54 PM

    LOL The original post is wrong. I was finding how to set the bitrate. Thanks for your correct coments !!!!



  12. Rsh (guest)

    # Posted on 04 April 2010 at 09:27 PM

    it's the -ab switch that sets audio bitrate, not -b



  13. Name (guest)

    # Posted on 25 September 2010 at 02:16 AM

    This article is lame. Author didn't even bother to check his own commands before posting to public. Unless '-b' switch was for audio bit rate back in 2007?



  14. John (guest)

    # Posted on 13 November 2010 at 09:17 PM

    Really great article. Simple and to the point. Thanks for taking the time to share your knowledge of ffmpeg.



  15. MrBuhman (guest)

    # Posted on 13 March 2011 at 08:58 AM

    ROFL LOLFAIL! ffmpeg n00b!

    You got the second one completely wrong too. Input video bitrate... You should have explained the difference between a container and a codec.

    How do you plan on "using" lame if it's a library, like you say? I'm sure you're talking about the lame reference encoder, but seem to ignorant to know the difference. ffmpeg uses liblame.

    lame on ffmpeg will default to 64k; you'll always want to specify at least 128k. The minimum should look like this:

    ffmpeg -i input.wav -ab 128k -ar 41k -acodec libmp3lame output.mp3

    "Confusing switches"? The only one confused here appears to be you, placing -ab before -i. Oh wait, right, you used -b instead.

    You may also want to preserve metadata (if present) with -metadata track=0

    If you don't specify anything before -i, you're also taking the risk that the input file has proper headers and that ffmpeg can make intelligent decisions if something is missing.

    I'd suggest you fix your article, given it seems have gained pagerank on Google, regardless of its age.



  16. MrBuhman (guest)

    # Posted on 13 March 2011 at 09:02 AM

    Linux Mint? Really? You have a poor taste in Linux distributions too.



  17. Mr.NixBuh (guest)

    # Posted on 05 August 2011 at 06:36 AM

    Hello? You don't need to kick his bottom for being a "technology enthusiast" (rotflsd). And taste is nothing to discuss.

    Well I wouldn't promote the use of mp3 in a free environment. Use libvorbis and the standard vorbis quality settings thru "-aq", that should give you both: more control and a good quality dependancy of file size.



Home » Articles » Using ffmpeg to convert to MP3

Sign In