18#include "./vpx_config.h"
21#include "third_party/libyuv/include/libyuv/scale.h"
28#include "vpx_ports/mem_ops.h"
29#include "vpx_ports/vpx_timer.h"
31#if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
35#include "./md5_utils.h"
37#include "./tools_common.h"
43static const char *exec_name;
45struct VpxDecInputContext {
46 struct VpxInputContext *vpx_input_ctx;
47 struct WebmInputContext *webm_ctx;
50static const arg_def_t help =
51 ARG_DEF(NULL,
"help", 0,
"Show usage options and exit");
52static const arg_def_t looparg =
53 ARG_DEF(NULL,
"loops", 1,
"Number of times to decode the file");
54static const arg_def_t codecarg = ARG_DEF(NULL,
"codec", 1,
"Codec to use");
55static const arg_def_t use_yv12 =
56 ARG_DEF(NULL,
"yv12", 0,
"Output raw YV12 frames");
57static const arg_def_t use_i420 =
58 ARG_DEF(NULL,
"i420", 0,
"Output raw I420 frames");
59static const arg_def_t flipuvarg =
60 ARG_DEF(NULL,
"flipuv", 0,
"Flip the chroma planes in the output");
61static const arg_def_t rawvideo =
62 ARG_DEF(NULL,
"rawvideo", 0,
"Output raw YUV frames");
63static const arg_def_t noblitarg =
64 ARG_DEF(NULL,
"noblit", 0,
"Don't process the decoded frames");
65static const arg_def_t progressarg =
66 ARG_DEF(NULL,
"progress", 0,
"Show progress after each frame decodes");
67static const arg_def_t limitarg =
68 ARG_DEF(NULL,
"limit", 1,
"Stop decoding after n frames");
69static const arg_def_t skiparg =
70 ARG_DEF(NULL,
"skip", 1,
"Skip the first n input frames");
71static const arg_def_t postprocarg =
72 ARG_DEF(NULL,
"postproc", 0,
"Postprocess decoded frames");
73static const arg_def_t summaryarg =
74 ARG_DEF(NULL,
"summary", 0,
"Show timing summary");
75static const arg_def_t outputfile =
76 ARG_DEF(
"o",
"output", 1,
"Output file name pattern (see below)");
77static const arg_def_t threadsarg =
78 ARG_DEF(
"t",
"threads", 1,
"Max threads to use");
79static const arg_def_t frameparallelarg =
80 ARG_DEF(NULL,
"frame-parallel", 0,
"Frame parallel decode (ignored)");
81static const arg_def_t verbosearg =
82 ARG_DEF(
"v",
"verbose", 0,
"Show version string");
83static const arg_def_t error_concealment =
84 ARG_DEF(NULL,
"error-concealment", 0,
"Enable decoder error-concealment");
85static const arg_def_t scalearg =
86 ARG_DEF(
"S",
"scale", 0,
"Scale output frames uniformly");
87static const arg_def_t continuearg =
88 ARG_DEF(
"k",
"keep-going", 0,
"(debug) Continue decoding after error");
89static const arg_def_t fb_arg =
90 ARG_DEF(NULL,
"frame-buffers", 1,
"Number of frame buffers to use");
91static const arg_def_t md5arg =
92 ARG_DEF(NULL,
"md5", 0,
"Compute the MD5 sum of the decoded frame");
93#if CONFIG_VP9_HIGHBITDEPTH
94static const arg_def_t outbitdeptharg =
95 ARG_DEF(NULL,
"output-bit-depth", 1,
"Output bit-depth for decoded frames");
97static const arg_def_t svcdecodingarg = ARG_DEF(
98 NULL,
"svc-decode-layer", 1,
"Decode SVC stream up to given spatial layer");
99static const arg_def_t framestatsarg =
100 ARG_DEF(NULL,
"framestats", 1,
"Output per-frame stats (.csv format)");
101static const arg_def_t rowmtarg =
102 ARG_DEF(NULL,
"row-mt", 1,
"Enable multi-threading to run row-wise in VP9");
103static const arg_def_t lpfoptarg =
104 ARG_DEF(NULL,
"lpf-opt", 1,
105 "Do loopfilter without waiting for all threads to sync.");
107static const arg_def_t *all_args[] = { &help,
128#if CONFIG_VP9_HIGHBITDEPTH
137#if CONFIG_VP8_DECODER
138static const arg_def_t addnoise_level =
139 ARG_DEF(NULL,
"noise-level", 1,
"Enable VP8 postproc add noise");
140static const arg_def_t deblock =
141 ARG_DEF(NULL,
"deblock", 0,
"Enable VP8 deblocking");
142static const arg_def_t demacroblock_level = ARG_DEF(
143 NULL,
"demacroblock-level", 1,
"Enable VP8 demacroblocking, w/ level");
144static const arg_def_t mfqe =
145 ARG_DEF(NULL,
"mfqe", 0,
"Enable multiframe quality enhancement");
147static const arg_def_t *vp8_pp_args[] = { &addnoise_level, &deblock,
148 &demacroblock_level, &mfqe, NULL };
153 FilterModeEnum mode) {
154#if CONFIG_VP9_HIGHBITDEPTH
178static void show_help(FILE *fout,
int shorthelp) {
181 fprintf(fout,
"Usage: %s <options> filename\n\n", exec_name);
184 fprintf(fout,
"Use --help to see the full list of options.\n");
188 fprintf(fout,
"Options:\n");
189 arg_show_usage(fout, all_args);
190#if CONFIG_VP8_DECODER
191 fprintf(fout,
"\nVP8 Postprocessing Options:\n");
192 arg_show_usage(fout, vp8_pp_args);
195 "\nOutput File Patterns:\n\n"
196 " The -o argument specifies the name of the file(s) to "
197 "write to. If the\n argument does not include any escape "
198 "characters, the output will be\n written to a single file. "
199 "Otherwise, the filename will be calculated by\n expanding "
200 "the following escape characters:\n");
202 "\n\t%%w - Frame width"
203 "\n\t%%h - Frame height"
204 "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
205 "\n\n Pattern arguments are only supported in conjunction "
206 "with the --yv12 and\n --i420 options. If the -o option is "
207 "not specified, the output will be\n directed to stdout.\n");
208 fprintf(fout,
"\nIncluded decoders:\n\n");
210 for (i = 0; i < get_vpx_decoder_count(); ++i) {
211 const VpxInterface *
const decoder = get_vpx_decoder_by_index(i);
212 fprintf(fout,
" %-6s - %s\n", decoder->name,
217void usage_exit(
void) {
218 show_help(stderr, 1);
222static int raw_read_frame(FILE *infile, uint8_t **buffer,
size_t *bytes_read,
223 size_t *buffer_size) {
224 char raw_hdr[RAW_FRAME_HDR_SZ];
225 size_t frame_size = 0;
227 if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) {
228 if (!feof(infile)) warn(
"Failed to read RAW frame size\n");
230 const size_t kCorruptFrameThreshold = 256 * 1024 * 1024;
231 const size_t kFrameTooSmallThreshold = 256 * 1024;
232 frame_size = mem_get_le32(raw_hdr);
234 if (frame_size > kCorruptFrameThreshold) {
235 warn(
"Read invalid frame size (%u)\n", (
unsigned int)frame_size);
239 if (frame_size < kFrameTooSmallThreshold) {
240 warn(
"Warning: Read invalid frame size (%u) - not a raw file?\n",
241 (
unsigned int)frame_size);
244 if (frame_size > *buffer_size) {
245 uint8_t *new_buf = realloc(*buffer, 2 * frame_size);
248 *buffer_size = 2 * frame_size;
250 warn(
"Failed to allocate compressed data buffer\n");
257 if (fread(*buffer, 1, frame_size, infile) != frame_size) {
258 warn(
"Failed to read full frame\n");
261 *bytes_read = frame_size;
268static int dec_read_frame(
struct VpxDecInputContext *input, uint8_t **buf,
269 size_t *bytes_in_buffer,
size_t *buffer_size) {
270 switch (input->vpx_input_ctx->file_type) {
273 return webm_read_frame(input->webm_ctx, buf, bytes_in_buffer);
276 return raw_read_frame(input->vpx_input_ctx->file, buf, bytes_in_buffer,
279 return ivf_read_frame(input->vpx_input_ctx->file, buf, bytes_in_buffer,
285static void update_image_md5(
const vpx_image_t *img,
const int planes[3],
289 for (i = 0; i < 3; ++i) {
290 const int plane = planes[i];
291 const unsigned char *buf = img->
planes[plane];
292 const int stride = img->
stride[plane];
293 const int w = vpx_img_plane_width(img, plane) *
295 const int h = vpx_img_plane_height(img, plane);
297 for (y = 0; y < h; ++y) {
298 MD5Update(md5, buf, w);
304static void write_image_file(
const vpx_image_t *img,
const int planes[3],
307#if CONFIG_VP9_HIGHBITDEPTH
310 const int bytes_per_sample = 1;
313 for (i = 0; i < 3; ++i) {
314 const int plane = planes[i];
315 const unsigned char *buf = img->
planes[plane];
316 const int stride = img->
stride[plane];
317 const int w = vpx_img_plane_width(img, plane);
318 const int h = vpx_img_plane_height(img, plane);
320 for (y = 0; y < h; ++y) {
321 fwrite(buf, bytes_per_sample, w, file);
327static int file_is_raw(
struct VpxInputContext *input) {
334 if (fread(buf, 1, 32, input->file) == 32) {
337 if (mem_get_le32(buf) < 256 * 1024 * 1024) {
338 for (i = 0; i < get_vpx_decoder_count(); ++i) {
339 const VpxInterface *
const decoder = get_vpx_decoder_by_index(i);
343 input->fourcc = decoder->fourcc;
345 input->height = si.
h;
346 input->framerate.numerator = 30;
347 input->framerate.denominator = 1;
358static void show_progress(
int frame_in,
int frame_out, uint64_t dx_time) {
360 "%d decoded frames/%d showed frames in %" PRId64
" us (%.2f fps)\r",
361 frame_in, frame_out, dx_time,
362 (
double)frame_out * 1000000.0 / (
double)dx_time);
365struct ExternalFrameBuffer {
371struct ExternalFrameBufferList {
372 int num_external_frame_buffers;
373 struct ExternalFrameBuffer *ext_fb;
380static int get_vp9_frame_buffer(
void *cb_priv,
size_t min_size,
383 struct ExternalFrameBufferList *
const ext_fb_list =
384 (
struct ExternalFrameBufferList *)cb_priv;
385 if (ext_fb_list == NULL)
return -1;
388 for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) {
389 if (!ext_fb_list->ext_fb[i].in_use)
break;
392 if (i == ext_fb_list->num_external_frame_buffers)
return -1;
394 if (ext_fb_list->ext_fb[i].size < min_size) {
395 free(ext_fb_list->ext_fb[i].data);
396 ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size,
sizeof(uint8_t));
397 if (!ext_fb_list->ext_fb[i].data)
return -1;
399 ext_fb_list->ext_fb[i].size = min_size;
402 fb->
data = ext_fb_list->ext_fb[i].data;
403 fb->
size = ext_fb_list->ext_fb[i].size;
404 ext_fb_list->ext_fb[i].in_use = 1;
407 fb->
priv = &ext_fb_list->ext_fb[i];
414static int release_vp9_frame_buffer(
void *cb_priv,
416 struct ExternalFrameBuffer *
const ext_fb =
417 (
struct ExternalFrameBuffer *)fb->
priv;
423static void generate_filename(
const char *pattern,
char *out,
size_t q_len,
424 unsigned int d_w,
unsigned int d_h,
425 unsigned int frame_in) {
426 const char *p = pattern;
430 char *next_pat = strchr(p,
'%');
438 case 'w': snprintf(q, q_len - 1,
"%d", d_w);
break;
439 case 'h': snprintf(q, q_len - 1,
"%d", d_h);
break;
440 case '1': snprintf(q, q_len - 1,
"%d", frame_in);
break;
441 case '2': snprintf(q, q_len - 1,
"%02d", frame_in);
break;
442 case '3': snprintf(q, q_len - 1,
"%03d", frame_in);
break;
443 case '4': snprintf(q, q_len - 1,
"%04d", frame_in);
break;
444 case '5': snprintf(q, q_len - 1,
"%05d", frame_in);
break;
445 case '6': snprintf(q, q_len - 1,
"%06d", frame_in);
break;
446 case '7': snprintf(q, q_len - 1,
"%07d", frame_in);
break;
447 case '8': snprintf(q, q_len - 1,
"%08d", frame_in);
break;
448 case '9': snprintf(q, q_len - 1,
"%09d", frame_in);
break;
449 default: die(
"Unrecognized pattern %%%c\n", p[1]);
break;
453 if (pat_len >= q_len - 1) die(
"Output filename too long.\n");
462 copy_len = strlen(p);
464 copy_len = next_pat - p;
466 if (copy_len >= q_len - 1) die(
"Output filename too long.\n");
468 memcpy(q, p, copy_len);
477static int is_single_file(
const char *outfile_pattern) {
478 const char *p = outfile_pattern;
482 if (p && p[1] >=
'1' && p[1] <=
'9')
490static void print_md5(
unsigned char digest[16],
const char *filename) {
493 for (i = 0; i < 16; ++i) printf(
"%02x", digest[i]);
494 printf(
" %s\n", filename);
497static FILE *open_outfile(
const char *name) {
498 if (strcmp(
"-", name) == 0) {
499 set_binary_mode(stdout);
502 FILE *file = fopen(name,
"wb");
503 if (!file) fatal(
"Failed to open output file '%s'", name);
508#if CONFIG_VP9_HIGHBITDEPTH
509static int img_shifted_realloc_required(
const vpx_image_t *img,
512 return img->
d_w != shifted->
d_w || img->
d_h != shifted->
d_h ||
513 required_fmt != shifted->
fmt;
517static int main_loop(
int argc,
const char **argv_) {
521 int ret = EXIT_FAILURE;
523 size_t bytes_in_buffer = 0, buffer_size = 0;
525 int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0;
526 int do_md5 = 0, progress = 0;
527 int stop_after = 0, postproc = 0, summary = 0, quiet = 1;
531 int enable_row_mt = 0;
532 int enable_lpf_opt = 0;
533 const VpxInterface *
interface = NULL;
534 const VpxInterface *fourcc_interface = NULL;
535 uint64_t dx_time = 0;
537 char **argv, **argi, **argj;
544#if CONFIG_VP9_HIGHBITDEPTH
545 unsigned int output_bit_depth = 0;
547 int svc_decoding = 0;
548 int svc_spatial_layer = 0;
549#if CONFIG_VP8_DECODER
552 int frames_corrupted = 0;
556#if CONFIG_VP9_HIGHBITDEPTH
559 int frame_avail, got_data, flush_decoder = 0;
560 int num_external_frame_buffers = 0;
561 struct ExternalFrameBufferList ext_fb_list = { 0, NULL };
563 const char *outfile_pattern = NULL;
564 char outfile_name[PATH_MAX] = { 0 };
565 FILE *outfile = NULL;
567 FILE *framestats_file = NULL;
570 unsigned char md5_digest[16];
572 struct VpxDecInputContext input = { NULL, NULL };
573 struct VpxInputContext vpx_input_ctx;
575 struct WebmInputContext webm_ctx;
576 memset(&(webm_ctx), 0,
sizeof(webm_ctx));
577 input.webm_ctx = &webm_ctx;
579 input.vpx_input_ctx = &vpx_input_ctx;
582 exec_name = argv_[0];
583 argv = argv_dup(argc - 1, argv_ + 1);
585 fprintf(stderr,
"Error allocating argument list\n");
588 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
589 memset(&arg, 0,
sizeof(arg));
592 if (arg_match(&arg, &help, argi)) {
593 show_help(stdout, 0);
595 }
else if (arg_match(&arg, &codecarg, argi)) {
596 interface = get_vpx_decoder_by_name(arg.val);
598 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
599 }
else if (arg_match(&arg, &looparg, argi)) {
601 }
else if (arg_match(&arg, &outputfile, argi))
602 outfile_pattern = arg.val;
603 else if (arg_match(&arg, &use_yv12, argi)) {
607 }
else if (arg_match(&arg, &use_i420, argi)) {
611 }
else if (arg_match(&arg, &rawvideo, argi)) {
613 }
else if (arg_match(&arg, &flipuvarg, argi))
615 else if (arg_match(&arg, &noblitarg, argi))
617 else if (arg_match(&arg, &progressarg, argi))
619 else if (arg_match(&arg, &limitarg, argi))
620 stop_after = arg_parse_uint(&arg);
621 else if (arg_match(&arg, &skiparg, argi))
622 arg_skip = arg_parse_uint(&arg);
623 else if (arg_match(&arg, &postprocarg, argi))
625 else if (arg_match(&arg, &md5arg, argi))
627 else if (arg_match(&arg, &summaryarg, argi))
629 else if (arg_match(&arg, &threadsarg, argi))
630 cfg.
threads = arg_parse_uint(&arg);
631#if CONFIG_VP9_DECODER
632 else if (arg_match(&arg, &frameparallelarg, argi)) {
636 else if (arg_match(&arg, &verbosearg, argi))
638 else if (arg_match(&arg, &scalearg, argi))
640 else if (arg_match(&arg, &fb_arg, argi))
641 num_external_frame_buffers = arg_parse_uint(&arg);
642 else if (arg_match(&arg, &continuearg, argi))
644#if CONFIG_VP9_HIGHBITDEPTH
645 else if (arg_match(&arg, &outbitdeptharg, argi)) {
646 output_bit_depth = arg_parse_uint(&arg);
649 else if (arg_match(&arg, &svcdecodingarg, argi)) {
651 svc_spatial_layer = arg_parse_uint(&arg);
652 }
else if (arg_match(&arg, &framestatsarg, argi)) {
653 framestats_file = fopen(arg.val,
"w");
654 if (!framestats_file) {
655 die(
"Error: Could not open --framestats file (%s) for writing.\n",
658 }
else if (arg_match(&arg, &rowmtarg, argi)) {
659 enable_row_mt = arg_parse_uint(&arg);
660 }
else if (arg_match(&arg, &lpfoptarg, argi)) {
661 enable_lpf_opt = arg_parse_uint(&arg);
663#if CONFIG_VP8_DECODER
664 else if (arg_match(&arg, &addnoise_level, argi)) {
668 }
else if (arg_match(&arg, &demacroblock_level, argi)) {
672 }
else if (arg_match(&arg, &deblock, argi)) {
675 }
else if (arg_match(&arg, &mfqe, argi)) {
678 }
else if (arg_match(&arg, &error_concealment, argi)) {
687 for (argi = argv; *argi; argi++)
688 if (argi[0][0] ==
'-' && strlen(argi[0]) > 1)
689 die(
"Error: Unrecognized option %s\n", *argi);
696 fprintf(stderr,
"No input file specified!\n");
700 infile = strcmp(fn,
"-") ? fopen(fn,
"rb") : set_binary_mode(stdin);
703 fatal(
"Failed to open input file '%s'", strcmp(fn,
"-") ? fn :
"stdin");
707 if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) {
709 "Not dumping raw video to your terminal. Use '-o -' to "
714 input.vpx_input_ctx->file = infile;
715 if (file_is_ivf(input.vpx_input_ctx))
716 input.vpx_input_ctx->file_type = FILE_TYPE_IVF;
718 else if (file_is_webm(input.webm_ctx, input.vpx_input_ctx))
719 input.vpx_input_ctx->file_type = FILE_TYPE_WEBM;
721 else if (file_is_raw(input.vpx_input_ctx))
722 input.vpx_input_ctx->file_type = FILE_TYPE_RAW;
724 fprintf(stderr,
"Unrecognized input file type.\n");
726 fprintf(stderr,
"vpxdec was built without WebM container support.\n");
732 outfile_pattern = outfile_pattern ? outfile_pattern :
"-";
733 single_file = is_single_file(outfile_pattern);
735 if (!noblit && single_file) {
736 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
737 vpx_input_ctx.width, vpx_input_ctx.height, 0);
741 outfile = open_outfile(outfile_name);
744 if (use_y4m && !noblit) {
747 "YUV4MPEG2 not supported with output patterns,"
748 " try --i420 or --yv12 or --rawvideo.\n");
753 if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) {
754 if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) {
756 "Failed to guess framerate -- error parsing "
764 fourcc_interface = get_vpx_decoder_by_fourcc(vpx_input_ctx.fourcc);
765 if (interface && fourcc_interface && interface != fourcc_interface)
766 warn(
"Header indicates codec: %s\n", fourcc_interface->name);
768 interface = fourcc_interface;
770 if (!interface)
interface = get_vpx_decoder_by_index(0);
776 fprintf(stderr,
"Failed to initialize decoder: %s\n",
782 svc_spatial_layer)) {
783 fprintf(stderr,
"Failed to set spatial layer for svc decode: %s\n",
788 if (interface->fourcc == VP9_FOURCC &&
790 fprintf(stderr,
"Failed to set decoder in row multi-thread mode: %s\n",
794 if (interface->fourcc == VP9_FOURCC &&
796 fprintf(stderr,
"Failed to set decoder in optimized loopfilter mode: %s\n",
800 if (!quiet) fprintf(stderr,
"%s\n", decoder.
name);
802#if CONFIG_VP8_DECODER
805 fprintf(stderr,
"Failed to configure postproc: %s\n",
811 if (arg_skip) fprintf(stderr,
"Skipping first %d frames.\n", arg_skip);
813 if (dec_read_frame(&input, &buf, &bytes_in_buffer, &buffer_size))
break;
817 if (num_external_frame_buffers > 0) {
818 ext_fb_list.num_external_frame_buffers = num_external_frame_buffers;
819 ext_fb_list.ext_fb = (
struct ExternalFrameBuffer *)calloc(
820 num_external_frame_buffers,
sizeof(*ext_fb_list.ext_fb));
821 if (!ext_fb_list.ext_fb) {
822 fprintf(stderr,
"Failed to allocate ExternalFrameBuffer\n");
826 release_vp9_frame_buffer,
828 fprintf(stderr,
"Failed to configure external frame buffers: %s\n",
837 if (framestats_file) fprintf(framestats_file,
"bytes,qp\n");
840 while (frame_avail || got_data) {
843 struct vpx_usec_timer timer;
847 if (!stop_after || frame_in < stop_after) {
848 if (!dec_read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) {
852 vpx_usec_timer_start(&timer);
857 warn(
"Failed to decode frame %d: %s", frame_in,
859 if (detail) warn(
"Additional information: %s", detail);
861 if (!keep_going)
goto fail;
864 if (framestats_file) {
867 warn(
"Failed VPXD_GET_LAST_QUANTIZER: %s",
869 if (!keep_going)
goto fail;
871 fprintf(framestats_file,
"%d,%d\n", (
int)bytes_in_buffer, qp);
874 vpx_usec_timer_mark(&timer);
875 dx_time += vpx_usec_timer_elapsed(&timer);
883 vpx_usec_timer_start(&timer);
890 if (!keep_going)
goto fail;
900 vpx_usec_timer_mark(&timer);
901 dx_time += (
unsigned int)vpx_usec_timer_elapsed(&timer);
906 if (!keep_going)
goto fail;
908 frames_corrupted += corrupted;
910 if (progress) show_progress(frame_in, frame_out, dx_time);
912 if (!noblit && img) {
915 const int *planes = flipuv ? PLANES_YVU : PLANES_YUV;
918 if (frame_out == 1) {
924 int render_width = vpx_input_ctx.width;
925 int render_height = vpx_input_ctx.height;
926 if (!render_width || !render_height) {
931 render_width = img->
d_w;
932 render_height = img->
d_h;
934 render_width = render_size[0];
935 render_height = render_size[1];
941 fprintf(stderr,
"Failed to allocate scaled image (%d x %d)\n",
942 render_width, render_height);
948 if (img->
d_w != scaled_img->
d_w || img->
d_h != scaled_img->
d_h) {
950 libyuv_scale(img, scaled_img, kFilterBox);
954 "Failed to scale output frame: %s.\n"
955 "Scaling is disabled in this configuration. "
956 "To enable scaling, configure with --enable-libyuv\n",
962#if CONFIG_VP9_HIGHBITDEPTH
964 if (!output_bit_depth && single_file && !do_md5) {
968 if (output_bit_depth != 0 && output_bit_depth != img->
bit_depth) {
970 output_bit_depth == 8
974 img_shifted_realloc_required(img, img_shifted, shifted_fmt)) {
982 fprintf(stderr,
"Failed to allocate image\n");
985 img_shifted->
bit_depth = output_bit_depth;
988 vpx_img_upshift(img_shifted, img, output_bit_depth - img->
bit_depth);
990 vpx_img_downshift(img_shifted, img,
999 char buf[Y4M_BUFFER_SIZE] = { 0 };
1002 fprintf(stderr,
"Cannot produce y4m output for 440 sampling.\n");
1005 if (frame_out == 1) {
1007 len = y4m_write_file_header(
1008 buf,
sizeof(buf), vpx_input_ctx.width, vpx_input_ctx.height,
1011 MD5Update(&md5_ctx, (md5byte *)buf, (
unsigned int)len);
1013 fputs(buf, outfile);
1018 len = y4m_write_frame_header(buf,
sizeof(buf));
1020 MD5Update(&md5_ctx, (md5byte *)buf, (
unsigned int)len);
1022 fputs(buf, outfile);
1025 if (frame_out == 1) {
1031 fprintf(stderr,
"Cannot produce i420 output for bit-stream.\n");
1039 fprintf(stderr,
"Cannot produce yv12 output for bit-stream.\n");
1047 update_image_md5(img, planes, &md5_ctx);
1049 if (!corrupted) write_image_file(img, planes, outfile);
1052 generate_filename(outfile_pattern, outfile_name, PATH_MAX, img->
d_w,
1053 img->
d_h, frame_in);
1056 update_image_md5(img, planes, &md5_ctx);
1057 MD5Final(md5_digest, &md5_ctx);
1058 print_md5(md5_digest, outfile_name);
1060 outfile = open_outfile(outfile_name);
1061 write_image_file(img, planes, outfile);
1068 if (summary || progress) {
1069 show_progress(frame_in, frame_out, dx_time);
1070 fprintf(stderr,
"\n");
1073 if (frames_corrupted) {
1074 fprintf(stderr,
"WARNING: %d frames corrupted.\n", frames_corrupted);
1082 fprintf(stderr,
"Failed to destroy decoder: %s\n",
1088 if (!noblit && single_file) {
1090 MD5Final(md5_digest, &md5_ctx);
1091 print_md5(md5_digest, outfile_name);
1098 if (input.vpx_input_ctx->file_type == FILE_TYPE_WEBM)
1099 webm_free(input.webm_ctx);
1102 if (input.vpx_input_ctx->file_type != FILE_TYPE_WEBM) free(buf);
1105#if CONFIG_VP9_HIGHBITDEPTH
1109 for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) {
1110 free(ext_fb_list.ext_fb[i].data);
1112 free(ext_fb_list.ext_fb);
1115 if (framestats_file) fclose(framestats_file);
1122int main(
int argc,
const char **argv_) {
1123 unsigned int loops = 1, i;
1124 char **argv, **argi, **argj;
1128 argv = argv_dup(argc - 1, argv_ + 1);
1130 fprintf(stderr,
"Error allocating argument list\n");
1131 return EXIT_FAILURE;
1133 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
1134 memset(&arg, 0,
sizeof(arg));
1137 if (arg_match(&arg, &looparg, argi)) {
1138 loops = arg_parse_uint(&arg);
1143 for (i = 0; !error && i < loops; i++) error = main_loop(argc, argv_);
vpx_codec_err_t vpx_codec_set_frame_buffer_functions(vpx_codec_ctx_t *ctx, vpx_get_frame_buffer_cb_fn_t cb_get, vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv)
Pass in external frame buffers for the decoder to use.
const char * vpx_codec_error_detail(vpx_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
Destroy a codec instance.
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:190
const char * vpx_codec_iface_name(vpx_codec_iface_t *iface)
Return the name for a given interface.
#define vpx_codec_control(ctx, id, data)
vpx_codec_control wrapper macro
Definition: vpx_codec.h:407
const char * vpx_codec_error(vpx_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data, unsigned int data_sz, void *user_priv, long deadline)
Decode data.
#define VPX_CODEC_USE_ERROR_CONCEALMENT
Conceal errors in decoded frames.
Definition: vpx_decoder.h:75
#define VPX_CODEC_USE_POSTPROC
Initialization-time Feature Enabling.
Definition: vpx_decoder.h:73
#define vpx_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_dec_init_ver()
Definition: vpx_decoder.h:143
vpx_image_t * vpx_codec_get_frame(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Decoded frames iterator.
vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface, const uint8_t *data, unsigned int data_sz, vpx_codec_stream_info_t *si)
Parse stream info from a buffer.
@ VP9D_SET_ROW_MT
Codec control function to set row level multi-threading.
Definition: vp8dx.h:149
@ VP9D_SET_LOOP_FILTER_OPT
Codec control function to set loopfilter optimization.
Definition: vp8dx.h:159
@ VPXD_GET_LAST_QUANTIZER
Codec control function to get last decoded frame quantizer.
Definition: vp8dx.h:141
@ VP9_DECODE_SVC_SPATIAL_LAYER
Definition: vp8dx.h:133
@ VP9D_GET_DISPLAY_SIZE
Definition: vp8dx.h:101
@ VP8D_GET_FRAME_CORRUPTED
Definition: vp8dx.h:79
@ VP8_SET_POSTPROC
Definition: vp8.h:49
post process flags
Definition: vp8.h:79
int noise_level
Definition: vp8.h:84
int post_proc_flag
the types of post processing to be done, should be combination of "vp8_postproc_level"
Definition: vp8.h:82
int deblocking_level
Definition: vp8.h:83
Codec context structure.
Definition: vpx_codec.h:200
const char * name
Definition: vpx_codec.h:201
Initialization Configurations.
Definition: vpx_decoder.h:106
unsigned int threads
Definition: vpx_decoder.h:107
External frame buffer.
Definition: vpx_frame_buffer.h:39
void * priv
Definition: vpx_frame_buffer.h:42
size_t size
Definition: vpx_frame_buffer.h:41
uint8_t * data
Definition: vpx_frame_buffer.h:40
Stream properties.
Definition: vpx_decoder.h:88
unsigned int sz
Definition: vpx_decoder.h:89
unsigned int w
Definition: vpx_decoder.h:90
unsigned int h
Definition: vpx_decoder.h:91
Image Descriptor.
Definition: vpx_image.h:72
vpx_img_fmt_t fmt
Definition: vpx_image.h:73
unsigned int d_h
Definition: vpx_image.h:84
unsigned int d_w
Definition: vpx_image.h:83
unsigned int bit_depth
Definition: vpx_image.h:80
unsigned char * planes[4]
Definition: vpx_image.h:100
int stride[4]
Definition: vpx_image.h:101
Provides definitions for using VP8 or VP9 within the vpx Decoder interface.
Describes the decoder algorithm interface to applications.
#define VPX_PLANE_Y
Definition: vpx_image.h:96
vpx_image_t * vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
#define VPX_IMG_FMT_HIGHBITDEPTH
Definition: vpx_image.h:35
#define VPX_PLANE_U
Definition: vpx_image.h:97
@ VPX_IMG_FMT_I44016
Definition: vpx_image.h:50
@ VPX_IMG_FMT_YV12
Definition: vpx_image.h:40
@ VPX_IMG_FMT_I42016
Definition: vpx_image.h:47
@ VPX_IMG_FMT_I440
Definition: vpx_image.h:45
@ VPX_IMG_FMT_I420
Definition: vpx_image.h:42
#define VPX_PLANE_V
Definition: vpx_image.h:98
enum vpx_img_fmt vpx_img_fmt_t
List of supported image formats.
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.