This is a basic guide on how to set up a RPi as an MJPEG streamer. Particularly useful for home security projects!
- Connect wifi
- 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.
- As always, run
sudo apt-get update&
sudo apt-get upgradefirst.
sudo apt-get install build-essential libjpeg8-dev imagemagick libv4l-dev
sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
git clone email@example.com:jacksonliam/mjpg-streamer.git
make mjpg_streamer input_file.so input_uvc.so input_raspicam.so output_http.so
- Move the install to a better location:
cd .. | cd .. | sudo cp mjpg_streamer /usr/local/bin | sudo cp input_file.so input_uvc.so input_raspicam.so output_http.so /usr/local/lib/ | sudo cp -R www /usr/local/www
sudo nano ~/.bashrcand add
export LD_LIBRARY_PATH=/usr/local/lib/to the end of the file
That’s it! To run MJPEG-streamer, run:
mjpg_streamer -i input_uvc.so -o "output_http.so -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!