Results 1 to 4 of 4
Hi
I have an Acer Laptop with a built-in Crystal Eye webcam
which works (tested it with luvcview).
The camera is represented by /dev/video0.
I would like to read data ...
- 07-17-2010 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 18
how to read data from /dev/video0
Hi
I have an Acer Laptop with a built-in Crystal Eye webcam
which works (tested it with luvcview).
The camera is represented by /dev/video0.
I would like to read data from this device, but i don't manage to do it.
This codewill successfully open the device (filedescriptor fd is 3), but theCode:#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #include <errno.h> int main(int iArgC, char *apArgV[]) { char *buf[76800]; // camera resolution 320x240 int iErr = 0; int fd = open("/dev/video0", O_RDONLY); if (fd >= 0) { printf("fd is %d\n", fd); ssize_t num=read(fd, buf, 76800); if (num > 0) { printf("Read %d bytes\n", num); } else { iErr = errno; printf("Coudn't read - error %d:[%s]\n", iErr, strerror(iErr)); } close(fd); } else { iErr = errno; printf("Couldn't open - error %d:[%s]\n", iErr, strerror(iErr)); } return iErr; }
subsequent call to "read" returns errno 19 ("No such device"),
even though it exists. Same happens if i have luvcview working
at the same time.
Also, the call 'cat /dev/video0' returns "No such device":(BTW: i am member of the group 'video',Code:jody@enki ~ $ ls -l /dev/video0 crw-rw----+ 1 root video 81, 0 Jul 17 00:09 /dev/video0 jody@enki ~ $ cat /dev/video0 cat: /dev/video0: No such device
but i also get the same error if i do this as 'root')
Can anybody give me some pointers how i can open the device,
get som data from it and close it again?
Thank You
Jody
- 07-18-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,961
You probably need to open it for read+write access and then send some sort of command (probably an ioctl() call) to enable it.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 07-20-2010 #3Just Joined!
- Join Date
- Sep 2007
- Posts
- 18
[solved] how to read data from /dev/video0
HI Rubberman
You are right.
The V4L2 API documentation
describes all the required ioctl-commands and also has example code.
JodyLast edited by jody; 07-20-2010 at 06:18 AM. Reason: solved
- 07-20-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,961
Kewl! Glad you got that sorted out. Sometimes all one needs is a nudge in the right direction. Like the old parable, if you give a person a fish, they are fed for a day. If you teach them how to fish, they will never go hungry (unless they live on the Gulf of Mexico).
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
