Chapter 2. Image Formats

Table of Contents

Single-planar format structure
Multi-planar format structures
Standard Image Formats
Colorspaces
Defining Colorspaces in V4L2
Detailed Colorspace Descriptions
Colorspace SMPTE 170M (V4L2_COLORSPACE_SMPTE170M)
Colorspace Rec. 709 (V4L2_COLORSPACE_REC709)
Colorspace sRGB (V4L2_COLORSPACE_SRGB)
Colorspace Adobe RGB (V4L2_COLORSPACE_ADOBERGB)
Colorspace BT.2020 (V4L2_COLORSPACE_BT2020)
Colorspace SMPTE 240M (V4L2_COLORSPACE_SMPTE240M)
Colorspace NTSC 1953 (V4L2_COLORSPACE_470_SYSTEM_M)
Colorspace EBU Tech. 3213 (V4L2_COLORSPACE_470_SYSTEM_BG)
Colorspace JPEG (V4L2_COLORSPACE_JPEG)
Indexed Format
RGB Formats
Packed RGB formats — Packed RGB formats
V4L2_PIX_FMT_SBGGR8 ('BA81') — Bayer RGB format
V4L2_PIX_FMT_SGBRG8 ('GBRG') — Bayer RGB format
V4L2_PIX_FMT_SGRBG8 ('GRBG') — Bayer RGB format
V4L2_PIX_FMT_SRGGB8 ('RGGB') — Bayer RGB format
V4L2_PIX_FMT_SBGGR16 ('BYR2') — Bayer RGB format
V4L2_PIX_FMT_SRGGB10 ('RG10'), V4L2_PIX_FMT_SGRBG10 ('BA10'), V4L2_PIX_FMT_SGBRG10 ('GB10'), V4L2_PIX_FMT_SBGGR10 ('BG10'), — 10-bit Bayer formats expanded to 16 bits
V4L2_PIX_FMT_SRGGB10P ('pRAA'), V4L2_PIX_FMT_SGRBG10P ('pgAA'), V4L2_PIX_FMT_SGBRG10P ('pGAA'), V4L2_PIX_FMT_SBGGR10P ('pBAA'), — 10-bit packed Bayer formats
V4L2_PIX_FMT_SBGGR10ALAW8 ('aBA8'), V4L2_PIX_FMT_SGBRG10ALAW8 ('aGA8'), V4L2_PIX_FMT_SGRBG10ALAW8 ('agA8'), V4L2_PIX_FMT_SRGGB10ALAW8 ('aRA8'), — 10-bit Bayer formats compressed to 8 bits
V4L2_PIX_FMT_SBGGR10DPCM8 ('bBA8'), V4L2_PIX_FMT_SGBRG10DPCM8 ('bGA8'), V4L2_PIX_FMT_SGRBG10DPCM8 ('BD10'), V4L2_PIX_FMT_SRGGB10DPCM8 ('bRA8'), — 10-bit Bayer formats compressed to 8 bits
V4L2_PIX_FMT_SRGGB12 ('RG12'), V4L2_PIX_FMT_SGRBG12 ('BA12'), V4L2_PIX_FMT_SGBRG12 ('GB12'), V4L2_PIX_FMT_SBGGR12 ('BG12'), — 12-bit Bayer formats expanded to 16 bits
YUV Formats
Packed YUV formats — Packed YUV formats
V4L2_PIX_FMT_GREY ('GREY') — Grey-scale image
V4L2_PIX_FMT_Y10 ('Y10 ') — Grey-scale image
V4L2_PIX_FMT_Y12 ('Y12 ') — Grey-scale image
V4L2_PIX_FMT_Y10BPACK ('Y10B') — Grey-scale image as a bit-packed array
V4L2_PIX_FMT_Y16 ('Y16 ') — Grey-scale image
V4L2_PIX_FMT_UV8 ('UV8') — UV plane interleaved
V4L2_PIX_FMT_YUYV ('YUYV') — Packed format with ½ horizontal chroma resolution, also known as YUV 4:2:2
V4L2_PIX_FMT_UYVY ('UYVY') — Variation of V4L2_PIX_FMT_YUYV with different order of samples in memory
V4L2_PIX_FMT_YVYU ('YVYU') — Variation of V4L2_PIX_FMT_YUYV with different order of samples in memory
V4L2_PIX_FMT_VYUY ('VYUY') — Variation of V4L2_PIX_FMT_YUYV with different order of samples in memory
V4L2_PIX_FMT_Y41P ('Y41P') — Format with ¼ horizontal chroma resolution, also known as YUV 4:1:1
V4L2_PIX_FMT_YVU420 ('YV12'), V4L2_PIX_FMT_YUV420 ('YU12') — Planar formats with ½ horizontal and vertical chroma resolution, also known as YUV 4:2:0
V4L2_PIX_FMT_YUV420M ('YM12') — Variation of V4L2_PIX_FMT_YUV420 with planes non contiguous in memory.
V4L2_PIX_FMT_YVU420M ('YM21') — Variation of V4L2_PIX_FMT_YVU420 with planes non contiguous in memory.
V4L2_PIX_FMT_YVU410 ('YVU9'), V4L2_PIX_FMT_YUV410 ('YUV9') — Planar formats with ¼ horizontal and vertical chroma resolution, also known as YUV 4:1:0
V4L2_PIX_FMT_YUV422P ('422P') — Format with ½ horizontal chroma resolution, also known as YUV 4:2:2. Planar layout as opposed to V4L2_PIX_FMT_YUYV
V4L2_PIX_FMT_YUV411P ('411P') — Format with ¼ horizontal chroma resolution, also known as YUV 4:1:1. Planar layout as opposed to V4L2_PIX_FMT_Y41P
V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21') — Formats with ½ horizontal and vertical chroma resolution, also known as YUV 4:2:0. One luminance and one chrominance plane with alternating chroma samples as opposed to V4L2_PIX_FMT_YVU420
V4L2_PIX_FMT_NV12M ('NM12'), V4L2_PIX_FMT_NV21M ('NM21'), V4L2_PIX_FMT_NV12MT_16X16 — Variation of V4L2_PIX_FMT_NV12 and V4L2_PIX_FMT_NV21 with planes non contiguous in memory.
V4L2_PIX_FMT_NV12MT ('TM12') — Formats with ½ horizontal and vertical chroma resolution. This format has two planes - one for luminance and one for chrominance. Chroma samples are interleaved. The difference to V4L2_PIX_FMT_NV12 is the memory layout. Pixels are grouped in macroblocks of 64x32 size. The order of macroblocks in memory is also not standard.
V4L2_PIX_FMT_NV16 ('NV16'), V4L2_PIX_FMT_NV61 ('NV61') — Formats with ½ horizontal chroma resolution, also known as YUV 4:2:2. One luminance and one chrominance plane with alternating chroma samples as opposed to V4L2_PIX_FMT_YVU420
V4L2_PIX_FMT_NV16M ('NM16'), V4L2_PIX_FMT_NV61M ('NM61') — Variation of V4L2_PIX_FMT_NV16 and V4L2_PIX_FMT_NV61 with planes non contiguous in memory.
V4L2_PIX_FMT_NV24 ('NV24'), V4L2_PIX_FMT_NV42 ('NV42') — Formats with full horizontal and vertical chroma resolutions, also known as YUV 4:4:4. One luminance and one chrominance plane with alternating chroma samples as opposed to V4L2_PIX_FMT_YVU420
V4L2_PIX_FMT_M420 ('M420') — Format with ½ horizontal and vertical chroma resolution, also known as YUV 4:2:0. Hybrid plane line-interleaved layout.
Compressed Formats
SDR Formats
V4L2_SDR_FMT_CU8 ('CU08') — Complex unsigned 8-bit IQ sample
V4L2_SDR_FMT_CU16LE ('CU16') — Complex unsigned 16-bit little endian IQ sample
V4L2_SDR_FMT_CS8 ('CS08') — Complex signed 8-bit IQ sample
V4L2_SDR_FMT_CS14LE ('CS14') — Complex signed 14-bit little endian IQ sample
V4L2_SDR_FMT_RU12LE ('RU12') — Real unsigned 12-bit little endian sample
Reserved Format Identifiers

The V4L2 API was primarily designed for devices exchanging image data with applications. The v4l2_pix_format and v4l2_pix_format_mplane structures define the format and layout of an image in memory. The former is used with the single-planar API, while the latter is used with the multi-planar version (see the section called “Single- and multi-planar APIs”). Image formats are negotiated with the VIDIOC_S_FMT ioctl. (The explanations here focus on video capturing and output, for overlay frame buffer formats see also VIDIOC_G_FBUF.)

Single-planar format structure

Table 2.1. struct v4l2_pix_format

__u32widthImage width in pixels.
__u32heightImage height in pixels. If field is one of V4L2_FIELD_TOP, V4L2_FIELD_BOTTOM or V4L2_FIELD_ALTERNATE then height refers to the number of lines in the field, otherwise it refers to the number of lines in the frame (which is twice the field height for interlaced formats).
Applications set these fields to request an image size, drivers return the closest possible values. In case of planar formats the width and height applies to the largest plane. To avoid ambiguities drivers must return values rounded up to a multiple of the scale factor of any smaller planes. For example when the image format is YUV 4:2:0, width and height must be multiples of two.
__u32pixelformatThe pixel format or type of compression, set by the application. This is a little endian four character code. V4L2 defines standard RGB formats in Table 2.16, “Packed RGB Image Formats”, YUV formats in the section called “YUV Formats”, and reserved codes in Table 2.20, “Reserved Image Formats”
enum v4l2_fieldfieldVideo images are typically interlaced. Applications can request to capture or output only the top or bottom field, or both fields interlaced or sequentially stored in one buffer or alternating in separate buffers. Drivers return the actual field order selected. For more details on fields see the section called “Field Order”.
__u32bytesperlineDistance in bytes between the leftmost pixels in two adjacent lines.

Both applications and drivers can set this field to request padding bytes at the end of each line. Drivers however may ignore the value requested by the application, returning width times bytes per pixel or a larger value required by the hardware. That implies applications can just set this field to zero to get a reasonable default.

Video hardware may access padding bytes, therefore they must reside in accessible memory. Consider cases where padding bytes after the last line of an image cross a system page boundary. Input devices may write padding bytes, the value is undefined. Output devices ignore the contents of padding bytes.

When the image format is planar the bytesperline value applies to the first plane and is divided by the same factor as the width field for the other planes. For example the Cb and Cr planes of a YUV 4:2:0 image have half as many padding bytes following each line as the Y plane. To avoid ambiguities drivers must return a bytesperline value rounded up to a multiple of the scale factor.

For compressed formats the bytesperline value makes no sense. Applications and drivers must set this to 0 in that case.

__u32sizeimageSize in bytes of the buffer to hold a complete image, set by the driver. Usually this is bytesperline times height. When the image consists of variable length compressed data this is the maximum number of bytes required to hold an image.
enum v4l2_colorspacecolorspaceThis information supplements the pixelformat and must be set by the driver for capture streams and by the application for output streams, see the section called “Colorspaces”.
__u32priv

This field indicates whether the remaining fields of the v4l2_pix_format structure, also called the extended fields, are valid. When set to V4L2_PIX_FMT_PRIV_MAGIC, it indicates that the extended fields have been correctly initialized. When set to any other value it indicates that the extended fields contain undefined values.

Applications that wish to use the pixel format extended fields must first ensure that the feature is supported by querying the device for the V4L2_CAP_EXT_PIX_FORMAT capability. If the capability isn't set the pixel format extended fields are not supported and using the extended fields will lead to undefined results.

To use the extended fields, applications must set the priv field to V4L2_PIX_FMT_PRIV_MAGIC, initialize all the extended fields and zero the unused bytes of the v4l2_format raw_data field.

When the priv field isn't set to V4L2_PIX_FMT_PRIV_MAGIC drivers must act as if all the extended fields were set to zero. On return drivers must set the priv field to V4L2_PIX_FMT_PRIV_MAGIC and all the extended fields to applicable values.

__u32flagsFlags set by the application or driver, see Table 2.21, “Format Flags”.
enum v4l2_ycbcr_encodingycbcr_encThis information supplements the colorspace and must be set by the driver for capture streams and by the application for output streams, see the section called “Colorspaces”.
enum v4l2_quantizationquantizationThis information supplements the colorspace and must be set by the driver for capture streams and by the application for output streams, see the section called “Colorspaces”.