19 #include "config/aom_config.h" 24 #elif !defined(STDOUT_FILENO) 25 #define STDOUT_FILENO 1 31 #include "aom_ports/aom_timer.h" 32 #include "aom_ports/mem_ops.h" 33 #include "common/args.h" 34 #include "common/ivfdec.h" 35 #include "common/md5_utils.h" 36 #include "common/obudec.h" 37 #include "common/tools_common.h" 40 #include "common/webmdec.h" 43 #include "common/y4menc.h" 46 #include "third_party/libyuv/include/libyuv/scale.h" 49 static const char *exec_name;
51 struct AvxDecInputContext {
52 struct AvxInputContext *aom_input_ctx;
53 struct ObuDecInputContext *obu_ctx;
54 struct WebmInputContext *webm_ctx;
57 static const arg_def_t help =
58 ARG_DEF(NULL,
"help", 0,
"Show usage options and exit");
59 static const arg_def_t looparg =
60 ARG_DEF(NULL,
"loops", 1,
"Number of times to decode the file");
61 static const arg_def_t codecarg = ARG_DEF(NULL,
"codec", 1,
"Codec to use");
62 static const arg_def_t use_yv12 =
63 ARG_DEF(NULL,
"yv12", 0,
"Output raw YV12 frames");
64 static const arg_def_t use_i420 =
65 ARG_DEF(NULL,
"i420", 0,
"Output raw I420 frames");
66 static const arg_def_t flipuvarg =
67 ARG_DEF(NULL,
"flipuv", 0,
"Flip the chroma planes in the output");
68 static const arg_def_t rawvideo =
69 ARG_DEF(NULL,
"rawvideo", 0,
"Output raw YUV frames");
70 static const arg_def_t noblitarg =
71 ARG_DEF(NULL,
"noblit", 0,
"Don't process the decoded frames");
72 static const arg_def_t progressarg =
73 ARG_DEF(NULL,
"progress", 0,
"Show progress after each frame decodes");
74 static const arg_def_t limitarg =
75 ARG_DEF(NULL,
"limit", 1,
"Stop decoding after n frames");
76 static const arg_def_t skiparg =
77 ARG_DEF(NULL,
"skip", 1,
"Skip the first n input frames");
78 static const arg_def_t postprocarg =
79 ARG_DEF(NULL,
"postproc", 0,
"Postprocess decoded frames");
80 static const arg_def_t summaryarg =
81 ARG_DEF(NULL,
"summary", 0,
"Show timing summary");
82 static const arg_def_t outputfile =
83 ARG_DEF(
"o",
"output", 1,
"Output file name pattern (see below)");
84 static const arg_def_t threadsarg =
85 ARG_DEF(
"t",
"threads", 1,
"Max threads to use");
86 static const arg_def_t verbosearg =
87 ARG_DEF(
"v",
"verbose", 0,
"Show version string");
88 static const arg_def_t scalearg =
89 ARG_DEF(
"S",
"scale", 0,
"Scale output frames uniformly");
90 static const arg_def_t continuearg =
91 ARG_DEF(
"k",
"keep-going", 0,
"(debug) Continue decoding after error");
92 static const arg_def_t fb_arg =
93 ARG_DEF(NULL,
"frame-buffers", 1,
"Number of frame buffers to use");
94 static const arg_def_t md5arg =
95 ARG_DEF(NULL,
"md5", 0,
"Compute the MD5 sum of the decoded frame");
96 static const arg_def_t framestatsarg =
97 ARG_DEF(NULL,
"framestats", 1,
"Output per-frame stats (.csv format)");
98 static const arg_def_t outbitdeptharg =
99 ARG_DEF(NULL,
"output-bit-depth", 1,
"Output bit-depth for decoded frames");
100 static const arg_def_t tilem = ARG_DEF(NULL,
"tile-mode", 1,
102 "(0 for normal tile coding mode)");
103 static const arg_def_t tiler = ARG_DEF(NULL,
"tile-row", 1,
104 "Row index of tile to decode " 105 "(-1 for all rows)");
106 static const arg_def_t tilec = ARG_DEF(NULL,
"tile-column", 1,
107 "Column index of tile to decode " 108 "(-1 for all columns)");
109 static const arg_def_t isannexb =
110 ARG_DEF(NULL,
"annexb", 0,
"Bitstream is in Annex-B format");
111 static const arg_def_t oppointarg = ARG_DEF(
112 NULL,
"oppoint", 1,
"Select an operating point of a scalable bitstream");
113 static const arg_def_t outallarg = ARG_DEF(
114 NULL,
"all-layers", 0,
"Output all decoded frames of a scalable bitstream");
116 static const arg_def_t *all_args[] = {
117 &help, &codecarg, &use_yv12, &use_i420, &flipuvarg,
118 &rawvideo, &noblitarg, &progressarg, &limitarg, &skiparg,
119 &postprocarg, &summaryarg, &outputfile, &threadsarg, &verbosearg,
120 &scalearg, &fb_arg, &md5arg, &framestatsarg, &continuearg,
121 &outbitdeptharg, &tilem, &tiler, &tilec, &isannexb,
122 &oppointarg, &outallarg, NULL
127 FilterModeEnum mode) {
151 void show_help(FILE *fout,
int shorthelp) {
152 fprintf(fout,
"Usage: %s <options> filename\n\n", exec_name);
155 fprintf(fout,
"Use --help to see the full list of options.\n");
159 fprintf(fout,
"Options:\n");
160 arg_show_usage(fout, all_args);
162 "\nOutput File Patterns:\n\n" 163 " The -o argument specifies the name of the file(s) to " 164 "write to. If the\n argument does not include any escape " 165 "characters, the output will be\n written to a single file. " 166 "Otherwise, the filename will be calculated by\n expanding " 167 "the following escape characters:\n");
169 "\n\t%%w - Frame width" 170 "\n\t%%h - Frame height" 171 "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)" 172 "\n\n Pattern arguments are only supported in conjunction " 173 "with the --yv12 and\n --i420 options. If the -o option is " 174 "not specified, the output will be\n directed to stdout.\n");
175 fprintf(fout,
"\nIncluded decoders:\n\n");
177 for (
int i = 0; i < get_aom_decoder_count(); ++i) {
178 const AvxInterface *
const decoder = get_aom_decoder_by_index(i);
179 fprintf(fout,
" %-6s - %s\n", decoder->name,
184 void usage_exit(
void) {
185 show_help(stderr, 1);
189 static int raw_read_frame(FILE *infile, uint8_t **buffer,
size_t *bytes_read,
190 size_t *buffer_size) {
191 char raw_hdr[RAW_FRAME_HDR_SZ];
192 size_t frame_size = 0;
194 if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) {
195 if (!feof(infile)) warn(
"Failed to read RAW frame size\n");
197 const size_t kCorruptFrameThreshold = 256 * 1024 * 1024;
198 const size_t kFrameTooSmallThreshold = 256 * 1024;
199 frame_size = mem_get_le32(raw_hdr);
201 if (frame_size > kCorruptFrameThreshold) {
202 warn(
"Read invalid frame size (%u)\n", (
unsigned int)frame_size);
206 if (frame_size < kFrameTooSmallThreshold) {
207 warn(
"Warning: Read invalid frame size (%u) - not a raw file?\n",
208 (
unsigned int)frame_size);
211 if (frame_size > *buffer_size) {
212 uint8_t *new_buf = realloc(*buffer, 2 * frame_size);
215 *buffer_size = 2 * frame_size;
217 warn(
"Failed to allocate compressed data buffer\n");
224 if (fread(*buffer, 1, frame_size, infile) != frame_size) {
225 warn(
"Failed to read full frame\n");
228 *bytes_read = frame_size;
234 static int read_frame(
struct AvxDecInputContext *input, uint8_t **buf,
235 size_t *bytes_in_buffer,
size_t *buffer_size) {
236 switch (input->aom_input_ctx->file_type) {
239 return webm_read_frame(input->webm_ctx, buf, bytes_in_buffer,
243 return raw_read_frame(input->aom_input_ctx->file, buf, bytes_in_buffer,
246 return ivf_read_frame(input->aom_input_ctx->file, buf, bytes_in_buffer,
249 return obudec_read_temporal_unit(input->obu_ctx, buf, bytes_in_buffer,
255 static void update_image_md5(
const aom_image_t *img,
const int planes[3],
259 for (i = 0; i < 3; ++i) {
260 const int plane = planes[i];
261 const unsigned char *buf = img->
planes[plane];
262 const int stride = img->
stride[plane];
267 for (y = 0; y < h; ++y) {
268 MD5Update(md5, buf, w);
274 static void write_image_file(
const aom_image_t *img,
const int *planes,
275 const int num_planes, FILE *file) {
279 for (i = 0; i < num_planes; ++i) {
280 const int plane = planes[i];
281 const unsigned char *buf = img->
planes[plane];
282 const int stride = img->
stride[plane];
286 for (y = 0; y < h; ++y) {
287 fwrite(buf, bytes_per_sample, w, file);
293 static int file_is_raw(
struct AvxInputContext *input) {
297 memset(&si, 0,
sizeof(si));
299 if (fread(buf, 1, 32, input->file) == 32) {
302 if (mem_get_le32(buf) < 256 * 1024 * 1024) {
303 for (i = 0; i < get_aom_decoder_count(); ++i) {
304 const AvxInterface *
const decoder = get_aom_decoder_by_index(i);
308 input->fourcc = decoder->fourcc;
310 input->height = si.
h;
311 input->framerate.numerator = 30;
312 input->framerate.denominator = 1;
323 static void show_progress(
int frame_in,
int frame_out, uint64_t dx_time) {
325 "%d decoded frames/%d showed frames in %" PRId64
" us (%.2f fps)\r",
326 frame_in, frame_out, dx_time,
327 (
double)frame_out * 1000000.0 / (
double)dx_time);
330 struct ExternalFrameBuffer {
336 struct ExternalFrameBufferList {
337 int num_external_frame_buffers;
338 struct ExternalFrameBuffer *ext_fb;
345 static int get_av1_frame_buffer(
void *cb_priv,
size_t min_size,
348 struct ExternalFrameBufferList *
const ext_fb_list =
349 (
struct ExternalFrameBufferList *)cb_priv;
350 if (ext_fb_list == NULL)
return -1;
353 for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) {
354 if (!ext_fb_list->ext_fb[i].in_use)
break;
357 if (i == ext_fb_list->num_external_frame_buffers)
return -1;
359 if (ext_fb_list->ext_fb[i].size < min_size) {
360 free(ext_fb_list->ext_fb[i].data);
361 ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size,
sizeof(uint8_t));
362 if (!ext_fb_list->ext_fb[i].data)
return -1;
364 ext_fb_list->ext_fb[i].size = min_size;
367 fb->
data = ext_fb_list->ext_fb[i].data;
368 fb->
size = ext_fb_list->ext_fb[i].size;
369 ext_fb_list->ext_fb[i].in_use = 1;
372 fb->
priv = &ext_fb_list->ext_fb[i];
379 static int release_av1_frame_buffer(
void *cb_priv,
381 struct ExternalFrameBuffer *
const ext_fb =
382 (
struct ExternalFrameBuffer *)fb->
priv;
388 static void generate_filename(
const char *pattern,
char *out,
size_t q_len,
389 unsigned int d_w,
unsigned int d_h,
390 unsigned int frame_in) {
391 const char *p = pattern;
395 char *next_pat = strchr(p,
'%');
403 case 'w': snprintf(q, q_len - 1,
"%d", d_w);
break;
404 case 'h': snprintf(q, q_len - 1,
"%d", d_h);
break;
405 case '1': snprintf(q, q_len - 1,
"%d", frame_in);
break;
406 case '2': snprintf(q, q_len - 1,
"%02d", frame_in);
break;
407 case '3': snprintf(q, q_len - 1,
"%03d", frame_in);
break;
408 case '4': snprintf(q, q_len - 1,
"%04d", frame_in);
break;
409 case '5': snprintf(q, q_len - 1,
"%05d", frame_in);
break;
410 case '6': snprintf(q, q_len - 1,
"%06d", frame_in);
break;
411 case '7': snprintf(q, q_len - 1,
"%07d", frame_in);
break;
412 case '8': snprintf(q, q_len - 1,
"%08d", frame_in);
break;
413 case '9': snprintf(q, q_len - 1,
"%09d", frame_in);
break;
414 default: die(
"Unrecognized pattern %%%c\n", p[1]);
break;
418 if (pat_len >= q_len - 1) die(
"Output filename too long.\n");
427 copy_len = strlen(p);
429 copy_len = next_pat - p;
431 if (copy_len >= q_len - 1) die(
"Output filename too long.\n");
433 memcpy(q, p, copy_len);
442 static int is_single_file(
const char *outfile_pattern) {
443 const char *p = outfile_pattern;
447 if (p && p[1] >=
'1' && p[1] <=
'9')
455 static void print_md5(
unsigned char digest[16],
const char *filename) {
458 for (i = 0; i < 16; ++i) printf(
"%02x", digest[i]);
459 printf(
" %s\n", filename);
462 static FILE *open_outfile(
const char *name) {
463 if (strcmp(
"-", name) == 0) {
464 set_binary_mode(stdout);
467 FILE *file = fopen(name,
"wb");
468 if (!file) fatal(
"Failed to open output file '%s'", name);
473 static int img_shifted_realloc_required(
const aom_image_t *img,
476 return img->
d_w != shifted->
d_w || img->
d_h != shifted->
d_h ||
477 required_fmt != shifted->
fmt;
480 static int main_loop(
int argc,
const char **argv_) {
484 int ret = EXIT_FAILURE;
486 size_t bytes_in_buffer = 0, buffer_size = 0;
488 int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0;
489 int do_md5 = 0, progress = 0;
490 int stop_after = 0, postproc = 0, summary = 0, quiet = 1;
493 const AvxInterface *
interface = NULL;
494 const AvxInterface *fourcc_interface = NULL;
495 uint64_t dx_time = 0;
497 char **argv, **argi, **argj;
505 unsigned int output_bit_depth = 0;
506 unsigned int tile_mode = 0;
507 unsigned int is_annexb = 0;
510 int frames_corrupted = 0;
513 int operating_point = 0;
514 int output_all_layers = 0;
517 int frame_avail, got_data, flush_decoder = 0;
518 int num_external_frame_buffers = 0;
519 struct ExternalFrameBufferList ext_fb_list = { 0, NULL };
521 const char *outfile_pattern = NULL;
522 char outfile_name[PATH_MAX] = { 0 };
523 FILE *outfile = NULL;
525 FILE *framestats_file = NULL;
528 unsigned char md5_digest[16];
530 struct AvxDecInputContext input = { NULL, NULL, NULL };
531 struct AvxInputContext aom_input_ctx;
532 memset(&aom_input_ctx, 0,
sizeof(aom_input_ctx));
534 struct WebmInputContext webm_ctx;
535 memset(&webm_ctx, 0,
sizeof(webm_ctx));
536 input.webm_ctx = &webm_ctx;
538 struct ObuDecInputContext obu_ctx = { NULL, NULL, 0, 0, 0 };
540 obu_ctx.avx_ctx = &aom_input_ctx;
541 input.obu_ctx = &obu_ctx;
542 input.aom_input_ctx = &aom_input_ctx;
545 exec_name = argv_[0];
546 argv = argv_dup(argc - 1, argv_ + 1);
548 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
549 memset(&arg, 0,
sizeof(arg));
552 if (arg_match(&arg, &help, argi)) {
553 show_help(stdout, 0);
555 }
else if (arg_match(&arg, &codecarg, argi)) {
556 interface = get_aom_decoder_by_name(arg.val);
558 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
559 }
else if (arg_match(&arg, &looparg, argi)) {
561 }
else if (arg_match(&arg, &outputfile, argi)) {
562 outfile_pattern = arg.val;
563 }
else if (arg_match(&arg, &use_yv12, argi)) {
569 }
else if (arg_match(&arg, &use_i420, argi)) {
575 }
else if (arg_match(&arg, &rawvideo, argi)) {
580 }
else if (arg_match(&arg, &flipuvarg, argi)) {
582 }
else if (arg_match(&arg, &noblitarg, argi)) {
584 }
else if (arg_match(&arg, &progressarg, argi)) {
586 }
else if (arg_match(&arg, &limitarg, argi)) {
587 stop_after = arg_parse_uint(&arg);
588 }
else if (arg_match(&arg, &skiparg, argi)) {
589 arg_skip = arg_parse_uint(&arg);
590 }
else if (arg_match(&arg, &postprocarg, argi)) {
592 }
else if (arg_match(&arg, &md5arg, argi)) {
594 }
else if (arg_match(&arg, &framestatsarg, argi)) {
595 framestats_file = fopen(arg.val,
"w");
596 if (!framestats_file) {
597 die(
"Error: Could not open --framestats file (%s) for writing.\n",
600 }
else if (arg_match(&arg, &summaryarg, argi)) {
602 }
else if (arg_match(&arg, &threadsarg, argi)) {
603 cfg.
threads = arg_parse_uint(&arg);
604 }
else if (arg_match(&arg, &verbosearg, argi)) {
606 }
else if (arg_match(&arg, &scalearg, argi)) {
608 }
else if (arg_match(&arg, &fb_arg, argi)) {
609 num_external_frame_buffers = arg_parse_uint(&arg);
610 }
else if (arg_match(&arg, &continuearg, argi)) {
612 }
else if (arg_match(&arg, &outbitdeptharg, argi)) {
613 output_bit_depth = arg_parse_uint(&arg);
614 }
else if (arg_match(&arg, &tilem, argi)) {
615 tile_mode = arg_parse_int(&arg);
616 }
else if (arg_match(&arg, &isannexb, argi)) {
618 input.obu_ctx->is_annexb = 1;
619 }
else if (arg_match(&arg, &tiler, argi)) {
620 tile_row = arg_parse_int(&arg);
621 }
else if (arg_match(&arg, &tilec, argi)) {
622 tile_col = arg_parse_int(&arg);
623 }
else if (arg_match(&arg, &oppointarg, argi)) {
624 operating_point = arg_parse_int(&arg);
625 }
else if (arg_match(&arg, &outallarg, argi)) {
626 output_all_layers = 1;
633 for (argi = argv; *argi; argi++)
634 if (argi[0][0] ==
'-' && strlen(argi[0]) > 1)
635 die(
"Error: Unrecognized option %s\n", *argi);
642 fprintf(stderr,
"No input file specified!\n");
646 infile = strcmp(fn,
"-") ? fopen(fn,
"rb") : set_binary_mode(stdin);
649 fatal(
"Failed to open input file '%s'", strcmp(fn,
"-") ? fn :
"stdin");
651 #if CONFIG_OS_SUPPORT 653 if (!outfile_pattern && isatty(STDOUT_FILENO) && !do_md5 && !noblit) {
655 "Not dumping raw video to your terminal. Use '-o -' to " 660 input.aom_input_ctx->filename = fn;
661 input.aom_input_ctx->file = infile;
662 if (file_is_ivf(input.aom_input_ctx))
663 input.aom_input_ctx->file_type = FILE_TYPE_IVF;
665 else if (file_is_webm(input.webm_ctx, input.aom_input_ctx))
666 input.aom_input_ctx->file_type = FILE_TYPE_WEBM;
668 else if (file_is_obu(&obu_ctx))
669 input.aom_input_ctx->file_type = FILE_TYPE_OBU;
670 else if (file_is_raw(input.aom_input_ctx))
671 input.aom_input_ctx->file_type = FILE_TYPE_RAW;
673 fprintf(stderr,
"Unrecognized input file type.\n");
675 fprintf(stderr,
"aomdec was built without WebM container support.\n");
680 outfile_pattern = outfile_pattern ? outfile_pattern :
"-";
681 single_file = is_single_file(outfile_pattern);
683 if (!noblit && single_file) {
684 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
685 aom_input_ctx.width, aom_input_ctx.height, 0);
689 outfile = open_outfile(outfile_name);
692 if (use_y4m && !noblit) {
695 "YUV4MPEG2 not supported with output patterns," 696 " try --i420 or --yv12 or --rawvideo.\n");
701 if (aom_input_ctx.file_type == FILE_TYPE_WEBM) {
702 if (webm_guess_framerate(input.webm_ctx, input.aom_input_ctx)) {
704 "Failed to guess framerate -- error parsing " 712 fourcc_interface = get_aom_decoder_by_fourcc(aom_input_ctx.fourcc);
713 if (interface && fourcc_interface && interface != fourcc_interface)
714 warn(
"Header indicates codec: %s\n", fourcc_interface->name);
716 interface = fourcc_interface;
718 if (!interface)
interface = get_aom_decoder_by_index(0);
723 fprintf(stderr,
"Failed to initialize decoder: %s\n",
728 if (!quiet) fprintf(stderr,
"%s\n", decoder.
name);
730 #if CONFIG_AV1_DECODER 732 fprintf(stderr,
"Failed to set decode_tile_mode: %s\n",
738 fprintf(stderr,
"Failed to set is_annexb: %s\n",
aom_codec_error(&decoder));
743 fprintf(stderr,
"Failed to set decode_tile_row: %s\n",
749 fprintf(stderr,
"Failed to set decode_tile_col: %s\n",
755 fprintf(stderr,
"Failed to set operating_point: %s\n",
761 output_all_layers)) {
762 fprintf(stderr,
"Failed to set output_all_layers: %s\n",
768 if (arg_skip) fprintf(stderr,
"Skipping first %d frames.\n", arg_skip);
770 if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size))
break;
774 if (num_external_frame_buffers > 0) {
775 ext_fb_list.num_external_frame_buffers = num_external_frame_buffers;
776 ext_fb_list.ext_fb = (
struct ExternalFrameBuffer *)calloc(
777 num_external_frame_buffers,
sizeof(*ext_fb_list.ext_fb));
779 release_av1_frame_buffer,
781 fprintf(stderr,
"Failed to configure external frame buffers: %s\n",
790 if (framestats_file) fprintf(framestats_file,
"bytes,qp\r\n");
793 while (frame_avail || got_data) {
796 struct aom_usec_timer timer;
800 if (!stop_after || frame_in < stop_after) {
801 if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) {
805 aom_usec_timer_start(&timer);
809 warn(
"Failed to decode frame %d: %s", frame_in,
812 if (detail) warn(
"Additional information: %s", detail);
813 if (!keep_going)
goto fail;
816 if (framestats_file) {
819 warn(
"Failed AOMD_GET_LAST_QUANTIZER: %s",
821 if (!keep_going)
goto fail;
823 fprintf(framestats_file,
"%d,%d\r\n", (
int)bytes_in_buffer, qp);
826 aom_usec_timer_mark(&timer);
827 dx_time += aom_usec_timer_elapsed(&timer);
835 aom_usec_timer_start(&timer);
844 aom_usec_timer_mark(&timer);
845 dx_time += aom_usec_timer_elapsed(&timer);
854 if (!keep_going)
goto fail;
856 frames_corrupted += corrupted;
858 if (progress) show_progress(frame_in, frame_out, dx_time);
863 const int *planes = flipuv ? PLANES_YVU : PLANES_YUV;
866 if (frame_out == 1) {
872 int render_width = aom_input_ctx.width;
873 int render_height = aom_input_ctx.height;
874 if (!render_width || !render_height) {
879 render_width = img->
d_w;
880 render_height = img->
d_h;
882 render_width = render_size[0];
883 render_height = render_size[1];
891 if (img->
d_w != scaled_img->
d_w || img->
d_h != scaled_img->
d_h) {
893 libyuv_scale(img, scaled_img, kFilterBox);
898 "Failed to scale output frame: %s.\n" 899 "libyuv is required for scaling but is currently disabled.\n" 900 "Be sure to specify -DCONFIG_LIBYUV=1 when running cmake.\n",
907 if (!output_bit_depth && single_file && !do_md5) {
911 if (output_bit_depth != 0) {
913 output_bit_depth == 8
917 if (shifted_fmt != img->
fmt || output_bit_depth != img->
bit_depth) {
919 img_shifted_realloc_required(img, img_shifted, shifted_fmt)) {
926 img_shifted->
bit_depth = output_bit_depth;
930 aom_img_upshift(img_shifted, img,
933 aom_img_downshift(img_shifted, img,
940 aom_input_ctx.width = img->
d_w;
941 aom_input_ctx.height = img->
d_h;
943 int num_planes = (!use_y4m && opt_raw && img->
monochrome) ? 1 : 3;
947 char y4m_buf[Y4M_BUFFER_SIZE] = { 0 };
949 if (frame_out == 1) {
951 len = y4m_write_file_header(
952 y4m_buf,
sizeof(y4m_buf), aom_input_ctx.width,
953 aom_input_ctx.height, &aom_input_ctx.framerate, img->
fmt,
956 MD5Update(&md5_ctx, (md5byte *)y4m_buf, (
unsigned int)len);
958 fputs(y4m_buf, outfile);
963 len = y4m_write_frame_header(y4m_buf,
sizeof(y4m_buf));
965 MD5Update(&md5_ctx, (md5byte *)y4m_buf, (
unsigned int)len);
967 fputs(y4m_buf, outfile);
970 if (frame_out == 1) {
977 "Cannot produce i420 output for bit-stream.\n");
986 "Cannot produce yv12 output for bit-stream.\n");
994 update_image_md5(img, planes, &md5_ctx);
996 write_image_file(img, planes, num_planes, outfile);
999 generate_filename(outfile_pattern, outfile_name, PATH_MAX, img->
d_w,
1000 img->
d_h, frame_in);
1003 update_image_md5(img, planes, &md5_ctx);
1004 MD5Final(md5_digest, &md5_ctx);
1005 print_md5(md5_digest, outfile_name);
1007 outfile = open_outfile(outfile_name);
1008 write_image_file(img, planes, num_planes, outfile);
1016 if (summary || progress) {
1017 show_progress(frame_in, frame_out, dx_time);
1018 fprintf(stderr,
"\n");
1021 if (frames_corrupted) {
1022 fprintf(stderr,
"WARNING: %d frames corrupted.\n", frames_corrupted);
1030 fprintf(stderr,
"Failed to destroy decoder: %s\n",
1036 if (!noblit && single_file) {
1038 MD5Final(md5_digest, &md5_ctx);
1039 print_md5(md5_digest, outfile_name);
1046 if (input.aom_input_ctx->file_type == FILE_TYPE_WEBM)
1047 webm_free(input.webm_ctx);
1049 if (input.aom_input_ctx->file_type == FILE_TYPE_OBU)
1050 obudec_free(input.obu_ctx);
1052 if (input.aom_input_ctx->file_type != FILE_TYPE_WEBM) free(buf);
1057 for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) {
1058 free(ext_fb_list.ext_fb[i].data);
1060 free(ext_fb_list.ext_fb);
1063 if (framestats_file) fclose(framestats_file);
1070 int main(
int argc,
const char **argv_) {
1071 unsigned int loops = 1, i;
1072 char **argv, **argi, **argj;
1076 argv = argv_dup(argc - 1, argv_ + 1);
1077 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
1078 memset(&arg, 0,
sizeof(arg));
1081 if (arg_match(&arg, &looparg, argi)) {
1082 loops = arg_parse_uint(&arg);
1087 for (i = 0; !error && i < loops; i++) error = main_loop(argc, argv_);
#define AOM_PLANE_U
Definition: aom_image.h:170
unsigned int d_h
Definition: aom_image.h:157
#define AOM_PLANE_V
Definition: aom_image.h:171
aom_codec_err_t aom_codec_peek_stream_info(aom_codec_iface_t *iface, const uint8_t *data, size_t data_sz, aom_codec_stream_info_t *si)
Parse stream info from a buffer.
aom_image_t * aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Decoded frames iterator.
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
const char * name
Definition: aom_codec.h:205
uint8_t * data
Definition: aom_frame_buffer.h:41
Codec context structure.
Definition: aom_codec.h:204
int stride[4]
Definition: aom_image.h:174
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
External frame buffer.
Definition: aom_frame_buffer.h:40
Describes the decoder algorithm interface to applications.
int monochrome
Definition: aom_image.h:146
Image Descriptor.
Definition: aom_image.h:141
aom_image_t * aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, size_t data_sz, void *user_priv)
Decode data.
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition: aom_decoder.h:142
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
void * priv
Definition: aom_frame_buffer.h:43
void aom_img_free(aom_image_t *img)
Close an image descriptor.
unsigned int h
Definition: aom_decoder.h:85
Initialization Configurations.
Definition: aom_decoder.h:103
#define aom_codec_control(ctx, id, data)
aom_codec_control wrapper macro
Definition: aom_codec.h:423
int aom_img_plane_width(const aom_image_t *img, int plane)
Get the width of a plane.
Stream properties.
Definition: aom_decoder.h:83
unsigned int w
Definition: aom_decoder.h:84
int aom_img_plane_height(const aom_image_t *img, int plane)
Get the height of a plane.
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:194
size_t size
Definition: aom_frame_buffer.h:42
const char * aom_codec_error(aom_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
Definition: aom_image.h:52
Provides definitions for using AOM or AV1 within the aom Decoder interface.
aom_codec_err_t aom_codec_set_frame_buffer_functions(aom_codec_ctx_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get, aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv)
Pass in external frame buffers for the decoder to use.
Definition: aom_image.h:45
const char * aom_codec_error_detail(aom_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
unsigned int threads
Definition: aom_decoder.h:104
unsigned int bit_depth
Definition: aom_image.h:153
unsigned char * planes[4]
Definition: aom_image.h:173
unsigned int d_w
Definition: aom_image.h:156
Definition: aom_image.h:43
aom_img_fmt_t fmt
Definition: aom_image.h:142
#define AOM_CODEC_USE_POSTPROC
Definition: aom_decoder.h:73
#define AOM_PLANE_Y
Definition: aom_image.h:169