#include #include "video_decode.h" #include "util.h" int pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename) { FILE *f; int i; f = fopen(filename, "w"); if (f == NULL) return -1; 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); return 0; } void frame_mix(struct video_frame *frame_a, struct video_frame *frame_b) { 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; } } /* 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); }