102 lines · plain
1.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later2.. c:namespace:: V4L3 4.. _capture:5 6***********************7Video Capture Interface8***********************9 10Video capture devices sample an analog video signal and store the11digitized images in memory. Today nearly all devices can capture at full1225 or 30 frames/second. With this interface applications can control the13capture process and move images from the driver into user space.14 15Conventionally V4L2 video capture devices are accessed through character16device special files named ``/dev/video`` and ``/dev/video0`` to17``/dev/video63`` with major number 81 and minor numbers 0 to 63.18``/dev/video`` is typically a symbolic link to the preferred video19device.20 21.. note:: The same device file names are used for video output devices.22 23Querying Capabilities24=====================25 26Devices supporting the video capture interface set the27``V4L2_CAP_VIDEO_CAPTURE`` or ``V4L2_CAP_VIDEO_CAPTURE_MPLANE`` flag in28the ``capabilities`` field of struct29:c:type:`v4l2_capability` returned by the30:ref:`VIDIOC_QUERYCAP` ioctl. As secondary device31functions they may also support the :ref:`video overlay <overlay>`32(``V4L2_CAP_VIDEO_OVERLAY``) and the :ref:`raw VBI capture <raw-vbi>`33(``V4L2_CAP_VBI_CAPTURE``) interface. At least one of the read/write or34streaming I/O methods must be supported. Tuners and audio inputs are35optional.36 37Supplemental Functions38======================39 40Video capture devices shall support :ref:`audio input <audio>`,41:ref:`tuner`, :ref:`controls <control>`,42:ref:`cropping and scaling <crop>` and43:ref:`streaming parameter <streaming-par>` ioctls as needed. The44:ref:`video input <video>` ioctls must be supported by all video45capture devices.46 47Image Format Negotiation48========================49 50The result of a capture operation is determined by cropping and image51format parameters. The former select an area of the video picture to52capture, the latter how images are stored in memory, i. e. in RGB or YUV53format, the number of bits per pixel or width and height. Together they54also define how images are scaled in the process.55 56As usual these parameters are *not* reset at :c:func:`open()`57time to permit Unix tool chains, programming a device and then reading58from it as if it was a plain file. Well written V4L2 applications ensure59they really get what they want, including cropping and scaling.60 61Cropping initialization at minimum requires to reset the parameters to62defaults. An example is given in :ref:`crop`.63 64To query the current image format applications set the ``type`` field of65a struct :c:type:`v4l2_format` to66``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or67``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and call the68:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this69structure. Drivers fill the struct70:c:type:`v4l2_pix_format` ``pix`` or the struct71:c:type:`v4l2_pix_format_mplane` ``pix_mp``72member of the ``fmt`` union.73 74To request different parameters applications set the ``type`` field of a75struct :c:type:`v4l2_format` as above and initialize all76fields of the struct :c:type:`v4l2_pix_format`77``vbi`` member of the ``fmt`` union, or better just modify the results78of :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`79ioctl with a pointer to this structure. Drivers may adjust the80parameters and finally return the actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`81does.82 83Like :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` the :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl84can be used to learn about hardware limitations without disabling I/O or85possibly time consuming hardware preparations.86 87The contents of struct :c:type:`v4l2_pix_format` and88struct :c:type:`v4l2_pix_format_mplane` are89discussed in :ref:`pixfmt`. See also the specification of the90:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctls for91details. Video capture devices must implement both the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`92and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, even if :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ignores all93requests and always returns default parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does.94:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is optional.95 96Reading Images97==============98 99A video capture device may support the :ref:`read() function <func-read>`100and/or streaming (:ref:`memory mapping <func-mmap>` or101:ref:`user pointer <userp>`) I/O. See :ref:`io` for details.102