Programming the camera: Difference between revisions
(Begin description of what happens behind the scenes) |
(More explanations and a disclaimer...) |
||
Line 23: | Line 23: | ||
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 (<tt>src</tt>) and ends up in a sink (<tt>sink</tt>) and can go through a number of intermediate manipulations along the way. |
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 (<tt>src</tt>) and ends up in a sink (<tt>sink</tt>) 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 <tt>gst-launch</tt>. The <tt>gst-launch</tt> tool is a quick way to experiment with putting a pipeline together and seeing what it does. |
|||
⚫ | |||
Let's take a look at that first command line again: |
|||
gst-launch-0.10 v4l2src ! ffmpegcolorspace ! pngenc ! filesink location=foo.png |
|||
⚫ | The camera in a XO laptop is a regular [http://linuxtv.org/v4lwiki/ Video4Linux 2] device which is accessed via GStreamer's <tt>v4l2src</tt> source--see that wasn't just a pile of random characters my cat threw up. Since the camera is our source it's the first item in our pipeline--notice the individual parts of the pipeline are separated with <tt>!</tt> characters. (You could say the data goes out with a bang but it'd be a pretty bad joke.) |
||
Line 30: | Line 36: | ||
---- |
|||
Note: The author is learning this as he goes along, so items described may not be the best way or correct way to do anything. |
|||
[[Category:Developers]] |
[[Category:Developers]] |
Revision as of 15:45, 13 April 2007
This page explores how to interact with the laptop's built-in video camera.
Getting started
First, let's see the quickest way we can capture a still image from the camera--using a GStreamer command-line tool:
gst-launch-0.10 v4l2src ! ffmpegcolorspace ! pngenc ! filesink location=foo.png
You'll need to run the above command in either a terminal 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 ! ximagesink
Unlike the first command this command will only work when executed in a terminal in the developer console. The resulting video will 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.
Let's take a look at that first command line again:
gst-launch-0.10 v4l2src ! ffmpegcolorspace ! pngenc ! filesink location=foo.png
The camera in a XO laptop is a regular Video4Linux 2 device which is accessed via GStreamer's v4l2src source--see that wasn't just a pile of random characters my cat threw up. 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.)
Camera
- Have to script v4l2 via gstreamer to capture a single frame from the camera. See sugar/shell/intro/glive.py for sample code
Note: The author is learning this as he goes along, so items described may not be the best way or correct way to do anything.