Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Multi cam not working on main image #270

Open
Rylan-Meilutis opened this issue Sep 26, 2024 · 1 comment
Open

[BUG] Multi cam not working on main image #270

Rylan-Meilutis opened this issue Sep 26, 2024 · 1 comment
Labels

Comments

@Rylan-Meilutis
Copy link

Describe the bug
Multiple webcams do not work when the CAMERA_DEV variable contains more than 1 entry

Container Details

2024-06-18T08:11:07.371Z

To Reproduce
Steps to reproduce the behavior:

  1. add multiple camera devices to the container and to the CAMER_DEV variable
  2. run the image

Expected behavior
multiple camera streams are created

Additional context
docker compose file

  octoprint:
    image: octoprint/octoprint
    restart: always
    ports:
      - 8080:80
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
      - /dev/video2:/dev/video0
      - /dev/video0:/dev/video1
    volumes:
     - ./octoprint:/octoprint
     - /etc/localtime:/etc/localtime:ro

    environment:
      - ENABLE_MJPG_STREAMER=true
      - CAMERA_DEV=/dev/video0, /dev/video1

I see this in the logs

MJPG Streamer Version.: 2.0
[services.d] done.
 i: Using V4L2 device.: (null)
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: -1
 i: Format............: JPEG
 i: TV-Norm...........: DEFAULT
 i: init_VideoIn failed
MJPG Streamer Version.: 2.0
 i: Using V4L2 device.: (null)
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: -1
 i: Format............: JPEG
 i: TV-Norm...........: DEFAULT
 i: init_VideoIn failed
@darderik
Copy link

darderik commented Dec 24, 2024

That's because the way that the mjpg launch command gets formatted is just wrong. I don't know what happened there but there was a commit (#245) that tried to fix this, which was reverted. One must launch a mjpg streamer instance for each camera device. I use this code which copies the unaccepted pull request
(mjpg-streamer/run)

#!/usr/bin/with-contenv bash

# Check if the deprecated environment variable MJPEG_STREAMER_INPUT is set
if [ -n "$MJPEG_STREAMER_INPUT" ]; then
  echo "Deprecation warning: the environment variable '$MJPEG_STREAMER_INPUT' was renamed to '$MJPG_STREAMER_INPUT'"
  MJPG_STREAMER_INPUT=$MJPEG_STREAMER_INPUT
fi

# Ensure MJPG_STREAMER_INPUT contains a valid entry
if ! echo "$MJPG_STREAMER_INPUT" | grep -q "..so."; then
  MJPG_STREAMER_INPUT="input_uvc.so $MJPG_STREAMER_INPUT"
fi

# Split the CAMERA_DEV variable into an array of devices
IFS=',' read -ra CAMERA_DEVS <<<"$CAMERA_DEV"
PORT=8080  # Initial port

# Start mjpg_streamer for each camera
for CAMERA in ${CAMERA_DEVS[*]}; do
  echo "Starting mjpg_streamer for camera ${CAMERA} on port ${PORT}"
  mjpg_streamer -i "/usr/local/lib/mjpg-streamer/${MJPG_STREAMER_INPUT} -d ${CAMERA}" \
                -o "/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www -p ${PORT}" &
  PORT=$((PORT + 1))  # Increment the port for the next camera
done

# Wait for all background processes to complete
wait

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants