] by
chw
2021-09-01 12:33:41.
D 2021-09-01T12:33:41.007
L v4l2\scommand
P 053b0e7d46f47a717980202d2895948850fc542d
U chw
W 10143
<h2>v4l2 command</h2>
<h3>Name</h3>
<b>v4l2</b> - Video For Linux Two interface
<h3>Synopsis</h3>
<tt>package require v4l2</tt><br>
<tt>v4l2 <i>option</i> ?<i>arg ...</i>?</tt>
<h3>Description</h3>
This command provides several operations to interface Video For Linux
Two in order to operate camera devices. <tt><i>option</i></tt> indicates what
to carry out on the Video For Linux Two subsystem. Any unique
abbreviation for <tt><i>option</i></tt> is acceptable.
The valid options are:
<tt>v4l2 close <i>devid</i></tt>
Closes the device identified by <tt><i>devid</i></tt> which has been opened before using <tt>v4l2 open</tt>.
<tt>v4l2 counters <i>devid</i></tt>
Reports a two element list of statistic counters on the device identified by <tt><i>devid</i></tt>. The first element is the number of video frames received, the second the number of video frames processed with <tt>v4l2 greyimage</tt> and <tt>v4l2 image</tt>. This information can be used to detect dropped frames.
<tt>v4l2 devices</tt>
Returns a list of device names which can be used for <tt>v4l2 open</tt>. If <tt>udev</tt> 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 <tt>/dev</tt> directory.
<tt>v4l2 greyimage <i>devid mask</i> ?<i>photoImage</i>?</tt>
Copies the most recent captured image of the device <tt><i>devid</i></tt> into the photo image identified by <tt><i>photoImage</i></tt> and returns non-zero on success or zero if no data transfer has taken place. The image is converted to greyscale if the capture format delivers color images, where <tt><i>mask</i></tt>controls the conversion. If it is empty or <b>RGB</b>, all color components are used for conversion, otherwise for each letter <b>R</b>, <b>G</b>, and <b>B</b> the respective color component is used. If more than one color component is used in the conversion, the weights are 0.299 for red, 0.587 for green, and 0.114 for blue. If <tt><i>photoImage</i></tt> 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 (one or two), and the last the image's pixel values with one or two bytes per grey pixel as a byte array. In this case an error is indicated by throwing an exception.
<tt>v4l2 greyshift <i>devid</i> ?<i>shift</i>?</tt>
Returns or sets the bit shift to be applied on grey images with a bit depth higher than 8 which are captured from device <tt><i>devid</i></tt>. The default value is 4, which is suitable for greyscale cameras with 12 bit resolution. The shift is not applied when the <tt><i>image</i></tt> subcommand retrieves raw byte array data.
<tt>v4l2 image <i>devid</i> ?<i>photoImage</i>?</tt>
Copies the most recent captured image of the device <tt><i>devid</i></tt> into the photo image identified by <tt><i>photoImage</i></tt> and returns non-zero on success or zero if no data transfer has taken place. If <tt><i>photoImage</i></tt> 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.
<tt>v4l2 info <i>devid</i></tt>
Returns information on open devices. If <tt><i>devid</i></tt> 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 <tt>v4l2 open</tt>. If <tt><i>devid</i></tt> is omitted, a list of <tt><i>devid</i></tt>s, i.e. all currently opened devices is returned.
<tt>v4l2 isloopback <i>devname</i></tt>
Tests if <tt><i>devname</i></tt> is a loopback video device and returns true or false.
<tt>v4l2 listen ?<i>callback</i>?</tt>
Retrieves or sets the <tt><i>callback</i></tt> 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 (<tt>add</tt> or <tt>remove</tt>) and the device name which was added or removed. Only useable if <tt>udev</tt> support is available.
<tt>v4l2 loopback <i>devname<i> ?<i>fourcc width height fps<i>?</tt>
Retrieves or sets frame format and rate of the loopback video device <tt><i>devname</i></tt>. The parameter <tt><i>fourcc</i></tt> specifies the format code, the image size is given as <tt><i>width</i></tt> times <tt><i>height</i></tt> pixels, and the frame rate <tt><i>fps</i></tt> 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 <tt><i>fourcc</i></tt>, <tt><i>width</i></tt>, <tt><i>height</i></tt>, and <tt><i>fps</i></tt>.
<tt>v4l2 mbcopy <i>bytearray1 bytearray2 mask</i></tt>
Copies the content of RGB byte array <tt><i>bytearray2</i></tt> into the byte array <tt><i>bytearray1</i></tt> using an RGB <tt><i>mask</i></tt>. 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).
<tt>v4l2 mcopy <i>photo1 photo2 mask</i></tt>
Copies the content of the photo image <tt><i>photo2</i></tt> into the photo image <tt><i>photo1</i></tt> using an ARGB <tt><i>mask</i></tt>. 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).
<tt>v4l2 mirror <i>devid</i> ?<i>x y</i>?</tt>
Retrieves or sets flags to mirror captured images along the X or Y axis. Parameters <tt><i>x</i></tt> and <tt><i>y</i></tt> if specified must be boolean values.
<tt>v4l2 open <i>devname callback</i></tt>
Opens the device with device name (UN*X pathname) <tt><i>devname</i></tt> and establishes <tt><i>callback</i></tt> as command to be invoked on captured images and returns a <tt><i>devid</i></tt>, i.e. a handle to further deal with the device. Two additional parameters are appended when <tt><i>callback</i></tt> is invoked: the first is the <tt><i>devid</i></tt> 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 <b>error</b> is used instead of the frame counter.
<tt>v4l2 orientation <i>devid</i> ?<i>degrees</i>?</tt>
Retrieves or sets the orientation of captured images regarding image rotation. <tt><i>degrees</i></tt> if specified must be an integer number.
<tt>v4l2 parameters <i>devid</i> ?<i>key value ...</i>?</tt>
Returns or changes device parameters for the device identified by <tt><i>devid</i></tt> given as key-value pairs, e.g. <tt>frame-size 320x240</tt> 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 <tt>array set</tt> or <tt>dict get</tt>.
<tt>v4l2 start <i>devid</i></tt>
Starts capturing images of the device identified by <tt><i>devid</i></tt>. When an image is ready, the callback command set on <tt>v4l2 open</tt> is invoked.
<tt>v4l2 state <i>devid</i></tt>
Returns the image capture state of the device identified by <tt><i>devid</i></tt>. The result is the string <b>capture</b> if the device is started, <b>stopped</b> if the device is stopped, or <b>error</b> if an error has been detected while image capture was active.
<tt>v4l2 stop <i>devid</i></tt>
Stop capturing images of the device identified by <tt><i>devid</i></tt>.
<tt>v4l2 tophoto <i>width height bpp bytearray</i> ?<i>rot mirrorx mirrory</i>?</tt>
Makes the RGB (bpp is 3) or grey (bpp is 1) byte array <tt><i>bytearray</i></tt> of <tt><i>width</i></tt> times <tt><<i>height</i></tt> pixels into a Tk photo image. Optionally, the data is rotated by <tt><i>rot</i></tt> degrees (possible values 0, 90, 180, 270) and/or mirrored along the X and/or Y axis as specified by the boolean values <tt><i>mirrorx</i></tt> and <tt><i>mirrory</i></tt>.
<tt>v4l2 write <i>devid bytearray</i></tt>
Writes the bytes in <tt><i>bytearray</i></tt> to the device identified by <tt><i>devid</i></tt> which must be an open loopback video device. The size of <tt><i>bytearray</i></tt> must match the video width/height of the loopback device. Data is converted to <b>YUYV</b> if this is detected for the output path of the loopback device.
<tt>v4l2 writephoto <i>devid photo</i></tt>
Writes the content of the photo image <tt><i>photo</i></tt> to the device identified by <tt><i>devid</i></tt> which must be an open loopback video device. The format written is either <b>RGB4</b> or <b>YUYV</b> with the photo's dimensions depending on which format is detected for the output path of the loopback device.
The <tt>v4l2</tt> command tries to lazy load Tk, thus allowing to use it from a normal <b>tclsh</b>. Only when a photo image is required by a subcommand, Tk must be available and an attempt to load it is made.
For the <tt><i>fourcc</i></tt> format codes in <tt>v4l2 loopback</tt>, consult the Linux header file <tt>/usr/include/linux/videodev2.h</tt>. The most useful formats are <b>RGB4</b> (8 bits per color in a 32 bit value per pixel) and <b>RGB3</b> (8 bits per color packed into 24 bits). Limited support for <b>YUYV</b> and <b>YVYU</b> (YUV 4:2:2 interleaved) exists for the <b>v4l2 writephoto</b> subcommand, too.
Z c8841b4b23f5381818c6530388d62a7d