Life, The Universe and Everything


Wednesday, June 20, 2007

Capturing Youtube videos and extracting audio from video

Another HGFP (High Geekitude Factor Post)...

Capturing videos from Youtube and saving them to your hardrive is actually more straightforward than I thought it would be! Well, not quite as straightforward as right clicking on the video and selecting "Save as". If you right click on a Youtube video, all you get is the flash player context menu that has no save option. But it's still very easily doable.

In order to extract the video, you need to get a program that will do this for you. And the magical program is youtube.dl. The site has instructions on how to obtain it, install it and run it. For this post, I only share the third portion, which is using it. The good thing about this little piece of software is that you can use it on both Windows and Linux, so my Windows-running blogren should not feel left out.

For this post, I will use the following clip from Youtube of the opening credits for The Simpsons as an example:



To extract this video from the Youtube servers to your computer, you will need to issue the following command from wherever you installed the youtube.dl program. Again, this post assumes you are running Linux. You can reference the site linked to above for the appropriate commands to give in a Windows machine.

./youtube-dl -o file.flv http://youtube.com/watch?v=cZY7mSoZbCw

The only option needed is the -o which indicates what to name the output file, in this case, file.flv. Make sure to use the .flv extension, since you are extracting a flash video file. You then give the URL of the video as the argument. And off it goes.

Once done, you should have your file good to go and you can play it at will. In the unfortunate event you have a player that doesn't handle flash video files, then an extra step to convert the format to something else like mpeg will be necessary. Check my previous post for details on how to do this using MEncoder.

Next is the same clip that was extracted from Youtube.



And that's all there is to it. Something of note, before I move on. If you attempt to download a file and find that you need to be authenticated as a user, then you will have to give your youtube account username and password. The modified command would then be:

youtube-dl -u USERNAME -p PASSWORD -o file.flv http://youtube.com/watch?v=cZY7mSoZbCw

Just replace USERNAME and PASSWORD with your login info.

Moving on now to audio extraction. I will use audio from the video above for continuity's sake.

For audio extraction, I used mplayer. The command issued to get things going is:

mplayer -vc null -vo null -ao pcm file.flv

The options are:


  • -vc: this indicates what video codec to use in decoding. The choice given is null, which means no decoding of the video signal will happen, since none is selected

  • -vo: this indicates what video output drivers to use, i.e. what will be used to display the video. Again the choice given is null, meaning there will be no video output.

  • -ao: this indicates what output audio drivers to use, meaning what will be used to play the sound. PCM has been selected as the driver to use, which is the uncompressed raw audio.


The last item is the file.flv which is the input to the application.

After a few seconds, you should have an audiodump.wav file generated from this command. You could use this as is, but if like me you'd rather have a compressed audio file occupying less space, then you need to issue the following command:

lame audiodump.wav file.mp3

This uses the lame application to convert from wav to mp3. Once again, you are not limited to lame. You can use any application that suits your fancy. In the command above, audiodump.wav is the input file, and file.mp3 is the output file. For this example, audiodump.wav is 6.9MB whereas file.mp3 is just 639KB.

The podcast below is of the audio extracted from the movie clip up above.







Incidentally, this is how I got the audio for the tv theme songs mix. For that mix, however, there was one extra step, which was combining of the different audio files into one big file. For that, I used audacity, available for Windows, Mac and Linux. That's the same application I used to generate these two mixes as well.

Apart from letting you combine files, this programme will let you edit sound files as well. I used it to cut different sections from the podcast below which I reproduced to give another example of audio extraction. This is from the choir video I digitized earlier.







Enjoy!



16 comments:

Kirima said...

This looks interesting nita soma baadaye when I have free time.

mocha! said...

Haiya...kumbe wewe ni geekoid.

Sawa, bookmarked for future reference.

Application form coming soon

modo still zoobing said...

er...o-okay! A second bus has come flying by...

but this one, nimedandia. this is helpful...enyewe this process has been stressing my head...

Msanii_XL said...

Nice...not much of quality drop at all, will try this tonite.

Thanks!

beans said...

Thanks- I've always wanted to know about this! [The best I got too was flv players, which I'm quite ignorant of]

Will give it a go tonight hopefully! [I'm quite ignorant as to what linux is as well! :o ]

danda-excess said...

Excessively flowing with the tide. kiasi tu.

Majonzi said...

sweet! kwanza there's some music I need from youtube. wacha I save this post for when I get home. thanks!

Mitzy said...

Good stuff. I'll try it this weekend. Now, why does your blog's homepage always have Google ads about bread making?

Shiro said...

thanks for visiting my site... browsed through yours... love the photos...

egm said...

Kirima
Haya, nitangoja feedback

Mocha
Hehe, what can I say? :)

Eagerly awaiting form

Modo
Ala, what process is this? Kwani you tried doing this? I hope this saidias you vilivyo

Msanii
Karibu sana.

Let me know how it turns out for you!

Beans
I'm glad I was informative :)

Linux is an operating system. You can learn all about it here.

Inexess
Bora the tide is not drownishaing you...

Majonzi
Karibu sana. Muziki uliweza kupata? Do share!

Mitzy
Let me know how it goes.

Haiya, I hadn't noticed till you mentioned it. I don't know, maybe it's as fascniated with bread as I was back in high school

Shiro
Karibu kwangu. And thanks!

this modo is on the bus said...

this is just the best...kwanza i'm trying it out now. nimeweka blog yako hapo kando kama manual...

process ya the computer-idiots...we think everything is rightclick.

mitzy, nikidhani ni jaa inamsumbua! LOL!

Kayliz said...

Oh, thanks. I have to use this is the easiest way of doing this that I have come across. :)

egm said...

Modo
Ulifaulu?

Eti njaa? Hehe, what can I say? Bread to the rescue!

Kayliz
Let me know how it turns out for you. And you are welcome!

aegeus said...

I use two different ones too this one to get a *.flv file:

Firefox plug in..

and this one to get a converted *.m4v or *.mp3...

Stand alone app..

...very intuitive to use at least on the mac - no commands to give...Modo just click and go!

egm said...

Aegeus
Thanks for those links. I don't know why I didn't think of looking for plugins first! Good idea. I guess my preference for things commandline driven was a motivating factor. Good thing about the commandline is, the process is much easier to automate, especially if I want to do batch downloading and processing.

steveking said...

YouTubeRobot.com today announces YouTube Robot 2.0, a tool that enables you to download video from YouTube.com onto your PC, convert it to various formats to watch it when you are on the road on mobile devices like mobile phone, iPod, iPhone, Pocket PC, PSP, or Zune.

YouTube Robot allows you to search for videos using keywords or browse video by category, author, channel, language, tags, etc. When you find something noteworthy, you can preview the video right in YouTube Robot and then download it onto the hard disk drive. The speed, at which you will be downloading, is very high: up to 5 times faster than other software when you download a single file and up to 4 times faster when you download multiple files at a time.

Manual download is not the only option with YouTube Robot. You may as well schedule the download and conversion tasks to be executed automatically, even when you are not around. Downloading is followed by conversion to the format of your choice and uploading videos to a mobile device (if needed). For example, you can plug in iPod, select the video, go to bed, and when you wake up next morning, your iPod will be ready to play new YouTube videos.

Product page: http://www.youtuberobot.com
Direct download link: http://www.youtuberobot.com/download/utuberobot.exe
Company web-site: http://www.youtuberobot.com
E-mail: support@youtuberobot.com