From c7c47cdf23892f7209bbd2acaf420a8d34336406 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Thu, 15 Nov 2012 08:25:35 +0100 Subject: Add frame mix saving for high diffs. --- src/Makefile | 11 +++++++---- src/advtime.c | 25 ++++++++++++++++++++++--- src/util.c | 32 ++++++++++++++++++++++++++++++++ src/util.h | 3 +++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/Makefile b/src/Makefile index 43087cb..83892e7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,10 +1,13 @@ -CFLAGS=-std=c99 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wno-unused-parameter -LIBAV_DECODE_FLAGS=`pkg-config --libs --cflags libavformat libavcodec libavutil libswscale` +CFLAGS=-std=c99 -Wall -Wstrict-prototypes -Wmissing-prototypes \ + -Wno-unused-parameter +LIBAV_DECODE_FLAGS=`pkg-config --libs --cflags libavformat libavcodec \ + libavutil libswscale` all: advtime decode_frame frame_to_pgm -advtime: advtime.c video_decode.c - gcc $(CFLAGS) $(LIBAV_DECODE_FLAGS) -DDEBUG=0 advtime.c video_decode.c -o $@ +advtime: advtime.c video_decode.c util.c + gcc $(CFLAGS) $(LIBAV_DECODE_FLAGS) -DDEBUG=0 advtime.c video_decode.c \ + util.c -o $@ decode_frame: decode_frame.c gcc $(CFLAGS) $(LIBAV_DECODE_FLAGS) decode_frame.c -o $@ diff --git a/src/advtime.c b/src/advtime.c index 6144cc3..217b7ed 100644 --- a/src/advtime.c +++ b/src/advtime.c @@ -5,6 +5,7 @@ #include #include "video_decode.h" +#include "util.h" static double frame_diff(struct video_frame *frame_a, struct video_frame *frame_b) @@ -63,6 +64,8 @@ main(int argc, char **argv) int ret, ch; int diff_flag = 0, average_flag = 0; int64_t timestamp = 0; + double diff = 0.0; + char filename[BUFSIZ]; while ((ch = getopt(argc, argv, "ad")) != -1) { switch (ch) { @@ -94,11 +97,27 @@ main(int argc, char **argv) if (ret < 0) return -ret; - while (video_decode_get_frame(vd, &frame_b) == 0) { + for (int i = 0; video_decode_get_frame(vd, &frame_b) == 0; ++i) { + + printf("%d\t", i); + if (average_flag == 1) - printf("%f\n", frame_average(frame_a)); + printf("%f", frame_average(frame_a)); + + if (average_flag == 1 && diff_flag == 1) + printf("\t"); + if (diff_flag == 1) - printf("%f\n", frame_diff(frame_a, frame_b)); + printf("%f", diff = frame_diff(frame_a, frame_b)); + + if (diff > 40.0) { + snprintf(filename, BUFSIZ, "img/%04i.pgm", i); + frame_mix_pgm_save(frame_a, frame_b, filename); +// pgm_save(frame_a->data, frame_a->stride, frame_a->width, +// frame_a->height, filename); + } + + printf("\n"); video_decode_free_frame(&frame_a); frame_a = frame_b; } diff --git a/src/util.c b/src/util.c index bd4b7b8..4e496a4 100644 --- a/src/util.c +++ b/src/util.c @@ -1,3 +1,8 @@ +#include + +#include "video_decode.h" +#include "util.h" + void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename) { @@ -10,3 +15,30 @@ pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename) fwrite(buf + i * wrap, 1, xsize, f); fclose(f); } + +void +frame_mix_pgm_save(struct video_frame *frame_a, struct video_frame *frame_b, + char *filename) +{ + uint8_t *row_a = frame_a->data, *col_a = NULL; + uint8_t *row_b = frame_b->data, *col_b = NULL; + + for (int y = 0; y < frame_a->height; ++y) { + col_a = row_a; + col_b = row_b; + for (int x = 0; x < frame_a->width; ++x) { + if (x > frame_a->width / 2) + *col_a = *col_b; + col_a++; + col_b++; + } + row_a += frame_a->stride; + row_b += frame_b->stride; + } + + FILE *f = fopen(filename, "w"); + fprintf(f, "P5\n%d %d\n%d\n", frame_a->width, frame_a->height, 255); + for (int i = 0; i < frame_a->height; i++) + fwrite(frame_a->data+i*frame_a->stride, 1, frame_a->width, f); + fclose(f); +} diff --git a/src/util.h b/src/util.h index a58585e..e6f9bcf 100644 --- a/src/util.h +++ b/src/util.h @@ -3,5 +3,8 @@ void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename); +void +frame_mix_pgm_save(struct video_frame *frame_a, struct video_frame *frame_b, + char *filename); #endif /* _UTIL_H_ */ -- cgit