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:
http://192.168.0.12:8090/?action=stream
And to embed the video in a webpage, simply add this to the HTML:
<img src="http://192.168.0.12:8090/?action=stream"/>
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.