In the end of this proccess you’ll have an .mpg file on your local disk, generated from an Internet-only YouTube URL.
First make sure you have ffmpeg (video encoding and decoding tools) and lame (MP3 audio encoding and decoding tools) softwares and dependencies installed on your system. You will also require the youtube-dl scripts that downloads the actual YouTube video.
In a Red Hat or Fedora system you can install it from Dag or Livna RPM repositories, with a simple yum command:
bash# yum install ffmpeg lame youtube-dl
Then you get to the YouTube video page you want to download. In this example we’ll use the Heist video, the first Linux ad from IBM, that has http://www.youtube.com/watch?v=DO9ZWDaLLxA as its URL.
I’ll use youtube-dl this way:
bash$ youtube-dl -t http://www.youtube.com/watch?v=DO9ZWDaLLxA
And I saw it connecting to YouTube several times and downloading the video. In the end, I found a big file named the_heist-RRZyz1vXkPE.flv in the current firectory, which is the video file.
Now lets convert it into MPEG with ffmpeg:
bash$ ffmpeg -i the_heist-RRZyz1vXkPE.flv -acodec copy -sameq heist.mpg
-acodec copy will cause ffmpeg to copy the audio from input to output file, while -sameq causes the output video quality to be the same as the source, but output file will be very big. For YouTube videos, you can use -b 320000 instead of -sameq to get smaller file sizes.
I saw ffmpeg taking some time to convert, and in the end I got the heist.mpg file which I was able to confortablly play in any MPEG aware video player, as mplayer.
If you want to convert the video file into MP4, which is the format supported by iPod Video players, you just change the extension:
bash$ ffmpeg -i the_heist-RRZyz1vXkPE.flv -acodec copy -b 320000 heist.mp4
Ffmpeg will take care to use the maximum screen size available from the source (the .flv file) so the converted file will be as hi-fi as YouTube let be (not too high really).
Enjoy your video.