18#include "../tools_common.h"
19#include "../vp9/encoder/vp9_resize.h"
21static const char *exec_name = NULL;
25 printf(
"%s <input_yuv> <width>x<height> <target_width>x<target_height> ",
27 printf(
"<output_yuv> [<frames>]\n");
30void usage_exit(
void) {
35static int parse_dim(
char *v,
int *width,
int *height) {
36 char *x = strchr(v,
'x');
37 if (x == NULL) x = strchr(v,
'X');
38 if (x == NULL)
return 0;
40 *height = atoi(&x[1]);
41 if (*width <= 0 || *height <= 0)
47int main(
int argc,
char *argv[]) {
50 uint8_t *inbuf, *outbuf;
51 uint8_t *inbuf_u, *outbuf_u;
52 uint8_t *inbuf_v, *outbuf_v;
54 int width, height, target_width, target_height;
60 printf(
"Incorrect parameters:\n");
67 if (!parse_dim(argv[2], &width, &height)) {
68 printf(
"Incorrect parameters: %s\n", argv[2]);
72 if (!parse_dim(argv[3], &target_width, &target_height)) {
73 printf(
"Incorrect parameters: %s\n", argv[3]);
78 fpin = fopen(fin,
"rb");
80 printf(
"Can't open file %s to read\n", fin);
84 fpout = fopen(fout,
"wb");
87 printf(
"Can't open file %s to write\n", fout);
92 frames = atoi(argv[5]);
96 printf(
"Input size: %dx%d\n", width, height);
97 printf(
"Target size: %dx%d, Frames: ", target_width, target_height);
98 if (frames == INT_MAX)
101 printf(
"%d\n", frames);
103 inbuf = (uint8_t *)malloc(width * height * 3 / 2);
104 outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2);
105 if (!(inbuf && outbuf)) {
106 printf(
"Failed to allocate buffers.\n");
110 inbuf_u = inbuf + width * height;
111 inbuf_v = inbuf_u + width * height / 4;
112 outbuf_u = outbuf + target_width * target_height;
113 outbuf_v = outbuf_u + target_width * target_height / 4;
116 if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1)
break;
117 vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2, height,
118 width, outbuf, target_width, outbuf_u, outbuf_v,
119 target_width / 2, target_height, target_width);
120 fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout);
123 printf(
"%d frames processed\n", f);