I am looking for a simple video streaming program for linux (Raspberry Pi). It just needs to take video from a webcam and stream it in a format that can be embedded in a web page (served with NodeJS on the same RPi).

The only reason I'm not using Motion is I'm having difficulty setting it up, and I want to see if something else is easier.

  • Tons of how-tos incl. software recommendations on a quick search for "Raspi webcam" – ranging from simple webcams to DIY home alarm systems. Tried any of those? One of them includes a tutorial on setting up Motion, by the way, which sounds pretty easy and straight-forward.
    – Izzy
    Dec 22 '16 at 15:24
  • Izzy - thanks. Yes I've tried tonnes of them. But I've just managed to get mjpg-streamer working. It was painful, but got there in the end with the help of this: raspberrypi.org/forums/viewtopic.php?p=164539#p164539
    – CL22
    Dec 22 '16 at 15:29
  • Would you consider this (with a few more details) to be an answer to your question? If so, don't hesitate to present it in full :)
    – Izzy
    Dec 22 '16 at 15:32

So as per this link but with some condensing and adjustments, first run these commands:

apt-get update
apt-get install git libv4l-dev libjpeg8-dev imagemagick cmake -y
git clone git@github.com:jacksonliam/mjpg-streamer.git ~/mjpg-streamer
cd ~/mjpg-streamer/mjpg-streamer-experimental
make USE_LIBV4L2=true clean all
make DESTDIR=/usr install

Although I'm not sure the last line worked for me, I presume it all worked without it. I think it should have put files in the right places (e.g. so executables do not need full paths specified - so instead in the command below I specified the full paths for all files).

Start the server:

~/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -i "~/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so -f 15 -r 320x240" -o "~/mjpg-streamer/mjpg-streamer-experimental/output_http.so -p 8090 -w ./www"

And if you're having trouble with something already using the webcam, (e.g. if motion didn't exit cleanly, do the following and repeat the above command:

fuser /dev/video0

which will give output like this:

/dev/video0: 12324m

Then run this to kill whatever's using the webcam:

kill -9 12324

Finally to view the video, navigate to this address, substituting the IP address or URL of your server:

And to embed the video in a webpage, simply add this to the HTML:

<img src=""/>

As a side note, when running the video streaming server, you might want to change the frames per second by changing the argument after -f. It seems it has to be a figure that is supported by the webcam; an unsupported figure will in theory be coerced by mjpeg-streamer to a supported one, but it failed to stream when I set it to 10, for example. The same goes for resolution; only 320x240 and 640x480 worked for me.

  • Very clear and concise answer - very nice!
    – DankyNanky
    Dec 24 '16 at 4:16

I use VLC for streaming.

This works with the Raspicam:

raspivid -o - -t 0 -n | cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264

But I prefer streaming via rtsp (you can then use VLC again for watching)

raspivid -o - -t 0 -n | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

Good tutorial for Raspberry PI can be found here.

If you use another webcam instead of the Raspicam, you need to change the command to this (assuming the camera is recognized by v4l2):

cvlc -vvv v4l2:///dev/video0 --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264

Other Useful links you may wish to read:

  • I edited your answer, just added some formatting.
    – DankyNanky
    Dec 24 '16 at 4:17
  • I had no idea VLC could be used for this! +1
    – CL22
    Dec 24 '16 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.