18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci.. c:namespace:: V4L 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci.. _capture: 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci*********************** 78c2ecf20Sopenharmony_ciVideo Capture Interface 88c2ecf20Sopenharmony_ci*********************** 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciVideo capture devices sample an analog video signal and store the 118c2ecf20Sopenharmony_cidigitized images in memory. Today nearly all devices can capture at full 128c2ecf20Sopenharmony_ci25 or 30 frames/second. With this interface applications can control the 138c2ecf20Sopenharmony_cicapture process and move images from the driver into user space. 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciConventionally V4L2 video capture devices are accessed through character 168c2ecf20Sopenharmony_cidevice special files named ``/dev/video`` and ``/dev/video0`` to 178c2ecf20Sopenharmony_ci``/dev/video63`` with major number 81 and minor numbers 0 to 63. 188c2ecf20Sopenharmony_ci``/dev/video`` is typically a symbolic link to the preferred video 198c2ecf20Sopenharmony_cidevice. 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci.. note:: The same device file names are used for video output devices. 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciQuerying Capabilities 248c2ecf20Sopenharmony_ci===================== 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciDevices supporting the video capture interface set the 278c2ecf20Sopenharmony_ci``V4L2_CAP_VIDEO_CAPTURE`` or ``V4L2_CAP_VIDEO_CAPTURE_MPLANE`` flag in 288c2ecf20Sopenharmony_cithe ``capabilities`` field of struct 298c2ecf20Sopenharmony_ci:c:type:`v4l2_capability` returned by the 308c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl. As secondary device 318c2ecf20Sopenharmony_cifunctions they may also support the :ref:`video overlay <overlay>` 328c2ecf20Sopenharmony_ci(``V4L2_CAP_VIDEO_OVERLAY``) and the :ref:`raw VBI capture <raw-vbi>` 338c2ecf20Sopenharmony_ci(``V4L2_CAP_VBI_CAPTURE``) interface. At least one of the read/write or 348c2ecf20Sopenharmony_cistreaming I/O methods must be supported. Tuners and audio inputs are 358c2ecf20Sopenharmony_cioptional. 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ciSupplemental Functions 388c2ecf20Sopenharmony_ci====================== 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciVideo capture devices shall support :ref:`audio input <audio>`, 418c2ecf20Sopenharmony_ci:ref:`tuner`, :ref:`controls <control>`, 428c2ecf20Sopenharmony_ci:ref:`cropping and scaling <crop>` and 438c2ecf20Sopenharmony_ci:ref:`streaming parameter <streaming-par>` ioctls as needed. The 448c2ecf20Sopenharmony_ci:ref:`video input <video>` ioctls must be supported by all video 458c2ecf20Sopenharmony_cicapture devices. 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciImage Format Negotiation 488c2ecf20Sopenharmony_ci======================== 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ciThe result of a capture operation is determined by cropping and image 518c2ecf20Sopenharmony_ciformat parameters. The former select an area of the video picture to 528c2ecf20Sopenharmony_cicapture, the latter how images are stored in memory, i. e. in RGB or YUV 538c2ecf20Sopenharmony_ciformat, the number of bits per pixel or width and height. Together they 548c2ecf20Sopenharmony_cialso define how images are scaled in the process. 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ciAs usual these parameters are *not* reset at :c:func:`open()` 578c2ecf20Sopenharmony_citime to permit Unix tool chains, programming a device and then reading 588c2ecf20Sopenharmony_cifrom it as if it was a plain file. Well written V4L2 applications ensure 598c2ecf20Sopenharmony_cithey really get what they want, including cropping and scaling. 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciCropping initialization at minimum requires to reset the parameters to 628c2ecf20Sopenharmony_cidefaults. An example is given in :ref:`crop`. 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciTo query the current image format applications set the ``type`` field of 658c2ecf20Sopenharmony_cia struct :c:type:`v4l2_format` to 668c2ecf20Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or 678c2ecf20Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and call the 688c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this 698c2ecf20Sopenharmony_cistructure. Drivers fill the struct 708c2ecf20Sopenharmony_ci:c:type:`v4l2_pix_format` ``pix`` or the struct 718c2ecf20Sopenharmony_ci:c:type:`v4l2_pix_format_mplane` ``pix_mp`` 728c2ecf20Sopenharmony_cimember of the ``fmt`` union. 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciTo request different parameters applications set the ``type`` field of a 758c2ecf20Sopenharmony_cistruct :c:type:`v4l2_format` as above and initialize all 768c2ecf20Sopenharmony_cifields of the struct :c:type:`v4l2_pix_format` 778c2ecf20Sopenharmony_ci``vbi`` member of the ``fmt`` union, or better just modify the results 788c2ecf20Sopenharmony_ciof :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` 798c2ecf20Sopenharmony_ciioctl with a pointer to this structure. Drivers may adjust the 808c2ecf20Sopenharmony_ciparameters and finally return the actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` 818c2ecf20Sopenharmony_cidoes. 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciLike :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` the :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl 848c2ecf20Sopenharmony_cican be used to learn about hardware limitations without disabling I/O or 858c2ecf20Sopenharmony_cipossibly time consuming hardware preparations. 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciThe contents of struct :c:type:`v4l2_pix_format` and 888c2ecf20Sopenharmony_cistruct :c:type:`v4l2_pix_format_mplane` are 898c2ecf20Sopenharmony_cidiscussed in :ref:`pixfmt`. See also the specification of the 908c2ecf20Sopenharmony_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 918c2ecf20Sopenharmony_cidetails. Video capture devices must implement both the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` 928c2ecf20Sopenharmony_ciand :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, even if :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ignores all 938c2ecf20Sopenharmony_cirequests and always returns default parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. 948c2ecf20Sopenharmony_ci:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is optional. 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ciReading Images 978c2ecf20Sopenharmony_ci============== 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciA video capture device may support the :ref:`read() function <func-read>` 1008c2ecf20Sopenharmony_ciand/or streaming (:ref:`memory mapping <func-mmap>` or 1018c2ecf20Sopenharmony_ci:ref:`user pointer <userp>`) I/O. See :ref:`io` for details. 102