I want to read from the file /dev/video0 either through c or python,and store the incoming bytes in a different file. Here is my c code:
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main()
{
int fd,wfd;
fd=open("/dev/video0",O_RDONLY);
wfd=open("image",O_RDWR|O_CREAT|O_APPEND,S_IRWXU);
if(fd==-1)
perror("open");
while(1)
{
char buffer[50];
int rd;
rd=read(fd,buffer,50);
write(wfd,buffer,rd);
}
return 0;
}
When i run this code and after some time terminate the program nothing happens except a file name "image" is generated which is usual.
This is my python code:
image=open("/dev/video0","rb")
image.read()
and this is my error when my run this snippet:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 22] Invalid argument
I want to know how to do this using pure c or python code.Please no external library suggestions.