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 ) 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
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
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.
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
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.
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
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
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
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.
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 (960580 @ 5fps is doable) but it works.
Watching my fishtank at work
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.
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.