Add webcam to Octoprint Topic is solved

Suggestions for features and software you would like to see in DietPi, goes here.
alaw005
Posts: 1
Joined: Tue May 26, 2020 3:48 am

Add webcam to Octoprint

Post by alaw005 »

Hi,

I have spent hours trying to work out how to get webcam running on Octoprint. I have worked out that you need to build and install mjpg-streamer from git and I have got this going (just) but I cannot work out how to start automatically and included in Octoprint.

Maybe adding a separate mjpg-streamer software install would be a good alternatively. Unfortunately this is beyond my skill level. The following is what I have managed so far from https://github.com/jacksonliam/mjpg-streamer.

Login as dietpi user on fresh install of DietPi with Octoprint and FFMpeg (under Software Additional):

Code: Select all

sudo apt-get install cmake
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
make
sudo make install
I can then run mjpg_streamer:

Code: Select all

./mjpg_streamer -i "input_uvc.so" -o "output_http.so -p 5001"
And access stream or snapshot from:
http://dietpi:5001/?action=stream_0
http://dietpi:5001/?action=snapshot

I then go through the configuration steps for Octopi
http://dietpi:5000/

Under "Webcam & Timelapse Recordings": The above at least documents the install steps, which I cannot find anywhere else on the internet.
priyan776
Posts: 1
Joined: Thu Oct 15, 2020 3:21 pm

Re: Add webcam to Octoprint

Post by priyan776 »

It works great. have to keep the SSH running. is there a solution for that?
User avatar
Joulinar
Posts: 4864
Joined: Sat Nov 16, 2019 12:49 am

Re: Add webcam to Octoprint

Post by Joulinar »

Hi,

there are a couple of ways how you can put thinks into background. There is quite a good explanation on the following link https://unix.stackexchange.com/question ... disown-and

It describe all the difference between nohup, disown and &
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
WarHawk
Posts: 731
Joined: Thu Jul 20, 2017 8:55 am

Re: Add webcam to Octoprint

Post by WarHawk »

This tutorial uses armbian...but it should work just fine on DietPi

I have it running on an Orange Pi Lite using this method and it works GREAT!

https://www.youtube.com/watch?v=LcA9o6OGfEg
User avatar
Joulinar
Posts: 4864
Joined: Sat Nov 16, 2019 12:49 am

Re: Add webcam to Octoprint

Post by Joulinar »

well, DietPi is using Armbian as base image as well for a couple of devices. ;)
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
MichaIng
Site Admin
Posts: 3041
Joined: Sat Nov 18, 2017 6:21 pm

Re: Add webcam to Octoprint

Post by MichaIng »

That sounds like a systemd service for running mjpg_streamer -i "input_uvc.so" -o "output_http.so -p 5001" would be smart.

Wasn't there... ah yes a request for getting this to work: https://github.com/MichaIng/DietPi/issues/854
goaround
Posts: 1
Joined: Thu Jan 21, 2021 11:59 am

Re: Add webcam to Octoprint

Post by goaround »

@alaw005 thank you for your tutorial.

I can contribute how to start the script on reboot with systemctl and run in background:

Create a new .service file in /etc/systemd/system/

Code: Select all

sudo nano /etc/systemd/system/mjpg-streamer.service
Add the following script to the file:

Code: Select all

[Unit]
Description=Run mjpg-streamer

[Service]
Type=simple
ExecStart=/home/dietpi/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -i "/home/dietpi/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so" -o "/home/dietpi/mjpg-streamer/mjpg-streamer-experim$

[Install]
WantedBy=multi-user.target
If you have installed mjpg-streamer in a different location then /home/dietpi/mjpg-streamer/mjpg-streamer-experimental/, tweak the paths.

Save it.

Reload the systemctl daemon:

Code: Select all

sudo systemctl daemon-reload
Start mjpg-streamer

Code: Select all

sudo systemctl start mjpg-streamer
Check if mjpg-streamer is running without errors:

Code: Select all

sudo systemctl status mjpg-streamer
Check:
http://dietpi:5001/?action=stream_0
http://dietpi:5001/?action=snapshot

Enable on system start:

Code: Select all

sudo systemctl enable mjpg-streamer
Done!
User avatar
MichaIng
Site Admin
Posts: 3041
Joined: Sat Nov 18, 2017 6:21 pm

Re: Add webcam to Octoprint

Post by MichaIng »

Many thanks for sharing, I'm gonna add it as dietpi-software with v6.35, so the timing is great.
trigrhappy
Posts: 28
Joined: Sat Aug 31, 2019 6:38 am

Re: Add webcam to Octoprint

Post by trigrhappy »

I was just coming here to request this! Now I see that, thankfully, there is no point. Can't wait to see it added!

Thanks for the autostart instructions, but I believe the following line of code was cut off (which is causing issues):

Code: Select all

ExecStart=/home/dietpi/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -i "/home/dietpi/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so" -o "/home/dietpi/mjpg-streamer/mjpg-streamer-experim$
Got it working with the following as the full contents of the .service file:

Code: Select all

[Unit]
Description=Run mjpg-streamer

[Service]
Type=simple
ExecStart=/home/dietpi/mjpg-streamer/mjpg-streamer-experimental/mjpg_streamer -i "/home/dietpi/mjpg-streamer/mjpg-streamer-experimental/input_uvc.so" -o "/home/dietpi/mjpg-streamer/mjpg-streamer-experimental/output_http.so -p 5001"

[Install]
WantedBy=multi-user.target

Please correct it in your (awesomely helpful) comment and I'll delete this comment.
3km
Posts: 5
Joined: Tue Mar 26, 2019 9:27 am

Re: Add webcam to Octoprint

Post by 3km »

Thanks for tutorials!
Could you please explain how to add this additional parameters?

-r 1280x960 -f 30

i've tried do it in this area:

Run dietpi-services
Select mjpg-streamer
Select Edit

https://dietpi.com/docs/software/camera/#mjpg-streamer

and here:
sudo nano /etc/systemd/system/mjpg-streamer.service

but without any sucsess


Thank you in advance!
Post Reply