October 24, 2008
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
#!/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- Running up that Hill (Placebo vs. Kate Bush)
- Back up script
- Reputation Defender
- Music 2.0: Pitchfork
- GCalendar: Accessing Google Calendar from JavaScript
