}
}
-int main(int argc, char **argv)
+static int capture(char *dev_name, int x_res, int y_res, int n_frames,
+ char *out_dir)
{
struct v4l2_format fmt;
struct v4l2_buffer buf;
struct timeval tv;
int r, fd = -1;
unsigned int i, n_buffers;
- char *dev_name = "/dev/video0";
- char out_name[256];
+ char out_name[25 + strlen(out_dir)];
FILE *fout;
struct buffer *buffers;
CLEAR(fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- fmt.fmt.pix.width = 640;
- fmt.fmt.pix.height = 480;
+ fmt.fmt.pix.width = x_res;
+ fmt.fmt.pix.height = y_res;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
xioctl(fd, VIDIOC_S_FMT, &fmt);
printf("Libv4l didn't accept RGB24 format. Can't proceed.\n");
exit(EXIT_FAILURE);
}
- if ((fmt.fmt.pix.width != 640) || (fmt.fmt.pix.height != 480))
+ if ((fmt.fmt.pix.width != x_res) || (fmt.fmt.pix.height != y_res))
printf("Warning: driver is sending image at %dx%d\n",
fmt.fmt.pix.width, fmt.fmt.pix.height);
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
xioctl(fd, VIDIOC_STREAMON, &type);
- for (i = 0; i < 20; i++) {
+ for (i = 0; i < n_frames; i++) {
do {
FD_ZERO(&fds);
FD_SET(fd, &fds);
buf.memory = V4L2_MEMORY_MMAP;
xioctl(fd, VIDIOC_DQBUF, &buf);
- sprintf(out_name, "out%03d.ppm", i);
+ sprintf(out_name, "%s/out%03d.ppm", out_dir, i);
fout = fopen(out_name, "w");
if (!fout) {
perror("Cannot open image");
return 0;
}
+
+int main(int argc, char **argv)
+{
+ char *dev_name = "/dev/video0";
+ char *out_dir = ".";
+ int x_res = 640;
+ int y_res = 480;
+ int n_frames = 20;
+
+ return capture(dev_name, x_res, y_res, n_frames, out_dir);
+}