Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Possible Duplicate:
How to download a youtube video via terminal

There are several Q&A threads that explain how to download youtube videos using the terminal.

However, I would also like to learn how to extract the video's soundtracks as MP3 files--also using only the terminal.

Answers briefly explaining how to use youtube-dl or other similar utilities before explaining how to extract the MP3 would be ideal for the sake of having all the information in one place--even though this aspect has been covered in other posts.

share|improve this question

marked as duplicate by izx, jokerdino, Uri Herrera, Stephen Myall, Mitch Aug 25 '12 at 6:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I've noticed that your accept rate is very low. You may want to close some of your other open questions by selecting the best answer (if they have one). Consider which answers have been useful and need an upvote. We need users to maintain their questions so that the site can be an effective tool for the next person with your problems. For more details on best practices consider reading the FAQ on asking questions. –  Mitch Aug 21 '12 at 9:50
It's close but I think the fact that it is specifically looking for an mp3 makes it different enough. –  Jacob Tomlinson Aug 22 '12 at 12:58
add comment

3 Answers 3

You can also download the mp3 directly from youtube without converting using ffmpeg

youtube-dl --extract-audio --audio-format mp3 <video URL>

From the online help:

-x, --extract-audio        convert video files to audio-only files (requires
                           ffmpeg or avconv and ffprobe or avprobe)

Bear in mind as well that youtube-dl defaults to using avconv so you should consider specifying either avconv or FFmpeg at the commandline. From the online help:

--prefer-avconv                  Prefer avconv over ffmpeg for running the
                                 postprocessors (default)
--prefer-ffmpeg                  Prefer ffmpeg over avconv for running the

Further options for keeping the original video, adjusting the bitrate or quality of the audio and a few others can be seen by looking at youtube -h.

share|improve this answer
youtube-dl <video URL> --audio-format mp3 does not download me as mp3! –  fromnaboo Aug 23 '12 at 10:17
if you look at the man pages, this option tells you you still have to download ffmpeg –  user1527227 Feb 18 at 3:10
add comment

Downloading from youTube

Install youtube-dl from the official repository in Ubuntu:

sudo apt-get install youtube-dl

To download a video execute the following:

youtube-dl <url>


youtube-dl http://www.youtube.com/watch?v=_z-hEyVQDRA

You can also specify other options

-b            Best quality
-m            Mobile version
-d            High Definition
-g            Don’t download, just show the url
-c            Resume download of a video which was interrupted before
-w            Don’t overwrite existing file

For complete list of switches execute man youtube-dl in terminal.

Information from http://www.absolutelytech.com/2010/06/26/howto-download-youtube-video-from-command-line-ubuntu/

Converting to mp3

Now install ffmpeg from the official repo.

sudo apt-get install ffmpeg

Next have a look to make sure the flv file has downloaded from youtube by typing

ls *flv

This will list all the flv files you have. What you should see is a flv file with the same name as the 'v' component of the youtube url you downloaded.

E.g if you downloaded http://www.youtube.com/watch?v=_z-hEyVQDRA then you should have a file called _z-hEyVQDRA.flv

Next you need to copy that file name and then put it in an ffmpg command like

ffmpeg -i <file name>.flv -acodec liblamemp3 <song name>.mp3

So for this example you would type

ffmpeg -i _z-hEyVQDRA.flv -acodec liblamemp3 MasterOfPuppets.mp3

Once this has successfully completed you will now have the mp3 file you were after.

Note For cleanup you may want to type rm _z-hEyVQDRA.flv to get rid of the flv file that you no longer need.

Information from http://ubuntuforums.org/showthread.php?t=855433

share|improve this answer
You may want to add converting to mp3 with ffmpeg or aconv. –  NRoach44 Aug 22 '12 at 8:13
Updated, thanks –  Jacob Tomlinson Aug 22 '12 at 12:53
One more, -acodec liblamemp3 in the ffmpeg command line. –  NRoach44 Aug 23 '12 at 1:01
Yes you could force the codec to be sure, I have added this. You could also use -ac 2 -ab 128k to ensure it converts at 128k –  Jacob Tomlinson Aug 23 '12 at 10:06
add comment

youtube-dl is a small command-line program to download videos from YouTube.com and a few more sites in your preferred format.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.