/* v4lfps.c: based on Phil Blundell's v4lgrab.c */ #include #include #include #include #include #include #include #include #include #include #define FILE "/dev/video0" volatile int i = 0; void timeout(int x) { printf("Read %d frames in 10 seconds.\n", i); exit(0); } int main(int argc, char ** argv) { int fd = open(FILE, O_RDONLY), f; struct video_capability cap; struct video_window win; struct video_picture vpic; unsigned char *buffer, *src; int bpp = 24, r, g, b; unsigned src_depth; if (fd < 0) { perror(FILE); exit(1); } if (ioctl(fd, VIDIOCGCAP, &cap) < 0) { perror("VIDIOGCAP"); fprintf(stderr, "(" FILE " not a video4linux device?)\n"); close(fd); exit(1); } if (ioctl(fd, VIDIOCGWIN, &win) < 0) { perror("VIDIOCGWIN"); close(fd); exit(1); } if (ioctl(fd, VIDIOCGPICT, &vpic) < 0) { perror("VIDIOCGPICT"); close(fd); exit(1); } if (cap.type & VID_TYPE_MONOCHROME) { bpp = 8; vpic.depth=8; vpic.palette=VIDEO_PALETTE_GREY; /* 8bit grey */ if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) { vpic.depth=6; if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) { vpic.depth=4; if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) { fprintf(stderr, "Unable to find a supported capture format.\n"); close(fd); exit(1); } } } } else { vpic.depth=24; vpic.palette=VIDEO_PALETTE_RGB24; if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) { vpic.palette=VIDEO_PALETTE_RGB565; vpic.depth=16; if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) { vpic.palette=VIDEO_PALETTE_RGB555; vpic.depth=15; if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) { fprintf(stderr, "Unable to find a supported capture format.\n"); return -1; } } } } bpp /= 8; buffer = malloc(win.width * win.height * bpp); if (!buffer) { fprintf(stderr, "Out of memory.\n"); exit(1); } printf("Waiting for 10 seconds to measure FPS...\n"); fflush(stdout); i = 0; signal(SIGALRM, timeout); alarm(10); while (1) { read(fd, buffer, win.width * win.height * bpp); i++; } return 0; }