diff options
author | Benjamin M. Schwartz <bens@alum.mit.edu> | 2010-07-25 23:29:41 (GMT) |
---|---|---|
committer | Benjamin M. Schwartz <bens@alum.mit.edu> | 2010-07-25 23:29:41 (GMT) |
commit | aae3e541666bf1bf6e879976f95f027ed59a5fa1 (patch) | |
tree | 3ca236842bcf90b6db5d1020b20acb2f7a850a22 | |
parent | 7f9d48128c900be759843e3ebdca12fadecf87fd (diff) |
Add PGM output
-rw-r--r-- | capture.c | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -43,6 +43,9 @@ static io_method io = IO_METHOD_MMAP; static int fd = -1; struct buffer * buffers = NULL; static unsigned int n_buffers = 0; +FILE * output_file = NULL; +static unsigned int width = 640; +static unsigned int height = 480; static void errno_exit (const char * s) @@ -85,6 +88,12 @@ process_image (const void * p) { fputc ('.', stdout); fflush (stdout); + if (output_file) { + /* Write a portable graymap (PGM) binary file. + If num_frames > 1, all the files will be concatenated. */ + fprintf(output_file, "P5\n%d %d %d\n", width, height, 255); + fwrite(p, 1, width*height, output_file); + } } static int @@ -523,8 +532,8 @@ init_device (void) CLEAR (fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = 640; - fmt.fmt.pix.height = 480; + fmt.fmt.pix.width = width; + fmt.fmt.pix.height = height; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8; fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; @@ -609,7 +618,7 @@ usage (FILE * fp, argv[0]); } -static const char short_options [] = "d:hmrunf"; +static const char short_options [] = "d:hmrunfo"; static const struct option long_options [] = { @@ -620,6 +629,7 @@ long_options [] = { { "userp", no_argument, NULL, 'u' }, { "numframes", required_argument, NULL, 'n' }, { "framerate", required_argument, NULL, 'f' }, + { "outfile", required_argument, NULL, 'o' }, { 0, 0, 0, 0 } }; @@ -628,12 +638,12 @@ main (int argc, char ** argv) { dev_name = "/dev/video"; + unsigned int numframes = 1; + unsigned int framerate = 0; for (;;) { int index; int c; - unsigned int numframes = 1; - unsigned int framerate = 0; c = getopt_long (argc, argv, short_options, long_options, @@ -674,6 +684,10 @@ main (int argc, framerate = atoi(optarg); break; + case 'o': + output_file = fopen(optarg, "wb"); + break; + default: usage (stderr, argc, argv); exit (EXIT_FAILURE); @@ -695,6 +709,8 @@ main (int argc, uninit_device (); close_device (); + + if (output_file) fclose(output_file); exit (EXIT_SUCCESS); |