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.

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

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

  • August 30, 2010 at 5:13 am
    Permalink

    Simple and clear instructions — that work. Many thanks.

  • September 15, 2010 at 6:43 am
    Permalink

    I second that ^. It worked for flac so now I have lossless.

  • January 31, 2011 at 9:14 pm
    Permalink

    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/

  • February 18, 2011 at 10:28 am
    Permalink

    Hi,

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

  • March 13, 2011 at 6:40 am
    Permalink

    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.

  • August 13, 2011 at 10:34 pm
    Permalink

    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.

  • August 13, 2011 at 10:35 pm
    Permalink

    Opps — forgot the closing }. That command line is:

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

  • December 24, 2011 at 4:06 pm
    Permalink

    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)?

  • March 3, 2012 at 5:14 pm
    Permalink

    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

  • March 6, 2012 at 11:18 pm
    Permalink

    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.

  • April 13, 2012 at 1:37 am
    Permalink

    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?

  • April 14, 2012 at 7:23 am
    Permalink

    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.???

  • May 23, 2012 at 3:11 pm
    Permalink

    “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.

  • December 4, 2012 at 4:48 am
    Permalink

    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…

  • December 4, 2012 at 5:48 pm
    Permalink

    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??

  • February 7, 2013 at 12:50 pm
    Permalink

    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.

  • June 2, 2015 at 1:59 pm
    Permalink

    simple yet elegant solution !!! works perfectly for me… Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *


*