xref: /linux/Documentation/userspace-api/media/v4l/dev-capture.rst (revision fd5c32d80884268a381ed0e67cccef0b3d37750b)
1.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2
3.. _capture:
4
5***********************
6Video Capture Interface
7***********************
8
9Video capture devices sample an analog video signal and store the
10digitized images in memory. Today nearly all devices can capture at full
1125 or 30 frames/second. With this interface applications can control the
12capture process and move images from the driver into user space.
13
14Conventionally V4L2 video capture devices are accessed through character
15device special files named ``/dev/video`` and ``/dev/video0`` to
16``/dev/video63`` with major number 81 and minor numbers 0 to 63.
17``/dev/video`` is typically a symbolic link to the preferred video
18device.
19
20.. note:: The same device file names are used for video output devices.
21
22
23Querying Capabilities
24=====================
25
26Devices supporting the video capture interface set the
27``V4L2_CAP_VIDEO_CAPTURE`` or ``V4L2_CAP_VIDEO_CAPTURE_MPLANE`` flag in
28the ``capabilities`` field of struct
29:c:type:`v4l2_capability` returned by the
30:ref:`VIDIOC_QUERYCAP` ioctl. As secondary device
31functions 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 or
34streaming I/O methods must be supported. Tuners and audio inputs are
35optional.
36
37
38Supplemental Functions
39======================
40
41Video capture devices shall support :ref:`audio input <audio>`,
42:ref:`tuner`, :ref:`controls <control>`,
43:ref:`cropping and scaling <crop>` and
44:ref:`streaming parameter <streaming-par>` ioctls as needed. The
45:ref:`video input <video>` ioctls must be supported by all video
46capture devices.
47
48
49Image Format Negotiation
50========================
51
52The result of a capture operation is determined by cropping and image
53format parameters. The former select an area of the video picture to
54capture, the latter how images are stored in memory, i. e. in RGB or YUV
55format, the number of bits per pixel or width and height. Together they
56also define how images are scaled in the process.
57
58As usual these parameters are *not* reset at :ref:`open() <func-open>`
59time to permit Unix tool chains, programming a device and then reading
60from it as if it was a plain file. Well written V4L2 applications ensure
61they really get what they want, including cropping and scaling.
62
63Cropping initialization at minimum requires to reset the parameters to
64defaults. An example is given in :ref:`crop`.
65
66To query the current image format applications set the ``type`` field of
67a struct :c:type:`v4l2_format` to
68``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or
69``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and call the
70:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this
71structure. Drivers fill the struct
72:c:type:`v4l2_pix_format` ``pix`` or the struct
73:c:type:`v4l2_pix_format_mplane` ``pix_mp``
74member of the ``fmt`` union.
75
76To request different parameters applications set the ``type`` field of a
77struct :c:type:`v4l2_format` as above and initialize all
78fields of the struct :c:type:`v4l2_pix_format`
79``vbi`` member of the ``fmt`` union, or better just modify the results
80of :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
81ioctl with a pointer to this structure. Drivers may adjust the
82parameters and finally return the actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`
83does.
84
85Like :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` the :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl
86can be used to learn about hardware limitations without disabling I/O or
87possibly time consuming hardware preparations.
88
89The contents of struct :c:type:`v4l2_pix_format` and
90struct :c:type:`v4l2_pix_format_mplane` are
91discussed in :ref:`pixfmt`. See also the specification of the
92:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`, :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctls for
93details. Video capture devices must implement both the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`
94and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, even if :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ignores all
95requests and always returns default parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does.
96:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` is optional.
97
98
99Reading Images
100==============
101
102A video capture device may support the :ref:`read() function <func-read>`
103and/or streaming (:ref:`memory mapping <func-mmap>` or
104:ref:`user pointer <userp>`) I/O. See :ref:`io` for details.
105