blob: fd6357c995aa66b98468cd0493d8f005bd80dbd6 [file] [log] [blame]
Markus Heiser5377d912016-06-30 15:18:56 +02001.. -*- coding: utf-8; mode: rst -*-
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. Note the same device files are used for video output devices.
19
20
21Querying Capabilities
22=====================
23
24Devices supporting the video capture interface set the
25``V4L2_CAP_VIDEO_CAPTURE`` or ``V4L2_CAP_VIDEO_CAPTURE_MPLANE`` flag in
26the ``capabilities`` field of struct
27:ref:`v4l2_capability <v4l2-capability>` returned by the
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030028:ref:`VIDIOC_QUERYCAP <VIDIOC_QUERYCAP>` ioctl. As secondary device
Markus Heiser5377d912016-06-30 15:18:56 +020029functions they may also support the :ref:`video overlay <overlay>`
30(``V4L2_CAP_VIDEO_OVERLAY``) and the :ref:`raw VBI capture <raw-vbi>`
31(``V4L2_CAP_VBI_CAPTURE``) interface. At least one of the read/write or
32streaming I/O methods must be supported. Tuners and audio inputs are
33optional.
34
35
36Supplemental Functions
37======================
38
39Video capture devices shall support :ref:`audio input <audio>`,
40:ref:`tuner <tuner>`, :ref:`controls <control>`,
41:ref:`cropping and scaling <crop>` and
42:ref:`streaming parameter <streaming-par>` ioctls as needed. The
43:ref:`video input <video>` and :ref:`video standard <standard>`
44ioctls must be supported by all video capture devices.
45
46
47Image Format Negotiation
48========================
49
50The result of a capture operation is determined by cropping and image
51format parameters. The former select an area of the video picture to
52capture, the latter how images are stored in memory, i. e. in RGB or YUV
53format, the number of bits per pixel or width and height. Together they
54also define how images are scaled in the process.
55
56As usual these parameters are *not* reset at :ref:`open() <func-open>`
57time to permit Unix tool chains, programming a device and then reading
58from it as if it was a plain file. Well written V4L2 applications ensure
59they really get what they want, including cropping and scaling.
60
61Cropping initialization at minimum requires to reset the parameters to
62defaults. An example is given in :ref:`crop`.
63
64To query the current image format applications set the ``type`` field of
65a struct :ref:`v4l2_format <v4l2-format>` to
66``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or
67``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and call the
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030068:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this
Markus Heiser5377d912016-06-30 15:18:56 +020069structure. Drivers fill the struct
70:ref:`v4l2_pix_format <v4l2-pix-format>` ``pix`` or the struct
71:ref:`v4l2_pix_format_mplane <v4l2-pix-format-mplane>` ``pix_mp``
72member of the ``fmt`` union.
73
74To request different parameters applications set the ``type`` field of a
75struct :ref:`v4l2_format <v4l2-format>` as above and initialize all
76fields of the struct :ref:`v4l2_pix_format <v4l2-pix-format>`
77``vbi`` member of the ``fmt`` union, or better just modify the results
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030078of ``VIDIOC_G_FMT``, and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
Markus Heiser5377d912016-06-30 15:18:56 +020079ioctl with a pointer to this structure. Drivers may adjust the
80parameters and finally return the actual parameters as ``VIDIOC_G_FMT``
81does.
82
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030083Like ``VIDIOC_S_FMT`` the :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl
Markus Heiser5377d912016-06-30 15:18:56 +020084can be used to learn about hardware limitations without disabling I/O or
85possibly time consuming hardware preparations.
86
87The contents of struct :ref:`v4l2_pix_format <v4l2-pix-format>` and
88struct :ref:`v4l2_pix_format_mplane <v4l2-pix-format-mplane>` are
89discussed in :ref:`pixfmt`. See also the specification of the
90``VIDIOC_G_FMT``, ``VIDIOC_S_FMT`` and ``VIDIOC_TRY_FMT`` ioctls for
91details. Video capture devices must implement both the ``VIDIOC_G_FMT``
92and ``VIDIOC_S_FMT`` ioctl, even if ``VIDIOC_S_FMT`` ignores all
93requests and always returns default parameters as ``VIDIOC_G_FMT`` does.
94``VIDIOC_TRY_FMT`` is optional.
95
96
97Reading Images
98==============
99
100A video capture device may support the :ref:`read() function <rw>`
101and/or streaming (:ref:`memory mapping <mmap>` or
102:ref:`user pointer <userp>`) I/O. See :ref:`io` for details.
103
104
105.. ------------------------------------------------------------------------------
106.. This file was automatically converted from DocBook-XML with the dbxml
107.. library (https://github.com/return42/sphkerneldoc). The origin XML comes
108.. from the linux kernel, refer to:
109..
110.. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook
111.. ------------------------------------------------------------------------------