Mjpeg-streamer plugin in octoprint

Is it possible to activate a mjpeg-streamer plugin inside octoprint?
What im thinking of, is to create an overlay inside the camera stream like this example.

Does there exist any example plugins that use that feature?
Is it in general possible to hoock a plugin in to mjpeg-streamer within a octoprint-plugin?

OctoPrint doesn't deal with webcam streaming, it doesn't have control over mjpg streamer which is a separate piece of software. It just embeds/reads the stream provided by it.

So it would be difficult to make that an OctoPrint plugin really, there's no API to make use of, I think these plugins have to be added on to the command to start mjpg streamer, so you would have to edit the webcam service files I think.

As @Charlie_Powell stated, this is indeed not a use case OctoPrint handles.

It would be indeed far easier to change the service to use the input stream you're speaking of. There are at least two ways that I can think of to achieve what you want.

  • First one, won't take into account any modification you make to the octopi.txt or octopi.conf.d/*.txt files, would be to create a new mjpg-streamer.service inside /etc/systemd/system/ which could look like that:
[Unit]
Description=Mpjg-Streamer service
ConditionPathExists=/etc/octopi_streamer/mjpeg

[Service]
ExecStart=/opt/mjpg-streamer -i 'input_opencv include_other_relevant_options_here' -o 'output_http.so -l 127.0.0.1 -p 8080 -w /root/bin/www-octopi'
Restart=always
RestartSec=1

[Install]
WantedBy=multi-user.target

Then you'd have to run the following commands

systemctl daemon-reload
systemctl disable --now webcamd.service
systemctl enable --now mjpg-streamer.service
  • Second, modify the webcamd script. You would have to modify these lines at the beginning of the script:
MJPGSTREAMER_INPUT_USB="input_uvc.so"
MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so"

replacing the uvc and raspicam by opencv. You would then have to alter the

camera_usb_options=
camera_raspi_options=

lines with the correct options. This would present the advantage of keeping the same configuration files you're used to. Be aware, as stated in the mjpg-streamer documentation, that the opencv input is more CPU consumming. Your Rpi might not be able to sustain multiple cameras, or the maximum resolution depending on your setup.