← Documents Documentation/userspace-api/media/v4l/libv4l-introduction.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API / Media / V4L

libv4l 소개

libv4lconvert, libv4l1, libv4l2와 파일 연산 wrapper 및 형식 에뮬레이션을 설명합니다.

Source pathDocumentation/userspace-api/media/v4l/libv4l-introduction.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

libv4l-introduction.rst:1-180

libv4l은 장치별 픽셀 형식과 품질 차이를 얇은 사용자 공간 계층에서 흡수하고, 현대 응용 프로그램에는 libv4l2를 제공합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: V4L
3
4 .. _libv4l-introduction:
5
6 ************
7 Introduction
8 ************
9
10 libv4l is a collection of libraries which adds a thin abstraction layer
11 on top of video4linux2 devices. The purpose of this (thin) layer is to
12 make it easy for application writers to support a wide variety of
13 devices without having to write separate code for different devices in
14 the same class.
15
16 An example of using libv4l is provided by
17 :ref:`v4l2grab <v4l2grab-example>`.
18
19 libv4l consists of 3 different libraries:
20
21 libv4lconvert
22 =============
23
24 libv4lconvert is a library that converts several different pixelformats
25 found in V4L2 drivers into a few common RGB and YUY formats.
26
27 It currently accepts the following V4L2 driver formats:
28 :ref:`V4L2_PIX_FMT_BGR24 <V4L2-PIX-FMT-BGR24>`,
29 :ref:`V4L2_PIX_FMT_NV12_16L16 <V4L2-PIX-FMT-NV12-16L16>`,
30 :ref:`V4L2_PIX_FMT_JPEG <V4L2-PIX-FMT-JPEG>`,
31 :ref:`V4L2_PIX_FMT_MJPEG <V4L2-PIX-FMT-MJPEG>`,
32 :ref:`V4L2_PIX_FMT_MR97310A <V4L2-PIX-FMT-MR97310A>`,
33 :ref:`V4L2_PIX_FMT_OV511 <V4L2-PIX-FMT-OV511>`,
34 :ref:`V4L2_PIX_FMT_OV518 <V4L2-PIX-FMT-OV518>`,
35 :ref:`V4L2_PIX_FMT_PAC207 <V4L2-PIX-FMT-PAC207>`,
36 :ref:`V4L2_PIX_FMT_PJPG <V4L2-PIX-FMT-PJPG>`,
37 :ref:`V4L2_PIX_FMT_RGB24 <V4L2-PIX-FMT-RGB24>`,
38 :ref:`V4L2_PIX_FMT_SBGGR8 <V4L2-PIX-FMT-SBGGR8>`,
39 :ref:`V4L2_PIX_FMT_SGBRG8 <V4L2-PIX-FMT-SGBRG8>`,
40 :ref:`V4L2_PIX_FMT_SGRBG8 <V4L2-PIX-FMT-SGRBG8>`,
41 :ref:`V4L2_PIX_FMT_SN9C10X <V4L2-PIX-FMT-SN9C10X>`,
42 :ref:`V4L2_PIX_FMT_SN9C20X_I420 <V4L2-PIX-FMT-SN9C20X-I420>`,
43 :ref:`V4L2_PIX_FMT_SPCA501 <V4L2-PIX-FMT-SPCA501>`,
44 :ref:`V4L2_PIX_FMT_SPCA505 <V4L2-PIX-FMT-SPCA505>`,
45 :ref:`V4L2_PIX_FMT_SPCA508 <V4L2-PIX-FMT-SPCA508>`,
46 :ref:`V4L2_PIX_FMT_SPCA561 <V4L2-PIX-FMT-SPCA561>`,
47 :ref:`V4L2_PIX_FMT_SQ905C <V4L2-PIX-FMT-SQ905C>`,
48 :ref:`V4L2_PIX_FMT_SRGGB8 <V4L2-PIX-FMT-SRGGB8>`,
49 :ref:`V4L2_PIX_FMT_UYVY <V4L2-PIX-FMT-UYVY>`,
50 :ref:`V4L2_PIX_FMT_YUV420 <V4L2-PIX-FMT-YUV420>`,
51 :ref:`V4L2_PIX_FMT_YUYV <V4L2-PIX-FMT-YUYV>`,
52 :ref:`V4L2_PIX_FMT_YVU420 <V4L2-PIX-FMT-YVU420>`, and
53 :ref:`V4L2_PIX_FMT_YVYU <V4L2-PIX-FMT-YVYU>`.
54
55 Later on libv4lconvert was expanded to also be able to do various video
56 processing functions to improve webcam video quality. The video
57 processing is split in to 2 parts: libv4lconvert/control and
58 libv4lconvert/processing.
59
60 The control part is used to offer video controls which can be used to
61 control the video processing functions made available by
62 libv4lconvert/processing. These controls are stored application wide
63 (until reboot) by using a persistent shared memory object.
64
65 libv4lconvert/processing offers the actual video processing
66 functionality.
67
68 libv4l1
69 =======
70
71 This library offers functions that can be used to quickly make v4l1
72 applications work with v4l2 devices. These functions work exactly like
73 the normal open/close/etc, except that libv4l1 does full emulation of
74 the v4l1 api on top of v4l2 drivers, in case of v4l1 drivers it will
75 just pass calls through.
76
77 Since those functions are emulations of the old V4L1 API, it shouldn't
78 be used for new applications.
79
80 libv4l2
81 =======
82
83 This library should be used for all modern V4L2 applications.
84
85 It provides handles to call V4L2 open/ioctl/close/poll methods. Instead
86 of just providing the raw output of the device, it enhances the calls in
87 the sense that it will use libv4lconvert to provide more video formats
88 and to enhance the image quality.
89
90 In most cases, libv4l2 just passes the calls directly through to the
91 v4l2 driver, intercepting the calls to
92 :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`,
93 :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`,
94 :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`,
95 :ref:`VIDIOC_ENUM_FRAMESIZES <VIDIOC_ENUM_FRAMESIZES>` and
96 :ref:`VIDIOC_ENUM_FRAMEINTERVALS <VIDIOC_ENUM_FRAMEINTERVALS>` in
97 order to emulate the formats
98 :ref:`V4L2_PIX_FMT_BGR24 <V4L2-PIX-FMT-BGR24>`,
99 :ref:`V4L2_PIX_FMT_RGB24 <V4L2-PIX-FMT-RGB24>`,
100 :ref:`V4L2_PIX_FMT_YUV420 <V4L2-PIX-FMT-YUV420>`, and
101 :ref:`V4L2_PIX_FMT_YVU420 <V4L2-PIX-FMT-YVU420>`, if they aren't
102 available in the driver. :ref:`VIDIOC_ENUM_FMT <VIDIOC_ENUM_FMT>`
103 keeps enumerating the hardware supported formats, plus the emulated
104 formats offered by libv4l at the end.
105
106 .. _libv4l-ops:
107
108 Libv4l device control functions
109 -------------------------------
110
111 The common file operation methods are provided by libv4l.
112
113 Those functions operate just like the gcc function ``dup()`` and
114 V4L2 functions
115 :c:func:`open()`, :c:func:`close()`,
116 :c:func:`ioctl()`, :c:func:`read()`,
117 :c:func:`mmap()` and :c:func:`munmap()`:
118
119 .. c:function:: int v4l2_open(const char *file, int oflag, ...)
120
121 operates like the :c:func:`open()` function.
122
123 .. c:function:: int v4l2_close(int fd)
124
125 operates like the :c:func:`close()` function.
126
127 .. c:function:: int v4l2_dup(int fd)
128
129 operates like the libc ``dup()`` function, duplicating a file handler.
130
131 .. c:function:: int v4l2_ioctl (int fd, unsigned long int request, ...)
132
133 operates like the :c:func:`ioctl()` function.
134
135 .. c:function:: int v4l2_read (int fd, void* buffer, size_t n)
136
137 operates like the :c:func:`read()` function.
138
139 .. c:function:: void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd, int64_t offset);
140
141 operates like the :c:func:`mmap()` function.
142
143 .. c:function:: int v4l2_munmap(void *_start, size_t length);
144
145 operates like the :c:func:`munmap()` function.
146
147 Those functions provide additional control:
148
149 .. c:function:: int v4l2_fd_open(int fd, int v4l2_flags)
150
151 opens an already opened fd for further use through v4l2lib and possibly
152 modify libv4l2's default behavior through the ``v4l2_flags`` argument.
153 Currently, ``v4l2_flags`` can be ``V4L2_DISABLE_CONVERSION``, to disable
154 format conversion.
155
156 .. c:function:: int v4l2_set_control(int fd, int cid, int value)
157
158 This function takes a value of 0 - 65535, and then scales that range to the
159 actual range of the given v4l control id, and then if the cid exists and is
160 not locked sets the cid to the scaled value.
161
162 .. c:function:: int v4l2_get_control(int fd, int cid)
163
164 This function returns a value of 0 - 65535, scaled to from the actual range
165 of the given v4l control id. when the cid does not exist, could not be
166 accessed for some reason, or some error occurred 0 is returned.
167
168 v4l1compat.so wrapper library
169 =============================
170
171 This library intercepts calls to
172 :c:func:`open()`, :c:func:`close()`,
173 :c:func:`ioctl()`, :c:func:`mmap()` and
174 :c:func:`munmap()`
175 operations and redirects them to the libv4l counterparts, by using
176 ``LD_PRELOAD=/usr/lib/v4l1compat.so``. It also emulates V4L1 calls via V4L2
177 API.
178
179 It allows usage of binary legacy applications that still don't use
180 libv4l.
181

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

얇은 V4L2 추상화 계층

1-20

libv4l은 Video4Linux2 장치 위에 얇은 추상화 계층을 제공하는 라이브러리 모음입니다. 같은 장치 클래스 안에서도 장치별 코드를 따로 작성하지 않고 폭넓은 하드웨어를 지원하도록 응용 프로그램 작성 부담을 줄이는 것이 목적입니다.

사용 예는 `v4l2grab` 예제에서 볼 수 있으며, 구성 요소는 `libv4lconvert`, `libv4l1`, `libv4l2` 세 라이브러리입니다.

.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: V4L

.. _libv4l-introduction:

************
Introduction
************

libv4l is a collection of libraries which adds a thin abstraction layer
on top of video4linux2 devices. The purpose of this (thin) layer is to
make it easy for application writers to support a wide variety of
devices without having to write separate code for different devices in
the same class.

An example of using libv4l is provided by
:ref:`v4l2grab <v4l2grab-example>`.

libv4l consists of 3 different libraries:

libv4lconvert 형식 변환과 영상 처리

21-67

`libv4lconvert`는 V4L2 드라이버가 제공하는 여러 픽셀 형식을 소수의 공통 RGB 및 YUY 형식으로 변환합니다.

입력 형식
항목설명
RGB/JPEG`V4L2_PIX_FMT_BGR24`, `RGB24`, `JPEG`, `MJPEG`, `PJPG`
YUV`V4L2_PIX_FMT_NV12_16L16`, `UYVY`, `YUYV`, `YVYU`, `YUV420`, `YVU420`
Bayer`V4L2_PIX_FMT_SBGGR8`, `SGBRG8`, `SGRBG8`, `SRGGB8`
웹캠 전용 압축/배치`MR97310A`, `OV511`, `OV518`, `PAC207`, `SN9C10X`, `SN9C20X_I420`, `SQ905C`
SPCA 계열`V4L2_PIX_FMT_SPCA501`, `SPCA505`, `SPCA508`, `SPCA561`

현재 문서가 libv4lconvert 입력으로 열거한 모든 형식입니다.

이후 libv4lconvert는 웹캠 품질을 높이는 영상 처리 기능까지 확장되었습니다. 기능은 `libv4lconvert/control`과 `libv4lconvert/processing`으로 나뉩니다.

control 부분은 processing 기능을 조절하는 비디오 제어를 제공합니다. 값은 영속 공유 메모리 객체를 사용해 재부팅 전까지 응용 프로그램 전체 범위로 보존됩니다. processing 부분이 실제 영상 처리를 수행합니다.

libv4lconvert
=============

libv4lconvert is a library that converts several different pixelformats
found in V4L2 drivers into a few common RGB and YUY formats.

It currently accepts the following V4L2 driver formats:
:ref:`V4L2_PIX_FMT_BGR24 <V4L2-PIX-FMT-BGR24>`,
:ref:`V4L2_PIX_FMT_NV12_16L16 <V4L2-PIX-FMT-NV12-16L16>`,
:ref:`V4L2_PIX_FMT_JPEG <V4L2-PIX-FMT-JPEG>`,
:ref:`V4L2_PIX_FMT_MJPEG <V4L2-PIX-FMT-MJPEG>`,
:ref:`V4L2_PIX_FMT_MR97310A <V4L2-PIX-FMT-MR97310A>`,
:ref:`V4L2_PIX_FMT_OV511 <V4L2-PIX-FMT-OV511>`,
:ref:`V4L2_PIX_FMT_OV518 <V4L2-PIX-FMT-OV518>`,
:ref:`V4L2_PIX_FMT_PAC207 <V4L2-PIX-FMT-PAC207>`,
:ref:`V4L2_PIX_FMT_PJPG <V4L2-PIX-FMT-PJPG>`,
:ref:`V4L2_PIX_FMT_RGB24 <V4L2-PIX-FMT-RGB24>`,
:ref:`V4L2_PIX_FMT_SBGGR8 <V4L2-PIX-FMT-SBGGR8>`,
:ref:`V4L2_PIX_FMT_SGBRG8 <V4L2-PIX-FMT-SGBRG8>`,
:ref:`V4L2_PIX_FMT_SGRBG8 <V4L2-PIX-FMT-SGRBG8>`,
:ref:`V4L2_PIX_FMT_SN9C10X <V4L2-PIX-FMT-SN9C10X>`,
:ref:`V4L2_PIX_FMT_SN9C20X_I420 <V4L2-PIX-FMT-SN9C20X-I420>`,
:ref:`V4L2_PIX_FMT_SPCA501 <V4L2-PIX-FMT-SPCA501>`,
:ref:`V4L2_PIX_FMT_SPCA505 <V4L2-PIX-FMT-SPCA505>`,
:ref:`V4L2_PIX_FMT_SPCA508 <V4L2-PIX-FMT-SPCA508>`,
:ref:`V4L2_PIX_FMT_SPCA561 <V4L2-PIX-FMT-SPCA561>`,
:ref:`V4L2_PIX_FMT_SQ905C <V4L2-PIX-FMT-SQ905C>`,
:ref:`V4L2_PIX_FMT_SRGGB8 <V4L2-PIX-FMT-SRGGB8>`,
:ref:`V4L2_PIX_FMT_UYVY <V4L2-PIX-FMT-UYVY>`,
:ref:`V4L2_PIX_FMT_YUV420 <V4L2-PIX-FMT-YUV420>`,
:ref:`V4L2_PIX_FMT_YUYV <V4L2-PIX-FMT-YUYV>`,
:ref:`V4L2_PIX_FMT_YVU420 <V4L2-PIX-FMT-YVU420>`, and
:ref:`V4L2_PIX_FMT_YVYU <V4L2-PIX-FMT-YVYU>`.

Later on libv4lconvert was expanded to also be able to do various video
processing functions to improve webcam video quality. The video
processing is split in to 2 parts: libv4lconvert/control and
libv4lconvert/processing.

The control part is used to offer video controls which can be used to
control the video processing functions made available by
libv4lconvert/processing. These controls are stored application wide
(until reboot) by using a persistent shared memory object.

libv4lconvert/processing offers the actual video processing
functionality.

libv4l1 호환과 현대 libv4l2

68-107

`libv4l1`은 V4L1 응용 프로그램이 V4L2 장치에서 빠르게 동작하도록 돕습니다. 일반 open/close 계열과 같은 형태의 함수를 제공하고 V4L2 드라이버 위에서 V4L1 API를 완전히 에뮬레이션하며, 실제 V4L1 드라이버라면 호출을 그대로 전달합니다. 오래된 API 에뮬레이션이므로 새 응용 프로그램에는 사용하지 않아야 합니다.

`libv4l2`는 모든 현대 V4L2 응용 프로그램에 권장됩니다. open/ioctl/close/poll 호출 핸들을 제공하고 단순한 원시 장치 출력을 넘어서 libv4lconvert로 형식을 늘리고 영상 품질을 개선합니다.

libv4l2가 가로채는 형식 ioctl
항목설명
형식 협상`VIDIOC_TRY_FMT`, `VIDIOC_G_FMT`, `VIDIOC_S_FMT`
크기/간격 열거`VIDIOC_ENUM_FRAMESIZES`, `VIDIOC_ENUM_FRAMEINTERVALS`
에뮬레이션 형식드라이버에 없을 때 `BGR24`, `RGB24`, `YUV420`, `YVU420`을 제공합니다.
`VIDIOC_ENUM_FMT`하드웨어 지원 형식을 먼저 열거한 뒤 libv4l이 제공하는 에뮬레이션 형식을 끝에 덧붙입니다.

대부분은 드라이버로 그대로 전달하지만 형식 에뮬레이션에 필요한 호출은 중간에서 처리합니다.

libv4l1
=======

This library offers functions that can be used to quickly make v4l1
applications work with v4l2 devices. These functions work exactly like
the normal open/close/etc, except that libv4l1 does full emulation of
the v4l1 api on top of v4l2 drivers, in case of v4l1 drivers it will
just pass calls through.

Since those functions are emulations of the old V4L1 API, it shouldn't
be used for new applications.

libv4l2
=======

This library should be used for all modern V4L2 applications.

It provides handles to call V4L2 open/ioctl/close/poll methods. Instead
of just providing the raw output of the device, it enhances the calls in
the sense that it will use libv4lconvert to provide more video formats
and to enhance the image quality.

In most cases, libv4l2 just passes the calls directly through to the
v4l2 driver, intercepting the calls to
:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`,
:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>`,
:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`,
:ref:`VIDIOC_ENUM_FRAMESIZES <VIDIOC_ENUM_FRAMESIZES>` and
:ref:`VIDIOC_ENUM_FRAMEINTERVALS <VIDIOC_ENUM_FRAMEINTERVALS>` in
order to emulate the formats
:ref:`V4L2_PIX_FMT_BGR24 <V4L2-PIX-FMT-BGR24>`,
:ref:`V4L2_PIX_FMT_RGB24 <V4L2-PIX-FMT-RGB24>`,
:ref:`V4L2_PIX_FMT_YUV420 <V4L2-PIX-FMT-YUV420>`, and
:ref:`V4L2_PIX_FMT_YVU420 <V4L2-PIX-FMT-YVU420>`, if they aren't
available in the driver. :ref:`VIDIOC_ENUM_FMT <VIDIOC_ENUM_FMT>`
keeps enumerating the hardware supported formats, plus the emulated
formats offered by libv4l at the end.

.. _libv4l-ops:

파일 연산 함수와 v4l1compat wrapper

108-180
공통 파일 연산
항목설명
`v4l2_open()``open()`과 같은 방식으로 장치를 엽니다.
`v4l2_close()``close()`와 같은 방식으로 닫습니다.
`v4l2_dup()`libc `dup()`처럼 파일 핸들러를 복제합니다.
`v4l2_ioctl()``ioctl()`과 같은 방식으로 요청을 수행합니다.
`v4l2_read()``read()`와 같은 방식으로 데이터를 읽습니다.
`v4l2_mmap()``mmap()`과 같은 방식으로 버퍼를 매핑합니다.
`v4l2_munmap()``munmap()`과 같은 방식으로 매핑을 해제합니다.

각 libv4l 함수는 대응하는 libc/V4L2 연산처럼 동작합니다.

추가 제어 함수
항목설명
`v4l2_fd_open(fd, flags)`이미 열린 fd를 libv4l2에서 사용하도록 등록합니다. `V4L2_DISABLE_CONVERSION`을 지정하면 형식 변환을 끕니다.
`v4l2_set_control(fd, cid, value)`0~65535 입력을 실제 제어 범위로 비례 변환하고, 제어가 존재하며 잠기지 않았으면 값을 설정합니다.
`v4l2_get_control(fd, cid)`실제 제어 범위를 0~65535로 비례 변환해 반환합니다. 제어가 없거나 접근할 수 없거나 오류가 나면 0을 반환합니다.

libv4l2의 기본 동작과 정규화된 제어 범위를 다룹니다.

`v4l1compat.so`는 `LD_PRELOAD=/usr/lib/v4l1compat.so`를 이용해 open, close, ioctl, mmap, munmap 호출을 가로채 libv4l 대응 함수로 보냅니다. 동시에 V4L2 API로 V4L1 호출을 에뮬레이션하므로 libv4l을 직접 쓰지 않는 오래된 바이너리 응용 프로그램을 실행할 수 있습니다.

Libv4l device control functions
-------------------------------

The common file operation methods are provided by libv4l.

Those functions operate just like the gcc function ``dup()`` and
V4L2 functions
:c:func:`open()`, :c:func:`close()`,
:c:func:`ioctl()`, :c:func:`read()`,
:c:func:`mmap()` and :c:func:`munmap()`:

.. c:function:: int v4l2_open(const char *file, int oflag, ...)

   operates like the :c:func:`open()` function.

.. c:function:: int v4l2_close(int fd)

   operates like the :c:func:`close()` function.

.. c:function:: int v4l2_dup(int fd)

   operates like the libc ``dup()`` function, duplicating a file handler.

.. c:function:: int v4l2_ioctl (int fd, unsigned long int request, ...)

   operates like the :c:func:`ioctl()` function.

.. c:function:: int v4l2_read (int fd, void* buffer, size_t n)

   operates like the :c:func:`read()` function.

.. c:function:: void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd, int64_t offset);

   operates like the :c:func:`mmap()` function.

.. c:function:: int v4l2_munmap(void *_start, size_t length);

   operates like the :c:func:`munmap()` function.

Those functions provide additional control:

.. c:function:: int v4l2_fd_open(int fd, int v4l2_flags)

   opens an already opened fd for further use through v4l2lib and possibly
   modify libv4l2's default behavior through the ``v4l2_flags`` argument.
   Currently, ``v4l2_flags`` can be ``V4L2_DISABLE_CONVERSION``, to disable
   format conversion.

.. c:function:: int v4l2_set_control(int fd, int cid, int value)

   This function takes a value of 0 - 65535, and then scales that range to the
   actual range of the given v4l control id, and then if the cid exists and is
   not locked sets the cid to the scaled value.

.. c:function:: int v4l2_get_control(int fd, int cid)

   This function returns a value of 0 - 65535, scaled to from the actual range
   of the given v4l control id. when the cid does not exist, could not be
   accessed for some reason, or some error occurred 0 is returned.

v4l1compat.so wrapper library
=============================

This library intercepts calls to
:c:func:`open()`, :c:func:`close()`,
:c:func:`ioctl()`, :c:func:`mmap()` and
:c:func:`munmap()`
operations and redirects them to the libv4l counterparts, by using
``LD_PRELOAD=/usr/lib/v4l1compat.so``. It also emulates V4L1 calls via V4L2
API.

It allows usage of binary legacy applications that still don't use
libv4l.