Skip navigation links

Package au.edu.jcu.v4l4j

Video4Linux4java Main Package

See: Description

Package au.edu.jcu.v4l4j Description

Video4Linux4java Main Package

Introduction

The Video4Linux (V4L) API provides data structures & methods to access and control video input & output hardware, as well as radio tuners. The API is divided into several interfaces, including video capture, video overlay, video output & teletext interfaces. v4l4j provides access to the video capture interface of V4L only. v4l4j allows you to retrieve information about a video device, access its video controls & tuners and grab images from it.

Examples

v4l4j comes with many simple, easy-to-follow example applications in the au.edu.jcu.v4l4j.examples package. It is strongly suggested you take a look at them as you read these JavaDoc pages as they help illustrate concepts crucial to a correct use of this API.

Usage

Video device object

To use v4l4j, the first step is to create a VideoDevice object, which represents a physical video input hardware device. This includes webcams and capture / tuner cards. The only pre-requisite is that your hardware must be supported and its driver loaded. Creating a VideoDevice is simple. You only need the path to a valid device file to create this object:
VideoDevice vd = new VideoDevice("/dev/video0");
As it is the case most of the time when interacting with hardware, you must release resources and data structures when finished. All v4l4j classes follow this rule, including VideoDevices. The rare exceptions are clearly identified in their java documentation.
vd.release();
Once an object has been release()d, it must not be reused, and all references to it must be discarded, by explicitly setting them to null for example. Calling any release() method more than once will throw a StateException.
VideoDevice objects give you access to 4 broad categories: Each of these can be obtained independently from each other, by calling the appropriate method on a VideoDevice instance. This flexibility allows an application to create a GUI which provides access to video controls, while another application is streaming video from the device. For this to work, the device driver must allows multiple applications to open the device file simultaneously. As an example, the UVC driver works this way.

Video hardware information

With a valid VideoDevice object, you can retrieve information about the underlying hardware and find out, for example how many video inputs the device has, how many tuners are available, the set of supported video standards and capture resolutions. This kind of information is contained in a DeviceInfo object. You can get a reference to a DeviceInfo object for a given video device by calling VideoDevice.getDeviceInfo() on the VideoDevice object. See the documentation of the VideoDevice and DeviceInfo classes for more information.

Video controls

Video capture devices usually have a set of controls which influence various parameters related to the video stream. Examples are brightness, contrast, gamma & white balance. A single control is represented by Control object. The set of supported controls for a given video device hardware-dependent and is embedded into a ControlList object, which can be obtained by calling VideoDevice.getControlList(). The ControlList object must be released when controls are no longer needed. This is done by calling VideoDevice.releaseControlList(). Again, once released, neither the ControlList nor individual Controls must be used, and any reference to them must be discarded, by explicitly setting them to null for example. For more information, check the documentation of the Control and ControlList classes.

Video capture

Capture in v4l4j is extremely simple. v4l4j hands out captured frames in a VideoFrame object, either in a native image format ( also referred to as raw format in v4l4j's documentation) or one of the 5 convenience image formats (JPEG, RGB24, BGR24, YUV420 or YVU420). Each of these 6 image formats is output by a dedicated frame grabber object, which will grab frames and convert them to that format if required. The set of native ImageFormats supported by a video device can be obtained using the DeviceInfo object (see paragraph "Video hardware information" above). When capturing in a native format, v4l4j simply hands out the captured frame without further processing. When capturing in one of the convenience formats, v4l4j will transparently convert the image.
Frame grabbers operate in push mode: the frame grabber delivers captured frames to a callback object you provide. Frame capture in v4l4j is done using objects implementing the FrameGrabber interface. Check the documentation of the FrameGrabber class for more information.

Tuners

v4l4j provides access to tuners if present in the video device. A TunerList object can be obtained by calling VideoDevice.getTunerList(). Note that the tuner list need not be released when finished.
Skip navigation links

Copyright © 2013-2015 Bartosz Firyn (sarxos). All Rights Reserved.