diff options
author | Jan Klemkow <j.klemkow@wemelug.de> | 2012-11-15 08:25:35 +0100 |
---|---|---|
committer | Jan Klemkow <j.klemkow@wemelug.de> | 2012-11-15 08:25:35 +0100 |
commit | c7c47cdf23892f7209bbd2acaf420a8d34336406 (patch) | |
tree | 80b1abbaedd13de9bd188b91c63a887ded603286 | |
parent | bfcb903f8ff64c55cf3b4d0789369be495e5dac8 (diff) | |
download | advtime-c7c47cdf23892f7209bbd2acaf420a8d34336406.tar.gz advtime-c7c47cdf23892f7209bbd2acaf420a8d34336406.tar.bz2 advtime-c7c47cdf23892f7209bbd2acaf420a8d34336406.zip |
Add frame mix saving for high diffs.
-rw-r--r-- | src/Makefile | 11 | ||||
-rw-r--r-- | src/advtime.c | 25 | ||||
-rw-r--r-- | src/util.c | 32 | ||||
-rw-r--r-- | 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 <unistd.h> #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; } @@ -1,3 +1,8 @@ +#include <stdio.h> + +#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); +} @@ -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_ */ |