Skip to content

Commit

Permalink
Add --count option to limit number of times to loop. Closes #46
Browse files Browse the repository at this point in the history
  • Loading branch information
fsphil committed Feb 28, 2020
1 parent 9a995d6 commit 6a113f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions fswebcam.1
Expand Up @@ -55,6 +55,12 @@ Default behaviour is to capture a single image and exit.
\fB\-\-offset\fR \fI<seconds>\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<number>\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.
Expand Down
11 changes: 11 additions & 0 deletions fswebcam.c
Expand Up @@ -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,
Expand Down Expand Up @@ -123,6 +124,7 @@ typedef struct {
/* General options. */
unsigned long loop;
signed long offset;
unsigned int count;
unsigned char background;
char *pidfile;
char *logfile;
Expand Down Expand Up @@ -1114,6 +1116,7 @@ int fswc_usage()
" --version Displays the version and exits.\n"
" -l, --loop <seconds> Run in loop mode.\n"
" --offset <seconds> Sets the capture time offset in loop mode.\n"
" --count <number> Loop this many times and exit. Default is forever.\n"
" -b, --background Run in the background.\n"
" --pid <filename> Saves background process PID to filename.\n"
" -L, --log [file/syslog:]<filename> Redirect log messages to a file or syslog.\n"
Expand Down Expand Up @@ -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'},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 6a113f5

Please sign in to comment.