Youtube music

There's loads of music on YouTube. However, when I want to listen to music, I'm not necessarily interested in slideshows. And yes, that's a euphemism.

Luckily, extracting the video and audio from a youtube clip isn't very hard.

  • First, download the clip. Yes, that's possible. This will get you a movie clip, by default in the highest quality format available for the particular clip you're trying to download.
  • You want to know which codecs the clip is using. Mplayer to the rescue:
    wouter@carillon:~$ mplayer -frames 1 -v <file> 2>&1|grep -i 'stream.*audio'
    [lavf] stream 1: audio (vorbis), -aid 0
    
    meaning, this particular file has Vorbis audio.
  • Next, extract the audio:
  • ffmpeg -i <file> -vn -acodec copy <output>.ogg

The critical bit is the '-vn' part, which tells ffmpeg not to encode the video to the output file. The 'mplayer' step isn't strictly required; but since youtube only uses lossy audio codecs, re-encoding the audio to a different codec will cost you audio quality. You may not want to do that; hence the mplayer step (to figure out which codec the source file is using), and the '-acodec copy' argument to ffmpeg's command line (which tells ffmpeg to not re-encode the audio, but just store the unmodified original audio stream in a different container file).

Tadaa, music without video.