# Input/Output

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The V4L2 API defines several different methods to read from or write to a device. All drivers exchanging data with applications must support at least one of them.

<a id="rst-input-output"></a>
<a id="rst-io"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The V4L2 API defines several different methods to read from or write to a device. All drivers exchanging data with applications must support at least one of them.

The classic I/O method using the `read()` and `write()` function is automatically selected after opening a V4L2 device. When the driver does not support this method attempts to read or write will fail at any time.

Other methods must be negotiated. To select the streaming I/O method with memory mapped or user buffers applications call the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl.

Video overlay can be considered another I/O method, although the application does not directly receive the image data. It is selected by initiating video overlay with the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. For more information see [Video Overlay Interface](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

Generally exactly one I/O method, including overlay, is associated with each file descriptor. The only exceptions are applications not exchanging data with a driver ("panel applications", see [Opening and Closing Devices](</kernel/userspace/userspace-api/media-v4l/open.md#rst-open>)) and drivers permitting simultaneous video capturing and overlay using the same file descriptor, for compatibility with V4L and earlier versions of V4L2.

[VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) would permit this to some degree, but for simplicity drivers need not support switching the I/O method (after first switching away from read/write) other than by closing and reopening the device.

The following sections describe the various I/O methods in more detail.

- [Read/Write](</kernel/userspace/userspace-api/media-v4l/rw.md>)
- [Streaming I/O (Memory Mapping)](</kernel/userspace/userspace-api/media-v4l/mmap.md>)
- [Streaming I/O (User Pointers)](</kernel/userspace/userspace-api/media-v4l/userp.md>)
- [Streaming I/O (DMA buffer importing)](</kernel/userspace/userspace-api/media-v4l/dmabuf.md>)
- [buffer](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/buffer.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Field Order](</kernel/userspace/userspace-api/media-v4l/field-order.md>)
