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 nano /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 320×240 -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:

cd /etc/rc3.d/
sudo ln -s ../init.d/webcam-server S99webcam-server

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.

The java applet in the webcam.html file is, by default, configured to stream at 1 frame per second. It is also configured by default to use “localhost” as the domain. Here’s an example of a webcam.html file with a maximum FPS of 60 and hosted on hacktivision.com:

WebCam

Hacktivision

You should now be all set to show your webcam stream to the world!

Please, use the comments. Let me know if you have any problems. Call out my typos and bad grammar. Link to your site and show me how you use your webcam server.

อ้างถึง http://hacktivision.com/index.php/2009/06/16/setting-up-an-ubuntu-webcam-server?blog=2

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s