v4l2 command
Not logged in

v4l2 command

Name

v4l2 - Video For Linux Two interface

Synopsis

package require v4l2
v4l2 option ?arg ...?

Description

This command provides several operations to interface Video For Linux Two in order to operate camera devices. option indicates what to carry out on the Video For Linux Two subsystem. Any unique abbreviation for option is acceptable. The valid options are:

v4l2 close devid

Closes the device identified by devid which has been opened before using v4l2 open.

v4l2 counters devid

Reports a two element list of statistic counters on the device identified by devid. The first element is the number of video frames received, the second the number of video frames processed with v4l2 image. This information can be used to detect dropped frames.

v4l2 devices

Returns a list of device names which can be used for v4l2 open. If udev support is available, this list is refreshed on plug and unplug of devices. Otherwise it is made up of a snapshot of suitable file names in the /dev directory.

v4l2 greyshift devid ?shift?

Returns or sets the bit shift to be applied on grey images with a bit depth higher than 8 which are captured from device devid. The default value is 4, which is suitable for greyscale cameras with 12 bit resolution. The shift is not applied when the image subcommand retrieves raw byte array data.

v4l2 image devid ?photoImage?

Copies the most recent captured image of the device devid into the photo image identified by photoImage and returns non-zero on success or zero if no data transfer has taken place. If photoImage is omitted, a four element list is returned with the first element being the image width, the second the image height, the third the number of bytes per pixel, and the last the image's RGB values with 3 bytes per pixel in red, green, blue order as a byte array. In this case an error is indicated by throwing an exception.

v4l2 info devid

Returns information on open devices. If devid is specified, a list of two elements is returned, the first being the device name and the second the image callback command for that device, i.e. the same arguments which were used on v4l2 open. If devid is omitted, a list of devids, i.e. all currently opened devices is returned.

v4l2 isloopback devname

Tests if devname is a loopback video device and returns true or false.

v4l2 listen ?callback?

Retrieves or sets the callback command called on plug and unplug of devices. When a device is plugged or unplugged that callback is invoked with two additional arguments: the type of event (add or remove) and the device name which was added or removed. Only useable if udev support is available.

v4l2 loopback devname ?fourcc width height fps?

Retrieves or sets frame format and rate of the loopback video device devname. The parameter fourcc specifies the format code, the image size is given as width times height pixels, and the frame rate fps as fraction, i.e. 1/30, or as an integral number, both expressing frames per second. When no parameters are specified, the current settings are returned as a four element list of fourcc, width, height, and fps.

v4l2 mbcopy bytearray1 bytearray2 mask

Copies the content of RGB byte array bytearray2 into the byte array bytearray1 using an RGB mask. Both byte arrays must have identical length which must be a multiple of 3 (for RGB). The main purpose of this command is to combine images from two cameras into an anaglyph 3D, where (for a red-cyan anaglyph) the left camera image uses mask 0xFF0000 (red component) and the right camera image uses mask 0x00FFFF (green and blue components).

v4l2 mcopy photo1 photo2 mask

Copies the content of the photo image photo2 into the photo image photo1 using an ARGB mask. Both photo images must have identical width, height, and depth. The main purpose of this command is to combine images from two cameras into an anaglyph 3D, where (for a red-cyan anaglyph) the left camera image uses mask 0x00FF0000 (red component) and the right camera image uses mask 0x0000FFFF (green and blue components).

v4l2 mirror devid ?x y?

Retrieves or sets flags to mirror captured images along the X or Y axis. Parameters x and y if specified must be boolean values.

v4l2 open devname callback

Opens the device with device name (UN*X pathname) devname and establishes callback as command to be invoked on captured images and returns a devid, i.e. a handle to further deal with the device. Two additional parameters are appended when callback is invoked: the first is the devid of the device, the second a frame counter with initial value of zero based on the last start of image capture. If an error is detected during image capture, the word error is used instead of the frame counter.

v4l2 orientation devid ?degrees?

Retrieves or sets the orientation of captured images regarding image rotation. degrees if specified must be an integer number.

v4l2 parameters devid ?key value ...?

Returns or changes device parameters for the device identified by devid given as key-value pairs, e.g. frame-size 320x240 will change the size of captured images to width 320 and height 240. The command returns the current device parameters (after the potential change, when keys and values where given) as a key-value list which can be processed with array set or dict get.

v4l2 start devid

Starts capturing images of the device identified by devid. When an image is ready, the callback command set on v4l2 open is invoked.

v4l2 state devid

Returns the image capture state of the device identified by devid. The result is the string capture if the device is started, stopped if the device is stopped, or error if an error has been detected while image capture was active.

v4l2 stop devid

Stop capturing images of the device identified by devid.

v4l2 tophoto width height bpp bytearray ?rot mirrorx mirrory?

Makes the RGB (bpp is 3) or gray (bpp is 1) byte array bytearray of width times <height pixels into a Tk photo image. Optionally, the data is rotated by rot degrees (possible values 0, 90, 180, 270) and/or mirrored along the X and/or Y axis as specified by the boolean values mirrorx and mirrory.

v4l2 write devid bytearray

Writes the bytes in bytearray to the device identified by devid which must be an open loopback video device.

v4l2 writephoto devid photo

Writes the content of the photo image photo to the device identified by devid which must be an open loopback video device. The format written corresponds to RGB4 (see below) with the photo's dimensions. No color space conversion and no scaling takes place.

The v4l2 command tries to lazy load Tk, thus allowing to use it from a normal tclsh. Only when a photo image is required by a subcommand, Tk must be available and an attempt to load it is made.

For the fourcc format codes in v4l2 loopback, consult the Linux header file /usr/include/linux/videodev2.h. The most useful formats are RGB4 (8 bits per color in a 32 bit value per pixel) and RGB3 (8 bits per color packed into 24 bits).