Getting started

If you're typing that command in by hand, note that "v4l2src" begins with the characters vee-four-ell-two, an abbreviation for "Video 4 Linux 2.0", and not the number four hundred and twelve. You'll need to run the above command in a terminal, either the Terminal activity, in the developer console (alt-=) or one of the virtual terminals (e.g. ctrl-alt-f1). Note this means you don't need the Sugar GUI to be running to access the camera.

You can view the PNG image created as a result of the command in the Web activity.

Now, let's try and get some video on the screen:

gst-launch-0.10 v4l2src ! xvimagesink

Unlike the first command this command will only work with an X display, eg when executed in Terminal activity or a terminal in the developer console. The resulting video may appear behind the developer console window so you'll need to move the developer console window aside to see the video.

Since you've now had your first hit of "ooo, shiny" moving pictures let's take a look at what's happening behind the scenes.

What just happened?

I'm going to assume you have a passing familiarity with GStreamer, if not, you could go read about it. Basically, it's a series of pipes you can throw multimedia data down and get something in a file or on screen at the end. The data starts at a source (src) and ends up in a sink (sink) and can go through a number of intermediate manipulations along the way.

While we will get to using the camera from Python eventually, we've started out with using the GStreamer command line tool gst-launch. The gst-launch tool is a quick way to experiment with putting a pipeline together and seeing what it does.

The camera in a XO laptop is a regular Video4Linux 2 device which is accessed via GStreamer's v4l2src source. Since the camera is our source it's the first item in our pipeline--notice the individual parts of the pipeline are separated with ! characters. (You could say the data goes out with a bang but it'd be a pretty bad joke.)

Next, we'll skip to look at the end of the pipeline--the sink end--here we find the filesink which simply outputs some data to a particular file. The name of the file (in our case foo.png) is provided by specifying location=foo.png—this is an example of how to supply arguments to the individual items in the pipeline. (Note: if you try to use name= it won't work! The name parameter is for referring to the element in the pipeline, not the name of the destination file.)

As you can probably guess, the pngenc plugin is in the pipeline to convert the data from the video camera into the PNG file format before it is written to the the file.

The only other item in the pipeline is the delightfully named ffmpegcolorspace plugin which performs colorspace conversions—essentially the v4l2src and pngenc plugins can't talk to each other directly because they each describe images in different ways, it's the job of ffmpegcolorspace to enable them to communicate by translating between the two styles of image description.

GStreamer 101

See also

http://auricle.dyndns.org/ALE/ ALE is an image-processing program used for tasks such as image mosaicking, super-resolution, deblurring, noise reduction, anti-aliasing, and scene reconstruction. Its principle of operation is synthetic capture, combining multiple inputs representing the same scene.