убунту като уебкам сървър

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 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:

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:

<html>
<head>
<title>WebCam</title>
</head>
<p align="center">
<a href="http://hacktivision.com" title="hacktivision.com - Ubuntu webcam server">Hacktivision</a>
</p>
<div align="center">
<APPLET CODE = "WebCamApplet.class" archive="applet.jar" WIDTH = "320" HEIGHT = "240">
<param name=URL value="http://hacktivision.com:8888">
<param name=FPS value="60">
<param name=width value="320">
<param name=height value="240">
</APPLET>
</div>
</body>
</html>

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

С етикет: , ,
Публикувано в linux

Вашият коментар

Вашият имейл адрес няма да бъде публикуван. Задължителните полета са отбелязани с *

*