mycroes

There's always time to play

Thursday, June 5, 2008

Ripping audio from youtube movies (using gstreamer)

Today my girlfriend needed the audio from a youtube clip, so I decided to see how easy I could get it. I started by getting the flv from the clip, one useful source for that is downloadflv.com. After I had the file I verified I could actually play it, double clicking opened totem and started playing, so far so good.

Because totem managed to play I thought gstreamer should be able to open the file and I already knew gstreamer was capable of converting and after about 3 tries I came up with the following command:
gst-launch-0.10 filesrc location=file.flv ! decodebin ! audioconvert ! lame ! filesink location=file.mp3

This
- opens the file
- decodes the file (I guess this is needed to rip audio only)
- does something with audio, I don't know if you always need this but I think this is a sort of wrapper to match input with output plugins
- encodes to mp3 audio
- writes to a file

There's much more you can do with gstreamer, so if you found another one of those 'this might be useful every once or twice in five years' commands please let me know in comments.

5 comments:

Anonymous said...

what you wrote here does unnecessary encoding and re-encoding!

doing it right:

gst-launch-0.10 filesrc location=video.flv ! flvdemux ! audio/mpeg ! filesink location=out.mp3

this just demuxes the mp3 stream from the video file.

Michael Croes said...

I didn't know flv uses mp3 audio, but thanks for pointing that out!

Anonymous said...

The trick of the first commenter doesn't work, however, the original post works great, thanks!

Unknown said...

The first poster almost had it, they just needed to specify a container near the end.

gst-launch-0.10 filesrc location=video.flv ! flvdemux ! audio/mpeg ! qtmux ! filesink location=out.mp3

Unknown said...
This comment has been removed by the author.