diff options
Diffstat (limited to 'src/frame_to_pgm.c')
-rw-r--r-- | src/frame_to_pgm.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/frame_to_pgm.c b/src/frame_to_pgm.c new file mode 100644 index 0000000..f018099 --- /dev/null +++ b/src/frame_to_pgm.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +#include "video_decode.h" + +static void +pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename) +{ + FILE *f; + int i; + + f = fopen(filename, "w"); + fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255); + for(i=0; i < ysize; i++) + fwrite(buf + i * wrap, 1, xsize, f); + fclose(f); +} + +int +main(int argc, char **argv) +{ + struct video_decode *vd; + struct video_frame *frame; + int ret; + int64_t timestamp = 0; + + if (argc < 3) + return 1; + + if (argc == 4 && strtol(argv[3], NULL, 10) > 0) + timestamp = strtol(argv[3], NULL, 10); + + ret = video_decode_init(&vd, argv[1], timestamp); + if (ret < 0) + return -ret; + + ret = video_decode_get_frame(vd, &frame); + if (ret < 0) + return -ret; + + pgm_save(frame->data, frame->stride, frame->width, frame->height, + argv[2]); +} |