I’m writing down some notes about
installing, configuring, testing an 808 Keychain Webcam #3
even if i think it can be appliable to several different models (if they can actually act as webcam).
So, you just learned that your Keychain 808 Keychain Camera can be used as Webcam, and I have to say, I just plugged it into a Windows XP machine, switched into Webcam mode and it immediately appeared into “My PC” as Webcam, images were of good quality and also the frame rate was decent. (Please note: usage of “good quality” is reported to the price, i would never compare this device with better products as GoPro or reflex cameras: this is a 6,00 £ device.)
How to configure 808 keychain camera (or any other) with wheezy running on a Raspberryπ?
Simple: connect your device to the USB port, then let it being recognized as external drive (this is what append when you plug the Keychain to the USB port), once it has appeared into “My PC”, click once the Camera power button, just for a while, no long click, and you will see the external storage device disappearing from “My PC”. Now, if your PC/operating system can recognize the camera without drivers (windows) you are lucky, instead with Mac Os X Lion it does not work (but if it works in Linux Debian / Raspbian, probably will work on Os X too, I will investigate this point later).
Now go back to our Raspberry PI Debian headless video server with the duty to stream over the internet so what we do is to use the raspian bootfile for configure memory splitting in order to give the max amount of memory to the system instead of the video card (obviously here we are using raspberry with no desktop environment, just ssh). Otherwise if you have a desktop environment, or just if you are happy with your config, do not do nothing, this guide will work independently from graphical desktop environment.
root@raspberrypi:/boot# cp arm224_start.elf start.elf
This will increase the memory amount available to the system, reducing video memory to minimum (16 Mb).
if you are not root prepend “sudo” to each command.
at reboot again become root (or remember sudo) and type:
root@raspberrypi:/boot# apt-get update && apt-get upgrade
Note: The “&&” within this line, is used to concatenate two commands in order to execute the second one, if and after the first completes with no errors. It can be used several time per line. Usually I do this in order to let the machine work while I do something else: some tasks as compiling can require a lot of time especially on small CPU like this one).
It may take some time…
At the end of the process install hwinfo in order to discover as much information as possible on your webcam and modules needed to use it.
root@raspberrypi:/boot# apt-get install hwinfo
once installed, type
root@raspberrypi:/boot# hwinfo --usb
you should see several rows of output, search by excluding keyboard, usb hub, usb ethernet: in our case search for something like the following
04: USB 00.0: 0000 Unclassified device [Created at usb.122] Unique ID: dwDZ.fh_238dBrkB Parent ID: ADDn.GVovileGj8F SysFS ID: /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0 SysFS BusID: 1-1.3:1.0 Hardware Class: unknown Model: "Generic USB2.0 Device" Hotplug: USB Vendor: usb 0x1908 "Generic" Device: usb 0x3251 "USB2.0 Device" Revision: "1.00" Serial ID: "20110616010203" Driver: "uvcvideo" Driver Modules: "uvcvideo" Device File: /dev/input/event0 Device Files: /dev/input/event0, /dev/input/by-id/usb-Generic_USB2.0_Device_20110616010203-event-if00, /dev/input/by-path/platform-bcm2708_usb-usb-0:1.3:1.0-event Device Number: char 13:64 Speed: 480 Mbps Module Alias: "usb:v1908p3251d0100dcEFdsc02dp01ic0Eisc01ip00in00" Driver Info #0: Driver Status: uvcvideo is active Driver Activation Cmd: "modprobe uvcvideo" Config Status: cfg=new, avail=yes, need=no, active=unknown Attached to: #9 (Hub)
then you have to install and load the correct driver by typing:
sudo modprobe uvcvideo
Or in other cases:
sudo modprobe gspca_zc3xx
Now, normaly we would install a webcam viewer software but, for my experience, it is frustrating, because (maybe it’s my fault, but) it’s veeeeeery slow. Deadly.
So far we should have succesfully configured the webcam even if we don’t have an actual method to test it, that’s why letìs go straight to the next step:
INSTALL AND CONFIGURING FFMPEG
In order to install ffmpeg we need to download it first, so:
Add the following lines into /etc/apt/sources.list
deb-src http://www.deb-multimedia.org sid main deb http://www.deb-multimedia.org wheezy main non-free
Comment: I can’t remember why the first line is pointing to the sid repository while the second instead, is pointing to wheezy. For this reason I’m doing this procedure again, but using this time both wheezy repositories. And i will update this post as soon as I figure out this detail.
apt-get install deb-multimedia-keyring
Remove or comment the second line from /etc/apt/sources.list
#deb http://www.deb-multimedia.org wheezy main non-free
apt-get source ffmpeg-dmo
Check for the actual version and go into the newly created dir:
Now (2013-01-15) is:
./configure --enable-filter=movie --enable-avfilter make sudo make install
If you concatenate the commands together and use them as root, you have enough time to get a coffee…outside.
Concatenated commands (if you used the three commands before you don’t need to do this!)
./configure --enable-filter=movie --enable-avfilter && make && make install
Sudo is needed if you are NOT root already.
We need to create a configuration file for ffserver, we will place it in /etc/ and call it ffserver.conf
The content of this file will be as follows:
Port 80 BindAddress 0.0.0.0 MaxClients 10 MaxBandwidth 50000 CustomLog - #NoDaemon <Feed feed1.ffm> file /tmp/webcam.ffm FileMaxSize 10M </Feed> #We are going to use flash format (sorry internet explorer and iphone/pad/pod/whatever) <Stream test.swf> Feed feed1.ffm Format swf VideoFrameRate 4 VideoSize 320x240 VideoBitRate 64 VideoBufferSize 10 VideoQMin 6 VideoQMax 31 #VideoIntraOnly NoAudio </Stream> <Stream stat.html> Format status # Only allow local people to get the status ACL allow localhost ACL allow 192.168.0.0 192.168.255.255 #FaviconURL http://blog.giuseppeurso.net/favicon.ico </Stream> # Redirect index.html to the appropriate site <Redirect index.html> URL http://blog.giuseppeurso.net/ </Redirect>
Please, note the port 80 is in use, you can change it for a more convenient port if, 8080 for example, you already have a webserver instance running listening on that port.
Although the producer claims a resolution of 720, i know for sure it is interpolated by the poor chip of the camera, degradating the resulting quality. That’s why you will have better results if you use a resolution as close as possible with the camera native resolution.
Also, keep in mind that this parameter and the framerate & bitrate values can determine a bad quality stream.
Now it’s time to start ffserver with the command
ffserver -f /etc/ffserver.conf &
executed as root: this will start ffserver and send it in background.
Then we need to start capturing the video with ffmpeg and transmit the feed to ffserver with the configured path
ffmpeg -v verbose -r 10 -s 352x240 -f video4linux2 -i /dev/video0 http://localhost/feed1.ffm &
You are advised to save this command into an .sh shell script file , chmod +x and then you can use a single word command to star streaming or, better, you can do a startup script for this task.
An ideal startup shell script would do:
killall ffserver killall ffmpeg ffserver -f /etc/ffserver.conf ffmpeg -v verbose -r 10 -s 352x240 -f video4linux2 -i /dev/video0 http://localhost/feed1.ffm &
Point your browser to the Raspberry IP address specifying protocol and port as follows:
I used the 8080 port to demonstrate how to leave the 80/tcp free for the webserver.
Hope this helped!