Instantly share code, notes, and snippets.

Embed
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

@calebunleashed

This comment has been minimized.

Show comment
Hide comment
@calebunleashed

calebunleashed Sep 19, 2014

This is bloody awesome, thank you!

calebunleashed commented Sep 19, 2014

This is bloody awesome, thank you!

@duramato

This comment has been minimized.

Show comment
Hide comment
@duramato

duramato Sep 5, 2015

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

duramato commented Sep 5, 2015

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

@Galbi3000

This comment has been minimized.

Show comment
Hide comment
@Galbi3000

Galbi3000 Sep 27, 2015

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.

Galbi3000 commented Sep 27, 2015

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.

@SushilShrestha

This comment has been minimized.

Show comment
Hide comment
@SushilShrestha

SushilShrestha Sep 18, 2016

Wow!! That was super easy. Thank you.

SushilShrestha commented Sep 18, 2016

Wow!! That was super easy. Thank you.

@RandomArray

This comment has been minimized.

Show comment
Hide comment
@RandomArray

RandomArray Nov 9, 2016

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?.

RandomArray commented Nov 9, 2016

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

This comment has been minimized.

Show comment
Hide comment
@Salgat

Salgat Feb 19, 2017

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

stream_port 8080
stream_localhost off

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

This comment has been minimized.

Show comment
Hide comment
@mlliarm

mlliarm Apr 2, 2017

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

Thank you.

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.

@global-qa

This comment has been minimized.

Show comment
Hide comment
@global-qa

global-qa Apr 16, 2017

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

global-qa commented Apr 16, 2017

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

@danys94

This comment has been minimized.

Show comment
Hide comment
@danys94

danys94 Aug 31, 2017

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

danys94 commented Aug 31, 2017

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

@neeraj55206

This comment has been minimized.

Show comment
Hide comment
@neeraj55206

neeraj55206 Sep 12, 2017

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

neeraj55206 commented Sep 12, 2017

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

@johnnycatt

This comment has been minimized.

Show comment
Hide comment
@johnnycatt

johnnycatt Nov 20, 2017

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!

johnnycatt commented Nov 20, 2017

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!

@usermigallon

This comment has been minimized.

Show comment
Hide comment
@usermigallon

usermigallon Apr 16, 2018

Hello,
Motion doesn't work outside from your network

usermigallon commented Apr 16, 2018

Hello,
Motion doesn't work outside from your network

@endolith

This comment has been minimized.

Show comment
Hide comment
@endolith

endolith Apr 16, 2018

@johnnycatt: You can edit the motion.conf file and disable the saving of files

@usermigallon: You probably have to forward ports through your router?

Owner

endolith commented Apr 16, 2018

@johnnycatt: You can edit the motion.conf file and disable the saving of files

@usermigallon: You probably have to forward ports through your router?

@live4java

This comment has been minimized.

Show comment
Hide comment
@live4java

live4java May 29, 2018

@johnnycatt: The configuration option you want is:
output_pictures off

live4java commented May 29, 2018

@johnnycatt: The configuration option you want is:
output_pictures off

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