diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/findcut.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/findcut.c b/src/findcut.c new file mode 100644 index 0000000..2b2bc71 --- /dev/null +++ b/src/findcut.c @@ -0,0 +1,88 @@ +#define _XOPEN_SOURCE 500 +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <unistd.h> + +#include "video_decode.h" +#include "util.h" + +static void +usage(void) +{ + fprintf(stderr, "findcut [-dh] [-t THRESHOLD] VIDEO CUT\n" + "\n" + "OPTIONS\n" + "\t-d\tprint diff for every frame\n" + "\t-h\tprint this help message\n" + "\t-t\tthreshold matching\n" + "\t-T\tprint timestamp of every frame\n"); + + exit(EXIT_FAILURE); +} + +int +main(int argc, char **argv) +{ + struct video_decode *video_vd; + struct video_decode *cut_vd; + struct video_frame *cur_frame = NULL, *cut_frame = NULL; + int ret, ch; + int diff_flag = 0, time_flag = 0; + int64_t timestamp = 0; + int64_t threshold = 10; + double diff = 0.0; + + while ((ch = getopt(argc, argv, "dtTh")) != -1) { + switch (ch) { + case 'd': + diff_flag = 1; /* print diff of every frame */ + break; + case 't': + threshold = strtol(optarg, NULL, 10); + break; + case 'T': + time_flag = 1; + break; + case 'h': + default: + usage(); + /* NOTREACHED */ + } + } + argc -= optind; + argv += optind; + + if (argc < 2) + usage(); + + ret = video_decode_init(&cut_vd, argv[1], timestamp); + if (ret < 0) + return -ret; + + /* just get first frame of the cut */ + video_decode_get_frame(cut_vd, &cut_frame); + + ret = video_decode_init(&video_vd, argv[0], timestamp); + if (ret < 0) + return -ret; + + for (int i = 0; video_decode_get_frame(video_vd, &cur_frame) > 0; ++i) { + diff = frame_diff(cut_frame, cur_frame); + + if (diff <= threshold || diff_flag) { + if (time_flag) + printf("%lld", cur_frame->dts); + else + print_time(cur_frame->dts); + + printf(" %f\n", diff); + } + } + + video_decode_free_frame(&cur_frame); + video_decode_free_frame(&cut_frame); + video_decode_uninit(&video_vd); + video_decode_uninit(&cut_vd); + return EXIT_SUCCESS; +} |