Docker Mjpg streamer Config - rchamp26/Octoprint_AnycubicVyper GitHub Wiki

I used MJPG streamer in a docker container to keep it contained from Octoprint and the host machine itself. It's also very easy to update it should I ever need to.

Docker

Update the device

sudo apt update sudo apt upgrade

Install pre-reqs

sudo apt install \
apt-transport-https \ 
ca-certificates \ 
curl \ 
gnupg2 \ 
software-properties-common

After this is installed, reboot your device sudo reboot

Install Docker

From your home directory, create a directory and change to it

mkdir docker
cd docker

Run the official docker install script

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

Check to see if a user group "docker" has been created. If so, add your user to the docker group, so you don't have to run commands as sudo.

sudo usermod -aG docker [yourusername]

Log out and lock back in for changes to take effect. Once logged back in, check to see if Docker is up and running

docker ps

Install docker-compose

sudo apt install docker-compose

Create a docker-compose.yaml file for your mjpg-streamer container.

mkdir mjpg-streamer && cd mjpg-streamer 
nano docker-compose.yaml

Create your docker-compose file

version: '2.2'

services:
  mjpg-streamer:        
    restart: unless-stopped
    image: kvaps/mjpg-streamer
    devices:
      - /dev/video0 # this is the webcam path we are passing through to the container
    ports:
      - 8090:8090 # the port we will access mjpg-streamer from the host
    command: -i "/usr/lib64/input_uvc.so -y -d /dev/video0 -r 1920x1080 -f 25 -q 50" -o "/usr/lib64/output_http.so -p 8090 -w /usr/share/mjpeg-streamer/>

To start it up use: docker-compose up -d

The -d runs it as detached in the background. You should then be able to access the webcam feed by going to

http://[YourHostDeviceIPAddress]:8090/?action=stream

You can test getting a snapshot by using the following url in your browser http://[YourHostDeviceIPAddress]:8090/?action=snapshot

Now when configuring Octoprint you will be able to use those URLs to set up the webcam functionality

Octoprint Webcam Config

Octoprint Webcam Setup

Stream URL: http://[YourHostDeviceIPAddress]:8090/?action=stream

Snapshot URL: http://[YourHostDeviceIPAddress]:8090/?action=snapshot

Path to FFMPEG: /usr/bin/ffmpeg

More references on this topic below: