How to extract mp3 from YouTube video using Linux?
It's rather easy. I used 3 components:
- DownloadHelper extension for Firefox
- MPlayer
- lame
When DownloadHelper is installed and you open a YouTube video, it gives you the options to download the .flv or .mp4 file to your computer.
After the file is downloaded, we can use MPlayer to play it and also to dump the audio. It's nice because it plays both .flv and .mp4, so you just need one program. To dump the audio to .WAV format use:
mplayer -ao pcm:waveheader FILENAME.flv
This will create file called audiodump.wav. Now, use mp3lame to encode it to mp3 format. You can also use oggenc to convert it to OGG if you perfer open formats.
lame audiodump.wav song.mp3
That's all. I put these commands in a simple shell script (video2mp3.sh):
mplayer -ao pcm:waveheader $1
lame audiodump.wav $1.mp3
Run it from command line like this:
. video2mp3.sh FILENAME.flvTweet to @mbabuskov Tweet Milan Babuškov, 2011-12-01