#define _XOPEN_SOURCE 500 #include #include #include #include #include #include "video_decode.h" #include "util.h" static void usage(void) { fprintf(stderr, "overlap [-dh] [-t DURATION] FIRST_VIDEO SECOND_VIDEO\n" "\n" "OPTIONS\n" "\t-d\tprint diff for every frame\n" "\t-h\tprint this help message\n" "\t-t\tmax duration to find overlap in milliseconds\n" "\t\t(default 60000 = 1 min)\n"); exit(EXIT_FAILURE); } int main(int argc, char **argv) { struct video_decode *first_vd; struct video_decode *second_vd; struct video_frame *cur_frame = NULL, *last_frame = NULL; int ret, ch; int diff_flag = 0; int64_t timestamp = 0; int64_t duration = 60 * 1000; /* duration for searching min_diff */ /* default 1 min = 60 sec * 1000 msec */ int64_t min_diff_time = 0; /* dts at overlaping frame */ double min_diff, diff = 0.0; while ((ch = getopt(argc, argv, "dth")) != -1) { switch (ch) { case 'd': diff_flag = 1; /* print diff of every frame */ break; case 't': duration = strtol(optarg, NULL, 10); break; case 'h': default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc < 2) usage(); ret = video_decode_init(&first_vd, argv[0], timestamp); if (ret < 0) return -ret; /* just get last frame of move */ video_decode_seek(first_vd, first_vd->duration); for (int i = 0; video_decode_get_frame(first_vd, &last_frame) > 0; ++i); ret = video_decode_init(&second_vd, argv[1], timestamp); if (ret < 0) return -ret; for (int i = 0; video_decode_get_frame(second_vd, &cur_frame) > 0; ++i){ diff = frame_diff(last_frame, cur_frame); if (i == 0 || diff <= min_diff) { min_diff = diff; min_diff_time = cur_frame->dts; } if (diff_flag) printf("%" PRId64 " %f\n", cur_frame->dts, diff); if (cur_frame->dts > duration) break; } if (!diff_flag) { print_time(min_diff_time); printf("\n"); } video_decode_free_frame(&cur_frame); video_decode_free_frame(&last_frame); video_decode_uninit(&first_vd); video_decode_uninit(&second_vd); return EXIT_SUCCESS; }