Skip to content

Instantly share code, notes, and snippets.

@endolith
Last active November 2, 2024 10:33
Show Gist options
  • Save endolith/2052778 to your computer and use it in GitHub Desktop.
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

@abdoaboganima
Copy link

stream_quality 98
stream_maxrate 5
stream_port 8080
stream_localhost off
output_pictures off
framerate 30
ffmpeg_video_codec mpeg4
http://192.168.0.34:8080/ozzz1.cgi
width 320
height 240
auto_brightness off
contrast 0
saturation 0

Thanks that works for me

@rivermonk
Copy link

rivermonk commented Sep 6, 2022

helpful discussion. using new lubuntu 22.04LTS install, got local motion recording to work properly (after setting some chown directory issues). also can access live video in browser with localhost:8081 and localhost:8080. what I want to do is access the USB cam live video remotely. I know I'll need to find the IP address and somehow set a password, but no idea how to do either. any clues? thanks

@assadollahi
Copy link

if you don't want to video write files on the harddrive, you should switch the ffmpeg_output_moives off. i also increased the framerate to 10 (for watching my 3D printer), and increased the resolution, works with Ubuntu 22.04.1 LTS (Jammy Jellyfish):

stream_quality 98
stream_maxrate 10
stream_port 8080
stream_localhost off
output_pictures off
ffmpeg_output_movies off
framerate 30
ffmpeg_video_codec mpeg4
width 1024
height 768

@Juan013
Copy link

Juan013 commented Oct 21, 2022

How can I change to /dev/video1?

@Barry-IA
Copy link

Barry-IA commented Oct 22, 2022 via email

@skwzrd
Copy link

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

}

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