Streaming from a Raspberry Pi Camera to your Browser or VNC

Steps Outline

Here is an outline of the steps required. They will be covered in more detail in the next section:

  1. Login to your Pi (I did this over ssh)
  2. Update the operating system
  3. Enable the camera
  4. Create a project folder
  5. Download mjpg-streamer
  6. Compile mjpg-streamer (Don’t panic! I’ll walk your through it.)
  7. Set an environment variable
  8. Run mjpg-streamer passing in desired settings
  9. On a computer attached to the same network, browse to the device and view the stream

Detailed Steps

Step 1: Login to your Pi

Replace HOSTNAME with the hostname of your Pi.

  $ ssh pi@HOSTNAME.local

Step 2: Update the Operating System

$ sudo apt-get update

Step 3: Enable the camera

Launch raspi-config:

$ sudo raspi-config

From the menu options:

  • Select: 6. Enable Camera
  • Click: <Yes>
  • Click: <OK>
  • Click: <Finish>

Step 4: Create a Project Folder

$ mkdir projects
$ cd projects/

Step 5: Download mjpg-streamer

To download the project you will need a source control system called git. It may not be installed on a fresh image. I know it’s not on the lite image. So you may need to install it. Not sure? Type git, hit return and see what happens.

$ sudo apt-get install git

Now that you have git installed, use it to clone a copy of the mjpg-streamer to your Pi.

$ git clone

If you aren’t familiar with it, git is a very handy tool used by most developers.

Step 6: Compile mjpg-streamer

If you aren’t familiar with compilers, don’t panic. Just follow these steps and hopefully you won’t see any errors in the output.

$ cd mjpg-streamer/
$ cd mjpg-streamer-experimental/
$ sudo apt-get install cmake
$ sudo apt-get install python-imaging
$ sudo apt-get install libjpeg-dev
$ sudo make install

Step 7: Set an Environment Variable

This is so the program can know where to find the libraries that it needs. You will always need to run this first or you can learn how to make the setting permanent. That’s beyond the scope of this article. Don’t forget the period (‘.’) at the end of the command.

$ export LD_LIBRARY_PATH=.

Step 8: Run mjpg-streamer

$ ./mjpg_streamer -o " -w ./www" -i ""

Note that this worked fine on the Pi Zero. But on the Pi 3 the image was reversed and I had to add the -hf flag:

$ ./mjpg_streamer -o " -w ./www" -i " -hf"

Step 9: Browse to the Pi from Another Computer

On a web browser go to (replacing HOSTNAME with your Pi hostname):


NOTE: If you get a page error, wait a minute and see if it refreshes.
Click on the Stream tab on the left to see the image.
Or in VLC


You can specify options, like in raspivid:

$ ./mjpg_streamer -o " -w ./www" -i " -x 1280 -y 720 -fps 15 -ex night"

Or if it’s backwards and upside down, add the -hf and -vf flags:

$ ./mjpg_streamer -o " -w ./www" -i " -x 1280 -y 720 -fps 15 -ex night -hf"
$ ./mjpg_streamer -o " -w ./www" -i " -x 1280 -y 720 -fps 15 -ex night -vf -hf -ifx blackboard"


It does support upto 1080p 30fps, but the bandwidth produced would be more than the usb bus (and therefore ethernet port / wifi dongle) can provide. 720p 15fps is a good compromise.

Here’s some help for this input plugin:

Help for input plugin..: raspicam input plugin
The following parameters can be passed to this plugin:

[-fps | --framerate]...: set video framerate, default 5 frame/sec
[-x | --width ]........: width of frame capture, default 640
[-y | --height]........: height of frame capture, default 480
[-quality].............: set JPEG quality 0-100, default 85
[-usestills]...........: uses stills mode instead of video mode
[-preview].............: enable full screen preview
-sh : Set image sharpness (-100 to 100)
-co : Set image contrast (-100 to 100)
-br : Set image brightness (0 to 100)
-sa : Set image saturation (-100 to 100)
-ISO : Set capture ISO
-vs : Turn on video stabilisation
-ev : Set EV compensation
-ex : Set exposure mode (see raspistill notes)
-awb : Set AWB mode (see raspistill notes)
-ifx : Set image effect (see raspistill notes)
-cfx : Set colour effect (U:V)
-mm : Set metering mode (see raspistill notes)
-rot : Set image rotation (0-359)
-stats : Compute image stats for each picture (reduces noise)
-drc : Dynamic range compensation level (see raspistill notes)
-hf : Set horizontal flip
-vf : Set vertical flip

Some of the camera options like ISO may not work due to it not working in the mmal-libs.

Video mode is the default as it allows much smoother video (higher framerates). Stills mode allows you to use the full-frame of the sensor, but has a max framerate of around 8fps, probably less. Use stills mode with low FPS (e.g. 1 or 2).

In order to have preview output shown on the raspi screen add the -preview option.

This should run indefinitely. ctrl-c closes mjpeg streamer and raspicam gracefully.

More info on the camera can be found here.

Why is there a disclaimer on the Allstate Auto Insurance commericals that says "Not available in all states"?