Converting Youtube Videos to MP3

I recently lost all of my music collection due to a harddisk crash on my fileserver, which means that I have to start collecting all over again, and believe me, some rare songs are pretty hard to find.

On the other hand I often find a nice song on Youtube and decide that I have to keep it. And after a bit of looking around I found the handy youtube-dl script which automatically parses the pages content and downloads the video file, much like keepvid.com does, but all from the shell.

After we have the video file all we have to do is dump the audio and convert it to a format we like (most likely MP3 or OGG). Until today I used mplayer and mencoder to dump and encode the audio, but I stumbled across this article on howtoforge.org that uses ffmpeg, and is more flexible and avoids me one intermediate step :-)

So now I have a really simple script that fetches the video and converts it, which looks like this:
#!/bin/bash
# Just additional setting to use high quality video
YOUTUBE_OPTS="-b"

# Please make sure youtube-dl is in your path
youtube-dl $YOUTUBE_OPTS -o temp.flv "$1"

ffmpeg -i temp.flv -ab 128000 -ar 44100 "$2"

Please make sure, as stated above that youtube-dl is in your path. Usage is pretty darn simple:

ripyoutube <youtube-url> <mp3-name>

Don’t forget to enclode the URL and filename into doublequotes

  • Share/Bookmark

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

2 Responses to “Converting Youtube Videos to MP3”

  1. silver  on October 31st, 2008

    try http://www.mp3getter.com. do the same without coding and runs in a browser ;-) you get the bitrate of the video.

    Reply

  2. Christian Decker  on November 7th, 2008

    Thanks silver, that’s a great tip. I wonder if I could make a site just like that with the script above ^^

    Reply


Leave a Reply