Extract Audio (.mp3) from Video Files Like .flv, .mov, .avi and Others with Ubuntu

It is very easy to extract the audio track from video files using Linux. All you need is ffmpeg and some codecs.

Let’s get started…

Note: The commands below are for Ubuntu (or Debian derivatives) but you can do the same with any other Linux distribution provided you can install the necessary packages.

1. Add the Medibuntu’s repository to your sources.list:

sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update

2. Install ffmpeg:

sudo apt-get install ffmpeg

3. Let’s get the restricted packages and some codecs installed:

sudo apt-get install ubuntu-restricted-extras libmp3lame0 libdvdcss2 w32codecs

The above command is for i386 architecture. If you have an amd64 architecture, substitute w32codecs with w64codecs.

Note: This is not a complete list of codec packages by any stretch of the imagination. It will get you started though and you will be able to do most formats, but you might have to add codecs as you go along.

4. Now we are ready to extract the audio from the video files:

ffmpeg -i input_file.flv output_file.mp3

The above command will extract the audio from a Flash video file. You can do the same for a QuickTime file as well:

ffmpeg -i input_file.mov output_file.mp3

Or for an Audio Video Interface file:

ffmpeg -i input_file.avi output_file.mp3

YouTube and other video web sites:

Having done all this, now we can download flash files from places like YouTube and strip the audio from them. All you need besides the steps above is a way to save the Flash files (.flv) from YouTube. An easy way to do that is by using Firefox Add-ons like Download Flash and Video or Flash Video Downloader.

The quality of the audio in the YouTube videos for example is 64 bit/sec. Most of the mp3 files are normally compressed to 128 bit/sec or above. Obviously the quality will not be the same, but a human year cannot tell the difference.

The quality of the extracted mp3 will depend on the quality of the audio track in the video file. So the above statement about the 64 bit/sec audio is mostly the case for the files on some video sharing sites.

Wednesday, January 20th, 2010 Linux, Ubuntu

16 Comments to Extract Audio (.mp3) from Video Files Like .flv, .mov, .avi and Others with Ubuntu

  1. Simple and clear instructions — that work. Many thanks.

  2. Patrick on August 30th, 2010
  3. I second that ^. It worked for flac so now I have lossless.

  4. raequin on September 15th, 2010
  5. When will the Linux-world understand at last average computer users DON’T WANT THE COMMAND LINE CAUSE IT’S MEDIEVAL?
    When you want to extract audio from videofiles in Linux just use WINFF.
    That’s an excellent GRAPHICAL frontend for FFMPEG. WINFF is also available for Windows. Just import the videofile in WINFF. Select Convert to Audio, select the audioformat of your choice, fill in the desired bitrate (ie for mp3 128 kbps) and there it goes.
    WINFF is in the repositories of several major Linux distributions like Ubuntu and OpenSUSE. See also: http://winff.org/html_new/

  6. Willem Franssen on January 31st, 2011
  7. Hi,

    You can use an Any File to Audio Converter to convert video to mp3.

  8. Jack on February 18th, 2011
  9. I installed winff out of curiosity. It’s great but 1) I wouldn’t even have understood how to extract the audio without Willem’s advice, so it’s not better than the command line; 2) typing ffmpeg -i input_file.avi output_file.mp3 on the command line is so much faster that I don’t care looking medieval. This is one of those cases when I feel sorry for Windows users that have to waste so much time with the file open dialog and all the other GUI controls.
    I’m using audacity and openshot for my other video production steps, so I’m not always medieval. I just like to be efficient.

  10. Paolo on March 13th, 2011
  11. Especially when you can use the full power of the CLI and do this:

    #> for i in *.flv ; do ffmpeg -i ${i} ${i:s/flv/wav/” ; done

    And do them all at once. Change *.flv to *.mp4 or what have you. Change ${i:s/flv/wav} to ${i:s/flv/mp3} or ${i:s/flv/ogg} or what you want.

    This little command line loop will list each file that matches *.flv, feed it into whatever command follows the ‘do’ and it’s position in the command is wherever you put the ${i}. The added ‘s/flv/wav/’ means to search ‘s’ for flv and replace with wav. This substitution occurs *before* ffmpeg actually is run.

    Eazy squeezy.

  12. GuyS on August 13th, 2011
  13. Opps — forgot the closing }. That command line is:

    #> for i in *.flv ; do ffmpeg -i ${i} ${i:s/flv/wav/} ; done

  14. GuyS on August 13th, 2011
  15. interesting little cross flame upthread – the command line can be seen as medieval, or it can be seen as matrix-chic. Very much a matter of taste that one, regardless of what you can or cannot do with it. As for feeling sorry for windows users, it is possible to use a cli in windows i believe.

    Anyway nice command reference. As for compression issues with flash videos, I assume it is reasonable to replace the output format with flac (for instance)?

  16. korv on December 24th, 2011
  17. Here’s a simple nautilus script (I made it) which simply converts one or more selected files using the command described above. It shows progress window using zenity (which needs some tweak to show the right percentage but I’m on hurry now) and the current filename.

    Note: save the following script as file (no extension needed) in the nautilus scripts dir (~/.gnome2/nautilus-scripts) and don’t forget to make that file executable! (chmod +x … )

    #!/bin/bash
    cnt=0
    total= $#
    step= 100/$total

    (while [ $# -gt 0 ]; do
    file=$1
    mp3file=`echo “$file” | sed ‘s/\.\w*$/.mp3/’`
    echo “# $file to $mp3file”

    /usr/bin/ffmpeg -ab 128 -y -i “$file” “$mp3file”
    cnt= $cnt+$step
    echo “$cnt”
    shift
    done) | zenity –title=”Converting to mp3″ –progress –text=”Converting to 128Kbs mp3 file…” –auto-close –percentage=0

  18. vgfeit on March 3rd, 2012
  19. Good sugestions! I would also throw in soundconverter (found in the repositories). Just make sure you have the proper codecs installed. Once the output is confiured it’s drag, drop, convert and done. Has worked with avi, mkv, mov, flv, mpeg, and mp4 video formats for me.

  20. clastic on March 6th, 2012
  21. Simple, works, but when I extract from .flv which has 128 kbps bitrate I’v got 64kbps bitrate in the output file. How to extract in the same quality?

  22. Iwan on April 13th, 2012
  23. Hate to sound like a complete noob since that is what I am but, all I get when I use this method (infact anytime i use the command line) is a message that says, no such file or directory. I assume I change the “input_file.flv” to the name of the actual file to be converted. any ideas.???

  24. Geo on April 14th, 2012
  25. “When will the Linux-world understand at last average computer users DON’T WANT THE COMMAND LINE CAUSE IT’S MEDIEVAL?”

    The worst and most lazy comment I’ve seen. Command line is better just because works, it’s easy to debug and to develop your own frontend. Only hateful lazy dummies will not agree.

  26. Log Nulll on May 23rd, 2012
  27. I run into problem. When installing libmp3lame0 I got screen about MS EULA. How do I get over it? OK is not working.
    Besides, I’d like to keep my computer M$ free…

  28. Viltsu on December 4th, 2012
  29. Hi,

    I’m doing this to try and extract audio from a skype call saved to .mov (audio only). However, I only get one audio channel – the maker of the call and not my own voice. Both channels are there in the original mov. Any ideas??

  30. Lukw on December 4th, 2012
  31. After exploring a few of the articles on your web
    page, I honestly appreciate your way of blogging. I added it to my bookmark website list and will be
    checking back soon. Take a look at my website too and let me know how you feel.

  32. http://24-7press.com/ on February 7th, 2013

Leave a comment

*

Search

 

Archive

October 2014
M T W T F S S
« Jul    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Other