26

I'm looking for a simple example for camera access in Linux using V4L2. Where I can find it? As simple, as possible.

Thanks,

Alex Ivasyuv
  • 8,585
  • 17
  • 72
  • 90

3 Answers3

23

Try the uvccapture code here -> http://staticwave.ca/source/uvccapture/ It is very small yet very concrete example which makes use of all the V4l2 concepts (open,set format, allocate memory, Request Buffer, Dqbuffer and Query-buffer - all intems of ioclts).

uvcgrab() function is the one to look for which makes use of Dqbuffer and Query-buffer.

ioctl (vd->fd, VIDIOC_DQBUF, &vd->buf);

ioctl (vd->fd, VIDIOC_QBUF, &vd->buf)

While Studying it you can keep looking for the ioctl definition in this link which will ease your understanding.

Patrick B.
  • 11,773
  • 8
  • 58
  • 101
Raulp
  • 7,758
  • 20
  • 93
  • 155
6

In the API specification, there is an example, also downloadable as a C file

shodanex
  • 14,975
  • 11
  • 57
  • 91
  • This example works fine for me, but it's a little bit complex. I found this one http://credentiality2.blogspot.com/2010/04/v4l2-example.html but it doesn't work for me :( I get read error 22, Invalid argument – Alex Ivasyuv Oct 24 '10 at 18:34
  • The links are dead. I suppose that was [this one](https://www.kernel.org/doc/html/v4.10/media/uapi/v4l/capture.c.html), which works, but only outputs the image frames to stdout... – Déjà vu Aug 01 '20 at 07:49
4

I would advice also trying out v4l-utils.

http://linuxtv.org/downloads/v4l-utils/

It has some easy to use API calls to v4l devices and there is a qt based example in the source to build a custom interface for video devices.

ekmungi
  • 488
  • 2
  • 5
  • 12