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