1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L
354f38fcaSMauro Carvalho Chehab
454f38fcaSMauro Carvalho Chehab.. _capture:
554f38fcaSMauro Carvalho Chehab
654f38fcaSMauro Carvalho Chehab***********************
754f38fcaSMauro Carvalho ChehabVideo Capture Interface
854f38fcaSMauro Carvalho Chehab***********************
954f38fcaSMauro Carvalho Chehab
1054f38fcaSMauro Carvalho ChehabVideo capture devices sample an analog video signal and store the
1154f38fcaSMauro Carvalho Chehabdigitized images in memory. Today nearly all devices can capture at full
1254f38fcaSMauro Carvalho Chehab25 or 30 frames/second. With this interface applications can control the
1354f38fcaSMauro Carvalho Chehabcapture process and move images from the driver into user space.
1454f38fcaSMauro Carvalho Chehab
1554f38fcaSMauro Carvalho ChehabConventionally V4L2 video capture devices are accessed through character
1654f38fcaSMauro Carvalho Chehabdevice special files named ``/dev/video`` and ``/dev/video0`` to
1754f38fcaSMauro Carvalho Chehab``/dev/video63`` with major number 81 and minor numbers 0 to 63.
1854f38fcaSMauro Carvalho Chehab``/dev/video`` is typically a symbolic link to the preferred video
1954f38fcaSMauro Carvalho Chehabdevice.
2054f38fcaSMauro Carvalho Chehab
2154f38fcaSMauro Carvalho Chehab.. note:: The same device file names are used for video output devices.
2254f38fcaSMauro Carvalho Chehab
2354f38fcaSMauro Carvalho ChehabQuerying Capabilities
2454f38fcaSMauro Carvalho Chehab=====================
2554f38fcaSMauro Carvalho Chehab
2654f38fcaSMauro Carvalho ChehabDevices supporting the video capture interface set the
2754f38fcaSMauro Carvalho Chehab``V4L2_CAP_VIDEO_CAPTURE`` or ``V4L2_CAP_VIDEO_CAPTURE_MPLANE`` flag in
2854f38fcaSMauro Carvalho Chehabthe ``capabilities`` field of struct
2954f38fcaSMauro Carvalho Chehab:c:type:`v4l2_capability` returned by the
3054f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_QUERYCAP` ioctl. As secondary device
3154f38fcaSMauro Carvalho Chehabfunctions they may also support the :ref:`video overlay <overlay>`
3254f38fcaSMauro Carvalho Chehab(``V4L2_CAP_VIDEO_OVERLAY``) and the :ref:`raw VBI capture <raw-vbi>`
3354f38fcaSMauro Carvalho Chehab(``V4L2_CAP_VBI_CAPTURE``) interface. At least one of the read/write or
3454f38fcaSMauro Carvalho Chehabstreaming I/O methods must be supported. Tuners and audio inputs are
3554f38fcaSMauro Carvalho Chehaboptional.
3654f38fcaSMauro Carvalho Chehab
3754f38fcaSMauro Carvalho ChehabSupplemental Functions
3854f38fcaSMauro Carvalho Chehab======================
3954f38fcaSMauro Carvalho Chehab
4054f38fcaSMauro Carvalho ChehabVideo capture devices shall support :ref:`audio input <audio>`,
4154f38fcaSMauro Carvalho Chehab:ref:`tuner`, :ref:`controls <control>`,
4254f38fcaSMauro Carvalho Chehab:ref:`cropping and scaling <crop>` and
4354f38fcaSMauro Carvalho Chehab:ref:`streaming parameter <streaming-par>` ioctls as needed. The
4454f38fcaSMauro Carvalho Chehab:ref:`video input <video>` ioctls must be supported by all video
4554f38fcaSMauro Carvalho Chehabcapture devices.
4654f38fcaSMauro Carvalho Chehab
4754f38fcaSMauro Carvalho ChehabImage Format Negotiation
4854f38fcaSMauro Carvalho Chehab========================
4954f38fcaSMauro Carvalho Chehab
5054f38fcaSMauro Carvalho ChehabThe result of a capture operation is determined by cropping and image
5154f38fcaSMauro Carvalho Chehabformat parameters. The former select an area of the video picture to
5254f38fcaSMauro Carvalho Chehabcapture, the latter how images are stored in memory, i. e. in RGB or YUV
5354f38fcaSMauro Carvalho Chehabformat, the number of bits per pixel or width and height. Together they
5454f38fcaSMauro Carvalho Chehabalso define how images are scaled in the process.
5554f38fcaSMauro Carvalho Chehab
56407e84cdSMauro Carvalho ChehabAs usual these parameters are *not* reset at :c:func:`open()`
5754f38fcaSMauro Carvalho Chehabtime to permit Unix tool chains, programming a device and then reading
5854f38fcaSMauro Carvalho Chehabfrom it as if it was a plain file. Well written V4L2 applications ensure
5954f38fcaSMauro Carvalho Chehabthey really get what they want, including cropping and scaling.
6054f38fcaSMauro Carvalho Chehab
6154f38fcaSMauro Carvalho ChehabCropping initialization at minimum requires to reset the parameters to
6254f38fcaSMauro Carvalho Chehabdefaults. An example is given in :ref:`crop`.
6354f38fcaSMauro Carvalho Chehab
6454f38fcaSMauro Carvalho ChehabTo query the current image format applications set the ``type`` field of
6554f38fcaSMauro Carvalho Chehaba struct :c:type:`v4l2_format` to
6654f38fcaSMauro Carvalho Chehab``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or
6754f38fcaSMauro Carvalho Chehab``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and call the
6854f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this
6954f38fcaSMauro Carvalho Chehabstructure. Drivers fill the struct
7054f38fcaSMauro Carvalho Chehab:c:type:`v4l2_pix_format` ``pix`` or the struct
7154f38fcaSMauro Carvalho Chehab:c:type:`v4l2_pix_format_mplane` ``pix_mp``
7254f38fcaSMauro Carvalho Chehabmember of the ``fmt`` union.
7354f38fcaSMauro Carvalho Chehab
7454f38fcaSMauro Carvalho ChehabTo request different parameters applications set the ``type`` field of a
7554f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_format` as above and initialize all
7654f38fcaSMauro Carvalho Chehabfields of the struct :c:type:`v4l2_pix_format`
7754f38fcaSMauro Carvalho Chehab``vbi`` member of the ``fmt`` union, or better just modify the results
7854f38fcaSMauro Carvalho Chehabof :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
7954f38fcaSMauro Carvalho Chehabioctl with a pointer to this structure. Drivers may adjust the
8054f38fcaSMauro Carvalho Chehabparameters and finally return the actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`
8154f38fcaSMauro Carvalho Chehabdoes.
8254f38fcaSMauro Carvalho Chehab
8354f38fcaSMauro Carvalho ChehabLike :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` the :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl
8454f38fcaSMauro Carvalho Chehabcan be used to learn about hardware limitations without disabling I/O or
8554f38fcaSMauro Carvalho Chehabpossibly time consuming hardware preparations.
8654f38fcaSMauro Carvalho Chehab
8754f38fcaSMauro Carvalho ChehabThe contents of struct :c:type:`v4l2_pix_format` and
8854f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_pix_format_mplane` are
8954f38fcaSMauro Carvalho Chehabdiscussed in :ref:`pixfmt`. See also the specification of the
9054f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctls for
9154f38fcaSMauro Carvalho Chehabdetails. Video capture devices must implement both the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`
9254f38fcaSMauro Carvalho Chehaband :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, even if :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ignores all
9354f38fcaSMauro Carvalho Chehabrequests and always returns default parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does.
9454f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is optional.
9554f38fcaSMauro Carvalho Chehab
9654f38fcaSMauro Carvalho ChehabReading Images
9754f38fcaSMauro Carvalho Chehab==============
9854f38fcaSMauro Carvalho Chehab
9954f38fcaSMauro Carvalho ChehabA video capture device may support the :ref:`read() function <func-read>`
10054f38fcaSMauro Carvalho Chehaband/or streaming (:ref:`memory mapping <func-mmap>` or
10154f38fcaSMauro Carvalho Chehab:ref:`user pointer <userp>`) I/O. See :ref:`io` for details.
102