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

335 comments

  • #126 Mark said 2014-03-21T15:33:52Z

    Migeul, thanks for these instructions. However I am having some problems with step 7. When I run the commands I am presented with an endless repeat of text reading:

    mmal: Skipping frame ## to restart at frame ##

    With the # symbols indicating steadily increasing numbers. As a result I have no command line to enter any further steps from your instructions. Would you have any idea of the problem and how to fix it.

    Thanks

  • #127 Miguel Grinberg said 2014-03-21T16:02:28Z

    @Mark: the "skipping" messages are not normal. Do you always get them? Any chance you are doing too much on your Pi, try running this fresh from boot and without running any other processes.

  • #128 JohnS said 2014-03-21T16:41:53Z

    I have followed instruction and when I enter the 192.168.... :8080 I get a page from the mjpg people telling me I have successfully implemented the software but I cannot get my page? What mistake did I make? Thanks for help.

  • #129 pin y pon said 2014-03-21T16:42:34Z

    How do you to move the pan & tilt servos from the web brownser?

  • #130 Miguel Grinberg said 2014-03-22T03:32:27Z

    @JohnS: Not sure what's wrong. Is your camera running?

  • #131 Miguel Grinberg said 2014-03-22T03:33:19Z

    @pin y pon: That's a completely different topic. I'm sure there are plenty of tutorials on the web to implement pan & tilt, I have not done it myself.

  • #132 Lauren said 2014-03-25T18:42:35Z

    Hi, as this is a little old now I seem to not be able to find libv41-dev, is there any updated file that I need instead?

  • #133 Lauren said 2014-03-25T19:30:37Z

    I have everything running (I think) but I have the same problem as Mark with the "Skipping frame # to restart at frame ##". I've tried rebooting and having at as the first thing I do, but no luck :/

  • #134 Miguel Grinberg said 2014-03-26T16:43:16Z

    @Lauren: note that the character that follows the 4 is a lowercase letter L, not the number 1.

  • #135 Tom said 2014-03-27T22:58:02Z

    Hey Miguel,

    Is there anyway to get this to work with a different camera then the native pi camera, I have a Logitech C270 which is recognized and supported by the pi as I was using it with motion.

    pi@raspberrypi ~ $ lsusb Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 046d:0825 Logitech, Inc. Webcam C270 Bus 001 Device 005: ID 0a81:0205 Chesen Electronics Corp. PS/2 Keyboard+Mouse Adapter

    Thanks!

  • #136 Miguel Grinberg said 2014-03-29T04:51:52Z

    @Tom: Unfortunately I don't know. You need to use a camera that writes jpegs to the file system or else one that mjpg-streamer supports natively. I have only used the Pi camera, so I don't know what other cameras work, if any.

  • #137 MV said 2014-03-31T13:16:55Z

    Thank you so much - worked the very first time.

  • #138 LuisG said 2014-04-05T10:57:41Z

    I try to work and in one hour the raspb not respond, i need to work everytime to view my birds ...

    thanks a lots :-)

  • #139 jb1t said 2014-04-06T05:04:31Z

    execuse me I'm a noob:

    I've followed the directions above and the light on the raspiberry camera is on... the screen is filling up with mmal: Skipping frame x to restart at frame y

    I'm able to browse from another machine to http://192.168.1.100:8080/ and see the mjpg-streamer website, however anywhere there are supposed to be images/video they are blank.. the http requests never returned for those requests.

    Any thoughts or suggestions?

    Thanks

  • #140 jb1t said 2014-04-06T05:31:10Z

    Sorry... I found the issue... I somehow missed the -n pic.jpg option ... once I added that it seems to be working fine.

    Thank you for the great tutorial.

  • #141 tony said 2014-04-15T13:41:38Z

    Hello,i have installed the MJPG-streamer successfully,and MJPG-streamer is running.But there is no picture on the web page.I don't know why.

  • #142 anthony said 2014-04-16T05:03:34Z

    wget link no longer exist.
    I downloaded mjpg-streamer-r63 and MAKE
          input_file.so not found & V4L not found, etc... Is this version much different that your 182 downloads?
    thanks
    
  • #143 Remy said 2014-04-21T21:39:01Z

    This is a really big help so thanks, but i have encountered a problem and as i am new to the raspberry pi i am not too sure where to type the commands after "start the camera" i am just not sure where to type it as when i try to type it in the same thing it gets overwritten thanks

  • #144 Miguel Grinberg said 2014-04-23T14:36:17Z

    @Remy: the start camera command ends with a "&" which puts the command in the background. You should be able to type more commands after that.

  • #145 Amine said 2014-04-27T23:28:19Z

    hello Miguel,

    thank you for this article, i think it's so helpful for people like me :)

    i work on ZedBoard ( i make a Ubuntu as an OS ), my application is to run the MJPEG on this board, but with affecting the big task of MJPEG to FPGA ( named PL ( programming Logic ) which is also on the same board.

    My question is, what code i will need it to read from it the course of those thread ( MJPEG ), and when i can i place it, and finally how can i link the data input ( image or webcam stream) to my application ?

    thank you and have a nice day

  • #146 Vrishank said 2014-04-28T19:47:31Z

    Hey Miguel, I recently stumbled upon this while I was trying to do a streaming project with my pi but for some reason I can't unzip your file do you have any suggestions?

    Thanks

  • #147 Miguel Grinberg said 2014-04-29T15:54:40Z

    @Vrishank: I don't know. The link is valid, and I can download a valid zip from it. Maybe try a different unzip, or download again.

  • #148 fabio said 2014-05-02T17:18:25Z

    Hello Miguel!! Fantastic tutorial!! It works very well but the only problem it's a very low framerate... why in your opinion?

  • #149 Miguel Grinberg said 2014-05-03T01:31:35Z

    @fabio: stay tuned, I will be posting about a new method to stream MJPG soon. I get almost no delay for 640x480, and less than 2s for 1080p.

  • #150 Bex said 2014-05-20T19:41:02Z

    Hi Miguel,

    Thanks for the awesome tutorial!! Much appreciated. I got mine up and running but I am having the same problem as some other folks (I've read pretty much all of the comments on this article). After typing in the raspistill command, I also get the "mmal: Skipping frame ### to restart at frame ###" repeated over and over where it only records 1 frame then skips ahead the same amount of frames each time. If i have a smaller time lapse set, I get a larger break in the frames. For instance, with -tl 10, it skips 59 frames:

    "mmal: Skipping frame 5 to restart at frame 64"

    and with -tl 100, it skips 5 frames:

    "mmal: Skipping frame 5 to restart at frame 10"

    I am only averaging about 1.1 FPS, regardless of the quality or time lapse values.

    Any thoughts?? I am going to keep investigating this issue and I look forward to your new post on a new method to stream MJPG.

    Thanks! Bex

Leave a Comment