Access V4L2 device by following steps:
- Open video device /dev/video0
- Query capability. Supprot video capture device only
- Query crop (resolution) capability of video capture device
- Query video format of video capture device
- Request video buffer
- Query and mmap buffer created by ioctl VIDIOC_REQBUFS
- Queue video buffer and get one frame
- Turn on video streaming
- Dequeue video buffer
- Process video buffer (Save JPEG file)
- Turn off video streaming
- Unmap buffer
- Close device
(Step 2~4 are V4L2 device capability query)
(Step 5~7 are allocating video buffer)
(Step 9 is where video image come)
How to build (Ubuntu 14.04 LTS)
$ sudo apt-get install libjpeg-dev
$ git clone https://github.com/ArtisteHsu/SampleV4L2.git
$ cd SampleV4L2
$ gcc samplev4l2.c -ljpeg -o samplev4l2