This is a very brief HOWTO on how to capture Youtube and Google videos to your computer, saving them as AVI files encoded in the MPEG4 format, using only one command (actually, a few commands that you can cut & paste from this page).
Unlike most other articles around the net on this subject, this does not require the specialized plugins for Firefox or programs. All you need is a Linux workstation running any fairly recent Linux distro, and FFMpeg.
Step 1 — Make sure you have what you need
You need to be running Firefox. You’ll also need FFMpeg. To check if you have FFMpeg installed, just type “ffmpeg —version” at the shell prompt. You should see something like this:
$ ffmpeg --version
ffmpeg version CVS, build 3276800, Copyright (c) 2000-2004 Fabrice Bellard
(...) (many other lines removed)
If you don’t see the above, you’ll need to install ffmpeg. In Ubuntu and most other Debian variants, all you need is “apt-get install ffmpeg”. The installation procedure for other distributions of Linux will vary.
Step 2 — Locate and playback the content
Fire up Firefox and go to the website of your choice (usually Google Videos or Youtube). Select and play the movie you want. Allow the movie to end normally (this will guarantee that we have a fresh copy of the movie in the Firefox cache.)
Step 3 — Convert and save
Open command prompt and cut/paste the following into it:
ffmpeg -i "$(find ~/.mozilla -regex '.*Cache.*' -a -not -regex \
'.*_CACHE_.*' -printf '%T+ %p\n' | \
sort -n | awk '{ print $2 }' | xargs file | \
grep -i "Video" | tail -1 | awk -F : '{ print $1 }')" \
-vcodec msmpeg4v2 -b 200 -ab 64 -ar 22050 -s 320x240 \
/tmp/video.avi
You should see something like:
Input #0, flv, from '/home/youruser/.mozilla/firefox/randomnumber/Cache/5D2BD385d01':
Duration: N/A, bitrate: N/A
Stream #0.0: Audio: mp3, 22050 Hz, mono
Stream #0.1: Video: flv, yuv420p, 320x240, 1000.00 fps
Output #0, avi, to '/tmp/output3.avi':
Stream #0.0: Video: msmpeg4v2, yuv420p, 320x240, 25.00 fps, q=2-31, 200 kb/s
Stream #0.1: Audio: mp2, 22050 Hz, mono, 64 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Stream #0.0 -> #0.1
Press [q] to stop encoding
And a frame counter. At this point, FFMpeg is converting your movie to mpeg4. This will take a while, depending on the speed of your computer and the length of the movie.
When the bash prompt returns, you’ll have your file encoded as “/tmp/video.avi”.
Troubleshooting and optimizations
Despite its intimidating look, the script above does something very simple: it locates Firefox’s cache directory and encodes the most recent file that looks like a “Macromedia Video” file. There’s not a lot of intelligence to it, and a few things can go wrong.
Remember that only the most recent file is encoded. Thus, if you watch one video and watch another, the first one will not be encoded. Worse yet, if you try to watch the first video again, it’s already in the cache, so it won’t be reloaded. As a result, it will never be the “newest file” in the cache again. To fix this, on Firefox, click on “Edit->Preferences->Privacy->Cache” and then click on the “Clear Cache Now” button. Reload the desired video and repeat the procedure.
Another problem is that there are a number of versions of ffmpeg floating around. Yours may have a slightly different syntax, so YMMV.
If you intend to run the program more than once, it may be a good idea to save it into a shell script. To do that, cut & paste the commands into a file called “/usr/local/bin/ffcap”. Then, turn on the executable bit on this file with:
chmod 755 /usr/local/bin/ffcap
And you should be able to run all the shenanigans above just by type “ffcap” at the bash prompt.
You may also want to tweak the compression parameters or change the output codec. More compression means lower quality, but smaller resulting files. Check ffmpeg’s documentation for that.
If you’re using Gnome, you may want to change the output file from “/tmp/video.avi” to something like “~/Desktop/video.avi”. This will make the video appear on your Gnome desktop when processing is finished. If you save the commands into a script (see above), you may even create an icon in your desktop pointing to the script, so capturing videos is only a click away.
[Permalink] |
|
|
|
|
