General geeky interlude…
From time to time I need to download, grab from a webcam, convert, cut, and generally manipulate video files, and every time I do it I have to look up the settings for mplayer, mencoder or ffmpeg again from scratch. So I thought I’d put some recipes for common tasks up here just in case they are useful for anyone else. These use mplayer and mencoder which are available for windows, macosX and linux, but I can only comment on the linux version so don’t ask me any windows questions!
Finding a webcam
Lots of people put webcams pointing at sites of interest (or sites of utter dullness…) live on the internet. If you find yourself wanting to grab footage from these for later use, there are two ways to do it. Both of these methods start with finding a webcam (duh). You can do this using Google, either by searching for webcams or by searching for particular url strings. This search, for example http://www.google.com/search?q=inurl%3Aview%2Fview.shtml will find Axis brand web cams by looking for the term view/view.shtml in a website address.
If you’re going to go for a movie file, first you have to locate the actual movie file, which can involve poking around in the web source code.
For axis cams it’s often at /mjpg/video.mjpg (so the camera you can view at http://c-cam.uchicago.edu/view/view.shtml has the movie file located at http://c-cam.uchicago.edu/mjpg/video.mjpg).
Saving the stream
Once you have found this, you can get mplayer to save the file for you using this command line:
mplayer -dumpstream http://url_of_videofile -dumpfile outputfile
Note, videos are big, so make sure you’re not dumping it to somewhere with quota issues. In linux, you press control-c to quit downloading the file.
Building the index
The outputfile created by this command line can have some problems – some things will play it, but in order to cut, fastforward and otherwise edit it it’s useful to build an index for the video file. You do this in mplayer with this command line:
mencoder -idx input.avi -ovc copy -oac copy -o output.avi
That’s the first way.
Downloading a stack of jpegs instead of a video
The second way is REALLY HACKY and involves a shell script and a load of jpg files. Most webcams will let you get a snapshot image, and this method exploits that. It’s good for webcams where the video is really slow and you’re not actually bothered about frame rate in your output “video”, or webcams where you can find the snapshot option but not the actual video file. First find the snapshot image on the webcam’s website, view the image, check that pressing reload in your browser updates the image, and then copy the image address.
With the image address, this method gets “video” by using a shell script to download the image repeatedly as fast as it can, saving each image as consecutively numbered jpgs. Here’s a shell script – if you’re not sure how to run or change this, this method’s probably not for you.
#!/bin/sh
for i in $(seq 0 300000); do
k=10000000;
j=$(($i + $k));
echo "getting ";
wget http://server_name/jpg/image.jpg -O $j.jpg;
done
You can turn a stack of jpgs back into a video using mplayer or ffmpeg (I’ll do a post on that later). But if you just want to watch a stack of (numbered) jpgs as a movie, you can use mplayer as follows:
mplayer mf://*.jpg
If that’s going too fast for you, try adding a speed argument e.g.
mplayer -speed 0.1 mf://*.jpg
Wow this went way above my head but I’m a couple margaritas too deep to be on the webs anyway so good job and good night!