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.
Simple and clear instructions — that work. Many thanks.
I second that ^. It worked for flac so now I have lossless.
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/
Hi,
You can use an Any File to Audio Converter to convert video to mp3.
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.
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.
Opps — forgot the closing }. That command line is:
#> for i in *.flv ; do ffmpeg -i ${i} ${i:s/flv/wav/} ; done
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)?
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
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.
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?
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.???
“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.
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…
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??
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.
simple yet elegant solution !!! works perfectly for me… Thanks.
ffmpeg IS actually available for windows, and I really don’t care about the system variable editing, because it’s simple. Please don’t say you HAVE to use a different program if you can use the same program the same way.
If you want to convert MOV to MP3, iDealshare VideoGo can help you with all of them.
Hello 🙂
“Computer users don’t want the command line cause it’s medieval” what a Nonsens!
I think there is nothing easier than that. I geht headache using Windows cause it’s so complicated. I use the following command in wich i only change the in vor output format how i need it.
mkdir mp3; for i in *.avi ; do ffmpeg -i “$i” “‘basename “$i” .avi’.mp3 ; done; mv *.mp3 mp3/;
Very simple and works perfectly with every format i’ve tryied so far.
i use Avdshare Audio Converter to Extract Audio (.mp3) from Video Files Like .flv, .mov, .avi and Others