diff --git a/CHANGELOG b/CHANGELOG index ebeea1d..ff6c260 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ fswebcam-xxxxxxxx - Add new Bayer palettes. (Eugen Hristev) - Add WebP output support. - Add option to dump raw frames to stdout. (Philipp Simon Schmidt) + - Add option to limit number of times to loop. fswebcam-20140113 diff --git a/fswebcam.1 b/fswebcam.1 index 34a3d2f..5720aa8 100644 --- a/fswebcam.1 +++ b/fswebcam.1 @@ -55,6 +55,12 @@ Default behaviour is to capture a single image and exit. \fB\-\-offset\fR \fI\fR Sets the offset to use when calculating when the next image is due in loop mode. Value can be positive or negative. +.TP +\fB\-\-count\fR \fI\fR +Sets the number of times to capture an image in loop mode before exiting. +.IP +Default is 0, loop forever. + .TP \fB\-b\fR, \fB\-\-background\fR Run in the background. In this mode \fIstdout\fR and console logging are unavailable. diff --git a/fswebcam.c b/fswebcam.c index 56366b2..1381294 100644 --- a/fswebcam.c +++ b/fswebcam.c @@ -46,6 +46,7 @@ enum fswc_options { OPT_VERSION = 128, OPT_PID, OPT_OFFSET, + OPT_COUNT, OPT_LIST_INPUTS, OPT_LIST_TUNERS, OPT_LIST_FORMATS, @@ -123,6 +124,7 @@ typedef struct { /* General options. */ unsigned long loop; signed long offset; + unsigned int count; unsigned char background; char *pidfile; char *logfile; @@ -1114,6 +1116,7 @@ int fswc_usage() " --version Displays the version and exits.\n" " -l, --loop Run in loop mode.\n" " --offset Sets the capture time offset in loop mode.\n" + " --count Loop this many times and exit. Default is forever.\n" " -b, --background Run in the background.\n" " --pid Saves background process PID to filename.\n" " -L, --log [file/syslog:] Redirect log messages to a file or syslog.\n" @@ -1361,6 +1364,7 @@ int fswc_getopts(fswebcam_config_t *config, int argc, char *argv[]) {"version", no_argument, 0, OPT_VERSION}, {"loop", required_argument, 0, 'l'}, {"offset", required_argument, 0, OPT_OFFSET}, + {"count", required_argument, 0, OPT_COUNT}, {"background", no_argument, 0, 'b'}, {"pid", required_argument, 0, OPT_PID}, {"log", required_argument, 0, 'L'}, @@ -1436,6 +1440,7 @@ int fswc_getopts(fswebcam_config_t *config, int argc, char *argv[]) /* Set the defaults. */ config->loop = 0; config->offset = 0; + config->count = 0; config->background = 0; config->pidfile = NULL; config->logfile = NULL; @@ -1502,6 +1507,9 @@ int fswc_getopts(fswebcam_config_t *config, int argc, char *argv[]) case OPT_OFFSET: config->offset = atol(optarg); break; + case OPT_COUNT: + config->count = atol(optarg); + break; case 'b': config->background = -1; break; @@ -1723,6 +1731,9 @@ int main(int argc, char *argv[]) /* Capture the image. */ r = fswc_grab(config); + + /* Limit number of captures if a loop count was specified */ + if(config->count > 0 && !--config->count) break; } }