Setting up multiple webcams in OctoPi the right way

Got is woking like this:

Nov 18 18:27:23 octopi webcamd[1783]: Starting up webcamDaemon...
Nov 18 18:27:23 octopi webcamd[1783]: --- Configuration: ----------------------------
Nov 18 18:27:23 octopi webcamd[1783]: cfg_file:      /boot/octopi.txt
Nov 18 18:27:23 octopi webcamd[1783]: camera:        usb
Nov 18 18:27:23 octopi webcamd[1783]: usb options:   -r 1280x720 -f 25 -q 95
Nov 18 18:27:23 octopi webcamd[1783]: raspi options: -fps 10
Nov 18 18:27:23 octopi webcamd[1783]: http options:  -w ./www-octopi -n -p 8081
Nov 18 18:27:23 octopi webcamd[1783]: Explicitly USB device:
Nov 18 18:27:23 octopi webcamd[1783]: -----------------------------------------------
Nov 18 18:27:23 octopi webcamd[1783]: cfg_file:      /boot/octopi.conf.d/webcam2.txt
Nov 18 18:27:23 octopi webcamd[1783]: camera:        auto
Nov 18 18:27:23 octopi webcamd[1783]: usb options:   -r 1280x720 -f 25 -q 95
Nov 18 18:27:23 octopi webcamd[1783]: raspi options: -ev 5 -x 1280 -y 720 -fps 20 -awb off --awbgainR 1.0 --awbgainB 1.2 -ex -quality 50 -sa 30
Nov 18 18:27:23 octopi webcamd[1783]: http options:  -w ./www-octopi -n -p 8080
Nov 18 18:27:23 octopi webcamd[1783]: Explicitly USB device:
Nov 18 18:27:23 octopi webcamd[1783]: -----------------------------------------------
Nov 18 18:27:23 octopi webcamd[1783]: Found video devices:
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video0
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video1
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video10
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video11
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video12
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video13
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video14
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video15
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video16
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video18
Nov 18 18:27:23 octopi webcamd[1783]: /dev/video2
Nov 18 18:27:23 octopi webcamd[1783]: raspi
Nov 18 18:27:23 octopi webcamd[1783]: config file='/boot/octopi.txt':USB device was not set in options, start MJPG-streamer with the first found video device: /dev/video0
Nov 18 18:27:23 octopi webcamd[1783]: <13>Nov 18 18:27:23 root: Starting USB webcam
Nov 18 18:27:23 octopi webcamd[1783]: Running ./mjpg_streamer -o output_http.so -w ./www-octopi -n -p 8081 -i input_uvc.so -r 1280x720 -f 25 -q 95 -d /dev/video0
Nov 18 18:27:23 octopi webcamd[1783]: MJPG Streamer Version: git rev: 501f6362c5afddcfb41055f97ae484252c85c912
Nov 18 18:27:23 octopi webcamd[1783]:  i: Using V4L2 device.: /dev/video0
Nov 18 18:27:23 octopi webcamd[1783]:  i: Desired Resolution: 1280 x 720
Nov 18 18:27:23 octopi webcamd[1783]:  i: Frames Per Second.: 25
Nov 18 18:27:23 octopi webcamd[1783]:  i: Format............: JPEG
Nov 18 18:27:23 octopi webcamd[1783]:  i: TV-Norm...........: DEFAULT
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Pan (relative): Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Tilt (relative): Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Pan Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Tilt Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Pan/tilt Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Focus (absolute): Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Pan (relative): Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Tilt (relative): Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Pan Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Tilt Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Pan/tilt Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Focus (absolute): Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at LED1 Mode: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at LED1 Frequency: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Disable video processing: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Raw bits per pixel: Inappropriate ioctl for device (25)
Nov 18 18:27:23 octopi webcamd[1783]:  o: www-folder-path......: ./www-octopi/
Nov 18 18:27:23 octopi webcamd[1783]:  o: HTTP TCP port........: 8081
Nov 18 18:27:23 octopi webcamd[1783]:  o: HTTP Listen Address..: (null)
Nov 18 18:27:23 octopi webcamd[1783]:  o: username:password....: disabled
Nov 18 18:27:23 octopi webcamd[1783]:  o: commands.............: disabled
Nov 18 18:27:24 octopi webcamd[1783]: config file='/boot/octopi.conf.d/webcam2.txt':USB device was not set in options, start MJPG-streamer with the first found video device: /dev/video1
Nov 18 18:27:24 octopi webcamd[1783]: <13>Nov 18 18:27:24 root: Starting USB webcam
Nov 18 18:27:24 octopi webcamd[1783]: Running ./mjpg_streamer -o output_http.so -w ./www-octopi -n -p 8080 -i input_uvc.so -r 1280x720 -f 25 -q 95 -d /dev/video1
Nov 18 18:27:24 octopi webcamd[1783]: MJPG Streamer Version: git rev: 501f6362c5afddcfb41055f97ae484252c85c912
Nov 18 18:27:24 octopi webcamd[1783]:  i: Using V4L2 device.: /dev/video1
Nov 18 18:27:24 octopi webcamd[1783]:  i: Desired Resolution: 1280 x 720
Nov 18 18:27:24 octopi webcamd[1783]:  i: Frames Per Second.: 25
Nov 18 18:27:24 octopi webcamd[1783]:  i: Format............: JPEG
Nov 18 18:27:24 octopi webcamd[1783]:  i: TV-Norm...........: DEFAULT
Nov 18 18:27:24 octopi webcamd[1783]:  i: FPS coerced ......: from 25 to 24
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Pan (relative): Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Tilt (relative): Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Pan Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Tilt Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Pan/tilt Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_ADD - Error at Focus (absolute): Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Pan (relative): Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Tilt (relative): Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Pan Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Tilt Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Pan/tilt Reset: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Focus (absolute): Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at LED1 Mode: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at LED1 Frequency: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Disable video processing: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]: UVCIOC_CTRL_MAP - Error at Raw bits per pixel: Inappropriate ioctl for device (25)
Nov 18 18:27:24 octopi webcamd[1783]:  o: www-folder-path......: ./www-octopi/
Nov 18 18:27:24 octopi webcamd[1783]:  o: HTTP TCP port........: 8080
Nov 18 18:27:24 octopi webcamd[1783]:  o: HTTP Listen Address..: (null)
Nov 18 18:27:24 octopi webcamd[1783]:  o: username:password....: disabled
Nov 18 18:27:24 octopi webcamd[1783]:  o: commands.............: disabled
Nov 18 18:27:25 octopi webcamd[1783]: Done bring up all configured video device
Nov 18 18:27:25 octopi webcamd[1783]: Goodbye...
1 Like

Regarding the comment about Spaghetti Detective, where it says "any changes you make using this guide will not take effect." ... I'm not sure what you're trying to say. Changes made here won't work because Spaghetti Detective is installed? Or maybe changes made here won't show in Spaghetti Detective? Or maybe something else?

Nice guide. Easy to follow and clear (except for the noted point about Spaghetti Detective - but I think I'm OK here). I am trying to set up an Insta360 One R, which will act as a webcam and is recognized nicely in Windoze and the like. But I cannot seem to get it to work in this environment. It does show up under /dev/v4l/by-id as usb-Amba_Insta360_One_R-video-index* but does not show up under lsusb (well, maybe it does, but not in any recognizable way). When I try to test the stream, I get no image. I also don't seem to have a webcamd log file in /var/log. Is there some guide that might help me work through the process of adding some as-yet-little-known camera, and what the issue(s) might be?

It's also possible, I suppose, that that comment about Spaghetti Detective does apply to me - in which case I'd like to hear suggestions about what to do. Is it just a matter of installing some plugin?

Thanks!

The Spaghetti Detective Premium streaming takes over the webcam streaming, so it can provide a compressed h264 (I think) stream to use WebRTC in their apps/website, which is more data-efficient for streaming to the cloud. This means that any changes you make to the OctoPi webcam streaming config do not have any effect on the camera stream, since it's provided by TSD instead. Disabling premium streaming in TSD (& rebooting) should get the OctoPi-provided camera stream back up & running.

2 Likes

Thanks so much. That’s the answer I was looking for. Very detailed, thanks twice!

I am brand new to 3d printing and Octoprint. I ran into to some minor things that I had to figure out and streamline. Part of it is my lack of knowledge with linux. I wrote a guide to supplement this one as i ran into some minor issues and just wanted to highlight a couple of things.

Octopi Multi Camera Setup

  1. Login to the Raspberry Pi

  2. Creating the configuration files

    1. Change Directory
      cd /boot
    2. Make New Directory
      sudo mkdir octopi.conf.d
  3. Locating device long id

    1. Run ls /dev/v4l/by-id
      v4l is an lower case L

    2. Should have an output that appears like this for each device
      usb-046d_1080P_Pro_Stream_6E3591AF-video-index0 usb-046d_HD_Pro_Webcam_C920_829EB2AF-video-index1
      usb-046d_1080P_Pro_Stream_6E3591AF-video-index1 usb-046d_HD_Pro_Webcam_C920_BA7DB2AF-video-index0
      usb-046d_HD_Pro_Webcam_C920_829EB2AF-video-index0 usb-046d_HD_Pro_Webcam_C920_BA7DB2AF-video-index1

       We will use the the ones that end in index0.  Devices ending in index0 are preffered, as that is usually 
       the device with video streaming.
      
  4. Editing camera configuration file for multiple cameras
    Camera 1

    1. Change directory
      cd /boot
    2. Open file to edit
      sudo nano -l /boot/octopi.text
      the -l will privide line numbers in the document
    3. Locate line 16 remove the #(hashtag)
      Change camera="auto" to camera="usb"
    4. Locate line 24 remove the #(hashtag)
      Modify camera_usb_options
      original is camera_usb_options="-r 640x480 -f 10"
      new line is original is camera_usb_options="-r 640x480 -f 10 -d /dev/v4l/by-id/"
      Example: camera_usb_options="-r 640x480 -f 10 -d /dev/v4l/by-id/usb-046d_1080P_Pro_Stream_6E3591AF-video-index0"
      Camera 2
    5. Copy original configuration file to new directory
      sudo cp octopi.txt octopi.conf.d/webcam2.txt
    6. Change directory
      cd /boot/octopi.conf.d/
    7. Open file to edit
      sudo nano -l /boot/octopi.conf.d/webcam2.txt
      1. Locate line 16 confirm #(hashtag) has been removed if not remove the #(hashtag)
        Change camera="auto" to camera="usb"
    8. Locate line 24 confirm #(hashtag) has been removed if not remove the #(hashtag)
      Modify camera_usb_options using the device long name of the second device
      original is camera_usb_options="-r 640x480 -f 10"
      new line is original is camera_usb_options="-r 640x480 -f 10 -d /dev/v4l/by-id/"
      Example: camera_usb_options="-r 640x480 -f 10 -d /dev/v4l/by-id/usb-046d_1080P_Pro_Stream_6E3591AF-video-index0"
      5 Modify the port the second camera uses
      Locate line 76 remove the #(hashtag)
      Locate line 77
      Modify camera_http_options"-n" to camera_http_options="-n -p 8081"
      **If adding additonal camers follow steps for Camera 2
  5. Testing Cameras

    1. Restart webcamd service
      sudo service webcamd restart
    2. Open webbrowser and test camera by using the below
      http://:8081/?action=stream
    3. If successful you can use the stream and snapshot URLs in OctoPrint
      Stream: http://:8081/?action=stream
      Snapshot: http://:8081/?action=snapshot
  6. From inside of OctoPrint

    1. Click the wrench icon
    2. Left tab click "Plugin Manager"
    3. Click "+Get More"
    4. Inside seawrch type MultiCam
      Select MultiCam plugin click Install
      After installation Octoprint will require a reboot
    5. Navigate back to OctoPrint settings page
    6. From left column scroll down select the option that says "MultiCam"
    7. From Multicam Profiles page there will be the default camera
    8. Click the blue plus sign
      This will populate the second line, under the URL column provide this link http://:8081/?action=stream
      substiting your IP of the octoprint

Can also use this link as reference.

Setting up multiple webcams in OctoPi the right wayProcessing: OctopiMultiCam.txt...

1 Like

Hi @Justin_Posey!

Thanks, I appreciate your attempt to try and add some more details to the guide, if there were parts that you found difficult.

However, I'm not a fan of copying out and rewriting the guide in a comment. If I change anything with the original guide, it makes this comment out of date which might confuse some people. They don't know what's extra details and what has changed in the guide.

Whoopsie. Sorry. Won't do it again.

I'm having issues getting both webcams to work. The webcam on port 8080 works but not the one on 8081. I have tried every type of URL for the second webcam but nothing seems to be working. I even completely re-imaged octoprint on my SD card and repeated the steps with no luck. Here's the log messages I get on startup:

Dec 27 03:08:30 octopi root: Starting USB webcam
Dec 27 03:08:30 octopi MJPG-streamer [504]: starting application
Dec 27 03:08:30 octopi MJPG-streamer [504]: MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34
Dec 27 03:08:30 octopi MJPG-streamer [504]: Using V4L2 device.: /dev/video0
Dec 27 03:08:30 octopi MJPG-streamer [504]: Desired Resolution: 640 x 480
Dec 27 03:08:30 octopi MJPG-streamer [504]: Frames Per Second.: -1
Dec 27 03:08:30 octopi MJPG-streamer [504]: Format............: JPEG
Dec 27 03:08:30 octopi MJPG-streamer [504]: TV-Norm...........: DEFAULT
Dec 27 03:08:30 octopi MJPG-streamer [504]: www-folder-path......: ./www-octopi/
Dec 27 03:08:30 octopi MJPG-streamer [504]: HTTP TCP port........: 8080
Dec 27 03:08:30 octopi MJPG-streamer [504]: HTTP Listen Address..: 127.0.0.1
Dec 27 03:08:30 octopi MJPG-streamer [504]: username:password....: disabled
Dec 27 03:08:30 octopi MJPG-streamer [504]: commands.............: disabled
Dec 27 03:08:30 octopi MJPG-streamer [504]: starting input plugin input_uvc.so
Dec 27 03:08:30 octopi MJPG-streamer [504]: starting output plugin: output_http.so (ID: 00)
Dec 27 03:08:30 octopi kernel: [   10.776023] 8021q: adding VLAN 0 to HW filter on device eth0
Dec 27 03:08:31 octopi root: Starting USB webcam
Dec 27 03:08:31 octopi MJPG-streamer [545]: starting application
Dec 27 03:08:31 octopi MJPG-streamer [545]: MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34
Dec 27 03:08:31 octopi MJPG-streamer [545]: Using V4L2 device.: /dev/video1
Dec 27 03:08:31 octopi MJPG-streamer [545]: Desired Resolution: 640 x 480
Dec 27 03:08:31 octopi MJPG-streamer [545]: Frames Per Second.: -1
Dec 27 03:08:31 octopi MJPG-streamer [545]: Format............: JPEG
Dec 27 03:08:31 octopi MJPG-streamer [545]: TV-Norm...........: DEFAULT
Dec 27 03:08:31 octopi MJPG-streamer [545]: init_VideoIn failed

It is failing to get video from the camera - the error is there at the bottom init_VideoIn failed

The guide suggests using the /dev/v4l/by-id paths for the camera so you can make sure that you aren't using the same physical device each time. Maybe that part is worth following to make sure it's not trying to open the same camera twice?

The other thing to do would be to run v4l2-ctl --list-formats-ext to check the camera is actually a supported video device.

I followed all the steps including using /dev/v4l/by-id and taking each ID of the cameras from index0. Both cameras are Logitech c270's which are known to be supported for Octoprint.

Something in your configuration is not passing through to the streaming service then. You see in your log file, it is saying it's using /dev/video0 and /dev/video1. It might be easier for you to open your own thread so we can look at what you have specifically configured, as there are a lot of posts on this thread already.

Did you remove the # in the Webcamd file and the second file yoi copied? If you do not it will not work.

Using a Pi NoIR v2 camera and this tip caused me problems. The Pi v2 cameras are ignoring settings while using auto and get detected as the usb device, this can be observed using a single camera on a fresh install with no plugins. Setting it to raspi got things working correctly while I was using one camera, everything except for the fps setting.

However after using this guide (Thanks btw) and having one set to raspi and the other set to auto OR usb, the usb camera fails to load and the pi camera loads ignoring the raspi settings in both files, meaning it is getting detected as a usb device again. After various troubleshooting the only solution I could get working was to set the device long id for the usb webcam, that fixed all issues and both cameras worked as expected.

This seems to be more of an issue with Octoprints automatic detection of the v2 camera boards, not sure if it is going to be resolved in the future. I recommend either removing this hint or adding a note about v2 camera boards. Cheers

The Pi cams can also be treated in the same way that a USB camera is, the drivers can make them look the same. I guess this causes an issue if the Pi camera is detected first...

Ok I do see the problem with this approach. It should work to find both the cameras with the /dev/v4l/by-id path to stop that problem from happening.

Currently, I have two USB webcams connected from following this guide. A cheap endoscope cam and a C922, they both work fine. However my C922 webcam is constantly adjusting its autofocus. How could I disable the autofocus of this webcam while having two webcams active? When trying the following command:

sudo v4l2-ctl --set-ctrl=focus_auto=0
sudo v4l2-ctl --set-ctrl=focus_absolute=60

Returns: unkown control 'focus_auto' and 'focus_absolute'

The command v412-ctl -1 Doesn;t show the autofocus, however these commands worked before I had two webcams connected.

Already found the solution in case of anyone encounters this problem:

  1. Open the octopi.txt from the webcam you want to adjust
  2. copy the device name from -d ...............
  3. insert device id in v4l2-ctl -d .............. --set-ctrl=focus_auto=0 and it should work

You can also try the 'Camera Settings' plugin, although (afaik) it will only show one camera in its UI, you can control any cameras connected to the Pi. Uses the same method of v4l2-ctl, but with a nice UI.

Just found this plugin. This is even better!

I have added some basic support for multiple cameras in the Camera Settings plugin. If you also install the MultiCam plugin and configure it, you should be able to enable the integration and 'link' the camera profiles at the bottom of the Camera Settings page, and doing that will allow it to show the appropriate preview for the selected camera.

1 Like

Hi Charlie,
I have gotten the C920 working as the only camera but when I follow that guide to install a C270 I cannot get it to show in the:
"ls /dev/v4l/by-id" as shown below:

pi@octopi : /boot ** ls /dev/v4l/by-id **usb-046d_0825_6E9E6C90-video-index0** **usb-046d_0825_6E9E6C90-video-index1** **usb-046d_HD_Pro_Webcam_C920_EA8C33AF-video-index0** **usb-046d_HD_Pro_Webcam_C920_EA8C33AF-video-index1** **pi@octopi** : **/boot

However if I "cd" to "octopi.conf.d " it shows "webcam2.txt Is this the correct location for that file??

When I edit the file " /boot/octopi.conf.d $ sudo nano /boot/octopi.conf.d/webcam2.txt" I have the following enabled:
camera="usb"
camera_usb_options="-r 640x480 -f 10 -d /del/v4l/by-id/"
camera_http_options="-n -p 8081"

I did not see any reference to the long id of the 270?? Where can I get this??

Thanks
Kev