Guide to Setup Streaming Web Cam on the Yun

Hi All

Sharing my experience and tutorial below as it may be of use to some.

I thought I would try hooking up a web cam to my Yun and stream it over WiFi. Basically I am building a WiFi controlled robot and want to mount a camera which can be viewed over WiFi as well.

This is my experience:

The good:

  • It does work once you get everything configured

The bad:

  • Fairly tricky to set up if you don't know how
  • The CPU offers little speed for encoding so you end up with a laggy video. I counted about 4 seconds lag. Also the speed gets incrementally worse as the encoding runs.
  • No mjpg-streamer or gstreamer binary (unless you want to custom compile - I dont :slight_smile: ) so I used ffserver
  • Could only get it working with flv/swf format and at low resolution
  • Unless you want to tinker with your operating system a bit and move your installs to the SD card, you will use about 85% of your Yun's storage for the binaries and libraries

After this experiment, I would suggest avoiding trying to encode and stream live video over WiFi using the Yun. I think the processor is not up to this kind of task.
For this task, I have decided to use a separate security camera with inbuilt WiFi for video and run the Yun as my controller to issue commands to the robot over WiFi.

I would love to hear from anyone if they can get this running smoother.

Here are the instructions below if anyone is interested:

  • Join your Yun to your WLAN
  • SSH into OpenWRT via the IP or via arduino.local hostname
  • Check your camera's compatibility (some are UVC, some are GSPCA, some not supported at all). I would suggest taking a look here: USB Video Support [Old OpenWrt Wiki]
  • Install either the UVC driver or GSPCA (if not already installed) e.g. opkg install kmod-video-uvc
  • Plug your camera into usb slot (type dmesg to see if your camera is detected and drivers working correctly). I used a Microsoft LifeCam HD-3000
  • install ffmpeg via opgk install ffmpeg
  • install ffserver via opkg install ffserver
  • install video4linux2 package via opkg install v4l2
  • Install nano package so you can edit text (I like nano) - opkg install nano
  • add your micro sd card (it should appear as /dev/sda1 by default)
  • Create a folder /mnt/sda1 (mkdir /mnt/sda1)
  • mount your sd card - mount /dev/sda1 /mnt/sda1
  • Create an ffserver config file under /etc using nano (nano /etc/ffserver.conf). You may need to modify this file if your mount paths are different
  • Enter and save the following config:
Port 8090
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 10
MaxBandwidth 50000
RTSPPort 9090
NoDaemon

<Feed videofeed.ffm>
File /mnt/sda1/videofeed.ffm
#You should match the above to your SD Card's mount point
FileMaxSize 10M
ACL allow 127.0.0.1
</Feed>

<Stream video.swf>
# coming from live feed 'videofeed'
#Format mjpeg
Feed videofeed.ffm
Format flv

AVOptionVideo flags +global_header
VideoCodec  flv
VideoBitRate 128
VideoBufferSize 2000
VideoFrameRate 4
VideoSize 320x240
VideoQMin 1
VideoQMax 3
ACL allow 192.168.0.0 192.168.255.255

NoAudio

</Stream>

ACL allow localhost
  • Use CTRL + W to write your file
  • run ffserver command in SSH (since we are not running in daemon mode, it will occupy the SSH session). If you get an error then check your config file. Don't close this SSH window yet
  • Open a second ssh session and run the following command
ffmpeg -v verbose -r 5 -s 320x240 -f v4l2 -i /dev/video0 -c:v flv http://localhost:8090/videofeed.ffm
  • Hopefully your session will start running without errors. If any errors, review your setup as per above
  • Open your web browser to http://arduino.local:8090/video.swf
  • Your video should start showing

Hopefully I haven't forgotten any steps above.
As I said, its not perfect but it does work. If anyone can improve on this or wants to cross compile mjpg-streamer then please let me know

Also on a side note, if anyone wants to see what binaries are available, you can view the list here:
http://download.linino.org/dogstick/all-in-one/latest/packages/

Cheers
Daniel

Sure will do when done :slight_smile:

He is going to be the guardian of my apartment whilst I am out. Will have PIR motion detection should someone unwelcome enter and be accessible over the internet so I can take a poke around and see whats up.

very nice! congrats!!

and sorry for the lack of mjpg-streamer and gstreamer: we have their source code but they don't compile, that's why they are currently missing from the list. I hope we'll have them added soon

Ah I see. Happy to help if I can.

If possible can you send me the steps you are taking to cross compile and ill see if I can get it working?
Are you using Ubuntu to compile?
What kind of error message is it throwing during compile? If its due to system dependencies then we may be out of luck for now.

I got the mjpg-streamer compiled on my local toolchain, you can find the package, and the dependencies here: Dropbox - Yun-Packages - Simplify your life

To install them just copy them over the YUN and opkg install the complete filename(s).

It only works with an UVC webcam which I unfortunately don't have at hand. Hope it's useful.

The usage is described here: Webcam with the Linux UVC driver [Old OpenWrt Wiki]

fibasile:
I got the mjpg-streamer compiled on my local toolchain, you can find the package, and the dependencies here: Dropbox - Yun-Packages - Simplify your life

To install them just copy them over the YUN and opkg install the complete filename(s).

It only works with an UVC webcam which I unfortunately don't have at hand. Hope it's useful.

The usage is described here: Webcam with the Linux UVC driver [Old OpenWrt Wiki]

Nice one. Thanks for uploading. My webcam is UVC so I will give it a test later. I wonder how the performance will compare with ffmpeg and ffserver

fibasile:
I got the mjpg-streamer compiled on my local toolchain, you can find the package, and the dependencies here: Dropbox - Yun-Packages - Simplify your life

To install them just copy them over the YUN and opkg install the complete filename(s).

It only works with an UVC webcam which I unfortunately don't have at hand. Hope it's useful.

The usage is described here: Webcam with the Linux UVC driver [Old OpenWrt Wiki]

Tested and working a charm. Video streaming smoothly at 5fps 640x480 resolution.
Well done mate.

If anyone else is interested. I would suggest using this build of mjpg-streamer over ffmpeg and ffserver as the throughput is much faster.

Instructions are below. Credit to fibasile for the binary upload of mjpg-streamer:
Join your Yun to your WLAN

  • SSH into OpenWRT via the IP or via arduino.local hostname
  • Check your camera's compatibility (some are UVC, some are GSPCA, some not supported at all). I would suggest taking a look here: USB Video Support [Old OpenWrt Wiki]. At this time only UVC driver camera's are supported
  • Install either the UVC driver (if not already installed) e.g. opkg install kmod-video-uvc
  • Plug your camera into usb slot (type dmesg to see if your camera is detected and drivers working correctly). I used a Microsoft LifeCam HD-3000
  • add your micro sd card (it should appear as /dev/sda1 by default)
  • Create a folder or mount point /mnt/sda1 (mkdir /mnt/sda1)
  • mount your sd card - mount /dev/sda1 /mnt/sda1
  • use wget to download the mjpg-streamer binary ( you cant use it with drop box as it redirects to https. This module is not installed by default). I have uploaded it here for convenience : http://www.custommobileapps.com.au/downloads/mjpg-streamer.ipk
  • install the package (I installed it in my root folder ~) - opkg install mjpg-streamer.ipk
  • View the config options here - Webcam with the Linux UVC driver [Old OpenWrt Wiki]. I just ran it with the following command mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480" -o "output_http.so -p 8080 -w /mnt/share" (/mnt/share is my sd card). You can also set it to start upon boot
  • Open your web browser to: http://arduino.local:8080/?action=stream for a stream or http://192.168.1.1:8080?action=snapshot for a single snappy
  • Enjoy

Great, happy you made it.

btw, wget doesn't come with ssl compiled, but curl does!

Great guide MadScience. Works like a charm. Not with my Playstation eye but I bought a HD 3000 and it works great.

Thanks for this guide MadScience! This is working with a C170 Webcam from Logitech.

MadScience:

fibasile:
I got the mjpg-streamer compiled on my local toolchain, you can find the package, and the dependencies here: Dropbox - Yun-Packages - Simplify your life

To install them just copy them over the YUN and opkg install the complete filename(s).

It only works with an UVC webcam which I unfortunately don't have at hand. Hope it's useful.

The usage is described here: Webcam with the Linux UVC driver [Old OpenWrt Wiki]

Tested and working a charm. Video streaming smoothly at 5fps 640x480 resolution.
Well done mate.

If anyone else is interested. I would suggest using this build of mjpg-streamer over ffmpeg and ffserver as the throughput is much faster.

Instructions are below. Credit to fibasile for the binary upload of mjpg-streamer:
Join your Yun to your WLAN

  • SSH into OpenWRT via the IP or via arduino.local hostname
  • Check your camera's compatibility (some are UVC, some are GSPCA, some not supported at all). I would suggest taking a look here: USB Video Support [Old OpenWrt Wiki]. At this time only UVC driver camera's are supported
  • Install either the UVC driver (if not already installed) e.g. opkg install kmod-video-uvc
  • Plug your camera into usb slot (type dmesg to see if your camera is detected and drivers working correctly). I used a Microsoft LifeCam HD-3000
  • add your micro sd card (it should appear as /dev/sda1 by default)
  • Create a folder or mount point /mnt/sda1 (mkdir /mnt/sda1)
  • mount your sd card - mount /dev/sda1 /mnt/sda1
  • use wget to download the mjpg-streamer binary ( you cant use it with drop box as it redirects to https. This module is not installed by default). I have uploaded it here for convenience : http://www.custommobileapps.com.au/downloads/mjpg-streamer.ipk
  • install the package (I installed it in my root folder ~) - opkg install mjpg-streamer.ipk
  • View the config options here - Webcam with the Linux UVC driver [Old OpenWrt Wiki]. I just ran it with the following command mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480" -o "output_http.so -p 8080 -w /mnt/share" (/mnt/share is my sd card). You can also set it to start upon boot
  • Open your web browser to: http://arduino.local:8080/?action=stream for a stream or http://192.168.1.1:8080?action=snapshot for a single snappy
  • Enjoy

Hi MadScience,

I followed your useful steps with YUN and my Cam USB 2.0 PC Camera (Sabrent WCM-6LNV) that is UVC compatible as you can see from Linux UVC driver & tools.
But when I try this command

mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480" -o "output_http.so -p 8080 -w /mnt/share

and I try to connect to http://arduino.local:8080/?action=stream nothing happens.

What could be the problem?

Thanks a lot.

try this:

mjpg_streamer -i "input_uvc.so" -o "output_http.so"

it will use the default values an your link should work.

if you use

mjpg_streamer -i "input_uvc.so" -o "output_http.so -p 8080 -w /www/webcam"

http://arduino.local:8080/webcam 
will give you the demo page of mjpg streamer.

by the way, any idea how to stream on a webpage that runs on the yun's webserver?
i can see the stream on the mjpg-streamer webserver, ut i cant embedd it on the Yun webserver.

ex: yun webserver runs on port 81
mjpg-streamer runs on port 8080

i can go to yun.local:8080 to see the index.html with the webcam stream, but the

$('#content').load('/arduino/temperature');

does not work.

i can go to yun.local:81 and on index.html the above code snippet works, but the webcam stream does not.

Hi guy,

when I try your command, I receive this

MJPG Streamer Version: svn rev: exported
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format............: MJPEG
Unable to set format: 1196444237 res: 640x480
Init v4L2 failed !! exit fatal
i: init_VideoIn failed

:~

Hi guys,

some update.

With this command stream video work fine:

mjpg_streamer -i "input_uvc.so -y -n -f 30 -r 320x240" -o "output_http.so -p 8080 -n -w /www/webcam"

My web doesn't support MPEG stream, only YUV.

My cam support also 640X480@15 fps but stream is too slow. I tried also 640X480@5 but nothing. Some suggestion?

Tnx

Hi,

i use a microsoft lifecam 3000 and the yun can stream 1280720 @ 15fps without problems over wifi.
over internet i am limited by my 5Mbit upload speed to less (960
580 @ 5fps is doable) but it works.
Watching my fishtank at work :smiley:

Greetings

Thanks muh,

At this point, I believe is a WebCam problem.

Can you use your lifecam whit arduino-YUN at 960*580 @ 5fps ?

TNX

yes, it will crop out whatever resolution you set with the -r ###x### parameter.
Aslong as its smaller then what the webcam can supply.

Hey muhkuh,

I currently have a microsoft 3000 too and I was wondering in what browser are you streaming? Cause for me IE downloads the stream same as chrome and FF streams it the right way but the browser crashes at some point. If I try it on a Android tablet I have the same problem. Can you help me.

Thanks

Hi,

for me it works fine in FF and Chrome. not in IE 10.
but if you look in your www/webcam folder, there are some different ways of getting an image (jquery examples...)

easiest if you put

-w /www/webcam

as output parameter, and then you get the demo page for mjpg-streamer which shows all the different possibilities if you browse to your yun on port 8080.