Simple MJPG Streaming Raspberry Pi camera

This is a basic guide on how to set up a RPi as an MJPEG streamer. Particularly useful for home security projects!

After installing Raspbian onto your SD card and powering on your RPi for the first time, there are two things to do with a monitor, mouse, and keyboard present:
  1. Connect wifi
  2. Open a terminal and run: sudo raspi-config

– Enable SSH
– Enable camera port
– Console autologin, wait for network
– Change password
– Change timezone

After rebooting and verifying SSH connectivity, you can safely place your components into whatever camera housing you like; everything else can be done over SSH!

While there are many options for this next step, I find the easiest option to be to use MJPG-Streamer. RPi-Cam-Web-Interface is another option with more features (motion detection, time-lapse, etc…), but the live stream is poor quality. MJPG-Streamer is both lightweight and low-latency, with full-resolution live streaming. Github user jacksonliam has created a fork with raspicam support that works well.

  1. As always, run sudo apt-get updatesudo apt-get upgrade first.
  2. sudo apt-get install build-essential libjpeg8-dev imagemagick libv4l-dev
  3. sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
  4. git clone
  5. cd mjpg-streamer/mjpg-streamer-experimental
  6. make mjpg_streamer
  7. Move the install to a better location: cd .. | cd .. | sudo cp mjpg_streamer /usr/local/bin | sudo cp /usr/local/lib/ | sudo cp -R www /usr/local/www
  8. sudo nano ~/.bashrcand add export LD_LIBRARY_PATH=/usr/local/lib/ to the end of the file
  9. source ~/.bashrc

That’s it! To run MJPEG-streamer, run:

 mjpg_streamer -i -o " -w /usr/local/www"

-i – input to mjpg-streamer (our USB camera)
-o output from mjpg-streamer (our HTTP server)
-w a flag to the HTTP server of the location with the HTML and CSS which we moved to /usr/local/www.
-f – framerate in seconds
-c – protect the HTTP server with a username:password
-b – run in background
-p – port (default 8080)

To view your stream, go to http://pi-ip-address:8080/. I highly recommend using the -c flag to password protect the stream!

Finally, add your MJPEG-streamer line of code to your /etc/rc.local file so it starts at boot!