PiEye - webcam streaming in M-JPG format with Raspberry Pi

pieye live videopieye

With Raspberry Pi and a cheap web-camera connected via USB you can do video streaming in just a few simple steps. This solution is based on the mjpg-streamer server application. This solution is very simple as it uses existing streaming technologies.  Everything happnes over HTTP, a standard protocol found everywere and very accesible today.

Practicly, a mini-webserver that runs on Raspberry Pi, serves video as a M-JPG (Motion Jpeg, more info here) file. M-JPG is actually a set of JPG images as frames of a movie. M-JPG's advantage is that it requires no plugins or browser extension to play. A simple HTML IMG tag, with right dimmensions and source attribute set to point to the served M-JPG woudl be enough to show the video in a standard web page.

The whole solution is based on mjpg-streamer server application (you can find it here). The code was written by Tom Stöveken and has GPLv2 licence. I have compiled and prepared a version of this code for Raspberry PI. See below required steps to get a simple & efficient video streaming in a fiew minutes:

  1. Make sure you have an updated version of Raspberry PI's OS.
  2. Install libv4l-0 package, available in Raspbian: sudo aptitude install libv4l-0.
  3. Connect the web camera to USB. The web camera must be Linux compatible; to check this, make sure /dev/video0 file is available on Raspberry PI, else the camera does not have a Linux driver or required extra configuration to work (this issue is not discussed here).
  4. Download mjpg-streamer-rpi.tar.gz archive on Raspberry PI and extract it. Destination folder is not relevant. You don't need root access if you are using the default pi user. Go to mjpg-streamer folder, where you extracted the tar.gz file.
  5. Open mjpg-streamer.sh file; this is a simple bash script to control the mini-webserver. The header contains some writable parameters, as refresh rate or resolution. The default settings should work in most situations.
  6. Start the server with ./mjpg-streamer.sh start command in the current folder.
  7. Runt your prefered web browser and go to http://raspberrypi:8080/?action=stream (where raspberrypi is it's IP address). You should see the image from the webcam. Current version has some issues with Chrome, just use Firefox if the image is not refreshed.
  8. If the system doesn't work, see the mjpg-streamer.log file for debug info.


See below required commands for not-Linux geeks (install,download,rename,extract,configure,run):

sudo aptitude install libv4l-0
ls /dev/video0
wget http://www.bobtech.ro/get?download=36:mjpg-streamer-rpi
mv get\?download\=36\:mjpg-streamer-rpi mjpg-streamer-rpi.tar.gz
tar -zxvf mjpg-streamer-rpi.tar.gz
cd mjpg-streamer
sudo nano mjpg-streamer.sh
./mjpg-streamer.sh start


Change video parameters

To change video parameters you have to install v4l2-ctl:

sudo apt-get install v4l-utils
v4l2-ctl --list-ctrls
v4l2-ctl --set-ctrl brightness=200
v4l2-ctl --set-ctrl saturation=32


Live Demo

pieye live video

I have setup a webcam for live video stream from my aquarium at 5fps. Plants are moved by the water pump jet and a fish or shrimp can be seen from time to time.

Using the M-JPG format you can embedd live video in any web page with just a simple img tag:

<img src="http://raspberrypi:8080/?action=stream" />


UPDATE: 12-11-2012
  • automatic restart after 3 seconds if "error grabing frames"
UPDATE: 30-10-2012
  • added YUV option for webcams without MJPG protocol (default disabled; if you activate it, Raspberry Pi is used to process the MJPG files instead of webcam's CPU)
  • 6 pcs Rasbora (Trigonostigma heteromorpha)
UPDATE: 08-10-2012
  • bugfix for frequent crash (now should be online permanently)
UPDATE: 06-10-2012
  • autorestart when process stops
  • server clients are logged to mjpg-streamer.log
  • support multiple webcams (need to copy script to multiple locations)
  • start/stop messages, exit codes to be used by other scripts
  • 2 pcs Corydoras Nanus
  • 4 pcs Cherry Shrimp (Neocaridina heteropoda)

Where to buy

Below you can find affiliate linked images to buy directly from Amazon. Thank you for supporting this site!


  • Lewis

    it can't fin v41-utils. And it also says when trying to run ./motioneye it says please install tornado

    Posted at 2015-05-15 18:37:48


  • Mix

    i am not understanding how to run motioneye on boot, can some one help me

    Posted at 2015-08-16 03:29:29


  • pengo

    cp settings_default.py settings.py gives me error:
    pi@raspberrypi ~/motioneye $ cp settings_default.py settings.py
    cp: cannot stat `settings_default.py': No such file or directory

    ./motioneye.py or $ sudo python motioneye.py also won't run, no error, just new line in terminal after command.
    Any advice pls?

    Posted at 2015-09-25 18:43:47


  • TonyB

    Hi All, I have motion installed on a Raspberry PI 2, with wheezy. Install motion fine and for 3 days was getting the emails with attachments on. since 08:06 this morning, I only get emails - no attachments.

    what log can I look at to see why it suddenly started failing. I host my own email, and have no issues with that or attachments. The jpeg files are still being saved to the folder by date etc, but no attachments?

    Help appreciated

    Posted at 2016-02-16 20:19:13


  • Agent

    Hi. I tried it with git & clone. The file ./motioneye.py exists -- but its size is 0 Byte. So nothing happens. What's wrong there?

    Posted at 2016-02-24 17:00:03


  • Clint

    ffmpeg is now part of the libav-tools set

    sudo apt-get install libav-tools

    Posted at 2016-05-19 04:49:09


  • Ivan

    I have a PI 2 with the Motion Eye running for several months but my TP Link power plug lost internet. After it recovered it works again but the date is stuck at 1970 Jan 1. I have re-booted several times but it is stuck. Can anyone tell me what I am doing wrong?

    Posted at 2017-01-05 19:44:18