[raspberry-vi] youtube videos on your raspberry pi

  • From: Travis Siegel <tsiegel@xxxxxxxxxxx>
  • To: raspberry-vi@xxxxxxxxxxxxx
  • Date: Fri, 23 Oct 2015 16:47:23 -0400 (EDT)

Well, I was checking to see how much trouble youtube would be on the pi,
and I've found a solution that is a combination of programs, but it works
nicely.
First, you'll need to download youtube-dl with the command

sudo apt-get install youtube-dl

Then, we'll need to upgrade the version of youtube-dl, since the one in
the software archive isn't the latest version. You can get a newer
version at:
https://yt-dl.org/latest/youtube-dl
You can use wget, curl, or lynx, elinks, or some other method, but easiest
is probably using wget. If wget isn't installed, you'll need to install
it first.

sudo apt-get install wget

Then

wget https://yt-dl.org/latest/youtube-dl

After that, you'll need to move the new youtube-dl to the location of the
one we downloaded in the apt-get step.

sudo mv youtube-dl /usr/bin

Now, we can download a youtube video just by doing something like this:

youtube-dl http://www.youtube.com/watch?v=xxxxxxx (or what the url of the
youtube video you want is of course)

But, of course, since we're running in terminal, this won't help us much,
so we need to convert the youtube video into something we can use.
This we do with a program called avconv. There is no avconv app in the
apt-get repository, but you can install it in a number of ways, although
the one I used was:

sudo apt-get install ffmpeg

It's also available with the motion program, and likely others as well, so
check your system, if you've already installed one of the many programs
using avconv, you could already have it on your system.
To extract the audio from your mp4 file, you will need to grab the audio
track from the mp4 movie file by doing something like this:

avconv -i video.mp4 -codec:a:0 mp3 output.mp3

This will extract the first audio track from the mp4 file, and save it in
mp3
format in the file named output.mp3. If your mp4 file has more than 1
audio track, and you want the second one, then you'd use -codec:a:1
instead of 0.
Extracting video works this way too, where you can specify the video
format, and in fact, if you read the man entry for avconv, you will see it
can do all kinds of things, including produce live feeds, mix multiple
inputs, produce multiple output streams, and even recode dvd files into
plain video formats (assuming of course the vob files aren't encrypted.).
It's quite the versatile program, but this use to which I've put
it of allowing me to watch youtube videos, I think is quite useful in and
of itself.
It will take some time to perform the audio extraction, so if it's a
fairly long video, you may want to go get a snack or something, or you can
do what I did, switch to another terminal, and just keep working, and
allow it to process in the other terminal until it's finished. You'll of
course need to check on it periodically, but that's imple enough.
I extracted a 7 minute video that took about half an hour or so (I
actually didn't time it, so my estimate could be off a bit), but it gives
you an idea of how long converting videos will take.

Once the video has given up it's audio stream, you can play it using
mpg123 output.mp3, or of course, aplay if you extracted to wav format, or
omxplayer if you extracted to ogg format. (though, I've not tested to see
if ogg format is possible with the program.
Clearly, this is a powerful tool to have on your pi, and I have no doubt
folks will find other uses for it.
If anyone has questions, needs clarification, or needs help making all
this work, let me know, and I'll do what I can to assist.
hope this helps.
I'll see about writing up something a bit more organized, with more
details in a bit, but I thought folks would appreciate this little gem, so
I put it out there now, in case others were feeling left out of the
youtube world. :)
After all, foamy the squirrel should be on every pi.
(well, ok, probably not all pis, since some are owned by children, and he
does have some age inappropriate videos, but nonetheless, now I can sit
back, relax, and listen to my favorite crazy squirrel without needing to
move across the room to a windows or linux machine.



===========================================================
The raspberry-vi mailing list
Archives: //www.freelists.org/archives/raspberry-vi
Administrative contact: <mike.ray@xxxxxxxxxxxxxx>
-----------------------------------------------------------
Raspberry Pi and the Raspberry Pi logo are trademarks of the Raspberry Pi
Foundation.

This list is not affiliated to the Raspberry Pi Foundation and the views and
attitudes expressed by the subscribers to this list do not reflect those of the
Foundation.

Mike Ray, list creator, January 2013

Other related posts:

  • » [raspberry-vi] youtube videos on your raspberry pi - Travis Siegel