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
- Open a terminal on your Linux system.
- 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:
[Unit] Description=MJPG Streamer After=network.target [Service] ExecStart=
ExecStart=mjpg-streamer -i "input_uvc.so" -o "output_http.so -w /home/kzorluoglu/charts/octoprint/www"Restart=always [Install] WantedBy=multi-user.target
Step 2: Enable and Start the Service
- Reload the systemd daemon to read the new service unit file:
sudo systemctl daemon-reload
- Enable the service to start at boot
sudo systemctl enable mjpg-streamer.service
- Start the service:
sudo systemctl start mjpg-streamer.service
- Verify that the service is running without any errors
sudo systemctl status mjpg-streamer.service
- You should see the status of the service, indicating that it is active and running.
- Check the Webcam Output:
http://youriporhostname:8080/?action=stream
BONUS:
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>
Views: 273