Archive for March 2008
You would like to record the video stream from your USB webcam. Make sure you have the correct kernel drivers installed and then use ffmpeg to capture the video from the video for linux interface.
Linux Drivers for your Webcam
Before capturing video you must make sure your webcam as been recognized by Linux, many modern Linux distributions will load the drivers you need by default, but in case yours doesn't, you can take a look at my other article "Taking snapshots from a webcam under linux" for some notes on linux kernel drivers.
You can check if your webcam has been recoginised by linux after plugging it in look for files called /dev/video0 or /dev/video1 (if you have more than one) in the file system. Alternatively, using the 'dmesg' command from the bash command line shell you should be able to see initialization messages from the webcam and its drivers
Just a note on situations when you have more than one webcam attached to your computer. There is a bandwidth limit that you may hit with USB. I found that when I had two webcams connected to an external hub which linked into just one USB slot, when I tried to open the video stream from the second camera, with the first one already open I received a confusing error "No space left on device". I was able to cure this by connecting the two webcams to different slots in the back of the computer and not using the hub.
Grab the video with ffmpeg
Firstly make sure you have ffmpeg and its dependencies correctly installed. Just how you install a packges varies widely for each distribution, so consult your documentation on how to install a package. For example, to install ffmpeg under Gentoo use (from the command line):
emerge ffmpeg
To record video from your web cam, you can open a bash command shell and use the following command.
ffmpeg -an -f video4linux -s 320x240 -r 15 -i /dev/v4l/video0 -vcodec mpeg4 -vtag DIVX /tmp/out.avi
This will save video using mpeg4 encoding (which is the same as DivX) and at the default bandwidth. The default bandwidth may not provide sufficient quality, so you can increase the bandwidth and hence the quality of the encoding using the -b option like this:
ffmpeg -an -f video4linux -s 320x240 -b 600k -r 15 -i /dev/v4l/video0 -vcodec mpeg4 -vtag DIVX /tmp/out.avi
You want to grab individual images or snapshots from your USB webcam and save them to image files. Make sure you have the correct kernel drivers for your webcam and then use mplayer to save the images as described below
Linux Kernel Drivers
There are a huge number of Linux distributions many using different combinations of Linux Kernels and modules, however before you start to use your webcam under linux, you need to ensure that your hardware is supported by Linux, and that the appropriate modules have been compiled into the Linux Kernel. Recompiling kernels is beyond the scope of this article, and quite a lot has already been written on that subject. I'll just mention here that you need to look for support for 'Video for Linux' and the right driver. There is a very versatile module 'GSPCAv1' http://mxhaard.free.fr/download.html which supports a wide range of USB cameras and chipsets. If you have this compiled for your kernel along with Video for Linux (v4l) its very likely your USB camera will work. If your webcam is relatively modern, but is not supported by the GSPCA driver, you might also try the Linux UVC drivers. UVC - USB Device Class Definition for Video Devices, or USB Video Class, defines video streaming functionality on the Universal Serial Bus, and is a standard, so all webcams which support that standard should work with the driver.
Using mplayer to save images
The video viewing software Mplayer also comes with some tools which allow you to capture video and stills, once you have installed Mplayer, you can issue a command like:
mplayer tv:// -tv driver=v4l:device=/dev/video0:width=320:height=240:outfmt=rgb24 -frames 1 -vo jpeg
Mplayer will save a file 000000001.jpg with a snapshot. Mplayer uses ffmpeg to do the conversion, so you will usually need the ffmpeg suite installed too.
Enjoy taking pictures with your webcam!
Plesk already provides a script who's intention is to perform a full backup in a more or less machine/version/software independent manor, however, I have noticed that it doesn't necessarily backup every single property of every single application. For example, it doesn't backup and restore a lot of settings for the mailing list manager software it uses - Mailman -
An example of a full backup on Plesk, belt and braces:
dates=`date +%Y%m%d%H%M%S`
/usr/local/psa/bin/pleskbackup all /home/{myhome}/plesk-${dates}
source /root/shutdown-psa.sh
/etc/init.d/mysqld start mysqldump --all-databases --user=admin --password={mysqlrootpw} | bzip2 > /home/{myhome}/plesk-db-${dates}.sql.bz2
tar cvjf /home/{myhome}/plesk-bku-${dates}.tar.bz2 /var/www/vhosts /etc /var/lib/mailman /root/*.sh /var/qmail /home/{myhome}/plesk-db-${dates}.sql.bz2
chown {user}:{group} /home/{myhome}/plesk-db-${dates}.sql.bz2 chown {user}:{group} /home/{myhome}/plesk-bku-${dates}.tar.bz2
chown {user}:{group} /home/{myhome}/plesk-${dates}.gz
This is an example (and would need to be run as root ). The script referred to above 'shutdown-psa.sh' can be found here. Obviously it should be placed in the root directory when you have copied it to your server.
To use this scripts, please substitute:
{mysqlrootpw} : The SQL root password
{myhome}: Your home directory (its usually the same as your username)
{user}: Your username
{group}: Your Group
This runs the standard plesk backup (and also the plesk shutdown script mentioned in my previous post). It also creates a dump of the mysql database, and a file system backup of the critial data areas on your server. However before using this script, please review it carefully and make any alterations that might be suitable to your situation. If you have any doubts or questions, leave a comment and I'll see if I can help. Please of course remember to test your backups once you have made them, to be sure that this script works in your situation.
Delete bash history
Bash is a powerful, free, command line shell available in most Linux/Unix distributions. It has build in job control capabilities, in addition useful scripting capabilities. By default it maintains a history of up to the last 500 commands you have typed, which is clearly useful. However in an environment of shared computers and the need for increased privacy and security, its sometimes useful to be able to remove the history. This can be done easily.
1. Make sure you have only one bash instance open with your username
2. Use
history -c && rm -f ~/.bash_history
3. Your done!
Why does this work? Bash stores its history both in memory and in a file in the root of your home directory called .bash_history. In order to erase the history in bash, you must delete the history recorded in both places. You need to have the bash shell open only in one place, because if you clear it in one window, but not another, the .bash_history file will be re-written again by the 'other' bash shell (the one you didn't erase) when it exits.
References
The problem
The Linksys Compact Wireless-G Internet Video Camera WVC54GC is a linux based wireless webcam with its own streaming web server built in. Windows users can view the video stream through Microsoft Internet Explorer without the need to install any extra software other than allowing the supplied Active-X control to run. The webcam has a web based management interface which is mostly usable from Firefox under windows or Linux, the main exception is you cannot see the video stream from the webcam using the builtin Active-X control. Firefox doesn't support ActiveX, instead it uses a different plugin mechanism 'Netscape Plugin Application Programming Interface'. This does the same kind of job as ActiveX, but is more platform independent. In earlier versions of Firefox it was possible to use a wrapper to load ActiveX controls, as of Firefox 2, this is no longer possible.
The Solution
Using a combination of open source software you can obtain a very similar result, with a view of the stream appearing within the management interface. This solution works on both Windows and Linux. This solution has been tested on Windows XP, 32bit Gentoo Linux and 64bit Gentoo Linux.
How it works
Instead of using the Active-X control built into the webcam, a Greasemonkey script edits the page while its inside your browser, replace a reference to the Active-X control with a reference to an embedded VLC object, which takes its stream from the webcam. You may be wondering, why use VLC instead of Windows Media Player to view the stream from the WVC54GC? There are two good reasons. Firstly, and most obviously, that solution wouldn't work under Linux. Secondly when I was testing this solution, I found that Windows Media Player seemed to take a very long time buffering the stream before actually beginning to play it; while VLC only takes a couple of seconds to get started.
Step 1: Install the following software if you don't already have them.
VLC media player A powerful and versatile, multiplatform media player
Firefox 2 or above If you are reading this then I guess its your favorite browser
Greasemonkey firefox plugin A scripting tool for manipulating web pages on the fly
This might seem a lot of software to install just to view the video stream, however these pieces of software are both very good tools to have installed on your computer and each is worth taking a look at in its own right - they will certainly earn their disk space.
Step 2: Click here to install the Greasemonkey Script
Step 3: Visit your webcam web user interface as normal click on 'View Video', wait a couple of seconds and then enjoy.
The problem
For some locally installed programs, for example Eclipse SDK, when you try and invoke them you will see the following error:
* run-java-tool was invoked directly
* run-java-tool should only be used via symlinks to it
By locally installed, I mean java programs that you are running from somewhere in your home directory, rather than those which have been installed using emerge.
The workaround
This problem seems to be related to the way Java is managed under Gentoo Linux, and while we wait for a fix as the real solution, you can do the following (as root) to allow your programs to work.
cd /usr/bin
rm java
cp run-java-tool java
While I am not sure of the long term consequences for doing this in your Gentoo installation, it does solve the problem. I will post an update here, if there is anything you need to do to remedy the situation once an official fix is produced
For more information on how java is managed in Gentoo Linux, visit http://java.gentoo.org