Skip to content

Instantly share code, notes, and snippets.

@endolith
Last active December 27, 2025 21:24
Show Gist options
  • Select an option

  • Save endolith/2052778 to your computer and use it in GitHub Desktop.

Select an option

Save endolith/2052778 to your computer and use it in GitHub Desktop.
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

@Barry-IA
Copy link
Copy Markdown

Barry-IA commented Oct 22, 2022 via email

@skwzrd
Copy link
Copy Markdown

skwzrd commented Jun 6, 2023

After messing about with VLC, go2rtc, and webcamd for days, motion simply just works with MINIMAL fuss.

Here is my motion.conf file:

stream_quality 98
stream_maxrate 5
stream_port 1984
stream_localhost off
output_pictures off
framerate 30
ffmpeg_video_codec mpeg
width 640
height 480
auto_brightness off
contrast 0
saturation 0

Here is my NGINX server

server {
    server_name DOMAIN;
    root /var/www/html;

    auth_basic "Admin"; # password protected domain
    auth_basic_user_file /etc/apache2/.htpasswd;

    location / {
        proxy_pass http://127.0.0.1:1984/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Prefix /;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/DOMAIN/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/DOMAIN/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

@cjritola
Copy link
Copy Markdown

Installing motion requested half a gigabyte worth of dependencies to be installed on my embedded system.

@endolith
Copy link
Copy Markdown
Author

@cjritola I'm sure there are other better solutions

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