How to Set up an Ubuntu webcam server
Welcome to the tutorial guide. The guide will present the user with information on how to set up an Ubuntu webcam server. It is important to note that Apache should be installed in order to gain full benefits of webcam server.
If you follow the advise and steps as mentioned in this tutorial, then you will be able to set up an Ubuntu webcam server in a successful manner.
- Let’s 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.
- The next thing that you will need is to setup the startup script. This will allow you to control your webcam server as a daemon, and also start webcam-server at startup.
- You can open a new file in the /etc/init.d directory with Nano as an editor.
sudo nano /etc/init.d/webcam-server
- Now you have to write a starup script:
#!/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
- After writing the script as mentioned, you need to make your startup script run when Ubuntu starts up. You can use the following commands:
sudo chmod +x /etc/init.d/webcam-server
sudo update-rc.d webcam-server defaults
- Now, it’s time to test the webcam server. We will start it using the script, and then see if we can view the http image stream
sudo /etc/init.d/webcam-server start
- Now, you can open Firefox, or any web browser and navigate to http://localhost:8888/. You will be able to view 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.
It is good to know that Apache needs to be installed. If Apache is not installed, the you need to install it. You can run following:
sudo apt-get install apache2
- When you installed webcam-server, some of the web files will be installed on the hard drive. Please remeber that these files allow for a java app on a webpage to stream the webcam. If your webroot is /hat/www, then please replace /hat/www with whatever webroot you want to use in the code as provided below:
Copy the web files to the webroot
sudo cp /usr/share/doc/webcam-server/applet/* /hat/www/
- A testing can be carried out 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.
If you followed the advise and guidance as provided in this tutorial, then you would have succefully set up an Ubuntu webcam server.













