blob: 8415268d439ccc6eb12fccd74956d32805bb9933 [file] [log] [blame]
Mauro Carvalho Chehab82559ac2018-08-30 10:15:26 -04001.. 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/media/uapi/fdl-appendix.rst.
7..
8.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9
Markus Heiser5377d912016-06-30 15:18:56 +020010.. _field-order:
11
12***********
13Field Order
14***********
15
16We have to distinguish between progressive and interlaced video.
17Progressive video transmits all lines of a video image sequentially.
18Interlaced video divides an image into two fields, containing only the
19odd and even lines of the image, respectively. Alternating the so called
20odd and even field are transmitted, and due to a small delay between
21fields a cathode ray TV displays the lines interleaved, yielding the
22original frame. This curious technique was invented because at refresh
23rates similar to film the image would fade out too quickly. Transmitting
24fields reduces the flicker without the necessity of doubling the frame
25rate and with it the bandwidth required for each channel.
26
27It is important to understand a video camera does not expose one frame
28at a time, merely transmitting the frames separated into fields. The
29fields are in fact captured at two different instances in time. An
30object on screen may well move between one field and the next. For
31applications analysing motion it is of paramount importance to recognize
32which field of a frame is older, the *temporal order*.
33
34When the driver provides or accepts images field by field rather than
35interleaved, it is also important applications understand how the fields
36combine to frames. We distinguish between top (aka odd) and bottom (aka
37even) fields, the *spatial order*: The first line of the top field is
38the first line of an interlaced frame, the first line of the bottom
39field is the second line of that frame.
40
41However because fields were captured one after the other, arguing
42whether a frame commences with the top or bottom field is pointless. Any
43two successive top and bottom, or bottom and top fields yield a valid
44frame. Only when the source was progressive to begin with, e. g. when
45transferring film to video, two fields may come from the same frame,
46creating a natural order.
47
48Counter to intuition the top field is not necessarily the older field.
49Whether the older field contains the top or bottom lines is a convention
50determined by the video standard. Hence the distinction between temporal
51and spatial order of fields. The diagrams below should make this
52clearer.
53
54All video capture and output devices must report the current field
55order. Some drivers may permit the selection of a different order, to
56this end applications initialize the ``field`` field of struct
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030057:c:type:`v4l2_pix_format` before calling the
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -030058:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. If this is not desired it
Markus Heiser5377d912016-06-30 15:18:56 +020059should have the value ``V4L2_FIELD_ANY`` (0).
60
61
Mauro Carvalho Chehab6fa26352016-07-04 17:14:00 -030062enum v4l2_field
63===============
64
Mauro Carvalho Chehab56683d72016-09-08 06:41:26 -030065.. c:type:: v4l2_field
66
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -030067.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
68
Mauro Carvalho Chehab6fa26352016-07-04 17:14:00 -030069.. flat-table::
Markus Heiser5377d912016-06-30 15:18:56 +020070 :header-rows: 0
71 :stub-columns: 0
72 :widths: 3 1 4
73
Laurent Pinchartc2b66ca2016-09-05 08:44:34 -030074 * - ``V4L2_FIELD_ANY``
75 - 0
76 - Applications request this field order when any one of the
77 ``V4L2_FIELD_NONE``, ``V4L2_FIELD_TOP``, ``V4L2_FIELD_BOTTOM``, or
78 ``V4L2_FIELD_INTERLACED`` formats is acceptable. Drivers choose
79 depending on hardware capabilities or e. g. the requested image
80 size, and return the actual field order. Drivers must never return
81 ``V4L2_FIELD_ANY``. If multiple field orders are possible the
82 driver must choose one of the possible field orders during
83 :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or
84 :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`. struct
85 :c:type:`v4l2_buffer` ``field`` can never be
86 ``V4L2_FIELD_ANY``.
87 * - ``V4L2_FIELD_NONE``
88 - 1
89 - Images are in progressive format, not interlaced. The driver may
90 also indicate this order when it cannot distinguish between
91 ``V4L2_FIELD_TOP`` and ``V4L2_FIELD_BOTTOM``.
92 * - ``V4L2_FIELD_TOP``
93 - 2
94 - Images consist of the top (aka odd) field only.
95 * - ``V4L2_FIELD_BOTTOM``
96 - 3
97 - Images consist of the bottom (aka even) field only. Applications
98 may wish to prevent a device from capturing interlaced images
99 because they will have "comb" or "feathering" artefacts around
100 moving objects.
101 * - ``V4L2_FIELD_INTERLACED``
102 - 4
103 - Images contain both fields, interleaved line by line. The temporal
104 order of the fields (whether the top or bottom field is first
105 transmitted) depends on the current video standard. M/NTSC
106 transmits the bottom field first, all other standards the top
107 field first.
108 * - ``V4L2_FIELD_SEQ_TB``
109 - 5
110 - Images contain both fields, the top field lines are stored first
111 in memory, immediately followed by the bottom field lines. Fields
112 are always stored in temporal order, the older one first in
113 memory. Image sizes refer to the frame, not fields.
114 * - ``V4L2_FIELD_SEQ_BT``
115 - 6
116 - Images contain both fields, the bottom field lines are stored
117 first in memory, immediately followed by the top field lines.
118 Fields are always stored in temporal order, the older one first in
119 memory. Image sizes refer to the frame, not fields.
120 * - ``V4L2_FIELD_ALTERNATE``
121 - 7
122 - The two fields of a frame are passed in separate buffers, in
123 temporal order, i. e. the older one first. To indicate the field
124 parity (whether the current field is a top or bottom field) the
125 driver or application, depending on data direction, must set
126 struct :c:type:`v4l2_buffer` ``field`` to
127 ``V4L2_FIELD_TOP`` or ``V4L2_FIELD_BOTTOM``. Any two successive
128 fields pair to build a frame. If fields are successive, without
129 any dropped fields between them (fields can drop individually),
130 can be determined from the struct
131 :c:type:`v4l2_buffer` ``sequence`` field. This
132 format cannot be selected when using the read/write I/O method
133 since there is no way to communicate if a field was a top or
134 bottom field.
135 * - ``V4L2_FIELD_INTERLACED_TB``
136 - 8
137 - Images contain both fields, interleaved line by line, top field
138 first. The top field is transmitted first.
139 * - ``V4L2_FIELD_INTERLACED_BT``
140 - 9
141 - Images contain both fields, interleaved line by line, top field
142 first. The bottom field is transmitted first.
Markus Heiser5377d912016-06-30 15:18:56 +0200143
144
145
146.. _fieldseq-tb:
147
Mauro Carvalho Chehab6fa26352016-07-04 17:14:00 -0300148Field Order, Top Field First Transmitted
149========================================
150
Mauro Carvalho Chehab8fa1bb52017-03-09 15:14:52 -0300151.. kernel-figure:: fieldseq_tb.svg
152 :alt: fieldseq_tb.svg
Markus Heiser5377d912016-06-30 15:18:56 +0200153 :align: center
154
Mauro Carvalho Chehab8fa1bb52017-03-09 15:14:52 -0300155 Field Order, Top Field First Transmitted
156
Markus Heiser5377d912016-06-30 15:18:56 +0200157
158.. _fieldseq-bt:
159
Mauro Carvalho Chehab6fa26352016-07-04 17:14:00 -0300160Field Order, Bottom Field First Transmitted
161===========================================
162
Mauro Carvalho Chehab8fa1bb52017-03-09 15:14:52 -0300163.. kernel-figure:: fieldseq_bt.svg
164 :alt: fieldseq_bt.svg
Markus Heiser5377d912016-06-30 15:18:56 +0200165 :align: center
166
Mauro Carvalho Chehab8fa1bb52017-03-09 15:14:52 -0300167 Field Order, Bottom Field First Transmitted