Dual USB Webcams

Trying to get two identical USB webcams setup in Multicam. Can anyone help?
I'm not a total noob, but fairly new.

Thanks

Camera model
Amazon #B07MG5B9W7
X0020WNGSP
Usb Camera 5 Megapixel 2592X1944 Webcam with Aptina MI5100 CMOS Sensor and Aluminum Mini Case,Usb with Cameras with 100 Degree No Distortion Lens,Web cams with UVC for Use in Android Windows Linux Mac

What is the problem?
Trying to connect two identical webcams to a PI4. Only First one is streaming, don't know how to access the second camera.

What did you already try to solve it?
Searched internet extensively for solutions to similar situation. None found.

Logs (/var/log/webcamd.log, syslog, dmesg, ... no logs, no support)

pi@octopi:/var/log $ lsusb
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 05a3:9530 ARC International
Bus 001 Device 003: ID 05a3:9530 ARC International
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

pi@octopi:/boot $ nano octopi.txt
GNU nano 3.2 octopi.txt
camera="usb"

#camera_usb_options="-r 640x480 -f 10"
camera_usb_options="-r 2048x1152 -f 10 - q 40"
#input_uvc.so="-d /dev/video0"

pi@octopi:/var/log $ nano webcamd.log
GNU nano 3.2 webcamd.log

Starting up webcamDaemon...

  • Configuration: ----------------------------
    camera: auto
    usb options: -r 640x480 -f 10
    raspi options: -fps 10
    http options: -w ./www-octopi -n

Found video devices:
/dev/video0
/dev/video1
/dev/video10
/dev/video11
/dev/video12
/dev/video2
/dev/video3

USB device was not set in options, start MJPG-streamer with the first found video device: <13>Oct 30 19:33:50 pi: Starting USB webcam Running ./mjpg_streamer -o output_http.so -w ./www-octopi -n -i input_uvc.so -r 640x480 -
MJPG Streamer Version: git rev: 501f6362c5afddcfb41055f97ae484252c85c912
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 10
i: Format............: JPEG
i: TV-Norm...........: DEFAULT
i: FPS coerced ......: from 10 to 30
UVCIOC_CTRL_ADD - Error at Pan (relative): Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Tilt (relative): Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Pan Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Tilt Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Pan/tilt Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_ADD - Error at Focus (absolute): Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Pan (relative): Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Tilt (relative): Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Pan Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Tilt Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Pan/tilt Reset: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Focus (absolute): Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at LED1 Mode: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at LED1 Frequency: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Disable video processing: Inappropriate ioctl for device (25)
UVCIOC_CTRL_MAP - Error at Raw bits per pixel: Inappropriate ioctl for device (25)
o: www-folder-path......: ./www-octopi/
o: HTTP TCP port........: 8080
o: HTTP Listen Address..: (null)
o: username:password....: disabled
o: commands.............: disabled
Starting up webcamDaemon...

  • Configuration: ----------------------------
    camera: auto
    usb options: -r 640x480 -f 10
    raspi options: -fps 10
    http options: -w ./www-octopi -n

Additional information about your setup (OctoPrint version, OctoPi version, ...)

Pi4 with OctoPrint 1.3.12 running on OctoPi 0.17.0
Multicam plugin installed, but don't know how to configure for a second camera, or the URL to access it.

jk but you got a little messed up text formating there :smiley:

I guess there are many ways but here is how I would do it

first you check the device paths

v4l2-ctl --list-devices

it should output something like this

Webcam1name
        /dev/video0
        /dev/video1

Webcam2name
        /dev/video2
        /dev/video3

we want the first /dev/video device of the second listed webcam ( /dev/video2 in this case)

Next you do this part from the raspbian octoprint tutorial by @foosel (slightly modified)

put the following in /home/pi/scripts/webcam2 :

#!/bin/bash
# Start / stop streamer daemon 2

case "$1" in
    start)
        /home/pi/scripts/webcamDaemon2 >/dev/null 2>&1 &
        echo "$0: started"
        ;;
    stop)
        pkill -x webcamDaemon2
        pkill -x mjpg_streamer
        echo "$0: stopped"
        ;;
    *)
        echo "Usage: $0 {start|stop}" >&2
        ;;
esac

Put this in /home/pi/scripts/webcamDaemon2 :

#!/bin/bash

MJPGSTREAMER_HOME=/home/pi/mjpg-streamer
MJPGSTREAMER_INPUT_USB="input_uvc.so"
MJPGSTREAMER_INPUT_RASPICAM="input_raspicam.so"

# init configuration
camera="usb"
camera_usb_options="-r 640x480 -f 10"
camera_raspi_options="-fps 10"

# runs MJPG Streamer, using the provided input plugin + configuration
function runMjpgStreamer {
    input=$1
    pushd $MJPGSTREAMER_HOME
    echo Running ./mjpg_streamer -o "output_http.so -p 8081 -w ./www" -i "$input"
    LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -p 8081 -w ./www" -i "$input"
    popd
}

# starts up the RasPiCam
function startRaspi {
    logger "Starting Raspberry Pi camera"
    runMjpgStreamer "$MJPGSTREAMER_INPUT_RASPICAM $camera_raspi_options"
}

# starts up the USB webcam
function startUsb {
    logger "Starting USB webcam"
    runMjpgStreamer "$MJPGSTREAMER_INPUT_USB $camera_usb_options"
}

# we need this to prevent the later calls to vcgencmd from blocking
# I have no idea why, but that's how it is...
vcgencmd version

# echo configuration
echo camera: $camera
echo usb options: $camera_usb_options
echo raspi options: $camera_raspi_options

# keep mjpg streamer running if some camera is attached
while true; do
    if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" ] ; }; then
        startUsb
    elif [ "`vcgencmd get_camera`" = "supported=1 detected=1" ] && { [ "$camera" = "auto" ] || [ "$camera" = "raspi" ] ; }; then
        startRaspi
    fi

    sleep 120
done

Make sure both files are executable:

chmod +x /home/pi/scripts/webcam2
chmod +x /home/pi/scripts/webcamDaemon2

If you want autostart of the webcam you need to add the following line to /etc/rc.local (Just make sure to put it above the line that reads exit 0 ).

/home/pi/scripts/webcam2 start

the only thing you have to change is the camera_usb_options="-r 640x480 -f 10" line.
enter the resolution and framerate you want and add -d /dev/video? (replace the ? with the number of the path which we checked before)
it should look like this afterwards
camera_usb_options="-r 640x480 -f 10 -d /dev/video2"

also change the /dev/video0 part this line accordingly

if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" ] ; }; then

If everything works your new stream should be available at port 8081

I hope that works because I 'm not able to test it right now (only got one cam :wink: )

If you want to be able to start and stop the webcam server through OctoPrint's system menu, add the following to config.yaml :

system:
  actions:
   - action: streamon
     command: /home/pi/scripts/webcam2 start
     confirm: false
     name: Start video stream 2
   - action: streamoff
     command: sudo /home/pi/scripts/webcam2 stop
     confirm: false
     name: Stop video stream 2
1 Like

Thanks for the response.... Sorry about the formatting :slight_smile: . Apparently the comments in octopi.txt are consistent with the format codes of the editor, and I didn't have time to fix when originally posted.

After posting I found a youtube from "Chris's Basement" (https://www.youtube.com/watch?v=FzpBgEG_ksw).

It took a while to go through his video and make the changes and additions he noted, and unfortunately it didn't work for me.

His video uses two different webcam models. One has a serial number and the other not. In my case, two identical webcams, and neither has serial numbers so I assigned them to the port numbers as he indicated for his one.

I won't have the opportunity to test your suggestions in the above post for a few more days, and as it turns out I may have to change the Pi for a Windows or Linux PC for other reasons.

Regards, and I'll drop a post when I get a chance to test this further.

There is help in the post editor: Just select the text area you want to format and click </> in the icon bar above the editor area.

Hi, I have the same setup as Gordonra and have been trying to get my cams working on my setup.

I have followed PrintedWeez's instructions and am getting an error on mjpg_streamer in webcamDaemon2 file.

Error:
pi@octopi4:~/scripts $ /home/pi/scripts/webcamDaemon2 start
Sep 24 2019 17:36:31
Copyright (c) 2012 Broadcom
version cd3add54955f8fa065b414d8fc07c525e7ddffc8 (clean) (release) (start_x)
camera: usb
usb options: -r 640x480 -f 10 -d /dev/video2
raspi options: -fps 10
~/mjpg-streamer/mjpg-streamer-experimental ~/scripts
Running ./mjpg_streamer -o output_http.so -p 8081 -w ./www -i input_uvc.so -r 640x480 -f 10 -d /dev/video2
/home/pi/scripts/webcamDaemon2: line 17: ./mjpg_streamer: No such file or directory
~/scripts

Further context:
2x logitech c270 cams

v4l2-ctl --list-devices
bcm2835-codec-decode (platform:bcm2835-codec):
/dev/video10
/dev/video11
/dev/video12

UVC Camera (046d:0825) (usb-0000:01:00.0-1.1):
/dev/video0
/dev/video1

UVC Camera (046d:0825) (usb-0000:01:00.0-1.3):
/dev/video2
/dev/video3

Hoping someone can help?

Thanks!

Oh the mjpg streamer path is wrong
Change this line

MJPGSTREAMER_HOME=/home/pi/mjpg-streamer/mjpg-streamer-experimental

to

MJPGSTREAMER_HOME=/home/pi/mjpg-streamer
1 Like

YOU sir, are a hero! Thank you so much! Fixed it right up

1 Like

Why is this necessary, and why does it reference /dev/video0 instead of /dev/video2?

# keep mjpg streamer running if some camera is attached
while true; do
    if [ -e "/dev/video0" ] && { [ "$camera" = "auto" ] || [ "$camera" = "usb" ] ; }; then
        startUsb
    elif [ "`vcgencmd get_camera`" = "supported=1 detected=1" ] && { [ "$camera" = "auto" ] || [ "$camera" = "raspi" ] ; }; then
        startRaspi
    fi

    sleep 120
done

I added this to the guide

Iirc the part was needed in case the mjpeg-streamer stopped for some reason.

1 Like

I'm confused by the statement "If you want to be able to start and stop mjpeg-streamer from within OctoPrint". I don't actually want to start/stop it. I want mjpeg-streamer to start automatically when the Pi is booted. Assuming that mjpeg-streamer doesn't stop unexpectedly, is there a simpler way to just get /dev/video2 up and running?

removed that line

maybe but that's the only guide I have.