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/rawenc.h"
44#include "common/y4menc.h"
47#include "third_party/libyuv/include/libyuv/scale.h"
50static const char *exec_name;
52struct AvxDecInputContext {
53 struct AvxInputContext *aom_input_ctx;
54 struct ObuDecInputContext *obu_ctx;
55 struct WebmInputContext *webm_ctx;
58static const arg_def_t help =
59 ARG_DEF(NULL,
"help", 0,
"Show usage options and exit");
60static const arg_def_t looparg =
61 ARG_DEF(NULL,
"loops", 1,
"Number of times to decode the file");
62static const arg_def_t codecarg = ARG_DEF(NULL,
"codec", 1,
"Codec to use");
63static const arg_def_t use_yv12 =
64 ARG_DEF(NULL,
"yv12", 0,
"Output raw YV12 frames");
65static const arg_def_t use_i420 =
66 ARG_DEF(NULL,
"i420", 0,
"Output raw I420 frames");
67static const arg_def_t flipuvarg =
68 ARG_DEF(NULL,
"flipuv", 0,
"Flip the chroma planes in the output");
69static const arg_def_t rawvideo =
70 ARG_DEF(NULL,
"rawvideo", 0,
"Output raw YUV frames");
71static const arg_def_t noblitarg =
72 ARG_DEF(NULL,
"noblit", 0,
"Don't process the decoded frames");
73static const arg_def_t progressarg =
74 ARG_DEF(NULL,
"progress", 0,
"Show progress after each frame decodes");
75static const arg_def_t limitarg =
76 ARG_DEF(NULL,
"limit", 1,
"Stop decoding after n frames");
77static const arg_def_t skiparg =
78 ARG_DEF(NULL,
"skip", 1,
"Skip the first n input frames");
79static const arg_def_t summaryarg =
80 ARG_DEF(NULL,
"summary", 0,
"Show timing summary");
81static const arg_def_t outputfile =
82 ARG_DEF(
"o",
"output", 1,
"Output file name pattern (see below)");
83static const arg_def_t threadsarg =
84 ARG_DEF(
"t",
"threads", 1,
"Max threads to use");
85static const arg_def_t rowmtarg =
86 ARG_DEF(NULL,
"row-mt", 1,
"Enable row based multi-threading, default: 0");
87static const arg_def_t verbosearg =
88 ARG_DEF(
"v",
"verbose", 0,
"Show version string");
89static const arg_def_t scalearg =
90 ARG_DEF(
"S",
"scale", 0,
"Scale output frames uniformly");
91static const arg_def_t continuearg =
92 ARG_DEF(
"k",
"keep-going", 0,
"(debug) Continue decoding after error");
93static const arg_def_t fb_arg =
94 ARG_DEF(NULL,
"frame-buffers", 1,
"Number of frame buffers to use");
95static const arg_def_t md5arg =
96 ARG_DEF(NULL,
"md5", 0,
"Compute the MD5 sum of the decoded frame");
97static const arg_def_t framestatsarg =
98 ARG_DEF(NULL,
"framestats", 1,
"Output per-frame stats (.csv format)");
99static const arg_def_t outbitdeptharg =
100 ARG_DEF(NULL,
"output-bit-depth", 1,
"Output bit-depth for decoded frames");
101static const arg_def_t isannexb =
102 ARG_DEF(NULL,
"annexb", 0,
"Bitstream is in Annex-B format");
103static const arg_def_t oppointarg = ARG_DEF(
104 NULL,
"oppoint", 1,
"Select an operating point of a scalable bitstream");
105static const arg_def_t outallarg = ARG_DEF(
106 NULL,
"all-layers", 0,
"Output all decoded frames of a scalable bitstream");
107static const arg_def_t skipfilmgrain =
108 ARG_DEF(NULL,
"skip-film-grain", 0,
"Skip film grain application");
110static const arg_def_t *all_args[] = {
111 &help, &codecarg, &use_yv12, &use_i420,
112 &flipuvarg, &rawvideo, &noblitarg, &progressarg,
113 &limitarg, &skiparg, &summaryarg, &outputfile,
114 &threadsarg, &rowmtarg, &verbosearg, &scalearg,
115 &fb_arg, &md5arg, &framestatsarg, &continuearg,
116 &outbitdeptharg, &isannexb, &oppointarg, &outallarg,
123 FilterModeEnum mode) {
124 if (src->
fmt != dst->
fmt) {
126 "%s failed to scale output frame because format changed from %s to "
128 exec_name, image_format_to_string(dst->
fmt),
129 image_format_to_string(src->
fmt));
151 fprintf(stderr,
"%s cannot scale output frame of format %s\n", exec_name,
152 image_format_to_string(src->
fmt));
157static void show_help(FILE *fout,
int shorthelp) {
158 fprintf(fout,
"Usage: %s <options> filename\n\n", exec_name);
161 fprintf(fout,
"Use --help to see the full list of options.\n");
165 fprintf(fout,
"Options:\n");
166 arg_show_usage(fout, all_args);
168 "\nOutput File Patterns:\n\n"
169 " The -o argument specifies the name of the file(s) to "
170 "write to. If the\n argument does not include any escape "
171 "characters, the output will be\n written to a single file. "
172 "Otherwise, the filename will be calculated by\n expanding "
173 "the following escape characters:\n");
175 "\n\t%%w - Frame width"
176 "\n\t%%h - Frame height"
177 "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
178 "\n\n Pattern arguments are only supported in conjunction "
179 "with the --yv12 and\n --i420 options. If the -o option is "
180 "not specified, the output will be\n directed to stdout.\n");
181 fprintf(fout,
"\nIncluded decoders:\n\n");
183 for (
int i = 0; i < get_aom_decoder_count(); ++i) {
185 fprintf(fout,
" %-6s - %s\n", get_short_name_by_aom_decoder(decoder),
190void usage_exit(
void) {
191 show_help(stderr, 1);
195static int raw_read_frame(
struct AvxInputContext *input_ctx, uint8_t **buffer,
196 size_t *bytes_read,
size_t *buffer_size) {
197 unsigned char raw_hdr[RAW_FRAME_HDR_SZ];
198 size_t frame_size = 0;
200 if (read_from_input(input_ctx, RAW_FRAME_HDR_SZ, raw_hdr) !=
202 if (!input_eof(input_ctx))
203 aom_tools_warn(
"Failed to read RAW frame size\n");
205 const size_t kCorruptFrameThreshold = 256 * 1024 * 1024;
206 const size_t kFrameTooSmallThreshold = 256 * 1024;
207 frame_size = mem_get_le32(raw_hdr);
209 if (frame_size > kCorruptFrameThreshold) {
210 aom_tools_warn(
"Read invalid frame size (%u)\n",
211 (
unsigned int)frame_size);
215 if (frame_size < kFrameTooSmallThreshold) {
217 "Warning: Read invalid frame size (%u) - not a raw file?\n",
218 (
unsigned int)frame_size);
221 if (frame_size > *buffer_size) {
222 uint8_t *new_buf = realloc(*buffer, 2 * frame_size);
225 *buffer_size = 2 * frame_size;
227 aom_tools_warn(
"Failed to allocate compressed data buffer\n");
233 if (!input_eof(input_ctx)) {
234 if (read_from_input(input_ctx, frame_size, *buffer) != frame_size) {
235 aom_tools_warn(
"Failed to read full frame\n");
238 *bytes_read = frame_size;
245static int read_frame(
struct AvxDecInputContext *input, uint8_t **buf,
246 size_t *bytes_in_buffer,
size_t *buffer_size) {
247 switch (input->aom_input_ctx->file_type) {
250 return webm_read_frame(input->webm_ctx, buf, bytes_in_buffer,
254 return raw_read_frame(input->aom_input_ctx, buf, bytes_in_buffer,
257 return ivf_read_frame(input->aom_input_ctx, buf, bytes_in_buffer,
260 return obudec_read_temporal_unit(input->obu_ctx, buf, bytes_in_buffer,
266static int file_is_raw(
struct AvxInputContext *input) {
270 memset(&si, 0,
sizeof(si));
272 if (buffer_input(input, 32, buf,
true) == 32) {
275 if (mem_get_le32(buf) < 256 * 1024 * 1024) {
276 for (i = 0; i < get_aom_decoder_count(); ++i) {
280 input->fourcc = get_fourcc_by_aom_decoder(decoder);
282 input->height = si.
h;
283 input->framerate.numerator = 30;
284 input->framerate.denominator = 1;
291 rewind_detect(input);
295static void show_progress(
int frame_in,
int frame_out, uint64_t dx_time) {
297 "%d decoded frames/%d showed frames in %" PRId64
" us (%.2f fps)\r",
298 frame_in, frame_out, dx_time,
299 (
double)frame_out * 1000000.0 / (
double)dx_time);
302struct ExternalFrameBuffer {
308struct ExternalFrameBufferList {
309 int num_external_frame_buffers;
310 struct ExternalFrameBuffer *ext_fb;
317static int get_av1_frame_buffer(
void *cb_priv,
size_t min_size,
320 struct ExternalFrameBufferList *
const ext_fb_list =
321 (
struct ExternalFrameBufferList *)cb_priv;
322 if (ext_fb_list == NULL)
return -1;
325 for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) {
326 if (!ext_fb_list->ext_fb[i].in_use)
break;
329 if (i == ext_fb_list->num_external_frame_buffers)
return -1;
331 if (ext_fb_list->ext_fb[i].size < min_size) {
332 free(ext_fb_list->ext_fb[i].data);
333 ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size,
sizeof(uint8_t));
334 if (!ext_fb_list->ext_fb[i].data)
return -1;
336 ext_fb_list->ext_fb[i].size = min_size;
339 fb->
data = ext_fb_list->ext_fb[i].data;
340 fb->
size = ext_fb_list->ext_fb[i].size;
341 ext_fb_list->ext_fb[i].in_use = 1;
344 fb->
priv = &ext_fb_list->ext_fb[i];
351static int release_av1_frame_buffer(
void *cb_priv,
353 struct ExternalFrameBuffer *
const ext_fb =
354 (
struct ExternalFrameBuffer *)fb->
priv;
360static void generate_filename(
const char *pattern,
char *out,
size_t q_len,
361 unsigned int d_w,
unsigned int d_h,
362 unsigned int frame_in) {
363 const char *p = pattern;
367 char *next_pat = strchr(p,
'%');
375 case 'w': snprintf(q, q_len - 1,
"%d", d_w);
break;
376 case 'h': snprintf(q, q_len - 1,
"%d", d_h);
break;
377 case '1': snprintf(q, q_len - 1,
"%d", frame_in);
break;
378 case '2': snprintf(q, q_len - 1,
"%02d", frame_in);
break;
379 case '3': snprintf(q, q_len - 1,
"%03d", frame_in);
break;
380 case '4': snprintf(q, q_len - 1,
"%04d", frame_in);
break;
381 case '5': snprintf(q, q_len - 1,
"%05d", frame_in);
break;
382 case '6': snprintf(q, q_len - 1,
"%06d", frame_in);
break;
383 case '7': snprintf(q, q_len - 1,
"%07d", frame_in);
break;
384 case '8': snprintf(q, q_len - 1,
"%08d", frame_in);
break;
385 case '9': snprintf(q, q_len - 1,
"%09d", frame_in);
break;
386 default: die(
"Unrecognized pattern %%%c\n", p[1]);
390 if (pat_len >= q_len - 1) die(
"Output filename too long.\n");
399 copy_len = strlen(p);
401 copy_len = next_pat - p;
403 if (copy_len >= q_len - 1) die(
"Output filename too long.\n");
405 memcpy(q, p, copy_len);
414static int is_single_file(
const char *outfile_pattern) {
415 const char *p = outfile_pattern;
419 if (p && p[1] >=
'1' && p[1] <=
'9')
427static void print_md5(
unsigned char digest[16],
const char *filename) {
430 for (i = 0; i < 16; ++i) printf(
"%02x", digest[i]);
431 printf(
" %s\n", filename);
434static FILE *open_outfile(
const char *name) {
435 if (strcmp(
"-", name) == 0) {
436 set_binary_mode(stdout);
439 FILE *file = fopen(name,
"wb");
440 if (!file) fatal(
"Failed to open output file '%s'", name);
445static int main_loop(
int argc,
const char **argv_) {
449 int ret = EXIT_FAILURE;
451 size_t bytes_in_buffer = 0, buffer_size = 0;
453 int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0;
454 int do_md5 = 0, progress = 0;
455 int stop_after = 0, summary = 0, quiet = 1;
458 uint64_t dx_time = 0;
460 char **argv, **argi, **argj;
468 unsigned int fixed_output_bit_depth = 0;
469 unsigned int is_annexb = 0;
470 int frames_corrupted = 0;
473 int operating_point = 0;
474 int output_all_layers = 0;
475 int skip_film_grain = 0;
476 int enable_row_mt = 0;
479 int frame_avail, got_data, flush_decoder = 0;
480 int num_external_frame_buffers = 0;
481 struct ExternalFrameBufferList ext_fb_list = { 0, NULL };
483 const char *outfile_pattern = NULL;
484 char outfile_name[PATH_MAX] = { 0 };
485 FILE *outfile = NULL;
487 FILE *framestats_file = NULL;
490 unsigned char md5_digest[16];
492 struct AvxDecInputContext input = { NULL, NULL, NULL };
493 struct AvxInputContext aom_input_ctx;
494 memset(&aom_input_ctx, 0,
sizeof(aom_input_ctx));
496 struct WebmInputContext webm_ctx;
497 memset(&webm_ctx, 0,
sizeof(webm_ctx));
498 input.webm_ctx = &webm_ctx;
500 struct ObuDecInputContext obu_ctx = { NULL, NULL, 0, 0, 0 };
503 obu_ctx.avx_ctx = &aom_input_ctx;
504 input.obu_ctx = &obu_ctx;
505 input.aom_input_ctx = &aom_input_ctx;
508 exec_name = argv_[0];
509 argv = argv_dup(argc - 1, argv_ + 1);
511 fprintf(stderr,
"Error allocating argument list\n");
516 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
517 memset(&arg, 0,
sizeof(arg));
520 if (arg_match(&arg, &help, argi)) {
521 show_help(stdout, 0);
523 }
else if (arg_match(&arg, &codecarg, argi)) {
524 interface = get_aom_decoder_by_short_name(arg.val);
526 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
527 }
else if (arg_match(&arg, &looparg, argi)) {
529 }
else if (arg_match(&arg, &outputfile, argi)) {
530 outfile_pattern = arg.val;
531 }
else if (arg_match(&arg, &use_yv12, argi)) {
537 }
else if (arg_match(&arg, &use_i420, argi)) {
543 }
else if (arg_match(&arg, &rawvideo, argi)) {
548 }
else if (arg_match(&arg, &flipuvarg, argi)) {
550 }
else if (arg_match(&arg, &noblitarg, argi)) {
552 }
else if (arg_match(&arg, &progressarg, argi)) {
554 }
else if (arg_match(&arg, &limitarg, argi)) {
555 stop_after = arg_parse_uint(&arg);
556 }
else if (arg_match(&arg, &skiparg, argi)) {
557 arg_skip = arg_parse_uint(&arg);
558 }
else if (arg_match(&arg, &md5arg, argi)) {
560 }
else if (arg_match(&arg, &framestatsarg, argi)) {
561 framestats_file = fopen(arg.val,
"w");
562 if (!framestats_file) {
563 die(
"Error: Could not open --framestats file (%s) for writing.\n",
566 }
else if (arg_match(&arg, &summaryarg, argi)) {
568 }
else if (arg_match(&arg, &threadsarg, argi)) {
569 cfg.
threads = arg_parse_uint(&arg);
570#if !CONFIG_MULTITHREAD
572 die(
"Error: --threads=%d is not supported when CONFIG_MULTITHREAD = "
577 }
else if (arg_match(&arg, &rowmtarg, argi)) {
578 enable_row_mt = arg_parse_uint(&arg);
579 }
else if (arg_match(&arg, &verbosearg, argi)) {
581 }
else if (arg_match(&arg, &scalearg, argi)) {
583 }
else if (arg_match(&arg, &fb_arg, argi)) {
584 num_external_frame_buffers = arg_parse_uint(&arg);
585 }
else if (arg_match(&arg, &continuearg, argi)) {
587 }
else if (arg_match(&arg, &outbitdeptharg, argi)) {
588 fixed_output_bit_depth = arg_parse_uint(&arg);
589 }
else if (arg_match(&arg, &isannexb, argi)) {
591 input.obu_ctx->is_annexb = 1;
592 }
else if (arg_match(&arg, &oppointarg, argi)) {
593 operating_point = arg_parse_int(&arg);
594 }
else if (arg_match(&arg, &outallarg, argi)) {
595 output_all_layers = 1;
596 }
else if (arg_match(&arg, &skipfilmgrain, argi)) {
604 for (argi = argv; *argi; argi++)
605 if (argi[0][0] ==
'-' && strlen(argi[0]) > 1)
606 die(
"Error: Unrecognized option %s\n", *argi);
613 fprintf(stderr,
"No input file specified!\n");
617 const bool using_file = strcmp(fn,
"-") != 0;
619 infile = using_file ? fopen(fn,
"rb") : set_binary_mode(stdin);
622 fatal(
"Failed to open input file '%s'", using_file ? fn :
"stdin");
626 if (!outfile_pattern && isatty(STDOUT_FILENO) && !do_md5 && !noblit) {
628 "Not dumping raw video to your terminal. Use '-o -' to "
634 input.aom_input_ctx->filename = fn;
635 input.aom_input_ctx->file = infile;
643 }
else if (using_file && file_is_webm(input.webm_ctx, input.aom_input_ctx)) {
644 input.aom_input_ctx->file_type = FILE_TYPE_WEBM;
646 }
else if (file_is_ivf(input.aom_input_ctx)) {
647 input.aom_input_ctx->file_type = FILE_TYPE_IVF;
649 }
else if (file_is_obu(&obu_ctx)) {
650 input.aom_input_ctx->file_type = FILE_TYPE_OBU;
651 }
else if (file_is_raw(input.aom_input_ctx)) {
652 input.aom_input_ctx->file_type = FILE_TYPE_RAW;
654 fprintf(stderr,
"Unrecognized input file type.\n");
657 fprintf(stderr,
"aomdec does not support piped WebM input.\n");
660 fprintf(stderr,
"aomdec was built without WebM container support.\n");
666 outfile_pattern = outfile_pattern ? outfile_pattern :
"-";
667 single_file = is_single_file(outfile_pattern);
669 if (!noblit && single_file) {
670 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
671 aom_input_ctx.width, aom_input_ctx.height, 0);
675 outfile = open_outfile(outfile_name);
678 if (use_y4m && !noblit) {
681 "YUV4MPEG2 not supported with output patterns,"
682 " try --i420 or --yv12 or --rawvideo.\n");
687 if (aom_input_ctx.file_type == FILE_TYPE_WEBM) {
688 if (webm_guess_framerate(input.webm_ctx, input.aom_input_ctx)) {
690 "Failed to guess framerate -- error parsing "
699 get_aom_decoder_by_fourcc(aom_input_ctx.fourcc);
701 if (is_ivf && !fourcc_interface)
702 fatal(
"Unsupported fourcc: %x\n", aom_input_ctx.fourcc);
704 if (interface && fourcc_interface && interface != fourcc_interface)
705 aom_tools_warn(
"Header indicates codec: %s\n",
708 interface = fourcc_interface;
710 if (!interface)
interface = get_aom_decoder_by_index(0);
714 fprintf(stderr,
"Failed to initialize decoder: %s\n",
719 if (!quiet) fprintf(stderr,
"%s\n", decoder.
name);
722 fprintf(stderr,
"Failed to set is_annexb: %s\n",
aom_codec_error(&decoder));
728 fprintf(stderr,
"Failed to set operating_point: %s\n",
734 output_all_layers)) {
735 fprintf(stderr,
"Failed to set output_all_layers: %s\n",
742 fprintf(stderr,
"Failed to set skip_film_grain: %s\n",
748 fprintf(stderr,
"Failed to set row multithreading mode: %s\n",
753 if (arg_skip) fprintf(stderr,
"Skipping first %d frames.\n", arg_skip);
755 if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size))
break;
759 if (num_external_frame_buffers > 0) {
760 ext_fb_list.num_external_frame_buffers = num_external_frame_buffers;
761 ext_fb_list.ext_fb = (
struct ExternalFrameBuffer *)calloc(
762 num_external_frame_buffers,
sizeof(*ext_fb_list.ext_fb));
763 if (!ext_fb_list.ext_fb) {
764 fprintf(stderr,
"Failed to allocate ExternalFrameBuffer\n");
768 release_av1_frame_buffer,
770 fprintf(stderr,
"Failed to configure external frame buffers: %s\n",
779 if (framestats_file) fprintf(framestats_file,
"bytes,qp\r\n");
782 while (frame_avail || got_data) {
785 struct aom_usec_timer timer;
789 if (!stop_after || frame_in < stop_after) {
790 if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) {
794 aom_usec_timer_start(&timer);
798 aom_tools_warn(
"Failed to decode frame %d: %s", frame_in,
801 if (detail) aom_tools_warn(
"Additional information: %s", detail);
802 if (!keep_going)
goto fail;
805 if (framestats_file) {
809 aom_tools_warn(
"Failed AOMD_GET_LAST_QUANTIZER: %s",
811 if (!keep_going)
goto fail;
813 fprintf(framestats_file,
"%d,%d\r\n", (
int)bytes_in_buffer, qp);
816 aom_usec_timer_mark(&timer);
817 dx_time += aom_usec_timer_elapsed(&timer);
825 aom_usec_timer_start(&timer);
830 aom_tools_warn(
"Failed to flush decoder: %s",
835 aom_usec_timer_mark(&timer);
836 dx_time += aom_usec_timer_elapsed(&timer);
847 aom_tools_warn(
"Failed AOM_GET_FRAME_CORRUPTED: %s",
849 if (!keep_going)
goto fail;
851 frames_corrupted += corrupted;
853 if (progress) show_progress(frame_in, frame_out, dx_time);
858 const int *planes = flipuv ? PLANES_YVU : PLANES_YUV;
861 if (frame_out == 1) {
867 int render_width = aom_input_ctx.width;
868 int render_height = aom_input_ctx.height;
869 if (!render_width || !render_height) {
874 render_width = img->
d_w;
875 render_height = img->
d_h;
877 render_width = render_size[0];
878 render_height = render_size[1];
884 fprintf(stderr,
"Failed to allocate scaled image (%d x %d)\n",
885 render_width, render_height);
890 scaled_img->
csp = img->
csp;
893 if (img->
d_w != scaled_img->
d_w || img->
d_h != scaled_img->
d_h) {
895 if (libyuv_scale(img, scaled_img, kFilterBox) != 0)
goto fail;
900 "Failed to scale output frame: %s.\n"
901 "libyuv is required for scaling but is currently disabled.\n"
902 "Be sure to specify -DCONFIG_LIBYUV=1 when running cmake.\n",
909 unsigned int output_bit_depth;
910 if (!fixed_output_bit_depth && single_file) {
913 output_bit_depth = fixed_output_bit_depth;
916 if (output_bit_depth != 0) {
917 if (!aom_shift_img(output_bit_depth, &img, &img_shifted)) {
918 fprintf(stderr,
"Error allocating image\n");
923 aom_input_ctx.width = img->
d_w;
924 aom_input_ctx.height = img->
d_h;
926 int num_planes = (opt_raw && img->
monochrome) ? 1 : 3;
929 char y4m_buf[Y4M_BUFFER_SIZE] = { 0 };
931 if (frame_out == 1) {
933 len = y4m_write_file_header(
934 y4m_buf,
sizeof(y4m_buf), aom_input_ctx.width,
935 aom_input_ctx.height, &aom_input_ctx.framerate,
940 "Warning: Y4M lacks a colorspace for colocated "
941 "chroma. Using a placeholder.\n");
944 MD5Update(&md5_ctx, (md5byte *)y4m_buf, (
unsigned int)len);
946 fputs(y4m_buf, outfile);
951 len = y4m_write_frame_header(y4m_buf,
sizeof(y4m_buf));
953 MD5Update(&md5_ctx, (md5byte *)y4m_buf, (
unsigned int)len);
954 y4m_update_image_md5(img, planes, &md5_ctx);
956 fputs(y4m_buf, outfile);
957 y4m_write_image_file(img, planes, outfile);
960 if (frame_out == 1) {
967 "Cannot produce i420 output for bit-stream.\n");
976 "Cannot produce yv12 output for bit-stream.\n");
982 raw_update_image_md5(img, planes, num_planes, &md5_ctx);
984 raw_write_image_file(img, planes, num_planes, outfile);
988 generate_filename(outfile_pattern, outfile_name, PATH_MAX, img->
d_w,
993 y4m_update_image_md5(img, planes, &md5_ctx);
995 raw_update_image_md5(img, planes, num_planes, &md5_ctx);
997 MD5Final(md5_digest, &md5_ctx);
998 print_md5(md5_digest, outfile_name);
1000 outfile = open_outfile(outfile_name);
1002 y4m_write_image_file(img, planes, outfile);
1004 raw_write_image_file(img, planes, num_planes, outfile);
1013 if (summary || progress) {
1014 show_progress(frame_in, frame_out, dx_time);
1015 fprintf(stderr,
"\n");
1018 if (frames_corrupted) {
1019 fprintf(stderr,
"WARNING: %d frames corrupted.\n", frames_corrupted);
1027 fprintf(stderr,
"Failed to destroy decoder: %s\n",
1033 if (!noblit && single_file) {
1035 MD5Final(md5_digest, &md5_ctx);
1036 print_md5(md5_digest, outfile_name);
1043 if (input.aom_input_ctx->file_type == FILE_TYPE_WEBM)
1044 webm_free(input.webm_ctx);
1046 if (input.aom_input_ctx->file_type == FILE_TYPE_OBU)
1047 obudec_free(input.obu_ctx);
1049 if (input.aom_input_ctx->file_type != FILE_TYPE_WEBM) free(buf);
1054 for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) {
1055 free(ext_fb_list.ext_fb[i].data);
1057 free(ext_fb_list.ext_fb);
1060 if (framestats_file) fclose(framestats_file);
1067int main(
int argc,
const char **argv_) {
1068 unsigned int loops = 1, i;
1069 char **argv, **argi, **argj;
1073 argv = argv_dup(argc - 1, argv_ + 1);
1075 fprintf(stderr,
"Error allocating argument list\n");
1076 return EXIT_FAILURE;
1078 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
1079 memset(&arg, 0,
sizeof(arg));
1082 if (arg_match(&arg, &looparg, argi)) {
1083 loops = arg_parse_uint(&arg);
1088 for (i = 0; !error && i < loops; i++) error = main_loop(argc, argv_);
Describes the decoder algorithm interface to applications.
#define AOM_PLANE_U
Definition aom_image.h:240
@ AOM_CSP_COLOCATED
Definition aom_image.h:159
#define AOM_PLANE_Y
Definition aom_image.h:239
#define AOM_PLANE_V
Definition aom_image.h:241
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_IMG_FMT_I42016
Definition aom_image.h:65
@ AOM_IMG_FMT_I420
Definition aom_image.h:45
@ AOM_IMG_FMT_YV12
Definition aom_image.h:43
void aom_img_free(aom_image_t *img)
Close an image descriptor.
Provides definitions for using AOM or AV1 within the aom Decoder interface.
@ AOMD_GET_FRAME_CORRUPTED
Codec control function to check if the indicated frame is corrupted, int* parameter.
Definition aomdx.h:204
@ AV1D_SET_SKIP_FILM_GRAIN
Codec control function to set the skip film grain flag, int parameter.
Definition aomdx.h:390
@ AV1D_SET_IS_ANNEXB
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter.
Definition aomdx.h:352
@ AV1D_SET_ROW_MT
Codec control function to enable the row based multi-threading of decoding, unsigned int parameter.
Definition aomdx.h:347
@ AV1D_GET_DISPLAY_SIZE
Codec control function to get the current frame's intended display dimensions (as specified in the wr...
Definition aomdx.h:225
@ AV1D_SET_OUTPUT_ALL_LAYERS
Codec control function to indicate whether to output one frame per temporal unit (the default),...
Definition aomdx.h:374
@ AV1D_SET_OPERATING_POINT
Codec control function to indicate which operating point to use, int parameter.
Definition aomdx.h:362
@ AOMD_GET_LAST_QUANTIZER
Codec control function to get last decoded frame quantizer, int* parameter.
Definition aomdx.h:297
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.
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:271
const char * aom_codec_error(const aom_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition aom_codec.h:542
const char * aom_codec_error_detail(const aom_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
const void * aom_codec_iter_t
Iterator.
Definition aom_codec.h:305
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.
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:133
Codec context structure.
Definition aom_codec.h:315
const char * name
Definition aom_codec.h:316
Initialization Configurations.
Definition aom_decoder.h:91
unsigned int threads
Definition aom_decoder.h:92
External frame buffer.
Definition aom_frame_buffer.h:40
uint8_t * data
Definition aom_frame_buffer.h:41
size_t size
Definition aom_frame_buffer.h:42
void * priv
Definition aom_frame_buffer.h:43
Initialization-time Feature Enabling.
Definition aom_decoder.h:71
unsigned int h
Definition aom_decoder.h:73
unsigned int w
Definition aom_decoder.h:72
Image Descriptor.
Definition aom_image.h:211
unsigned int bit_depth
Definition aom_image.h:223
aom_chroma_sample_position_t csp
Definition aom_image.h:217
aom_img_fmt_t fmt
Definition aom_image.h:212
int stride[3]
Definition aom_image.h:250
unsigned int d_w
Definition aom_image.h:226
int monochrome
Definition aom_image.h:216
unsigned int d_h
Definition aom_image.h:227
aom_color_range_t range
Definition aom_image.h:218
unsigned char * planes[3]
Definition aom_image.h:244