├── .idea
├── libv4l2cxx.iml
├── misc.xml
├── vcs.xml
├── preferred-vcs.xml
├── modules.xml
└── codeStyles
│ └── Project.xml
├── CMakeLists.txt
├── examples
├── example1.cpp
└── main.cpp
├── LICENSE
├── README.md
└── src
├── v4l2cxx.h
└── util_v4l2.h
/.idea/libv4l2cxx.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/preferred-vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ApexVCS
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5.1)
2 | project(libv4l2cxx)
3 |
4 | set(CMAKE_CXX_STANDARD 17)
5 |
6 |
7 | set(HEADER_FILES src/util_v4l2.h src/v4l2cxx.h)
8 |
9 | set(SOURCE_FILES examples/main.cpp )
10 | add_executable(libv4l2cxx ${SOURCE_FILES} ${HEADER_FILES})
11 |
12 | set(EXAMPLE1_FILES examples/example1.cpp )
13 | add_executable(example1 ${EXAMPLE1_FILES} ${HEADER_FILES})
14 |
15 |
--------------------------------------------------------------------------------
/examples/example1.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by dan on 4/29/18.
3 | //
4 |
5 | #include "../src/v4l2cxx.h"
6 |
7 |
8 |
9 | void callback_stdout_pipe(uint8_t *p_data, size_t len) {
10 |
11 | uint8_t outBuff[921600];
12 | util_v4l2::raw_to_rgb(p_data, 0, outBuff, 921600, 640 * 480, 8);
13 | fwrite(outBuff, 640*480*3, 1, stdout);
14 | }
15 |
16 |
17 | int main() {
18 |
19 | ///////////////////////////////////////////////////////////////////////////////////////////////////
20 |
21 | capture cap("/dev/video0", 640,480,pixel_format ::V4L2CXX_PIX_FMT_YUYV,callback_stdout_pipe);
22 | cap.run();
23 |
24 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dan Yerushalmi dan.yerushalmi@gmail.com
4 | https://github.com/narfster/v4l2cxx/
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/examples/main.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "../src/v4l2cxx.h"
3 |
4 |
5 |
6 |
7 | int main(){
8 |
9 |
10 | error_code err = error_code::ERR_NO_ERROR;
11 |
12 | int fd = util_v4l2::open_device("/dev/video0", &err);
13 |
14 | auto vec = v4l2cxx::get_video_formats_ext(fd);
15 |
16 | v4l2cxx::print_fmt_ext(vec);
17 |
18 | ///////////////////////////////////////////////////////////////////////////////////////////////////
19 |
20 | //#elif (TEST_RUN == 2)
21 | // capture cap("/dev/video0", 640,480,pixel_format ::V4L2CXX_PIX_FMT_YUYV,callback_stdout_pipe);
22 | // while(1){
23 | // cap.read();
24 | // std::this_thread::sleep_for(std::chrono::milliseconds(16));
25 | // }
26 | //
27 | // ///////////////////////////////////////////////////////////////////////////////////////////////////
28 | //
29 | //#elif (TEST_RUN == 3)
30 |
31 | // struct util_v4l2::buffer buffers[4];
32 | //
33 | // error_code err = error_code::ERR_NO_ERROR;
34 | //
35 | // int fd = util_v4l2::open_device("/dev/video0", &err);
36 | // ASSERT_ERR_CODE(err);
37 | //
38 | // auto vec = v4l2cxx::get_video_formats_ext(fd);
39 | //
40 | // v4l2cxx::print_fmt_ext(vec);
41 |
42 | // auto cap = util_v4l2::query_capabilites(fd, &err);
43 | //
44 | // auto vec = util_v4l2::query_formats(fd, &err);
45 | //
46 | // util_v4l2::set_format(fd, 640, 480, pixel_format::V4L2CXX_PIX_FMT_YVYU, &err);
47 | //
48 | // auto vec_format = util_v4l2::get_current_format(fd, &err);
49 | //
50 | // //util_v4l2::printv4l2_fmt(vec_format);
51 | //
52 | // util_v4l2::init_mmap(fd, buffers, &err);
53 | //
54 | // util_v4l2::set_capture_steamon(fd,&err);
55 | //
56 | // util_v4l2::queue_frames(fd, 4, &err);
57 | //
58 | // util_v4l2::mainloop(fd, buffers, callback_stdout_pipe,&err);
59 |
60 | ///////////////////////////////////////////////////////////////////////////////////////////////////
61 |
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Video4Linux2 C++ simple wrapper
2 |
3 | - [Intro](#Intro)
4 | - [How to use](#How-to-use)
5 | - [Examples](#examples)
6 | - [Pipe to ffplay](#pipe-to-ffplay)
7 | - [ffmpeg commands](#ffmpeg-commands)
8 |
9 |
10 | ## Intro
11 | A simple C++ header library to capture frames from a usb camera into a callback function for image processing.
12 |
13 |
14 | ## How to use
15 |
16 | Run a simple hello camera to see how easy. no more v4l2 boilrplate code.
17 | ```cpp
18 | // callback function to pipe out image to stdout
19 | // later pipe to ffplay to display image
20 | void callback_stdout_pipe(uint8_t *p_data, size_t len) {
21 | uint8_t outBuff[921600];
22 | util_v4l2::raw_to_rgb(p_data, 0, outBuff, 921600, 640 * 480, 8);
23 | fwrite(outBuff, 640*480*3, 1, stdout);
24 | }
25 |
26 | int main() {
27 | // a capture instance
28 | // device, resolution, pixel format , and callback function this should be known in advance you can use
29 | // v4l2-ctl command to figure that out.
30 | capture cap("/dev/video0", 640,480,pixel_format ::V4L2CXX_PIX_FMT_YUYV,callback_stdout_pipe);
31 | // start streaming - a blocking function.
32 | cap.run();
33 | }
34 | ```
35 |
36 | ## Examples
37 | - TODO ; cmake; See example folder
38 |
39 | ## v4l2 Extension unit
40 | - TODO
41 | - TODO example with LI-USB30-V034M
42 |
43 | ### pipe to ffplay
44 | ./libv4l2cxx | ffplay -f rawvideo -i pipe:0 -video_size 640x480 -pixel_format rgb24 -framerate 60
45 |
46 |
47 | ## ffmpeg commands
48 |
49 | #### Play video device
50 | > ffplay -f v4l2 -i /dev/video0 -video_size 640x480 -pixel_format yuyv422 -framerate 30
51 |
52 | > ffplay -f v4l2 -i /dev/video0 -video_size 640x480 -pixel_format mjpeg
53 |
54 | > ffplay -f v4l2 -i /dev/video0 -video_size 1280x720 -pixel_format mjpeg -framerate 30
55 |
56 | #### Pipe libv4l2 to ffplay, tell ffplay to use input (-i pipe:0 = stdin standrd input)
57 | > ./libv4l2cxx | ffplay -f rawvideo -i pipe:0 -video_size 640x480 -pixel_format rgb24 -framerate 60
58 |
59 | #### List formats for device
60 | > v4l2-ctl --list-formats
61 |
62 | #### List exdtended formats including resolution info for device
63 | > v4l2-ctl --list-formats-ext
64 |
65 | > v4l2-ctl -L
66 |
67 | #### List controls for device
68 | > v4l2-ctl --all
69 |
70 | #### Change control option to value
71 | > v4l2-ctl -c \