summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/advtime.c78
1 files changed, 55 insertions, 23 deletions
diff --git a/src/advtime.c b/src/advtime.c
index 24be53c..01ad742 100644
--- a/src/advtime.c
+++ b/src/advtime.c
@@ -9,6 +9,20 @@
#include "video_decode.h"
#include "util.h"
+/* print time in format: "hh:mm:ss.xxx" */
+void
+print_time(int64_t msec) {
+
+ int hh = msec / 1000 / 60 / 60;
+ msec -= hh * 1000 * 60 * 60;
+ int mm = msec / 1000 / 60;
+ msec -= mm * 1000 * 60;
+ int ss = msec / 1000;
+ msec -= ss * 1000;
+
+ printf("%02d:%02d:%02d.%03jd", hh, mm, ss, msec);
+}
+
static double
frame_diff(struct video_frame *frame_a, struct video_frame *frame_b)
{
@@ -64,12 +78,13 @@ main(int argc, char **argv)
struct video_frame *frame_a;
struct video_frame *frame_b;
int ret, ch;
- int diff_flag = 0, average_flag = 0;
+ int diff_flag = 0, average_flag = 0, frame_flag = 0, showcut_flag = 0;
int64_t timestamp = 0;
double diff = 0.0, old_diff = 0.0;
+ uint64_t dts = 0, prev_dts = 0; /* decoding time stamp */
char filename[BUFSIZ];
- while ((ch = getopt(argc, argv, "ad")) != -1) {
+ while ((ch = getopt(argc, argv, "adfs")) != -1) {
switch (ch) {
case 'a':
average_flag = 1;
@@ -77,6 +92,12 @@ main(int argc, char **argv)
case 'd':
diff_flag = 1;
break;
+ case 'f':
+ diff_flag = 1;
+ break;
+ case 's':
+ showcut_flag = 1;
+ break;
default:
usage();
/* NOTREACHED */
@@ -98,7 +119,7 @@ main(int argc, char **argv)
ret = video_decode_get_frame(vd, &frame_a);
if (ret < 0)
return -ret;
-
+/*
printf("fps: %d\n", vd->fmt_ctx->fps_probe_size);
printf("streams: %d\n", vd->fmt_ctx->nb_streams);
printf("filename: %s\n", vd->fmt_ctx->filename);
@@ -112,39 +133,50 @@ main(int argc, char **argv)
printf("first: %ji\n", vd->fmt_ctx->streams[0]->first_dts);
printf("cur: %ji\n", vd->fmt_ctx->streams[0]->cur_dts);
printf("reference: %ji\n", vd->fmt_ctx->streams[0]->reference_dts);
-
+*/
for (int i = 0; video_decode_get_frame(vd, &frame_b) > 0; ++i) {
-// printf("first: %ji\t", vd->fmt_ctx->streams[0]->first_dts);
-// printf("cur: %ji\t", vd->fmt_ctx->streams[0]->cur_dts);
-// printf("reference: %ji\n", vd->fmt_ctx->streams[0]->reference_dts);
-
+ if (frame_flag) /* print frame number */
+ printf("%d\t", i);
-
-// printf("%d\t", i);
- if (average_flag == 1)
+ if (average_flag) /* print frame average */
printf("%f", frame_average(frame_a));
- if (average_flag == 1 && diff_flag == 1)
+ if (average_flag && diff_flag)
printf("\t");
- if (diff_flag == 1) {
- printf("%f", diff = frame_diff(frame_a, frame_b));
- printf("\t%f", (diff - old_diff));
+ if (diff_flag) {
+ diff = frame_diff(frame_a, frame_b);
+// printf("%f", diff);
+// printf("\t%f", (diff - old_diff));
old_diff = diff;
}
if (diff > 40.0) {
- printf("cut: %d\n", i);
- snprintf(filename, BUFSIZ, "img/%04i.pgm", i);
- frame_mix(frame_a, frame_b);
- if (pgm_save(frame_a->data, frame_a->stride,
- frame_a->width, frame_a->height,
- filename) < 0)
- exit(EXIT_FAILURE);
+ dts = vd->fmt_ctx->streams[0]->cur_dts;
+
+ print_time(dts);
+ printf("\t");
+ print_time(dts - prev_dts);
+ prev_dts = dts;
+
+ if (!frame_flag && !average_flag)
+ printf("\n");
+
+ if (showcut_flag == 1) {
+ snprintf(filename, BUFSIZ, "img/%04i.pgm", i);
+ frame_mix(frame_a, frame_b);
+
+ if (pgm_save(frame_a->data, frame_a->stride,
+ frame_a->width, frame_a->height,
+ filename) < 0)
+ exit(EXIT_FAILURE);
+ }
}
-// printf("\n");
+ if (frame_flag || average_flag)
+ printf("\n");
+
video_decode_free_frame(&frame_a);
frame_a = frame_b;
}