This is a simple example which illustrates how to capture video(or image if you like) using v4l2 and to display with SDL2.
Currently, most webcams supports YUYV422 output format. So the default output format is set to YUYV422. You can modify the format parameter both for v2lc and sdl2 to be compatible with your webcam.
To list support formats of your webcam, try following commands:
v4l2-ctl --list-formats-extor if ffmpeg installed
ffmpeg -f v4l2 -list_formats all -i /dev/video0Both Makefile and CMakeLists are provided.
- using
Makefile
git clone https://github.com/chendotjs/Webcam-SDL2
cd Webcam-SDL2/src
sudo apt-get install libsdl2-dev
make
./simple_cam 640 480 /dev/video0- using
CMakeLists
git clone https://github.com/chendotjs/Webcam-SDL2
cd Webcam-SDL2/
sudo apt-get install libsdl2-dev
mkdir build && cd build
cmake ../src
make
./simple_cam 640 480 /dev/video0