日期:2014-05-16 浏览次数:21110 次
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <malloc.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <asm/types.h>
#include <linux/videodev2.h>
#define CLEAR(x) memset (&(x), 0, sizeof (x))
struct buffer {
void * start;
size_t length;
};
static char * dev_name = "/dev/video0";
static int fd = -1;
struct buffer * buffers = NULL;
static unsigned int n_buffers = 0;
FILE *file_fd;
static unsigned long file_length;
static unsigned char *file_name;
static int read_frame (void)
{
struct v4l2_buffer buf;
unsigned int i;
CLEAR (buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
int ff = ioctl (fd, VIDIOC_DQBUF, &buf);
if(ff<0)
printf("failture\n");
assert (buf.index < n_buffers);
printf ("buf.index dq is %d,\n",buf.index);
fwrite(buffers[buf.index].start, buffers[buf.index].length, 1, file_fd);
ff=ioctl (fd, VIDIOC_QBUF, &buf);
if(ff<0)
printf("failture VIDIOC_QBUF\n");
return 1;
}
int main (int argc,char ** argv)
{
struct v4l2_capability cap;
struct v4l2_format fmt;
unsigned int i;
enum v4l2_buf_type type;
file_fd = fopen("jpgimage.jpg", "w");
fd = open (dev_name, O_RDWR | O_NONBLOCK, 0);
printf("000000000000000000000000000000000\n");
int ff=ioctl (fd, VIDIOC_QUERYCAP, &cap);
if(ff<0)
printf("failture VIDIOC_QUERYCAP\n");
printf("111111111111111111111111111111111\n");
struct v