Wednesday, September 22, 2010

Camera to Web the eagle has landed!

Pop quiz, hot shot; an n900 sits before you and something wonderful is happening in the distance. You've love to take advantage of the rear camera and share images of the wonderful event on any flickr API website or some sort of facial book site. What do you do? The camera has all sorts of custom APIs to access it, and the web sites all need some authentication and use REST.

Well, for those who know me, or of me, the answer is quite simple... just "cp" the data from your camera to the Web. And I've now got this working on the n900. I tried the front camera too, but unfortunately it comes out quite underexposed on in house shots.

To read the camera, libferris uses gstreamer. Because there are a whole bunch of ways you might like to read information, frame rates, transcodings etc, you use a file in your ~/.ferris directory to tell libferris how to create virtual files for your input hardware like so:

cat ~/.ferris/gstreamer.xml
<gstreamer>
<capture>
<file name="live.jpg">
<source>
v4l2src num-buffers=1
! videorate ! video/x-raw-yuv,framerate=\(fraction\)3/1
! ffmpegcolorspace ! jpegenc
! appsink name=sink
</source>
</file>
</capture>
</gstreamer>


Those with a keen eye will notice that the live.jpg is generated with the same thing you can use in gst-launch to create a jpeg image. The final element is an appsink which is where libferris gets the bytes from. I made that last element explicit because you can tee the data in gstreamer and do other things to have multiple end points.

Then to take a photo and put it up on the net:


$ fcat gstreamer://capture/live.jpg >| /Card/tmp/out.jpg
$ ferriscp gstreamer://capture/live.jpg 23hq://monkeyiq/upload


Of course, the fcat line above hints that you can use ssh to grab an image from the n900 to your laptop or server and upload it from there. See the ferris-capplet-auth for how to authenticate with the web sites and also how to have libferris scale before upload (optional) and what privacy settings to add during upload.

Next up is using the vimeo and youtube mounting in libferris to stream video to the net.

No comments: