Rabu, 16 Maret 2011

Setting up an Ubuntu webcam server

Sharing a webcam stream in Ubuntu is not the easiest thing, but it’s not too bad if you have some help. This tutorial will explain how to use the package webcam-server. It seems to work pretty well for me. I had to write the startup script myself, but I’m going to share that with you. To use webcam-server to it’s full potential, you should have Apache installed.

Follow up:
The first thing you will want to do is install the webcam-server package:
sudo apt-get install webcam-server
The webcam-server binary will be installed along with the java applet and html needed to host a live stream on a webpage.
Next, you will want to setup the startup script. This will allow you to control your webcam server as a daemon, and also start webcam-server at startup.
Open a new file in the /etc/init.d directory with your favorite editor. Nano is the easiest, so I’ll use that in the example:
sudo gedit /etc/init.d/webcam-server
Write a starup script, or simply use this one:
#!/bin/sh

SERVER_BIN=webcam-server
LOCK_FILE=/var/lock/$SERVER_BIN
RTRN=0
OPTIONS='-v -g 320x240 -p 8888 -c hacktivision.com'

start() {

[ -f $LOCK_FILE ] && echo "$SERVER_BIN already started"
[ -f $LOCK_FILE ] && return

echo -n "Starting $SERVER_BIN: "
export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so
nohup $SERVER_BIN $OPTIONS > /dev/null 2>/dev/null &
RTRN=$?
[ $RTRN -eq 0 ] && echo Started! || echo FAIL
[ $RTRN -eq 0 ] && touch $LOCK_FILE
}

stop() {
[ -f $LOCK_FILE ] || echo "$SERVER_BIN is not running"
[ -f $LOCK_FILE ] || return
echo -n "Stopping $SERVER_BIN: "
pkill -f "$SERVER_BIN $OPTIONS"
RTRN=$?
rm -f $LOCK_FILE
[ $RTRN -eq 0 ] && echo Stopped! || echo FAIL
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RTRN=1
esac

exit $RTRN
Now you just need to make your startup script run when Ubuntu starts up. Use the following commands:

sudo chmod +x /etc/init.d/webcam-server
sudo update-rc.d webcam-server defaults

Let’s test our webcam server now. We will start it using our script, and then see if we can view the http image stream (we will check out the video stream later).
sudo /etc/init.d/webcam-server start
Open Firefox, or any web browser and navigate to http://localhost:8888/. You should see an image of what your webcam server is pointed at. In Firefox, if you hold down CTRL+SHIFT+R, you can almost get a stream going by constantly refreshing the image.
The rest of this post requires that Apache be installed. If Apache is not installed, install it. Basically, you want to run:
sudo apt-get install apache2
When you installed webcam-server, it put some web files on your hard drive. These files allow for a java app on a webpage to stream your webcam. We will assume that your webroot is /var/www. Replace /var/www with whatever webroot you want to use in the following code.
Copy the web files to your webroot
sudo cp /usr/share/doc/webcam-server/applet/* /var/www/
and test by going to http://localhost/webcam.html.

0 komentar:

Posting Komentar

Silahkan masukkan saran dan kritik anda:

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by| Bloggerized by joevhan - Java Creation