How to install a web cam on an existing installation of octoprint (Linux Mint)

What is the problem?

What do I have to do to add a webcam e.g. Logitech HD5120 to an existing ad working octoprint installation on Linux Mint?

To be clear, Linux Mint is installed for month and running just fine.
octoprint is installed on this Linux Mint box and running.

Most of the videos and posting talking about to install octoprint incl. a webcam but I couldn't find any help how to install the webcam afterwards just o its own.
Are their specific plugins, a scripts I have to install/run?
To make it clear, I will not wipe the Linux box and install it fresh with octoprint.

Any help is much appreciated.
TIA

Mjpeg streamer should work fine
Check this post and skip to the Webcam part

I installed a jpg-streamer, but the one from the repo of John-clark, not from jacksonliam.
I proceeded with the setup up to the point running the script './install webcams install'.
That finished with an error

Blockquote fred@Ryzen3-3200:/usr/local/mjpg-streamer-setup$ ./installWebcams install
chmod: changing permissions of 'installWebcams': Operation not permitted
chmod: changing permissions of './bin/mjpgStart': Operation not permitted
chmod: changing permissions of './bin/startAllCams': Operation not permitted
cp: cannot create regular file '/etc/udev/rules.d/11-mjpg_streamer.rules': Permission denied
cp: cannot create regular file '/lib/systemd/system/mjpg_streamer.service': Permission denied
cp: cannot create regular file '/etc/sudoers.d/mjpg_streamer.sudo-perms': Permission denied
Failed to enable unit: Unit file mjpg_streamer.service does not exist.
Failed to start mjpg_streamer.service: Access denied
See system logs and 'systemctl status mjpg_streamer.service' for details.

As an additonal information, when I'm executing the command "ffplay /dev/video0" I can see a live stream of the cam.
I just have to get it into octoprint.
Thanks

pretty sure you're supposed to run the script with sudo.

1 Like

the terminal was opened with the credentials of 'root'.
But I can try it under sudo as well.

well at least in the snipped you posted it says user fred - not root.

This will get you sorted, first install packages. This has more than you need, but it won't hurt to install any of them:

apt-cache --generate pkgnames |
    grep --line-regexp --fixed-strings \
    -e make \
    -e v4l-utils \
    -e python-is-python3 \
    -e python3-venv \
    -e python3.9-venv \
    -e python3.10-venv \
    -e python3-setuptools \
    -e virtualenv \
    -e python3-dev \
    -e build-essential \
    -e python3-setuptools \
    -e libyaml-dev \
    -e python3-pip \
    -e cmake \
    -e libjpeg8-dev \
    -e libjpeg62-turbo-dev \
    -e gcc \
    -e g++ \
    -e libevent-dev \
    -e libjpeg-dev \
    -e libbsd-dev \
    -e ffmpeg \
    -e uuid-runtime -e ssh -e libffi-dev -e haproxy -e ssl-cert | xargs apt-get install -y

Then install ustreamer:

git clone --depth=1 https://github.com/pikvm/ustreamer
make -C ustreamer

Then sudo nano /etc/systemd/system/cam_octoprint.service and change the appropriate things to appropriate values for your system (yourusername).

[Unit]
Description=the OctoPi(buntu) ustreamer daemon with the user specified config
After=network.online.target
Wants=network.online.target

[Service]
User=yourusername
ExecStart=/home/yourusername/ustreamer/ustreamer -d /dev/video0 -s 0.0.0.0 -m MJPEG -r
640x480 -f 0 -p 8010 --device-timeout 8 --device-error-delay 8

[Install]
WantedBy=multi-user.target

Reboot, and set appropriate webcam address in Octoprint (http://hostname.local:8010?action=stream)

Or, if you want to simplify the whole process. Make a backup if your octoprint instance, reinstall octoprint witih octoprint_install script, setup a camera, and restore your octoprint instance (you will have to manually adjust stream address)

I'm fine with the common description, linked in erlier post, with my odroid C4 and 3rd party ubuntu distro.

1 Like

Except then you are stuck with mjpg-streamer which is pretty crappy.

it depends. if that's all you want then it does the job.

1 Like

I just wanted to say that in principle it works exactly as it is stated in the instructions and there is actually a reason to take the version from this repo and not the one from the os repo. Even if the questioner does not (yet) fail at the point that features are missing.
Of course you can do it differently, but then you should also deal with the issue.
mjpeg-streamer is not an octoprint package.
And of course there are more performant solutions e.g. using a generator to push the frames through a shared memory. .... in my opinion ... :wink: