Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to stream a webcam to a web browser in Ubuntu

Grr this took hours to figure out. I was trying to install MJPG-streamer and running VLC command lines and all this crap but nothing worked.

First install motion:

~> sudo apt-get install motion

Then create a config file:

~> mkdir ~/.motion
~> nano ~/.motion/motion.conf

In it, the bare minimum to run a web server and view it on other computers:

webcam_port 8081
webcam_localhost off

Then run motion:

~> motion

Now you can view the webcam at http://hostname:8081 If it doesn't work, try rebooting between steps or something.

Isn't that easy? >:(

See also: How to run webcam software only when I am not home

This is bloody awesome, thank you!

duramato commented Sep 5, 2015

i cant seem to make it work ,got any clue why?

There is a lot missing from the instructions, like setting the frame rate and other settings in the motion.conf file. There are many good tutorials on setting up motion as a web cam. You should also check that your camera is working, make sure there is a /dev/video0 device (which should be the default for your camera).

Personally I would like to see a change in the motion software to use something other than MJPEG stream compression as it is a bandwidth hog if you want live streaming.

Wow!! That was super easy. Thank you.

Don't forget to apt-get update first or you'll get E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?.

Salgat commented Feb 19, 2017

At least for me with Ubuntu I had to use these config settings

stream_port 8080
stream_localhost off

mlliarm commented Apr 2, 2017

On Lubuntu 16.04 I've used the config settings mentioned by Salgat and it works like a charm.

Thank you.

I want to show video from webcam at website with https. How to stream it via https protocol?
Thank you

danys94 commented Aug 31, 2017

Amazing, now I dont have to be afraid of loosing my stuff at the hotel room :D

Is this is valid for any other camera also ?
suppose i attach a camera to my system, will this work ?

while this DID work.. please not it fills whatever folder you put .motion into with EVERY frame that the camera shoots... for me this was 100's of single .jpg files after only about 15-20 seconds of the camera running - BUT IT DOES WORK!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment