Live webcam feed from your Raspberry Pi

Webcam on RaspberryPi

If you have a Raspberry Pi and a compatible USB webcam, you can easily create a live online feed over HTTP. In other words, you can use your cam connected to your Pi to stream a live feed of anything you want over the Internet. You can use it for surveillance of your house or yard, to see what your dog is doing while you’re away, to watch the birds in a birdhouse or who knows what else you might come up with.

The software that we are going to use to transmit the video stream is called MJPG-streamer. It was written by Tom Stoeveken and is available at

MJPG-streamer acts as a small HTTP server installed on the Raspberry Pi, transmitting the video feed captured using the webcam over HTTP, in motion jpeg format. To view the feed, you can just open a web browser and type the address (IP or domain name) of your Raspberry Pi and the port number associated with MJPG-streamer. What’s really great about MJPG-streamer is that you can easily embed the feed into any webpage by using a simple IMG tag, as we will see a bit later.

Installation, configuration, testing

1. Connect the webcam to the Raspberry Pi via USB.

A list of compatible webcams can be found here, so if you plan to buy a new one, verify that it’s on the list. If you have one laying around, give it a try even if it’s not listed as compatible. I’ve personally tried 3 webcams, none of them being on the list and all of them have worked.

To verify that your webcam is recognized by the Pi, just plug it in and check that the /dev/video0 entry is present in the system:

ls dev/video0

2. Make sure your system is up to date:

apt-get update

apt-get upgrade

3. Install the libv41-0 package on the Pi:

apt-get install libv41-0

4. Download the mjpg-streamer package onto the Raspberry Pi. I have put together a custom package which should work well on the Pi (Please note that MJPG-streamer is the work of Tom Stoeveken and the start-up script originates from, I have merely customized and enhanced the package in order to optimize it for the Raspberry Pi and to make it easy to use for our purposes):


5. Unpack the package:

tar -zxvf mjpg-streamer-rpi.tar.gz

6. Change into the newly created mjpg-streamer directory:

cd mjpg-streamer

7. Start the server application:

./ start

8. Test the live feed:

Open a web browser and in the address bar type the address of your Raspberry Pi and the port number associated with the mjpg-streamer server:

(mjpg-streamer will start on port 8083 by default)

You should now see a live feed from your webcam in a web browser. If you want to embed this feed into a web page, just put this into the HTML code:

<img src=”” width=”640″ height=”480″/>

Simple and nice! Obviously you can change the width and height parameters, but you should make sure that they are not more than the actual resolution of the feed.

When you start mjpg-streamer, it is possible to tell it which port to listen to, what resolution and what frame rate to use. The syntax of the start-up script looks like this: [start|stop|restart|status] [port number] [resolution] [framerate]

That’s pretty much it! Start the feed, open it in a browser, sit back and enjoy!



Live webcam feed from your Raspberry Pi — 52 Comments

    • Hi! Now that’s a good question. I never really needed it so I’ve never tried it. I’m pretty sure that mjpg-streamer is not suitable for that, you’ll have to use some other software.

  1. Hey!Great job!
    I’ve tried your version with 2 webcams at the same time, all works fine.
    But, the stream doesn’t work with my phone (NOKIA N9).
    When I was using another version ( of mjpg-streamer, my phone browser can display the image. And it has a good looking demo webpage by visiting http://“raspi ip”:8080/.
    Is there any possibility to have a demo webpage which allows you to choose “stream,java and javascript”? It is quite important for me, so that I can see the pictures with my phone by selecting javascript on the demo webpage.

    Thanks a lot!

    • Hi there Yimeng!

      I’m not entirely sure I understand your question. The stream doesn’t work on your phone because the phone does/doesn’t support java script but it works on a PC because on the PC java script isn’t/is supported? What is the connection between mjpg-streamer and java script?

      • Hi iqjar!

        Thanks for your reply. I’ve got it working now. Just simply put the demo webpage files under www folder. Now there is a demo webpage like the one mentioned in ( And I can use my phone to see the live pictures.

        In demo webpage, if you take a look into it, you will see some buttons such as Static, Stream, Java, Javascript, Video Lan and so on. If I press Javascript, my phone browser is able to display the pictures(same as you can view it in PC browser). However, if I use http://raspi ip:8083/?action=stream on my phone browser, it doesn’t display anything.

        • Glad to hear you manged to solve it! 🙂
          If I understand correctly, it was a problem of user access rights, because only stuff that is under the www folder can be accessed over the Internet.

  2. Here comes problems.
    When the first time I run mjpg-streamer, it took about 15% CPU usage which is fine by me. A day later, I run it, the CPU usage is about 3%, the video became very slow, frame droped a lot. It’s so weird that I have even tried to reinstall raspbian, the CPU usage of mjpg-streamer is still under 3% with slow and frame droped video. I’m sure that all the settings are same as the first time when I run it. Any advise?

    • Hi Yimeng!

      That sounds quite strange. In the past I’ve run mjpg-streamer for 1-2 days in a row and I did not experience any such problems. Are you sure your webcam is alright from a hardware point of view? Unfortunately I have no idea what could be wrong. I’m very curious though. If you get to the bottom of the problem, please let me know.

  3. I try to install libv41-0

    pi@raspberrypi ~ $ sudo apt-get install libv41-0
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package libv41-0

    Please help me.

      • I have this problem too, but no matter what i do it insists that it is ‘Unable to locate package Libv4l-o’. Any Ideas?

      • Hard to say… Is there any more detailed information in your system log files? Perhaps try a different port or a different resolution, see if it works like that.

        • I had the same problem. Turns out, my webcam doesn’t support that resolution. Solution: Start with

          ./ start 8083 640×480

          .. or whatever resolution _is_ supported. I still cannot see the image, though, but at least I solved the problem of starting mjpg-streamer. 😉

  4. Hi,

    I also get Failed to start.

    My system logs says.

    May 9 13:51:12 raspberrypi MJPG-streamer [9651]: starting application
    May 9 13:51:12 raspberrypi MJPG-streamer [9651]: MJPG Streamer Version: svn rev: 3:160M
    May 9 13:51:12 raspberrypi MJPG-streamer [9651]: Using V4L2 device.: /dev/video0
    May 9 13:51:12 raspberrypi MJPG-streamer [9651]: Desired Resolution: 800 x 600
    May 9 13:51:12 raspberrypi MJPG-streamer [9651]: Frames Per Second.: 15
    May 9 13:51:12 raspberrypi MJPG-streamer [9651]: Format…………: MJPEG
    May 9 13:51:12 raspberrypi MJPG-streamer [9651]: init_VideoIn failed

    I have a Logitech QuickCam Communicate STX and it isn´t among the supported cams for raspberrypi, might be it? Can I still make it work?

    • Can’t really draw a conclusion based on this log fragment but I have tried several “unsupported” cams and they all worked 🙂

      • I’m using a ‘Z-star Microelectronics corp. USB 1.1 webcam’.
        On entering “lsusb” -my webcam is found listed.

        But “sudo ls dev/video0” returns ‘ dev/video0: no such file or directory’
        what will be the reason ??

        • Hi vishal!

          I’m afraid I don’t know the answer to your question, but one of my readers might help you out. You shoudl post your question in the official Raspberry Pi forum, there are some heavy Linux gurus there, who might be able to help you.

          Good luck!

        • I don’t know about the flickering but it does not sound like a power problem to me. Who knows, though. In my experience, if this is important, it’s best to just buy a new webcam. For about 10-15$ you can get a pretty decent one which will also support high resolutions. But if it flickers too, you’ll be mad :p Get a good power supply for your Pi. I use a 1A ps.

          • Hi there, I had the same issue with flickers and it was related to my USB hub speed (1.0)

            I’ve changed it for a 2.0 and everythins rocks now 🙂

          • Great Michel!

            How do you change that? Is it a setting in the raspberry to put more speed on the usp ports or what is it?

  5. Hey,

    Fantastic example!!
    I was wandering is there away to start this running when the Raspi boots up? And perhaps write the configurations to a config file?

    Sorry I am new to Raspi,I would appreciate and help or links to resources.

    Thanks for all the work you have put into this so far

    • Hey! There should be a way to start it at boot and the configs can be passed from a batch file. Unfortunately I don’t have time these days to try it. You should ask the guys at the RPI forum, they will most likely be able to help. Good luck!

      • There is indeed a way to make it connect at startup.

        I’ve create a shell script that I placed in the /etc/init.d folder

        Here it is

        ### BEGIN INIT INFO
        # Provides: mjpg-streamer
        # Required-Start: $local_fs $remote_fs $network $syslog $named
        # Required-Stop: $local_fs $remote_fs $network $syslog $named
        # Default-Start: 2 3 4 5
        # Default-Stop: 0 1 6
        # X-Interactive: true
        # Short-Description: Start/stop mjpg-streamer webcam server
        ### END INIT INFO

        # If you want a command to always run, put it here

        # Carry out specific functions when asked to by the system
        case “$1” in
        echo “Starting mjpg-streamer”
        # run application you want to start
        export LD_LIBRARY_PATH=”/var/mjpg-streamer/mjpg-streamer”
        /var/mjpg-streamer/mjpg-streamer/mjpg_streamer -i “/var/mjpg-streamer/mjpg-streamer/ r 640×480 -f 25” -o “/var/mjpg-streamer/mjpg-streamer/ -w /var/mjpg-streamer/mjpg-streamer/www -p 8001” &
        echo “Stopping mjpg-streamer”
        # kill application you want to stop
        killall mjpg_streamer
        echo “Usage: /etc/init.d/noip {start|stop}”
        exit 1

        exit 0

  6. Hello

    I try to use streamer with the new camera board, but it doesn’t work ?
    failed to start
    I tried to change resultion, but no more results …
    Somebody can help ?

    • Some (maybe moest) Webcams don’t support MJPG-compression. I had to add a -y switch in my command line to use YUV-compression instead. Sad thing about that is it uses a lot of CPU (like 70%). To anyone: be sure to buy a webcam that supports MJPG-format

  7. Hello

    I tried to open and unpack as mentioned above, but this is what I get:

    $ sudo tar -zxvf mjph-streamer-rpi.tar.gz
    tar (child): mjpg-streamer-rpi.tar.gz: Cannot open: No such file or directory
    tar(child):Error is not recoverable: exiting now
    tar: Child returned status 2
    tar: Error is not recoverable: exiting now

    Yet everything beforehand in the instructions work up until this point… and the file does exist… any help?


    P.S. I got rid of the -rpi in the command line and something entirely different happened. Maybe this might be the cure.

    • If you mean the RPI camera module, I’m not sure. I only tested with USB cams when there was no official camera module yet and I do not have one, so I can’t try it. You’ll have to try and play with the config, see if it works or not.

  8. Hi and thank you for the tutorial. I have a logitech C310 connected which ios on the supported list but I am unable to get it to work. in the log file I see error code for CTRL_map which I guess has to do with your robot. when checking v4l2-ctl –all it gives me pixel format YUYV. I can’t find a reference MJPG the C310 is listed as “compatible”
    when going in to Chrome or Firefox I get file not found error. Also in the log file there is the last line that states serving client : that is not the IP for my Pi.

    thanks again and looking forward to your thoughts.


    • Hi Peter!

      I wish I could help you, but I’m afraid I do not really know the answer to your questions. From the first part of your comment it looks like you might have an incompatibility problem. Try borrowing another camera and see if it works with that. But from the second part of your comment it seems like you have some configuration problem. The Chrome/Firefox error is probably because they can’t access the stream. By the way, the streaming does not work in the newer versions of Chrome at all (they have removed MJPG support recently) and Firefox seems to have a bug which causes it to increase its memory usage during MJPG streaming until it crashes. Use VLC media player to view the stream.

      • thank you for the effort, I will have to find another way to get a webcam to work. this is the first step of a project I have in mind with the raspberry PI.


      • Try adding the -y switch when starting the mjpg-streamer:
        mjpg_streamer -i “ -y -f 15 -r 640×480” -o “ -w /usr/local/www”

  9. Hi Iqjar,

    Its a nice tutorial!!.

    I have followed instructions and I get ‘This page can’t be displayed’

    1. My camera : Logitech QuickCam® Communicate STX.
    (This is already used by someone in this discussion)

    2. My log is below.

    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: starting application
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: MJPG Streamer Version: svn rev: 3:160M
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: Using V4L2 device.: /dev/video0
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: Desired Resolution: 640 x 480
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: Frames Per Second.: 15
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: Format…………: MJPEG
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: www-folder-path…: www/
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: HTTP TCP port…..: 8083
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: username:password.: disabled
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: commands……….: enabled
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: starting input plugin
    Jan 18 14:42:01 raspberrypi MJPG-streamer [15113]: starting output plugin: (ID: 00)

    Jan 18 15:09:30 raspberrypi MJPG-streamer [15113]: serving client: <— this is IP address of laptop

    • Make sure you’re not trying to access it from Chrome, it won’t work lately…
      Are you trying to access it from the LAN or from outside your network? If from outside, is port forwarding enabled for port 8083?

  10. Also, here is my process :
    pi 15113 0.2 0.8 29660 1616 pts/2 Sl 14:42 0:08 ./mjpg_streamer -i -r 640×480 -d /dev/video0 -f 15 -o -p 8083 -w www
    pi 15124 0.2 0.3 4356 740 pts/2 S 14:42 0:09 /bin/bash ./ start
    pi 15125 0.1 0.3 4352 724 pts/2 S 14:42 0:05 /bin/bash ./ start

  11. This is my /etc/hosts file. localhost
    ::1 localhost ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters raspberrypi

  12. i have A4tech webcam, and i have used Ethernet cable to display raspberry pi GUI and to share internet with it, but when i connect the webcam the putty become inactive and internet connection stops on raspberry pi, and when i disconnect webcam after it raspberry pi works fine.. what is the problem ???now please help me.

  13. Hi Iqjar,
    Unfortunately I can’t get it to work with the Pi camera, it keeps saying ‘failed to start’ after step 7. I tried different resolution settings but so far no luck.
    I’d like to uninstall mjpg-streamer to make sure it won’t cause problems when I install something else to try and get a web feed working, but I’m not sure if a normal uninstall will get rid of everything (not sure if you maybe added other stuff in the package and dependencies etc.- don’t remember what it said when installing, did that a few days ago..)
    Could you let me know if apt-get –purge remove mjpg-streamer will get rid of everything or if I need to add anything else here? Thanks!

    • Well.. I decided to try and uninstall it anyway but it doesn’t find a package called mjpg-streamer.. so what is the actual package called? :/

  14. Great tutorial. I have a strange issue. I have everything up and running with the feed from mjpg streamer embedded in a site hosted on apache2. I can view everything fine locally just by accessing http://raspberrypiip. I have forwarded port 4030 to the pi’s port 80 (also have edited apache’s config to serve on other ports and tried those as well)but no matter what I do the stream will not load over the internet. I have tried both firefox and chrome. Both will display the page and frame for the video but the video itself will not load. Any suggestions would be appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *