Page 1 of 5 123 ... LastLast
Results 1 to 10 of 42

Thread: How to setup a webcam server using webcam-server (Includes daemon script)

  1. #1
    Join Date
    Oct 2006
    Beans
    14
    Distro
    Ubuntu Studio 9.04 Jaunty Jackalope

    How to setup a webcam server using webcam-server (Includes daemon script)

    This tutorial explains how to setup a webcam server using the webcam-server package. I have written a daemon script since webcam-server does not provide one. I will provide it to you. This tutorial comes from my blog. I will provide the link to the original post, but note, I am simply elaborating on my original writing.

    I used Ubuntu 9.04 and a Logitech QuickCam Communicate MP to create this tutorial. It is a good idea to see if your webcam is working by using "Cheese Webcam Booth" or "Camorama Webcam Viewer". Both can be installed using "Add/Remove..." in the main menu in the task bar.

    So let's get started!

    1. Installing the webcam-server package

    The webcam-server package can be installed by searching with synaptic if you prefer to use a GUI. The command line is

    Code:
    sudo apt-get install webcam-server
    Enter your password if prompted. Answer yes with a "y" if prompted.

    2. Create the startup script.

    Use your favorite text editor to create and edit the file /etc/init.d/webcam-server. You will need to be root or use sudo. This command will create and open the file in nano:

    Code:
    sudo nano /etc/init.d/webcam-server
    Once open, paste the following text into the file:

    Code:
    #!/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
    Please note that the line

    Code:
    export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so
    is required for some webcams, but you may be able to remove it if your webcam does not require it. The workaround was found at https://bugs.launchpad.net/ubuntu/+s...sn/+bug/314805.

    3. Set permissions and link the startup script

    You will need to set permissions and create a link in the /etc/rc3.d directory that points to the script. Here are the commands to do so:

    Code:
    sudo chmod +x /etc/init.d/webcam-server
    sudo update-rc.d webcam-server defaults
    Again, enter your password if prompted.

    4. Test your webcam and startup script

    It's a good idea to test if your startup script and webcam are working at this point. You can do this by running

    Code:
    sudo /etc/init.d/webcam-server start
    and then using your browser to view http://localhost:8888/. You should see a snapshot from your webcam. Do a full refresh to see an updated picture. If you do not see a picture, or get an error, consider adding or removing the "export LD_PRELOAD=..." line from your script. If that does not work, please reply with your findings and I will try to help.

    5. Install Apache HTTP Server

    Up to this point, you can view snapshots from your webcam locally, but you probably want to share your webcam with the world (or at least some friends). To do this, you will need to install Apache (or another web server if you choose).

    To install apache run

    Code:
    sudo apt-get install apache2
    Accept all the default options, or if you are an advanced user, configure Apache as you so choose. Apache will be started when installation is complete. Also, your webroot, or the directory that Apache will share.

    *You may need to forward port 80 on your router to your computers IP address.

    6. Copy the webcam-server html and applet to your webroot

    The webcam-server package comes with html and java files that will allow visitors to see a stream of images from your webcam. The webpage uses an applet to do this.

    To copy the files to your webroot run

    Code:
    sudo cp /usr/share/doc/webcam-server/applet/* /var/www/
    To test if you copied the files correctly, and if Apache is working, goto http://localhost/webcam.html.

    You should see a stream from your webcam. If you do not, make sure several files have been copied to your webroot, including webcam.html and some jar and gz files.

    Conclusion and tips

    You are now setup to stream your webcam on a webpage, but there is more to do to share it with the world.

    The default webcam.html file is setup to only run at 1 frame per second and only be server to localhost, meaning only on your computer. It can be edited to server at a domain or from an IP address though. You can also add your own HTML to customize the page that is streaming your webcam.

    Here is an example of what the webcam.html file would look like on my website, hacktivision.com at 60 frames per second:

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

    I wrote the original article which can be found at http://hacktivision.com/index.php/20...-server?blog=2.

    I found the workaround used in the startup script at https://bugs.launchpad.net/ubuntu/+s...sn/+bug/314805.

    And of course, much of my Linux knowledge was attained right here at Ubuntu Forums.
    Last edited by d3k4y; June 24th, 2009 at 10:27 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Kitakyushu Japan
    Beans
    9,361
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    The startup script won't allow a stop:
    Code:
    $ sudo /etc/init.d/webcam-server stop
    Stopping webcam-server: FAIL
    Also, I couldn't get this to output any video. Though to be fair, I haven't gotten any cam server software to output video. Cheese works though, and VLC will accept a live stream. Just can't get any server software to do squat.

  3. #3
    Join Date
    Oct 2006
    Beans
    14
    Distro
    Ubuntu Studio 9.04 Jaunty Jackalope

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    dmizer, start the webcam-server daemon as described in the tutorial, then run:

    Code:
    sudo rm -f /var/lock/webcam-server
    sudo pkill -f "webcam-server -v -g 320x240 -p 8888 -c hacktivision.com"
    to stop the webcam-server.

    Please report your results.

  4. #4
    Join Date
    Mar 2006
    Location
    Kitakyushu Japan
    Beans
    9,361
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    Yes, this kills the server.

    Still get zero output from the camera though.
    Last edited by dmizer; June 24th, 2009 at 07:38 AM.

  5. #5
    Join Date
    Oct 2006
    Beans
    14
    Distro
    Ubuntu Studio 9.04 Jaunty Jackalope

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    Well, then let's try to figure that out before we figure out the startup script. What happens if you run webcam-server by itself? Can you get anything when you goto http://localhost:8888/?

    Do you get an error? A black box?

  6. #6
    Join Date
    Mar 2006
    Location
    Kitakyushu Japan
    Beans
    9,361
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    This is the error I get:
    Code:
    dmizer@tsubame:~$ webcam-server
    No supported colour palette found.
    I've done some searching on that error and haven't found much. I get the same error from 3 different webcams, all of which work perfectly in skype and cheese. Cheese can even record video.

    Also, I've made sure that my account is a member of the video group, as well as made sure that www-data is a member of the video group:
    Code:
    $ cat /etc/group | grep video
    video:x:1002:dmizer,www-data
    Last edited by dmizer; June 25th, 2009 at 01:28 AM.

  7. #7
    Join Date
    Oct 2006
    Beans
    14
    Distro
    Ubuntu Studio 9.04 Jaunty Jackalope

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    I got that error with my logictech. That's what the line
    Code:
    export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so
    is supposed to fix.

    Try running this:
    Code:
    export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so; webcam-server
    If it starts webcam-server successfully, check to see if you get any output at the localhost address I gave you.

    That fixed my issue. But yeah, I'd start googling for your specific webcam and its compatibility with Ubuntu.

  8. #8
    Join Date
    Feb 2006
    Location
    Lansing MI
    Beans
    87
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    Hi d3k4y - Thank you for the excellent How-To. I've managed to setup everything you outlined here successfully, but when I use the preview at http://localhost:8888 I get a single picture from the web cam. Refreshing the browser does not change anything.

    It seems the camera takes one picture and nothing else until you restart the server, then the same thing happens again (new picture, doesn't take any others).

    If I run webcam -v by itself and connect to the preview URL I can see the following output from my terminal:

    Code:
    2009-08-04 15:13:38 [/dev/video0] webcam_server started
    2009-08-04 15:13:47 [/dev/video0] 127.0.0.1 connected via HTTP
    2009-08-04 15:13:49 [/dev/video0] 127.0.0.1 disconnected, 2 seconds, 4611 bytes, 2.25 Kbytes/second, 1 frames, 0.50 fps
    2009-08-04 15:13:52 [/dev/video0] 127.0.0.1 connected via HTTP
    2009-08-04 15:13:52 [/dev/video0] 127.0.0.1 disconnected, 0 seconds, 4611 bytes, 4.50 Kbytes/second, 1 frames, 1.00 fps
    2009-08-04 15:13:53 [/dev/video0] 127.0.0.1 connected via HTTP
    2009-08-04 15:13:53 [/dev/video0] 127.0.0.1 disconnected, 0 seconds, 4611 bytes, 4.50 Kbytes/second, 1 frames, 1.00 fps
    Any idea why I can't get it to update the image? I really want to use this software but a streaming webcam that only shows one frame is pretty useless.

    I am using a Logitech V-UBK45. Cheese can utilize the cam without any extra steps or modifications.

    Thanks in advance for any advice!

  9. #9
    Join Date
    Oct 2009
    Beans
    2

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    So I can get webcam-server working, and it SEEMS apache2 is working even though I get this error when starting:

    apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

    My symptom: localhost/webcam.html does not display anything. The source says:
    <html>
    <head>
    <title>WebCam</title>
    </head>
    <APPLET CODE = "WebCamApplet.class" archive="applet.jar" WIDTH = "320" HEIGHT = "240">
    <param name=URL value="http://localhost:8888">
    <param name=FPS value="4">
    <param name=width value="320">
    <param name=height value="240">
    </APPLET>
    </body>
    </html>
    and there are camera images on localhost:8888. I can even constant refresh to get a semi-stream going.

    Do I have to set up apache2 ports and/or virtual host for this to work?

  10. #10
    Join Date
    Oct 2009
    Beans
    2

    Re: How to setup a webcam server using webcam-server (Includes daemon script)

    Quote Originally Posted by radioraheem View Post
    Hi d3k4y - Thank you for the excellent How-To. I've managed to setup everything you outlined here successfully, but when I use the preview at http://localhost:8888 I get a single picture from the web cam. Refreshing the browser does not change anything.

    It seems the camera takes one picture and nothing else until you restart the server, then the same thing happens again (new picture, doesn't take any others).

    If I run webcam -v by itself and connect to the preview URL I can see the following output from my terminal:

    Code:
    2009-08-04 15:13:38 [/dev/video0] webcam_server started
    2009-08-04 15:13:47 [/dev/video0] 127.0.0.1 connected via HTTP
    2009-08-04 15:13:49 [/dev/video0] 127.0.0.1 disconnected, 2 seconds, 4611 bytes, 2.25 Kbytes/second, 1 frames, 0.50 fps
    2009-08-04 15:13:52 [/dev/video0] 127.0.0.1 connected via HTTP
    2009-08-04 15:13:52 [/dev/video0] 127.0.0.1 disconnected, 0 seconds, 4611 bytes, 4.50 Kbytes/second, 1 frames, 1.00 fps
    2009-08-04 15:13:53 [/dev/video0] 127.0.0.1 connected via HTTP
    2009-08-04 15:13:53 [/dev/video0] 127.0.0.1 disconnected, 0 seconds, 4611 bytes, 4.50 Kbytes/second, 1 frames, 1.00 fps
    Any idea why I can't get it to update the image? I really want to use this software but a streaming webcam that only shows one frame is pretty useless.

    I am using a Logitech V-UBK45. Cheese can utilize the cam without any extra steps or modifications.

    Thanks in advance for any advice!
    Mine was doing this without an internet connection. I brought eth0 back up, and could refresh to get new images.

Page 1 of 5 123 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •