Skip to content

Commit

Permalink
vidcap testcard: option to restrict number of cap vframes
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Sep 18, 2023
1 parent 04e1374 commit 2af94ed
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/video_capture/testcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct testcard_state {
struct audio_frame audio;
struct audio_len_pattern apattern;
int audio_frequency;
long long capture_frames;

char **tiles_data;
int tiles_cnt_horizontal;
Expand Down Expand Up @@ -437,6 +438,8 @@ static void show_help(bool full) {
color_printf(TBOLD("\t still ") " - send still image\n");
if (full) {
color_printf(TBOLD(" afrequency") " - embedded audio frequency\n");
color_printf(TBOLD("\t frames") " - total number of video "
"frames to capture\n");
}
color_printf("\n");
testcard_show_codec_help("testcard", false);
Expand Down Expand Up @@ -531,6 +534,9 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
filename = strchr(tmp, '=') + 1;
} else if (strstr(tmp, "afrequency=") == tmp) {
s->audio_frequency = atoi(strchr(tmp, '=') + 1);
} else if (strstr(tmp, "frames=") == tmp) {
s->capture_frames =
strtoll(strchr(tmp, '=') + 1, NULL, 0);
} else {
fprintf(stderr, "[testcard] Unknown option: %s\n", tmp);
goto error;
Expand Down Expand Up @@ -654,7 +660,9 @@ static struct video_frame *vidcap_testcard_grab(void *arg, struct audio_frame **
state = (struct testcard_state *)arg;

time_ns_t curr_time = get_time_in_ns();
if ((curr_time - state->last_frame_time) / NS_IN_SEC_DBL < 1.0 / state->frame->fps) {
if (state->video_frames + 1 == state->capture_frames ||
(curr_time - state->last_frame_time) / NS_IN_SEC_DBL <
1.0 / state->frame->fps) {
return NULL;
}
state->last_frame_time = curr_time;
Expand Down

0 comments on commit 2af94ed

Please sign in to comment.