162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _capture: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci*********************** 762306a36Sopenharmony_ciVideo Capture Interface 862306a36Sopenharmony_ci*********************** 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciVideo capture devices sample an analog video signal and store the 1162306a36Sopenharmony_cidigitized images in memory. Today nearly all devices can capture at full 1262306a36Sopenharmony_ci25 or 30 frames/second. With this interface applications can control the 1362306a36Sopenharmony_cicapture process and move images from the driver into user space. 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciConventionally V4L2 video capture devices are accessed through character 1662306a36Sopenharmony_cidevice special files named ``/dev/video`` and ``/dev/video0`` to 1762306a36Sopenharmony_ci``/dev/video63`` with major number 81 and minor numbers 0 to 63. 1862306a36Sopenharmony_ci``/dev/video`` is typically a symbolic link to the preferred video 1962306a36Sopenharmony_cidevice. 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci.. note:: The same device file names are used for video output devices. 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ciQuerying Capabilities 2462306a36Sopenharmony_ci===================== 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciDevices supporting the video capture interface set the 2762306a36Sopenharmony_ci``V4L2_CAP_VIDEO_CAPTURE`` or ``V4L2_CAP_VIDEO_CAPTURE_MPLANE`` flag in 2862306a36Sopenharmony_cithe ``capabilities`` field of struct 2962306a36Sopenharmony_ci:c:type:`v4l2_capability` returned by the 3062306a36Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl. As secondary device 3162306a36Sopenharmony_cifunctions they may also support the :ref:`video overlay <overlay>` 3262306a36Sopenharmony_ci(``V4L2_CAP_VIDEO_OVERLAY``) and the :ref:`raw VBI capture <raw-vbi>` 3362306a36Sopenharmony_ci(``V4L2_CAP_VBI_CAPTURE``) interface. At least one of the read/write or 3462306a36Sopenharmony_cistreaming I/O methods must be supported. Tuners and audio inputs are 3562306a36Sopenharmony_cioptional. 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ciSupplemental Functions 3862306a36Sopenharmony_ci====================== 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ciVideo capture devices shall support :ref:`audio input <audio>`, 4162306a36Sopenharmony_ci:ref:`tuner`, :ref:`controls <control>`, 4262306a36Sopenharmony_ci:ref:`cropping and scaling <crop>` and 4362306a36Sopenharmony_ci:ref:`streaming parameter <streaming-par>` ioctls as needed. The 4462306a36Sopenharmony_ci:ref:`video input <video>` ioctls must be supported by all video 4562306a36Sopenharmony_cicapture devices. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciImage Format Negotiation 4862306a36Sopenharmony_ci======================== 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ciThe result of a capture operation is determined by cropping and image 5162306a36Sopenharmony_ciformat parameters. The former select an area of the video picture to 5262306a36Sopenharmony_cicapture, the latter how images are stored in memory, i. e. in RGB or YUV 5362306a36Sopenharmony_ciformat, the number of bits per pixel or width and height. Together they 5462306a36Sopenharmony_cialso define how images are scaled in the process. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciAs usual these parameters are *not* reset at :c:func:`open()` 5762306a36Sopenharmony_citime to permit Unix tool chains, programming a device and then reading 5862306a36Sopenharmony_cifrom it as if it was a plain file. Well written V4L2 applications ensure 5962306a36Sopenharmony_cithey really get what they want, including cropping and scaling. 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciCropping initialization at minimum requires to reset the parameters to 6262306a36Sopenharmony_cidefaults. An example is given in :ref:`crop`. 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ciTo query the current image format applications set the ``type`` field of 6562306a36Sopenharmony_cia struct :c:type:`v4l2_format` to 6662306a36Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or 6762306a36Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and call the 6862306a36Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this 6962306a36Sopenharmony_cistructure. Drivers fill the struct 7062306a36Sopenharmony_ci:c:type:`v4l2_pix_format` ``pix`` or the struct 7162306a36Sopenharmony_ci:c:type:`v4l2_pix_format_mplane` ``pix_mp`` 7262306a36Sopenharmony_cimember of the ``fmt`` union. 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ciTo request different parameters applications set the ``type`` field of a 7562306a36Sopenharmony_cistruct :c:type:`v4l2_format` as above and initialize all 7662306a36Sopenharmony_cifields of the struct :c:type:`v4l2_pix_format` 7762306a36Sopenharmony_ci``vbi`` member of the ``fmt`` union, or better just modify the results 7862306a36Sopenharmony_ciof :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` 7962306a36Sopenharmony_ciioctl with a pointer to this structure. Drivers may adjust the 8062306a36Sopenharmony_ciparameters and finally return the actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` 8162306a36Sopenharmony_cidoes. 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciLike :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` the :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl 8462306a36Sopenharmony_cican be used to learn about hardware limitations without disabling I/O or 8562306a36Sopenharmony_cipossibly time consuming hardware preparations. 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ciThe contents of struct :c:type:`v4l2_pix_format` and 8862306a36Sopenharmony_cistruct :c:type:`v4l2_pix_format_mplane` are 8962306a36Sopenharmony_cidiscussed in :ref:`pixfmt`. See also the specification of the 9062306a36Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctls for 9162306a36Sopenharmony_cidetails. Video capture devices must implement both the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` 9262306a36Sopenharmony_ciand :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, even if :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ignores all 9362306a36Sopenharmony_cirequests and always returns default parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. 9462306a36Sopenharmony_ci:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is optional. 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ciReading Images 9762306a36Sopenharmony_ci============== 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ciA video capture device may support the :ref:`read() function <func-read>` 10062306a36Sopenharmony_ciand/or streaming (:ref:`memory mapping <func-mmap>` or 10162306a36Sopenharmony_ci:ref:`user pointer <userp>`) I/O. See :ref:`io` for details. 102