OpenWrt Forum Archive

Topic: Multiple webcams streaming with mjpg-streamer

The content of this topic has been archived on 15 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

would like to know if anyone tried to stream multiple webcam streams from a single device using an mjpg-streamer.
my current situation:
router - tp-link mr-3020 (single usb2.0 port); cams - MS HD-3000 (720p) and some noname cam (480p).
usb_video support is installed and both cameras work fine when only one of them connected.
tried simply that command:
mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 1280x720" -o "output_http.so -p 8080 -w /www/webcam1"&mjpg_streamer -i "input_uvc.so -d /dev/video1 -r 640x480" -o "output_http.so -p 8081 -w /www/webcam2"&
and it's not working, of course.

need your opinion on if this even possible or directions where to dig

If you didn't notice.... Just one of the camera cunsumes a lot of your RAM and CPU resources....
another thing, cameras used to use huge energy... so... don't think twice your little router can drown those requirements...
Think about the TP-LINK WDR 3600 or the 4300...it has two USB ports on board. an a more powered CPU....
Maybe it will fits to your needed!!!!

This is definitely possible to do using a USB hub, and is documented in several other places on the web.

I'm currently having issues getting both cameras to turn on simultaneously, however each one works independently like a charm. 

I followed the tutorial here , but once you start the second mjpeg-streamer2 service, the first one stops working (i.e. video stops on port 8080).  I'm running Barrier Breaker, have all the drivers and have one camera working.  Both cameras are recognized (/dev/video0 and /dev/video1), and both have different PID files under /var/run.

If anyone has had some success or troubleshooting tips, that would be great.

Here's my logread output after trying to start the second cam:

09:41:32 OpenWrt user.info MJPG-streamer [1580]: Using V4L2 device.: /dev/video0
09:41:32 OpenWrt user.info MJPG-streamer [1580]: Desired Resolution: 640 x 481
09:41:32 OpenWrt user.info MJPG-streamer [1580]: Frames Per Second.: 2
09:41:32 OpenWrt user.info MJPG-streamer [1580]: Format............: MJPEG
09:41:32 OpenWrt user.info MJPG-streamer [1580]: init_VideoIn failed

- Which router?
- Which cams? -> Post the output of lsusb
- You are running both mjpeg-streamers on the same port (8080)?

(Last edited by tmo26 on 1 Jun 2015, 20:14)

tmo26,
- Netgear WNDR3700v4
- Creative Livecam Sync HD
-Of course not.  One is 8080, one is on 8081. 

Bus 001 Device 002: ID 2101:8500 ActionStar
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 2101:8501 ActionStar
Bus 001 Device 004: ID 041e:4095 Creative Technology, Ltd
Bus 001 Device 005: ID 041e:4095 Creative Technology, Ltd

Also here is my init.d files for each instance and my config file.

/etc/init.d/mjpg-streamer

#!/bin/sh /etc/rc.common
# Copyright (C) 2009-2012 OpenWrt.org

START=50

SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1

PROG=/usr/bin/mjpg_streamer

error() {
        echo "${initscript}:" "$@" 1>&2
}

section_enabled() {
        config_get_bool enabled "$1" 'enabled' 0
        [ $enabled -gt 0 ]
}

start_instance() {
        local s="$1"
        local auth=""

        section_enabled "$s" || return 1


        config_get device "$s" 'device'
        config_get resolution "$s" 'resolution'
        config_get fps "$s" 'fps'
        config_get yuv "$s" 'yuv' 0
        config_get port "$s" 'port'
        config_get www "$s" 'www' "/usr/lib/mjpg-streamer/www"
        config_get username "$s" 'username'
        config_get password "$s" 'password'

        [ $yuv = "1" ] && yuv="-y" || yuv=""

        [ -c "$device" ] || {
                error "device '$device' does not exist"
                return 1
        }

        [ -n "$username" -a -n "$password" ] && {
                auth="--credentials $username:$password"
        }

        service_start /usr/bin/mjpg_streamer --input "input_uvc.so $yuv --device $device --fps $fps --resolution $resolution" --output "output_http.so --www $www --port $port $auth"
}

stop_instance() {
        local s="$1"

        section_enabled "$s" || return 1

        service_stop /usr/bin/mjpg_streamer
}

start() {
        config_load 'mjpg-streamer'
        config_foreach start_instance 'mjpg-streamer'
}

stop() {
        config_load 'mjpg-streamer'
        config_foreach stop_instance 'mjpg-streamer'
}

/etc/init.d/mjpg-streamer2

#!/bin/sh /etc/rc.common
# Copyright (C) 2009-2012 OpenWrt.org

START=50

SSD=start-stop-daemon
NAME=mjpg_streamer
PIDF=/var/run/$NAME.2.pid
PROG=/usr/bin/$NAME

SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1


error() {
        echo "${initscript}:" "$@" 1>&2
}

section_enabled() {
        config_get_bool enabled "$1" 'enabled' 0
        [ $enabled -gt 0 ]
}

start_instance() {
        local s="$1"
        local auth=""

        section_enabled "$s" || return 1


        config_get device "$s" 'device2'
        config_get resolution "$s" 'resolution'
        config_get fps "$s" 'fps'
        config_get yuv "$s" 'yuv' 0
        config_get port "$s" 'port2'
        config_get www "$s" 'www' "/usr/lib/mjpg-streamer/www"
        config_get username "$s" 'username'
        config_get password "$s" 'password'


        [ $yuv = "1" ] && yuv="-y" || yuv=""

        [ -c "$device" ] || {
                error "device '$device' does not exist"
                return 1
        }

        [ -n "$username" -a -n "$password" ] && {
                auth="--credentials $username:$password"
        }

        service_start /usr/bin/mjpg_streamer --input "input_uvc.so $yuv --device $device --fps $fps --resolution $resolution" --output "output_http.so --www $www --port $port $auth -p $PIDF"
}

stop_instance() {
        local s="$1"

        section_enabled "$s" || return 1

        service_stop /usr/bin/mjpg_streamer
}

start() {
        config_load 'mjpg-streamer'
        config_foreach start_instance 'mjpg-streamer'
[ $enabled -gt 0 -a -c $device ] && sleep 3 && $SSD -S -m -p $PIDF -q -x $PROG --input "input_uvc.so --device $device --fps $fps --resolution $resolution" --output "output_http.so --port $port"
}

stop() {
        config_load 'mjpg-streamer'
        config_foreach stop_instance 'mjpg-streamer'
}

/etc/config/mjpg-streamer

config mjpg-streamer 'core'
        option yuv '0'
        option enabled '1'
        option fps '20'
        option resolution '1280x720'
        option device '/dev/video0'
        option device2 '/dev/video1'
        option port '8080'
        option port2 '8081'

My apologies for lack of detail in the original post.  My thoughts are that there is some sort of typo in the tutorial either under "service_start" or just start(), but my ignorance of coding in openwrt is hindering me at this point.

How much bandwidth does each cam allocate?

Have you read this?
http://stackoverflow.com/questions/9781 … 5#23881125

BTW: Are you sure about the chosen resolution (640x481, see your first posting)?
How comes the "option resolution '1280x720'" in your /etc/config/mjpg-streamer is ignored and you end up with 640x481?

What happens if you start mjpg-streamer manually two times?
What happens if you add a different (!) webcam and run mjpg-streamer twice?

Tmo,

Not sure how much bandwidth is being allocated.  I assume I should just use wireshark to determine that?

I just read that stackedoverflow post, thank you for researching that!  I tried for hours and couldn't find anything regarding my camera setup specifically.  It looks like Acorn posted the most relevant finding which says:

Acorn wrote:

I am using a Creative "Live Cam Sync HD VF0770" which incorrectly reports its bandwidth requirements. The quirks=128 fix works for 320x240 uncompressed video. But for compressed (mjpg) format the quirks=128 does not work (it does nothing for compressed formats).

Unfortunately he is using Linux and not OpenWRT, so the commands to remake a driver will be quite different I would suspect.

If I start mjpg-streamer manually twice I do see the "No space left on device" message, so I am assuming I have bandwidth issues using the hub...

I'll have to try a two different types of cameras at once and see if that works... I would be annoyed if it did smile

(Last edited by jstromsoe on 1 Jun 2015, 23:26)

To get the bandwidth the camera requires, search lsusb -v for

   wWidth                  640
   wHeight                 480
   dwMinBitRate       24576000
   dwMaxBitRate      147456000

   wWidth                  800
   wHeight                 600
   dwMinBitRate       38400000
   dwMaxBitRate      230400000

(adapt width/height to your chosen resolution).

Alternatively, look at /sys/kernel/debug/usb/devices and search for something like B: Alloc=485/800 us (61%) while the camera is connected and transmitting video.

Tmo,

OK, so made some discoveries.  Keep in mind that with two of the Creative Livecam Sync HD, I would get the "out of space" error in logread.

Tried using two, but different cameras both at 640x480, 5 fps.  This worked like a charm and I could see both streams, one on port 8080 and one on 8081.  I used a Logitech Orbit Sphere MP with the previously discussed Creative Livecam Sync HD.

Since the Logitech Orbit Sphere was basically a spare with a pretty bad picture (one solid white line vertically though the picture, probably dropped it at some point in college), I happily trotted over to Fry's to pickup a different camera, thinking that I had solved the problem and that it was just that you couldn't use two of the exact same camera.

I picked up a little "better" one than the Creative Livecam, the Microsoft HD-3000.  With a name like HD-3000, how could you go wrong? smile 

I unplug the Logitech and replace it with the HD-3000.  So now on the system I've got the HD-3000 and the Creative Livecam Sync HD, attempting to run them simultaneously, both same 5fps and 640x480 res.  Should work right?  Wrong.  Does NOT work.  Same error message as when using two of the same Creative Sync HD Cams simultaneously.  One stream will work, but when you attempt to initiate the other stream you get the "out of space" error. 

So now I've definitely narrowed the problem down to bandwidth over USB.  I know this after Tmo's suggestion of running lvusb -v and checking the dwMinBitRate fields.  The reason why the Logitech and the Creative Lifecam work together is this:

Creative Lifecam Sync HD
    wWidth                            640
        wHeight                           480
        dwMinBitRate                 24576000
        dwMaxBitRate                147456000

Logitech Orbit Sphere MP
    wWidth                            640
        wHeight                           480
        dwMinBitRate                 24576000
        dwMaxBitRate                147456000

However when I tried the Creative Lifecam and the newer MS HD-3000 together, you would have this combo:

Creative Lifecam Sync HD
    wWidth                            640
        wHeight                           480
        dwMinBitRate                 24576000
        dwMaxBitRate                147456000

Microsoft HD-3000
    wWidth                            640
        wHeight                           480
        dwMinBitRate                 36864000      
        dwMaxBitRate                147456000

Which probably exceed the maximum amount of bitrate for the one usb port on my router connected to a USB hub. 


If that's the case, what device are you using Tmo that allows to have that much usb traffic for multiple (15???) cameras?

(Last edited by jstromsoe on 2 Jun 2015, 18:47)

jstromsoe wrote:

If that's the case, what device are you using Tmo that allows to have that much usb traffic for multiple (15???) cameras?

Your assumption, that all my 15 webcams are streaming in parallel via mjpg-streamer, is wrong. smile

are you simply doing stills?  are you doing 1 frame from each camera at a time?

I cycle through the 15cams in a 10min interval, taking stills with fswebcam.
Could be done faster, if I wouldn't switch off the cam's usb power after use.

The discussion might have continued from here.