Dec
28
Raspberry PI Web Cam

Raspberry PI Web Cam

The Raspberry PI is perfectly equipped to turn your USB based web cam into a fully functional IP web cam that you can have lots of fun with, from there you could use tools such as Python to make your project more unique, im having a go at counting passing traffic.

If your wanting to something a bit more simple you could just have a web cam that can be access from anywhere with an internet connection, which is what you will end up with at the end of this guide.

Your shopping list…
  • Raspberry Pi with an OS installed
  • USB Powered HubAmazon UK – Amazon US
    • Important; This one worked for me, however it’s not worked for others, you will find this is the case with a lot of the powered USB hubs, research before buying.
    • We need a hub because the camera’s draw more power than the Raspberry Pi can actually provide, you see the same with some keyboards and USB dongles.
  • Web Cam

You could also look at an external power back and WiFi if you want to make it mobile, a few people have put these in a garden or somewhere without a static power/network source.

1. Get the software ready

Ok so I am going to assume that you have a working PI on some kind of LAN with internet access, the next step as always is to update your PI ensuring you have the latest software and drivers installed.

sudo apt-get update
sudo apt-get upgrade

Now we need to install the software, we are going to be using a great little application called Motion, this will do a few things for us including accessing the USB cam, getting the images, and streaming them via a built in web server. As the name suggests it will also track and trigger events on motion been detected in the video frames (more on that later).

sudo apt-get install motion
2. Plug in your web cam

So now the software is on there it’s time to plug in the web cam and ensure that everything is working, ensuring that you plug it into the powered hub, and then into the PI. Otherwise the webcam will not get enough power to turn on.

When plugged in type the “lsusb” command, you should see a line there with your web cam manufacture, that proves that you have the basic connectivity working.

lsusb
....
Bus 001 Device 002: ID 04ea:1142 Microsoft Corp.
....
3. Configure the software
sudo nano /etc/motion/motion.conf

In here there are a few basic changes that you need to perform:

  • Daemon = OFF to ON
  • webcam_localhost = ON to OFF

You can change other settings but it’s recommend you don’t take more than 2 frames, and you been the default frame pixel size, for stability.

4. Start the software

To ensure that the motion service will actually start as a daemon we need to change another configuration setting, so enter the following:

sudo nano /etc/default/motion

Then change the value “start_motion_daemon=no” to “yes”

Finally you can start the motion service to stream the web cam images

sudo service motion start
Quick Example Image

Quick Example Image

Then after about 30 seconds browse to the new web interface, which should be at the below URL (where 192.168.0.100 is your Raspberry PI’s IP address)

http://192.168.0.100:8081

5. Final Tweeks

Web Port

You could change the web interface port to 80 (from the default 8081), so that you can just browse to the IP address without having to put :8081 at the end, it’s really simple to do, just:

sudo nano /etc/motion/motion.conf

And then change “webcam_port 8081″ to “webcam_port 80″, save the file, and restart the motion service.

sudo service motion restart

Port Forwarding

Final suggestion is enable port forwarding on your home broadband router to the Raspberry PI on port 80, that will mean you can access the web cam from anywhere in the world. There are too many routers in the word to explain how to do it here, but I am sure you will find some help on Google, if not please just leave a comment.

Warning; If you give it internet access via port forwarding this does take up quite a bit of bandwidth, and anyone can see your webcam feed, so only show what you want people to see ;)

Bookmark this on Digg
Share on reddit
Share on StumbleUpon
Bookmark this on Delicious
Share on LinkedIn

You can leave a response, or trackback from your own site.

153 Responses to “How To: Raspberry PI Web Cam Server”

 
  1. Tony G says:

    Many thanks for this, I was almost expecting it not to work as it seemed too simple, but I had it running in 10 mins. Just one point though I had to edit another file as I recieved this error when trying to start the motion service -

    pi@raspberrypi ~/c $ sudo service motion start
    Not starting motion daemon, disabled via /etc/default/motion … (warning).

    I edited /etc/default/motion and all was good.

    pi@raspberrypi /etc/default $ more motion
    # set to ‘yes’ to enable the motion daemon
    start_motion_daemon=no

    pi@raspberrypi /etc/default $ sudo nano motion
    pi@raspberrypi /etc/default $ sudo service motion start
    Starting motion detection daemon: motion.
    pi@raspberrypi /etc/default $

    Thanks again!

  2. LezTastic says:

    Thank you so much, like Tony G, I also had to alter /etc/default/motion, but then I was good to go. I used a Logitech C210 ($17 @ RadioShack).

  3. Fabien says:

    Hi,

    What resolution did you choose ? As far, I only succeed with small resolution like 320×240 … :/

  4. Hunter says:

    If I don’t port forward is it possible to still use this from an outside IP?

  5. Richard Wilkinson says:

    Thanks very much, after a few minutes I had my first RPi streaming video.

  6. Russell says:

    Thanks a lot! It works perfectly.

  7. mike says:

    Thanks for the how to! This was exactly the job that I had my second RPi slated for.

  8. Tushaar Vishnu says:

    Hi I’m making a robot,
    I need to stream multiple webcams Simultaneously. I got one cam working with the above steps, is it possible to stream more than one.

  9. dr_robert says:

    Hi there,

    Thanks for the instructions – I spent all weekend trying to get this to work and eventually succeeded, but the fault was mine and not the instructions which with the right preparation were perfect! so while this may be totally obvious to others, maybe I could share my experience to save noobs like me the pain.

    1)Make sure you are on the latest release – I tried all sorts with no luck until i reflashed my SD and then it worked straight off (update/upgrade wasn’t enough).

    2) The website doesn’t work on midori or ie – worked a treat on firefox though

    only issue I have now is that it seems to stop intermittently, but I haven’t started to investigate yet

  10. Jaypi says:

    Got a grey image with : “unable to open video device”

    • Tom says:

      Have you tired a powered USB hub? can you see the device on a ‘lsusb’ output via terminal?

      • Will says:

        My webcam is showing up on lsusb as bus 001 device 016. It is plugged into a powered USB hub. Still, my browser is showing me a gray box saying UNABLE TO OPEN VIDEO DEVICE. I’ve tried changing the device from /dev/video0 to /dev/bus/001/016 but still no luck.

        Any ideas?

        • Tom says:

          What make of web cam is it?

        • Les Atkins says:

          I’ve just installed this and have this problem too. However, it worked fine on my Ubuntu desktop. What I have discovered is that if I do ‘sudo motion’ in a terminal window on the pi with ‘daemon on’ in motion.conf then it works ok but if i do ‘sudo service motion start’ I get a grey box with the message ‘cannot open video device’. I guess its something to do with permissions. I did see a post that said to ‘chmod 777 /media’ but I don’t have anything listed in /media on my pi.

          • vishal says:

            I encountered the same hurdle with “sudo motion start”.
            I tried “sudo motion” with daemon=On in ‘motion.conf’ and I got ,

            ‘Motion 3.2.12 started’
            ‘Motion going to daeman mode’

            but my ‘sudo uvcdynctrl -f’ command not found

      • Will says:

        So I ran with the -n command and am getting a few things that look suspicious. Here’s what shows up:

        motion thread 1 restart
        thread 1 started
        cap.driver: “pac207″
        cap.card: “CIF single chip ”
        cap.bus_info: “usb-bcm2708_usb-1.2.4″
        cap.capabilities = 0×50000001
        -VIDEO CAPTURE
        -READWRITE
        -STREAMING
        config palette index 8 (YU12) doesn’t work.
        supported palettes:
        0: P207 (P207)
        Unable to find compatible palette format.
        ioctl (VIDIOCGCAP): Inappropriate ioctl for device
        Could not fetch initial image from camera
        motion continues using width and height from config file(s)
        resizing pre_capture buffer to 1 items
        bind(): Address already in use
        problem enabling stream server in port 8081: address already in use
        thread exiting

        • Tom says:

          Sounds like something is already bound to port 8081..

          Check using a ‘netstat -lnutp’ to see your network bindings.

          • Will says:

            Thanks, I’m using port 60080 now and I’m not getting that error message but I’m still getting the p207 issue:

            config palette index 8 (YU12) doesn’t work.
            supported palettes:
            0: P207 (P207)
            Unable to find compatible palette format.
            ioctl (VIDIOCGCAP): Inappropriate ioctl for device

            The thing is, index 0 is not P207, it’s BA81.

            So if I understand this correctly, I think my camera wants to use the p207 palette but that isn’t supported by motion. Is there any way to deal with this issue or do I just need to use a different camera that is compatible with one of the other palettes?

          • Will says:

            Sorry, index 0 is S910. Still not sure how to get it to use p207 since it isn’t one of the palettes listed.

  11. Graham O says:

    Hi, I’ve gone through the above process and get through to the end of Step 4 without any reported problems. But how do I view the webcam image please? Do I go to a web browser on the network, i.e. another PC or a tablet, and type in the ip address? Sorry if it’s a really basic question, but I’m very new to the Pi.
    Thanks

    • Tom says:

      No problem; You go to any device on the network and browse to the address http://192.168.0.100:8081 using your normal web browser, that could be another PC, tablet or even the raspberry PI if you have a monitor plugged in to it.

      Just remember you need to replace the IP address in the above example (192.168.0.100) with the IP address of your Raspberry PI, you can find that by running the command ‘ifconfig’ on the raspberry PI and looking on the eth0 interface, so if your IP is 192.168.1.20, you would browse to http://192.168.1.20:8081

      Hope that helps :)

      • DAN BENDAN says:

        I followed the procedure published except I did not do:
        <>

        I then do this:
        <> I use “http://192.168.0.109:8081″ which is my device.

        I get a file download (file name is “192.168.0.109″).?

        Can anyone tell me what is going on?

        Win7 64 Pro, browser IE 10

        • Mikeymike says:

          I’ve found that the only browser that works is firefox.

          I’ve also found that I can use the VLC media player: go to Media-> open network stream, then type in the full ip address, including the port.

  12. Mobius says:

    Performed all of the steps and I can see that my webcam is turning on/off with the “service motion” commands but when I use Internet Explorer to browse to my Pi’s address (with port 8081 added) I get the dialog box that asks if I want to open or save the download. If I say “open”, I can see that it is collecting data but nothing is displayed in the browset window. Same thing with the “save” option. Is there some sort of browser plug-in that is required to actually view the video stream?

    • Tom says:

      Strange it should just display a webpage with an image at the top left, does this happen on all computers/browsers?

      • Mobius says:

        A poster on the Raspberry Pi forum said that Internet Explorer requires a plug-in but he didn’t know what it was. Told me to try pretty much any other browser like Foxfire, Chrome, or Opera. I installed Foxfire and it came up as it should. I’d still like to find the proper plug-in for Internet Explorer if I can. By the way, you can add the Hewlett Packard KQ246AA webcam to the list of usable devices. Thanks for this simple install procedure.

  13. Shawn says:

    Easy as pi. Next step is getting the camera mounted on some servos and tracking movement?

  14. Tickle says:

    Whenever I go to my Cameras IP, the image only updates for a few seconds, do you know how to fix this?

    • Tom says:

      It could be a few things, frame rate too high? resolution too high? or no USB powered hub between the camera and Raspberry PI.

  15. Hunter says:

    When I go to my cameras IP, the image only updates for a few seconds, any fix?

    • Hunter says:

      # Number can be defined by multiplying actual webcam rate by desired number of $
      # Actual webcam rate is the smallest of the numbers framerate and webcam_maxrate
      webcam_limit 15

      Should read

      # Number can be defined by multiplying actual webcam rate by desired number of $
      # Actual webcam rate is the smallest of the numbers framerate and webcam_maxrate
      webcam_limit 0

  16. Reanaissanceman says:

    Hi, I managed to get it all up and running with some difficulties from my side (this is the best way to learn though). I have only one (final I think) issue: no image on the webpage. I keep getting the messsage : This webpage is not available, Chromium’s connection attempt to 192.168.0.107 was rejected. I ried Firefox as well, but with the same result. My cam’s on 192.168.0.107:8081.
    Can you give me a hint please ?

  17. Reanaissanceman says:

    Fixed it myself: webcam_localhost was still on.

    Thanx for the great tutorial !!!

  18. FunkD says:

    Hi All,

    Thanks for the guide, I had the webcam up and running in no time.

    I cant seem to get motion to work on port 80. it works fine on other ports. Does anyone have any suggestions?

    Thanks in advance.

    • Tom says:

      Ensure that nothing else is already using port 80, check your ‘netstat -lnutp’ output

    • Mike says:

      Port 80 (and anything less than 1024) is a ‘privileged’ port. Only processes currently running as root may bind to those ports.

      Since motion runs as the user ‘motion’, it’s restricted to ports 1024-65535.

      You can edit /etc/init.d/motion, and remove the ‘–chuid motion’ bits should you want to run motion as root.

  19. Renaissanceman says:

    Plugged in a different cam (Trust Spacec@m200) and all I get is a grey image saying: unable to open video device. It shows up in Putty though as a Omnivision )V511+ Webcam.
    Is the device maybe too old to be recognized ?

    • Tom says:

      Could be too old, or not enough of them around meaning there isn’t a lot of people trying to make drivers for them.

      Try updating to the latest software ‘sudo apt-get update’ and ‘sudo apt-get upgrade’

  20. Raedwald says:

    I have also been trying to get motion to run on port 80. I had apache2 running on port 80 but stopped that, modified motion.conf to change the port from 8081 to 80 and restarted the motion service. However I am unable to connect to port 80 using a browser and netstat -lnutp only shows the control port 8080 for motion.

    Any ideas please?

    • Tom says:

      Had the same problem with my raspberry pi, fairly sure a reboot fixed it, although guessing you have tried that already?

      • guziec says:

        Lower ports are available only for processes running with root privleges. You can redirect incoming connections from 80 to 8081 port using iptable command, ex:
        iptables -t nat -A PREROUTING -i wlan0 -p tcp –dport 80 -j REDIRECT –to-port 8081
        (change wlan0 to real webcam interface)

        • dave says:

          logitech webcam is not working on port 80, light just keeps flashing, tried the following

          iptables -t nat -A PREROUTING -i wlan0 -p tcp –dport 80 -j REDIRECT –to-port 8081

          Bad argument `–dport’

          Any other ideas?

          Cheers

          Dave

  21. Richard Scholl says:

    A very good description for the Raspberry Webcam.
    It works directly and I’m happy with it.
    Thank you very much.

  22. Will says:

    FINALLY got motion to run with no errors by installing the imgproc libraries from:

    http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/image_processing/

    now when type in ip:port in my browser I get a page that says:

    Motion 3.2.12 Running [1] Threads
    ALL

    ALL links to the settings in the config file but I don’t see the actual image anywhere.

    • Paul Webster says:

      There are two ports that you can get responses on.
      By default 8081 is the image and 8080 is the control … and it looks like you were going to 8080 (control).

  23. Weston Ruter says:

    Thank you for the excellent blog post. It got me up and running with my own Raspberry Pi webcam server, which was quite exciting.

    I am wrestling with a difficult problem, however. The Microsoft LifeCam goes becomes lost after a few hours of use. I’ve tried everything I can think of to prevent this from happening and having to physically re-connect the camera so that it will be recognized again, but I’m at my wits’ end. So I’ve posted a question up on the Raspberry Pi StackExchange and I’m hoping you might have an idea for what’s going wrong? http://raspberrypi.stackexchange.com/questions/4984/webcam-disconnects-after-a-few-hours-of-running-motion

    • Tom says:

      Hi Weston,

      Thanks for the comment, unfortunately there isn’t any easy answer to get it working, however here are a few things I would try in your case;

      First off I would try lowering your resolution to something like 320×240 and see if it’s any more stable, basically that should lower any load on the Pi.

      You could actually go one step further and change “webcam_port” to zero for one of your tests, that will disable the web server but keep your snapshot functionality running, your not going to get the load much lower than this setup.

      Next get out a multimeter (if you have one), check the USB power output before you plug in the web cam, then once it’s in, and finally once its failed. I have heard of a few powered USB hubs out there that don’t really inject enough power, especially if there are a few devices using it.

      Finally I would also look at trying a wired network connection for a while instead of WiFi, again just to rule it out.

      Hope some of them might help you pin it down :)

      Tom

  24. Grim says:

    What is the cpu usage you guys got? I needed to take down the quality and now i got 60% cpu usage for the motion daemon. If I take al teh default settings the cpu goes to 100%. Someone with the same problem or a solution?
    greetz

    • Tom says:

      Try lowering the frame rate instead of the quality, sometimes that helps.
      But your correct, it does use quite a lot of CPU on the default.

  25. murali says:

    Hi tom,
    Thanks for the post. Helped me a lot :)
    I would like to save the images acquired from webcam on desktop. I am new to python and reasonably good with C programming. Please let me know how to go about it.
    Thanks!

    • Tom says:

      If you mean the desktop on your Raspberry Pi then just change the save directory.

      But if you mean onto your desktop computer then instal an FTP server on the Pi, and create a script that collects the images.

  26. [...] Install Motion http://pingbin.com/2012/12/raspberry-pi-web-cam-server-motion/ [...]

  27. AI-Samurai says:

    Thanks for the tutorial. Everything worked perfectly,even with a $4.99 generic chinese webcam, but I cannot view the images using the Midori browser on the start-up Raspberry image, although google over the network works fine. I have run update and upgrade etc. Instead of a webcam stream, Midori on PRi just displays text.
    Any solutions anyone? Thanks, and keep building.

  28. Josh says:

    Thank you so much for this great tutorial! It worked right away without any extra configuration! Is there any way to make it have a faster frame rate or at least go faster on the hosted site?

  29. Tim Fesig says:

    Found that motion puts images in /tmp/motion… Might that fill the
    SD card after some time???? Should options be turned off to keep the SD card from becoming full???

  30. Nelson Minar says:

    What a great tutorial, thanks! The USB hub may not be necessary; at least, it’s not with this old Microsoft Lifecam I have. OTOH you need a source of USB power anyway so might as well get a proper hub.

    To the folks trying to use port 80; on Unix by default you have to be root to bind to ports < 1024, and motion runs as the user motion. Various workarounds here: http://stackoverflow.com/questions/413807/is-there-a-way-for-non-root-processes-to-bind-to-privileged-ports-1024-on-l

  31. Paul_griff says:

    I followed your instructions without any problem but think my webcam may be the problem (Logitech E1000 with no drivers) when I try to browse to my PI’s address I just get “the page cannot be loaded”
    The webcam is recognised when I use the lsusb command, does motion act as the webserver?
    The webcam does work very slowly using CHEESE and it uses 100% CPU resources, any help or advice much appreciated.

    • Tom says:

      Yes motion should act as a web server, do a ‘netstat -lnutp’ and you should be able to check that it’s listening on a port.

      When you know the port browse to that using any normal browser, e.g. http://192.168.1.10:8080 if your Pi is 192.168.1.10 and motion is listening on port 8080

      • OK says:

        Hey I have exactly the same problem. In Midori I get:

        Error – http://10.0.0.95:8080/

        The page ‘http://10.0.0.95:8080/’ couldn’t be loaded.

        Cannot connect to destination (10.0.0.95)

        I have a Logitech Quickcam 4000 which is detected when I type lsusb.

        If I type netstat -lnutp I get:

        tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN

        Connecting to 127.0.0.1 doesnt help either, nor did changing port to 80. What should I do now?

        • Richard says:

          Same problem here.
          Common issue then with Logitech devices?

          • Les Atkins says:

            The port is 8081 if you post is not a typo. 8080 is the control port and you should just see ‘All’ on the screen. Access from a computer other than the pi is controlled by ‘control_localhost off’ for 8080 and ‘webcam_localhost off’ for 8081 in motion.conf. Hope this helps.

          • webhead says:

            Hi, thanks for the instructions and everyone’s comments. But I get the message “the image …:8081 cannot be displayed because it contains errors”. I have a Logitec webcam and I’m using iceweasel. I also tried several different USB ports (all powered).

  32. Carlo says:

    Fantastic tutorial! Thanks a lot!

  33. Paul R says:

    This was a life saver – great tutorial. Had a few issues accessing the webcam from outside the network but i think that was user error mainly.

    Follow the advice above and it’ll work.

  34. Harry says:

    Logitech QuickCAM 9000pro works perfekt!
    http://canonversteher.de/webcam

    • Tom says:

      Thanks for letting us know!

    • Harry says:

      Since todays system-updates motion crashes after less than a minute….

      • Kiran says:

        For me it up running fine, i am using Logitech Webcam C110

        Below is my configuration
        daemon=on
        norm=3
        input=8
        auto_brightness=on
        framerate=300
        height=640width=480
        jpeg_filename=motion/%Y%m%d/%v-%H%M%S-%q
        noise_tune=on
        output_all=off
        output_motion=on
        output_normal=on
        quality=1000
        snapshot_interval=500
        target_dir=/home/pi/motion
        text_left=(c) Nestcam
        text_right=%d %b %Y\n%k:%M:%S
        threshold=500
        v4l2_palette=6
        videodevice=/dev/video0
        webcam_localhost=off
        webcam_maxrate=50
        webcam_port=8080
        wecam_quality=100

  35. Sean says:

    I am getting the gray image with “UNABLE TO OPEN VIDEO DEVICE” message, so I tried running motion from the CLI to gather clues…

    Of interest, I see:
    [1] Supported palettes:
    [1] 0: PWC2 (Raw Philips Webcam)
    [1] 1: YU12 (4:2:0, planar, Y-Cb-Cr)
    [1] Selected palette YU12
    [1] Test palette YU12 (320×240)
    [1] Error setting pixel format VIDIOC_S_FMT: Device or resource busy
    [1] VIDIOC_TRY_FMT failed for format YU12: Device or resource busy
    [1] Unable to find a compatible palette format.

    However, I *am* able to run:
    v4l2-ctl –set-fmt-video=width=320,height=240,pixelformat=1
    without error.

    Suspecting permission problems, I checked:
    pi@raspberrypi:/etc/motion# ll /dev/vid*
    crw-rw—T 1 root video 81, 0 Dec 31 1969 /dev/video0

    and:
    pi@raspberrypi:/etc/motion# grep motion /etc/group
    video:x:44:pi,motion
    motion:x:119:

    Any suggestions will be greatly appreciated!

  36. [...] motion detection, I took most of my instructions from this tutorial on motion sensing with Raspberry Pi, which leverages the Motion [...]

  37. xray says:

    http://192.168.0.4:8081/ was my server, not the one you mentioned. If you can’t access your server with one mentioned, type on your pi:

    ifconfig

    Then find your ip address :)

  38. CyberCowboy says:

    Is there a way (preferably with motion) to stream audio as well?

    I’m using the above setup as a “crib cam” and would like to include audio as well so that I can use the Raspberry Pi and a smartphone as a universal baby monitor

  39. JammerX19 says:

    Just wanted to let you know that this worked perfectly! I rigged up my Microsoft LifeCam under an overturned Tupperware container that I hot-glued to a board, then secured the board under a porch window. It is now suspended above a bird nest that is being built on a ledge below the window. Now we can watch mama bird lay her eggs and hopefully we’ll see them hatch!

  40. ez says:

    Thanks for the detailed instructions. The set up went really smooth!
    It doesn’t work in Midori though. The feed is coming through but Midori fails to display the image. Instead, it show a bunch of letters and numbers, similar to when reading a binary file with an editor.

    I’m running wheezy and it the motion feed works great in Chromium, but this sends the CPU running at 100%.

    Any ideas for an alternative browser will be really helpful.

    Thanks

  41. Aminga says:

    I get this when I do “sudo motion -n”:

    [0] Thread 1 – Watchdog timeout, trying to do a graceful restart
    [0] Thread 1 – Watchdog timeout, did NOT restart graceful,killing it!

    It is constantly doing it.

    I have a Cisco VT webcam and I do not get any error whil it is initializing it.I am using port 8080.

    This is cosole messages:

    pi@raspberrypi /etc/motion $ sudo motion -n
    [0] Processing thread 0 – config file /etc/motion/motion.conf
    [0] Motion 3.2.12 Started
    [0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478785
    [0] Thread 1 is from /etc/motion/motion.conf
    [0] motion-httpd/3.2.12 running, accepting connections
    [1] Thread 1 started
    [0] motion-httpd: waiting for data on port TCP 8080
    [1] cap.driver: “pwc”
    [1] cap.card: “Cisco VT Camera”
    [1] cap.bus_info: “usb-bcm2708_usb-1.3.3″
    [1] cap.capabilities=0×85000001
    [1] – VIDEO_CAPTURE
    [1] – READWRITE
    [1] – STREAMING
    [1] Test palette YU12 (320×240)
    [1] Using palette YU12 (320×240) bytesperlines 320 sizeimage 115200 colorspace 00000008
    [1] found control 0×00980900, “Brightness”, range 0,127
    [1] “Brightness”, default 66, current 12
    [1] found control 0×00980901, “Contrast”, range 0,63
    [1] “Contrast”, default 16, current 16
    [1] found control 0×00980902, “Saturation”, range -100,100
    [1] “Saturation”, default -8, current -8
    [1] found control 0x0098090e, “Red Balance”, range 0,255
    [1] “Red Balance”, default 128, current 32
    [1] found control 0x0098090f, “Blue Balance”, range 0,255
    [1] “Blue Balance”, default 128, current 36
    [1] found control 0×00980910, “Gamma”, range 0,31
    [1] “Gamma”, default 1, current 1
    [1] found control 0×00980911, “Exposure”, range 0,255
    [1] “Exposure”, default 241, current 236
    [1] found control 0×00980912, “Gain, Automatic”, range 0,1
    [1] “Gain, Automatic”, default 1, current 1
    [1] found control 0×00980913, “Gain”, range 0,63
    [1] “Gain”, default 34, current 43
    [1] found control 0×08000000, “Auto contour”, range 0,1
    [1] “Auto contour”, default 0, current 0
    [1] found control 0×08000001, “Contour”, range 0,63
    [1] “Contour”, default 32, current 32
    [1] mmap information:
    [1] frames=4
    [1] 0 length=462848
    [1] 1 length=462848
    [1] 2 length=462848
    [1] 3 length=462848
    [1] Using V4L2
    [1] Resizing pre_capture buffer to 1 items
    [0] Thread 1 – Watchdog timeout, trying to do a graceful restart
    [0] httpd – Finishing
    [0] httpd Closing
    [0] httpd thread exit
    [0] Thread 1 – Watchdog timeout, did NOT restart graceful,killing it!
    [0] Calling vid_close() from motion_cleanup
    [0] Closing video device /dev/video0
    [0] Motion thread 1 restart
    [1] Thread 1 started
    [1] cap.driver: “pwc”
    [1] cap.card: “Cisco VT Camera”
    [1] cap.bus_info: “usb-bcm2708_usb-1

  42. Detlef says:

    Great tutorial. 15 mins – up and running.
    Now I want to store the stream on my NAS. Can u pls point me at some tutorial for doing this. Thx

    • gelu says:

      I did that by mounting a nfs shared directory in wheezy filesystem (edit /etc/fstab with this line “:/shared/nfs/dir /mnt/nfs nfs rw 0 0″ then mount it and in /etc/cron.hourly i added a simple script to move all data from /tmp/motion in a directory on the nas.

  43. adridele says:

    I have attached a usb camera to my raspberry pi, and it works well except for one thing: the size is of the image is half of devices’ specs. The specs say that can effective resolution is Up to 352 x 288. The image I get when I use the browser on port 8081, is 176 x 144. I have set the width and height of the motion.conf respectively. Is there a reason it’s not working as expected, and is there a way to make it work?

  44. HFLaursen says:

    Great tutorial. I have tried using ffmpeg to stream from my 3D-stereo webcam (a cheap “EnVivo”) but it seems unreliable.
    Using ‘motion’ it works perfectly (using only one camera, though).
    Would it be possible to have ‘motion’ capture from both cameras? The register nicely as /dev/video0 and video1. ffmpeg plus some filter setting can output the images next to each other as standard 3D-stereo, preferrably as Right-Left.

    This works on a windows-box with .mp4 files as input (but I haven’t been able to make it work on the RasPi):

    ffmpeg.exe -i c:\temp\outL.mp4 -vf “[in] scale=iw/2:ih/2, pad=2*iw:ih [left] movie=c:\temp\outR.mp4, scale=iw/3:ih/3, fade=out:300:30:alpha=1 [right] [left][right] overlay=main_w/2:0 [out]” -b:v 768k OutSBS.mp4

  45. Matteo says:

    Would like to have found this thread before…
    Anyway I figured out (not without some problems) how to get an IR-modded PS3 Eye camera equipped with 70 LED emitters to work with Motion and have the video stream accessible over the local network from my mobile phone running Firefox for Android.
    Next steps: email alerts from the Raspberry Pi at motion detections (sure it’s quite immediate) and find the easier way to get the access to the stream from anywhere (not sure if possible without a static IP address).

  46. Jan says:

    Hello Tom,
    I have 2 questions:
    1: I get stuck in step 3:
    “In here there are a few basic changes that you need to perform:
    Daemon = OFF to ON
    webcam_localhost = ON to OFF”
    How do I do this? I can’t find this in the text file. Please explain in more detail so that dummies like me can understand it.

    2: “You can change other settings but it’s recommend you don’t take more than 2 frames” Do you mean the webcam can only make ‘video’ of 2 frames/s? that’s not video but pictures…

    Thanks!
    Jan

    • Tom says:

      1)If you type in the below command from terminal it should ask you for a password, after typing that in you should be able to navigate around the text document (using your keyboard) and change the settings like any text file.

      sudo nano /etc/motion/motion.conf

      When you have done changing the configuration close the file and save the changes, by holding ctrl and then pressing ‘x’, this will prompt you to save the changes, simply press ‘y’ followed by enter/return.

      2) That figure is frames per second, not static pictures, you can increase that it just adds more processing load on the device.

  47. jan says:

    Hello Tom,

    Two questions:

    1. “In here there are a few basic changes that you need to perform:
    Daemon = OFF to ON
    webcam_localhost = ON to OFF”

    Could you explain for dummies like me how to do this?

    2. “You can change other settings but it’s recommend you don’t take more than 2 frames…” Does this mean the webcam can only take 2 pics/s, so not real video?

  48. jan says:

    hello Tom,

    thanks for the quick reply. Sorry for posting twice, the website doesn’t confirm my post so I tried again.
    I’ve done step 3 now. But I’m not sure what the IP adress is. As you suggested in one of your answers, I typed ifconfig with the result:
    etho: HW addr: b8:27 etc…
    lo: inet addr: 127.0.0.1
    wlan0: inet addr: 192.168.1.35
    the result at eth0 is not a valid Ip adress, so should I use the one listed at lo?
    something else: I want to put the PI on a (not yet built) robot. Any ideas how to make a powered USB hub (do I really need one?) on batteries?
    Thanks for al the help,
    Jan

  49. Graham says:

    Hi Tom,
    Great tutorial, thanks! My new Microsoft LifeCam Camera works fine for a few minutes then stops responding. starting the deamon as motion -n produces the following, when the website returns “Unable to open video device” and the console shows:

    [1] Retrying until successful connection with camera
    [1] cap.driver: “uvcvideo”
    [1] cap.card: “Microsoft® LifeCam Cinema(TM)”
    [1] cap.bus_info: “usb-bcm2708_usb-1.3.2.1″
    [1] cap.capabilities=0×04000001
    [1] – VIDEO_CAPTURE
    [1] – STREAMING
    [1] Error selecting input 0 VIDIOC_S_INPUT: Device or resource busy
    [1] ioctl (VIDIOCGCAP): Inappropriate ioctl for device

    and then it repeats.

    Do you have any ideas? I’ve tried reinstalling. If I stop/start the daemon it often comes good.

    Thanks
    Graham

  50. [...] Do you have home CCTV? Worried about whether it is running ok or want to check some of the feed remotely. You used to have to use your home PC to do this but this can be expensive to do. The Raspberry Pi makes a great alternative and gives you the ability to remotely connect it and check yo…. [...]

  51. [...] die Google gebruikt had (met VLC) moest werken, maar ben eerst met Motion aan de slag gegaan. De setup ervan is redelijk eenvoudig. Er zitten wat beperkingen aan. De framerate is tamelijk laag. Er worden [...]

  52. Pete says:

    Has anyone tried this with a pi cam? I want to take stills and save to the sd card?

  53. dave says:

    actually change port command should be

    iptables -A PREROUTING -t nat -i wlan0 -p tcp –dport 80 -j REDIRECT –to-port 8080

    but I got

    ERROR: could not insert ‘ip_tables’: Operation not permitted
    iptables v1.4.14: can’t initialize iptables table `nat’: Table does not exist (do you need to insmod?)
    Perhaps iptables or your kernel needs to be upgraded.

  54. Joe Johnston says:

    This worked like a champ! I didn’t know about motion before.

    I used a cheap-o Hercules web cam with Rasberrian and everything worked right out of the box.

    Thanks for the write up.

  55. HJ Smith says:

    Hi Tom,

    Thanks for the great tutorial. I have got everything working and can pull up a picture on my desktop computer which is on my home network. The picture does not refresh and when I try to refresh the browser I can no longer see the picture unless I reboot my Pi. Any idea why this might happen?

  56. [...] From : http://pingbin.com/2012/12/raspberry-pi-web-cam-server-motion/ [...]

  57. Doug Himelic says:

    How can I get the new Raspberry Pi camera to work with this setup?

  58. Doug Himelic says:

    Is there a way to use the new raspberry pi camera?

  59. Doug Himelic says:

    Is there a way to get this to work with the new raspberry pi camera?

  60. Doug Himelic says:

    Can this be used with the new raspberry pi camera?
    What would have to be changed?

  61. Martin says:

    HI
    Thx for configuration.everything is working perfect with the port 8081 and without.I opened port in my router.But could u tell me why I cant get connection using mobile network???

  62. James Richins says:

    Can this work by plugging a camera into the Ethernet connection rather than the USB to receive data and the send to the web via USB dongle?

  63. Steve says:

    Great post – I got my webcam working in minutes. Do you know how to embed the stream in a web page? I tried using iframes, but couldn’t get it to work in Chrome.

  64. Kj says:

    Had problems and port 8081 was not listed after running command netstat -lnutp. The solution was to run the command motion.

  65. eSITe says:

    How I can capture video and save it to the directory ?

  66. Silviu says:

    Hi,

    I followed the guidelines on this page but it seems something is wrong for me.

    When browsing to the web interface (using Midori), I get instead of images a webpage with strange characters which updates continuously (probably every time a new frame is received).

    This is the sort of things I get: “”–BoundaryString Content-type: image/jpeg Content-Length: 3944 ÿØÿà?JFIF????ÿÛC????? ?? ??????(?????1#%?(:3=Mqypdx\egcÿÛC???????/??/cB8BccccccccccccccccccccccccccccccccccccccccccccccccccÿÀ??ð?@??”??????ÿÄ????????????????? ?ÿĵ?????????????}???????!1A??Qa?”q?2‘¡?#B±Á?RÑð$3br‚ ?????%&’()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤”" and it continues on and on.

    This is when using the 8081 port. When modifying the port to 80 and typing only the IP, I get an error saying “the page couldn`t be loaded”.

    I am running on a Raspberry PI connected to monitor, keyboard and mouse and trying to access it directly from the PI. I tried using both “eth0″ and “wlan0″ IPs just to make sure (the one sending me the characters is the eth0 one, the wlan0 IP address gives me error).

    I managed to get images on my PC which is in the same network as the PI, but ideally I would manage to access it directly from the PI as this is what I will need it for later on. Please can anyone help me with this?

    Thank you,
    Silviu

  67. shaun says:

    This will not work over the internet at all for me. If I try to view it locally, it works intermittently and I have to restart the pi or my computer for it to work again. Refreshing the page causes it to stop working.

  68. cxphong says:

    Thanks you for your posting!

  69. Thomas says:

    Is it posible to use motion with the RaspberryPi cameraboard?

    T

  70. Supra says:

    I’m using raspiberry pi camera and used latest raspbian 2013-07-26.
    On raspi. I opened midor’s browseri and typed 192.168.X.X:8081, and I got dummy characters, but still? running.
    On pc, I typed 192.168.x.x:8081 on google chrome’s browser.I got grey screen stating that Unable to open video device
    I went 8080 to set configuration for both pc and pi, but no available on video.
    Is there something wrong for using raspi camera?
    I appreciate ur helping
    Supra

  71. Markus says:

    hey, Thx for the very nice discription!

    Sorry for my english:

    Is it possibile to detecting Motion and send an alert mail ?

    Thx

  72. AbstractName says:

    Thanks for the instructions.

    I have noticed one thing though. I’m able to view the feed in Firefox only.

    IE treets the address like a file to download but it never finishes.

    Chrome doesn’t do anything at all. This is particularly strange as it doesn’t report an error, doesn’t start downloading just a new blank tab.

    Has anyone else seen this behavior?

    • Postmaster General says:

      I too am experiencing this. Even on my android it just wants to download a file. Any help would be great.

  73. Sanjeev says:

    Hi, thank you for your post, it is brill. Webcam is working and now busy looking at the front door. Is there a way i can send the output to my google drive account every hour of so, or alternatively save the files locally onto the raspberry pi and then FTP it to the web. Purpose is I would like to keep 24 hrs work on images.

    Thanks

  74. flutey says:

    Hi. Thanks for the post. I followed the instructions exactly, but even though motion is running, when I try to access the pi, all I get in Chrome is the message “This webpage is not available”.

    Just can’t access the webpage. What could be the problem?

  75. Sam J says:

    I followed the directions but when I go to the page in chrome, Nothing happens. It just stays on the current page. When I try in internet explorer or on my android using the internet app, it downloads a file of indefinite size. Any suggestions?

  76. GeekRPI says:

    Hi,
    Thanks for post. I have some troubles…
    My cam works on internal 8081 port, but when I change 8081 -> 80 and set forwarding in router there is only 404
    I’ve forward in router correctly, becouse my RPI wworked as PHP server.
    I have no idea to fix this problem….

    • Tom says:

      Motion comes with it’s own light weight web server that does not run PHP, so I assume that you have another web server installed on the RPi if you also have PHP functionality on there? Your not trying to start both of these on TCP Port 8081 are you?

      I would suggest using “netstat -lnutp” to get a list of all the processes on your box and their network bindings, ensure that the Motion web server is successfully bound to the port you think it should be on.

      As your getting a 404 I would guess your hitting that other web server process, either stop it for a while and re-test, or check the access/error logs on the PHP web server and see if there’s any entires for your 404, if there is then you defiantly have some kind of binding issue.

      Hope that helps!

  77. marc carter says:

    This worked a treat. However I notice it occasionally saves a swf file in the tmp folder. What’s this for?

  78. GeekRPI says:

    Unfortunatelly it works only with many ports eq. 8005, 8081, 8070 (in thise case camera LED light) etc but not with 80, 95 etc (camera LED blinking).

  79. GeekRPI says:

    The second problem is with my mobile phone… (lenovo A800)… when I put myIPadres:8081 , I can see that browser download file but not see like on laptop or computer. Instead of normal cam-view it download any *** file…

  80. MrTran says:

    Hi Tom,

    Thanks for your guide, I’m had error: “unable to open video device” when I access address http://raspberryIP:8081. Can you tell me solution for this?

    Thank you!

  81. Mattskee says:

    Got this working using the following:

    Rpi (duh!)
    Microsoft Lifecam
    Belkin Wireless Adapter
    Samsung 2 amp Cell Phone Charger (it is slimmer to plug in anywhere)

    I have 640×480 video and it looks good! Little choppy but good for monitoring my back yard! And I did not need a usb hub.

  82. Dick Smith says:

    I’ve checked all the settings and it appears to be in order. Web Browser does not connect to 192.168.0.100:8081. Says it cannot connect.

    If I stop the service and just type “motion” something starts up and begins to take rapid fire pictures with my webcam and store them in the home folder.

    I’m using a Hercules WebCam Model WC04.

    this is the output from netstat:
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN –
    tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN –
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN –
    udp 0 0 0.0.0.0:26252 0.0.0.0:* –
    udp 0 0 0.0.0.0:68 0.0.0.0:* –
    udp 0 0 192.168.11.20:123 0.0.0.0:* –
    udp 0 0 127.0.0.1:123 0.0.0.0:* –
    udp 0 0 0.0.0.0:123 0.0.0.0:*

  83. dane says:

    Can’t connect to 192.168.1.16:8081 from any browser FF included. Any suggestions?

  84. Gary says:

    How can I change the default DHCP IP address to a static IP?

  85. Dave B says:

    Anyway to limit how many pictures are taken or to change the directory for the saved images?

  86. […] This is a good and cheap solution: How To: Raspberry PI Web Cam Server | PingBin […]

  87. Milt J says:

    Thanks for the tutorial….web cam up and running.

 

Leave a Reply

Our Sponsors