MJPG-streamer installation and run at System Startup using Systemd – Ubuntu Server

Hits: 54

mjpg-streamer is a popular tool for streaming MJPEG video from webcams. In this tutorial, we will learn how to configure mjpg-streamer to run automatically at system startup using a systemd service unit file.

Installation via Snap

sudo snap install mjpg-streamer
#give camera access
snap connect mjpg-streamer:camera

Step 1: Create the Service Unit File

  1. Open a terminal on your Linux system.
  2. Run the following command to create a new systemd service unit file
sudo nano /etc/systemd/system/mjpg-streamer.service

In the text editor, paste the following content:

Description=MJPG Streamer

ExecStart=ExecStart=mjpg-streamer -i "input_uvc.so" -o "output_http.so -w /home/kzorluoglu/charts/octoprint/www"


Step 2: Enable and Start the Service

  1. Reload the systemd daemon to read the new service unit file:
    • sudo systemctl daemon-reload
  2. Enable the service to start at boot
    • sudo systemctl enable mjpg-streamer.service
  3. Start the service:
    • sudo systemctl start mjpg-streamer.service
  4. Verify that the service is running without any errors
    • sudo systemctl status mjpg-streamer.service
  5. You should see the status of the service, indicating that it is active and running.
  6. Check the Webcam Output:
    • http://youriporhostname:8080/?action=stream


if you want to run mjpg-streamer without sudo, you can try the following steps. Add your user to the video group:

sudo usermod -aG video <your_username>