2013-10-01T05:45:43Z
How to build and run MJPG-Streamer on the Raspberry Pi
It's been a while since I wrote the article on streaming video from the Raspberry Pi using MJPG-Streamer. Since I published that article I have received several comments and questions regarding issues building MJPG-Streamer, so in this short post I'm giving you revised build instructions.
1. Install build dependencies
The following command installs the three libraries that MJPG-Streamer uses:
$ sudo apt-get install libjpeg8-dev imagemagick libv4l-dev
2. Add missing videodev.h
The videodev.h
header file that MJPG-Streamer needs has been replaced with a videodev2.h
. To make MJPG-Streamer happy you have to create a symbolic link:
$ sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
3. Download MJPG-Streamer
The source code for MJPG-Streamer is available at sourceforge.net, but it is tricky to find the direct download link:
$ wget http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/mjpg-streamer-code-182.zip
Note that sometimes the link above fails to work. If that is the case, you can also download from your web browser by opening this page: http://sourceforge.net/p/mjpg-streamer/code/HEAD/tarball.
4. Unzip the MJPG-Streamer source code
The source code download is a compressed zip file. Put the file in your home directory (or a temporary folder, if you prefer) and run the following to extract the files:
$ unzip mjpg-streamer-code-182.zip
5. Build MJPG-Streamer
MJPG-Streamer comes with several plugins, but only a couple of them are needed to stream video according to the method I explained in my previous article. The command below only builds what's needed:
$ cd mjpg-streamer-code-182/mjpg-streamer
$ make mjpg_streamer input_file.so output_http.so
6. Install MJPG-Streamer
I did not discuss installation in the previous article, and that confused many readers. The following commands copy all the needed files into system directories:
$ sudo cp mjpg_streamer /usr/local/bin
$ sudo cp output_http.so input_file.so /usr/local/lib/
$ sudo cp -R www /usr/local/www
7. Start the camera
We are almost there. Now it is time to start the camera module:
$ mkdir /tmp/stream
$ raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 &
Of course, you can use different options to raspistill
if you like.
8. Start MJPG-Streamer
The camera is now writing images, so all that is left is to start MJPG-Streamer:
LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www"
9. Watch the Stream!
Now you can connect with your web browser and watch the stream live. If you want to watch from within the same Raspberry Pi you can enter http://localhost:8080
in the browser's address bar. If you want to watch from another computer in your network use http://<IP-address>:8080
.
10. Cleanup
After you verify that everything is working you can remove the source code:
$ cd ../../
$ rm -rf mjpg-streamer-182
Conclusion
I hope these instructions clarify all the aspects of setting up the streaming server on the Pi. If you still have questions let me know below!
Miguel
#76 Miguel Grinberg said 2013-12-21T18:39:16Z
#77 Fabian said 2013-12-25T18:49:05Z
#78 jens said 2013-12-30T19:52:17Z
#79 Miguel Grinberg said 2013-12-30T19:58:59Z
#80 Hugo Coolens said 2014-01-03T13:45:40Z
#81 chris said 2014-01-03T18:05:25Z
#82 Jack Kirk said 2014-01-04T10:57:19Z
#83 Yacked2 said 2014-01-05T13:20:04Z
#84 Miguel Grinberg said 2014-01-06T03:11:45Z
#85 Miguel Javier said 2014-01-09T20:22:48Z
#86 Miguel Grinberg said 2014-01-10T04:55:23Z
#87 Miguel Javier said 2014-01-10T14:59:39Z
#88 Colin Jones said 2014-01-10T15:42:11Z
#89 Miguel Grinberg said 2014-01-10T15:43:09Z
#90 seif said 2014-01-18T15:21:51Z
#91 Miguel Grinberg said 2014-01-18T19:17:50Z
#92 Anthony said 2014-01-19T13:39:39Z
#93 Miguel Grinberg said 2014-01-20T00:33:34Z
#94 james wolf said 2014-01-24T03:54:45Z
#95 Miguel Grinberg said 2014-01-24T05:23:05Z
#96 jdlenton said 2014-01-26T20:32:52Z
#97 jdlenton said 2014-01-27T18:53:19Z
#98 Stephan said 2014-01-28T21:26:06Z
#99 Kris said 2014-01-30T16:00:47Z
#100 Miguel Grinberg said 2014-01-30T16:46:29Z