Difference between revisions of "CM-T3730: Linux: Camera"
(→See also) |
(→Snapshots) |
||
Line 208: | Line 208: | ||
Once there is an output streamed on the display, press {{parameter|s}} to take a snapshot. Each snapshot will be saved in your current directory as shotXXXX.png. | Once there is an output streamed on the display, press {{parameter|s}} to take a snapshot. Each snapshot will be saved in your current directory as shotXXXX.png. | ||
<br style="clear: both" /> | <br style="clear: both" /> | ||
+ | |||
==== Playback ==== | ==== Playback ==== | ||
Revision as of 13:10, 3 April 2012
Contents
Overview
CM-T3730 Linux supports various camera devices connected either to the USB subsystem or to the camera interface (CIF). This article describes the USB camera setup and configuration and provides several usage examples. Linux USB camera support is provided by USB Video Class (UVC) driver. All UVC compliant camera peripherals can be managed by the UVC driver. Linux also supports various non UVC cameras, but with some limitations. Therefore non UVC cameras are not covered in this article. Linux UVC driver implements the Video for Linux Two (V4L2) API. V4L2 is a suite of driver specifications for different types of video devices and video-related data. Examples in this article are using a AV301W-based camera.
Linux kernel
All the use cases and examples in this article were tested with the CM-T3730 Linux package, that can be obtained from CM-T3730 product webpage.
The following kernel configuration procedure is required:
- Enable "Multimedia support" in the "Device Drivers" submenu:
┌──────────────────────────────── Device Drivers ─────────────────────────────────┐ │ ┌────^(-)─────────────────────────────────────────────────────────────────────┐ │ │ │ [*] Watchdog Timer Support ---> │ │ │ │ Sonics Silicon Backplane ---> │ │ │ │ Broadcom specific AMBA ---> │ │ │ │ -*- Multifunction device drivers ---> │ │ │ │ -*- Voltage and Current Regulator Support ---> │ │ │ │ <*> Multimedia support ---> │ │ │ │ Graphics support ---> │ │ │ │ <*> Sound card support ---> │ │ │ │ [*] HID Devices ---> │ │ │ └────v(+)─────────────────────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ <Select> < Exit > < Help > │ └─────────────────────────────────────────────────────────────────────────────────┘
- Enable "Video For linux" and "Video capture adapters" in the "Multimedia support" submenu:
┌────────────────────────────── Multimedia support ───────────────────────────────┐ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │ │ │ --- Multimedia support │ │ │ │ *** Multimedia core support *** │ │ │ │ [ ] Media Controller API (EXPERIMENTAL) │ │ │ │ <*> Video For Linux │ │ │ │ < > DVB for Linux │ │ │ │ *** Multimedia drivers *** │ │ │ │ <*> Remote Controller adapters ---> │ │ │ │ [ ] Load and attach frontend and tuner driver modules as needed │ │ │ │ [*] Customize analog and hybrid tuner modules to build │ │ │ │ Customize TV tuners ---> │ │ │ │ [*] Video capture adapters ---> │ │ │ │ [ ] Memory-to-memory multimedia devices ---> │ │ │ │ [*] Radio Adapters ---> │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ <Select> < Exit > < Help > │ └─────────────────────────────────────────────────────────────────────────────────┘
- Enable "OMAP2/OMAP3 V4L2-Display driver" and "V4L USB devices" in the "Video capture adapters" submenu:
┌──────────────────────────── Video capture adapters ─────────────────────────────┐ │ ┌────^(-)─────────────────────────────────────────────────────────────────────┐ │ │ │ [ ] Enable old-style fixed minor ranges for video devices │ │ │ │ [ ] Autoselect pertinent encoders/decoders and other helper chips │ │ │ │ <*> I2C module for IR │ │ │ │ Encoders, decoders, sensors and other helper chips ---> │ │ │ │ < > Virtual Video Driver │ │ │ │ < > VPFE Video Capture Driver │ │ │ │ <*> OMAP2/OMAP3 V4L2-Display driver │ │ │ │ < > CPiA2 Video For Linux │ │ │ │ < > Support for timberdale Video In/LogiWIN │ │ │ │ < > SR030PC30 VGA camera sensor support │ │ │ │ < > NOON010PC30 CIF camera sensor support │ │ │ │ < > SoC camera support │ │ │ │ [*] V4L USB devices ---> │ │ │ └─────────────────────────────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ <Select> < Exit > < Help > │ └─────────────────────────────────────────────────────────────────────────────────┘
- Enable "USB Video Class (UVC)" in "V4L USB devices" submenu:
┌──────────────────────────────── V4L USB devices ────────────────────────────────┐ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │ │ │ --- V4L USB devices │ │ │ │ <*> USB Video Class (UVC) │ │ │ │ [*] UVC input events device support │ │ │ │ <M> GSPCA based webcams ---> │ │ │ │ < > Hauppauge WinTV-PVR USB2 support │ │ │ │ < > Hauppauge HD PVR support │ │ │ └────v(+)─────────────────────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ <Select> < Exit > < Help > │ └─────────────────────────────────────────────────────────────────────────────────┘
UVC camera and the driver do not need any special kernel command line parameters option.
Video support validation
Check that your camera has been recognized correctly through the kernel debug messages log (using the dmesg command):
usb 1-2.2: New USB device found, idVendor=1871, idProduct=0f01 usb 1-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 usb 1-2.2: Product: USB2.0 Camera usb 1-2.2: Manufacturer: AVEO Technology Corp. usb 1-2.2: usb_probe_device usb 1-2.2: configuration #1 chosen from 1 choice usb 1-2.2: adding 1-2.2:1.0 (config #1, interface 0) uvcvideo 1-2.2:1.0: usb_probe_interface uvcvideo 1-2.2:1.0: usb_probe_interface - got id uvcvideo: Found UVC 1.00 device USB2.0 Camera (1871:0f01) input: USB2.0 Camera as /devices/platform/usbhs-omap.0/ehci-omap.0/usb1/1-2/1-2.2/1-2.2:1.0/input/input7 usb 1-2.2: adding 1-2.2:1.1 (config #1, interface 1)
Also, the /dev/video0 device special file should be created.
Playback and Streaming tools
Linux provides a variety of playback and streaming tools for the V4L2 compliant devices. We provide several examples that do not necessarily require a X Window System to operate your camera and capture images.
MPlayer
MPlayer has support for most modern video and audio formats. MPlayer is highly configurable, and can be controlled by keyboard, mouse, joystick or remote control (with LIRC). MPlayer package is included in the CM-T3730 Angstrom Linux root filesystem image.
Output to display
Following command can be used to stream the camera output to the display using default configuration settings.
mplayer tv:// -vo omapfb
Press q or ESC to stop playing and quit program.
Adding more parameters will do some customization as shown below.
mplayer tv:// -tv driver=v4l2:width=800:height=600:device=/dev/video0:brightness=80:contrast=10:saturation=-30 -fs -vf mirror -vo omapfb
Parameters description:
mplayer tv:// | Stream data using TV capture module | ||
-tv | This option tunes various properties of the TV capture module (see below). | ||
|
Set TV input driver. | ||
|
Output window width and height. | ||
|
Specify TV device. | ||
|
Set the image equalizer. | ||
-fs | Fullscreen playback. Note: -fs is not necessarily supported by all MPlayer video output drivers. | ||
-vf | Video filters allow modification of the video stream and its properties. | ||
|
Mirrors the image on the Y axis. | ||
|
Allows acquiring screenshots of the movie. Make sure that the screenshot filter is the last filter, so the exact picture on the display will be saved. | ||
-vo | Specifies MPlayer video output driver. | ||
|
TI OMAP video frame buffer output. | ||
|
Separate output window if using X Window System. |
To start X Window application (e.g. MPlayer) from your serial console, the DISPLAY environment variable must be set. |
Additional example for streaming camera output to a separate window in the X Window system:
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -vo xv
Snapshots
File:Usb camera screenshoot.png To take snapshots, run the MPlayer with the following command line:
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -vf screenshot -vo omapfb
Once there is an output streamed on the display, press s to take a snapshot. Each snapshot will be saved in your current directory as shotXXXX.png.
Playback
To play a movie, run the MPlayer with the following command line:
mplayer media_file.ogg -vo omapfb
GStreamer
GStreamer is a pipeline-based multimedia framework that allows you to create a variety of media-handling software components. This includes simple audio playback, audio and video playback, recording, streaming, and editing. The pipeline design allows you to easily write any type of streaming multimedia application. GStreamers capabilities are extended through plugins. Several simple media manipulations are demonstrated below.
Installation
For the GStreamer to function properly, there are several packages that need to be installed. Those can be found on the The Ångström Distribution official website.
- To install the basic GStreamer set, use the following command:
opkg install libxml2_2.7.8-r9.1.6_armv7a.ipk libgcc1_4.5-r47+svnr184907_armv7a.ipk libc6_2.12-r28_armv7a.ipk libffi5_3.0.10-r0_armv7a.ipk \ libz1_1.2.6-r1_armv7a.ipk libglib-2.0-0_2.30.3-r0_armv7a.ipk gstreamer_0.10.36-r0_armv7a.ipk libxcb1_1.8.1-r0_armv7a.ipk \ libxv1_1.0.7-r0_armv7a.ipk libuuid1_2.21-r5_armv7a.ipk libudev0_182-r0_armv7a.ipk libgudev-1.0-0_182-r0_armv7a.ipk \ libgstinterfaces-0.10-0_0.10.36-r1_armv7a.ipk libgstvideo-0.10-0_0.10.36-r1_armv7a.ipk --force-overwrite
- For GStreamer to support Video4Linux2 and several plugins for manipulating the output stream, the following needs to be installed:
opkg install gst-plugins-good-video4linux2_0.10.31-r0_armv7a.ipk gst-plugin-videorate_0.10.35-r1_armv7a.ipk \ gst-plugin-ffmpegcolorspace_0.10.35-r1_armv7a.ipk gst-plugin-ximagesink_0.10.35-r1_armv7a.ipk
- To support encoding with Theora codec (required if you want to save the encoded video to a file), the following needs to be installed:
opkg install libogg0_1.3.0-r0_armv7a.ipk libtheora_1.1.1-r1_armv7a.ipk libgsttag-0.10-0_0.10.36-r1_armv7a.ipk gst-plugin-theora_0.10.35-r1_armv7a.ipk \ libgstpbutils-0.10-0_0.10.36-r1_armv7a.ipk libgstaudio-0.10-0_0.10.36-r1_armv7a.ipk libgstriff-0.10-0_0.10.36-r1_armv7a.ipk \ gst-plugin-ogg_0.10.35-r1_armv7a.ipk --force-overwrite
Validation
To validate the installation of the GStreamer components, launch gst-inspect GStreamer utility.
Testing the basic streaming to OMAP frame buffer:
gst-launch videotestsrc ! omapdmaifbsink
Streaming to display
To start streaming the video to display the simple GStreamer pipeline can be used.
The basic GStreamer pipeline should have at least the source of the stream and the output sink specified.
The below example streams the video from the V4L2 /dev/video0 device to the OMAP frame buffer (sink) with several stream manipulations applied.
gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv,format=(fourcc)YUY2,width=640,height=480' ! videorate ! ffmpegcolorspace ! omapdmaifbsink
Pipeline parameters in details:
v4l2src | Element for reading frames from a Video4Linux2 device. | ||
|
Specify the V4L2 /dev/video0 device as a stream source. | ||
|
Disable copying of the stream buffers. This can slightly improve the GStreamer performance. | ||
video/x-raw-yuv,format=(fourcc)YUY2,width=640,height=480 | Link the source to a capability, which is defined by a mime type and a few optional properties. The properties are: video and resolution. | ||
videorate | Use each frame of the source stream and feed it to the next element at the requested framerate. | ||
ffmpegcolorspace | Make the color space conversion, required by the sink element. | ||
omapdmaifbsink | Define the OMAP frame buffer as the output sink. Sink can be: a file, screen or a network. For X Window System, the ximagesink parameter can be used. |
Streaming to a file
To encode and save the output stream to a file, using the Theora codec, run the following command:
gst-launch v4l2src ! 'video/x-raw-yuv,width=320,height=240' ! queue ! videorate ! 'video/x-raw-yuv,framerate=10/1' ! ffmpegcolorspace ! \ theoraenc ! queue ! oggmux ! filesink location=media_file.ogg
Parameters in details:
queue | Provides a buffer for the next element in the pipeline. |
theoraenc | Encodes raw video into theora stream. |
oggmux | Muxes a stream into an ogg container. |
filesink | Writes the incoming data to a file. |
Streaming to a file and display
Following command splits the source stream and links to the frame buffer and to an encoded file:
gst-launch v4l2src always-copy=false ! 'video/x-raw-yuv,width=320,height=240' ! tee name=t_video ! queue ! videorate ! ffmpegcolorspace ! \ omapdmaifbsink t_video. ! queue ! videorate ! 'video/x-raw-yuv,framerate=10/1' ! ffmpegcolorspace ! theoraenc ! \ queue ! oggmux ! filesink location=media_file.ogg
tee | Split data to multiple streams (element pads). | ||
|
Names the element's pad. t_video is then linked to theora encoder. |
File playback
To play a movie encoded by Theora codec and saved in ogg contaner, use the following command line:
gst-launch filesrc location=media_file.ogg ! oggdemux ! theoradec ! ffmpegcolorspace ! omapdmaifbsink
See also
- Linux UVC driver and tools
- MPlayer official resource
- GStreamer official resource
- Introducing GStreamer
- GStreamer TI Plugin
- Ångström Distribution Feed browser
- CM-T3730: Linux: Getting started
- CM-T3730: Linux: Angstrom
- CM-T3730: Linux: Kernel
- CM-T3530: Linux: Video playback
- Linux Development for ARM modules