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"
39 #include "./webmdec.h"
43 static const char *exec_name;
45 struct VpxDecInputContext {
46 struct VpxInputContext *vpx_input_ctx;
47 struct WebmInputContext *webm_ctx;
50 static const arg_def_t looparg = ARG_DEF(
51 NULL,
"loops", 1,
"Number of times to decode the file");
52 static const arg_def_t codecarg = ARG_DEF(
53 NULL,
"codec", 1,
"Codec to use");
54 static const arg_def_t use_yv12 = ARG_DEF(
55 NULL,
"yv12", 0,
"Output raw YV12 frames");
56 static const arg_def_t use_i420 = ARG_DEF(
57 NULL,
"i420", 0,
"Output raw I420 frames");
58 static const arg_def_t flipuvarg = ARG_DEF(
59 NULL,
"flipuv", 0,
"Flip the chroma planes in the output");
60 static const arg_def_t rawvideo = ARG_DEF(
61 NULL,
"rawvideo", 0,
"Output raw YUV frames");
62 static const arg_def_t noblitarg = ARG_DEF(
63 NULL,
"noblit", 0,
"Don't process the decoded frames");
64 static const arg_def_t progressarg = ARG_DEF(
65 NULL,
"progress", 0,
"Show progress after each frame decodes");
66 static const arg_def_t limitarg = ARG_DEF(
67 NULL,
"limit", 1,
"Stop decoding after n frames");
68 static const arg_def_t skiparg = ARG_DEF(
69 NULL,
"skip", 1,
"Skip the first n input frames");
70 static const arg_def_t postprocarg = ARG_DEF(
71 NULL,
"postproc", 0,
"Postprocess decoded frames");
72 static const arg_def_t summaryarg = ARG_DEF(
73 NULL,
"summary", 0,
"Show timing summary");
74 static const arg_def_t outputfile = ARG_DEF(
75 "o",
"output", 1,
"Output file name pattern (see below)");
76 static const arg_def_t threadsarg = ARG_DEF(
77 "t",
"threads", 1,
"Max threads to use");
78 static const arg_def_t frameparallelarg = ARG_DEF(
79 NULL,
"frame-parallel", 0,
"Frame parallel decode");
80 static const arg_def_t verbosearg = ARG_DEF(
81 "v",
"verbose", 0,
"Show version string");
82 static const arg_def_t error_concealment = ARG_DEF(
83 NULL,
"error-concealment", 0,
"Enable decoder error-concealment");
84 static const arg_def_t scalearg = ARG_DEF(
85 "S",
"scale", 0,
"Scale output frames uniformly");
86 static const arg_def_t continuearg = ARG_DEF(
87 "k",
"keep-going", 0,
"(debug) Continue decoding after error");
88 static const arg_def_t fb_arg = ARG_DEF(
89 NULL,
"frame-buffers", 1,
"Number of frame buffers to use");
90 static const arg_def_t md5arg = ARG_DEF(
91 NULL,
"md5", 0,
"Compute the MD5 sum of the decoded frame");
92 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
93 static const arg_def_t outbitdeptharg = ARG_DEF(
94 NULL,
"output-bit-depth", 1,
"Output bit-depth for decoded frames");
97 static const arg_def_t *all_args[] = {
98 &codecarg, &use_yv12, &use_i420, &flipuvarg, &rawvideo, &noblitarg,
99 &progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile,
100 &threadsarg, &frameparallelarg, &verbosearg, &scalearg, &fb_arg,
101 &md5arg, &error_concealment, &continuearg,
102 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
108 #if CONFIG_VP8_DECODER
109 static const arg_def_t addnoise_level = ARG_DEF(NULL,
"noise-level", 1,
110 "Enable VP8 postproc add noise");
111 static const arg_def_t deblock = ARG_DEF(NULL,
"deblock", 0,
112 "Enable VP8 deblocking");
113 static const arg_def_t demacroblock_level = ARG_DEF(NULL,
"demacroblock-level", 1,
114 "Enable VP8 demacroblocking, w/ level");
115 static const arg_def_t pp_debug_info = ARG_DEF(NULL,
"pp-debug-info", 1,
116 "Enable VP8 visible debug info");
117 static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL,
"pp-dbg-ref-frame", 1,
118 "Display only selected reference frame per macro block");
119 static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL,
"pp-dbg-mb-modes", 1,
120 "Display only selected macro block modes");
121 static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL,
"pp-dbg-b-modes", 1,
122 "Display only selected block modes");
123 static const arg_def_t pp_disp_mvs = ARG_DEF(NULL,
"pp-dbg-mvs", 1,
124 "Draw only selected motion vectors");
125 static const arg_def_t mfqe = ARG_DEF(NULL,
"mfqe", 0,
126 "Enable multiframe quality enhancement");
128 static const arg_def_t *vp8_pp_args[] = {
129 &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info,
130 &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe,
137 FilterModeEnum mode) {
138 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
139 if (src->
fmt == VPX_IMG_FMT_I42016) {
140 assert(dst->
fmt == VPX_IMG_FMT_I42016);
141 return I420Scale_16((uint16_t*)src->
planes[VPX_PLANE_Y],
142 src->
stride[VPX_PLANE_Y]/2,
143 (uint16_t*)src->
planes[VPX_PLANE_U],
144 src->
stride[VPX_PLANE_U]/2,
148 (uint16_t*)dst->
planes[VPX_PLANE_Y],
149 dst->
stride[VPX_PLANE_Y]/2,
150 (uint16_t*)dst->
planes[VPX_PLANE_U],
151 dst->
stride[VPX_PLANE_U]/2,
160 return I420Scale(src->
planes[VPX_PLANE_Y], src->
stride[VPX_PLANE_Y],
175 fprintf(stderr,
"Usage: %s <options> filename\n\n"
176 "Options:\n", exec_name);
177 arg_show_usage(stderr, all_args);
178 #if CONFIG_VP8_DECODER
179 fprintf(stderr,
"\nVP8 Postprocessing Options:\n");
180 arg_show_usage(stderr, vp8_pp_args);
183 "\nOutput File Patterns:\n\n"
184 " The -o argument specifies the name of the file(s) to "
185 "write to. If the\n argument does not include any escape "
186 "characters, the output will be\n written to a single file. "
187 "Otherwise, the filename will be calculated by\n expanding "
188 "the following escape characters:\n");
190 "\n\t%%w - Frame width"
191 "\n\t%%h - Frame height"
192 "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
193 "\n\n Pattern arguments are only supported in conjunction "
194 "with the --yv12 and\n --i420 options. If the -o option is "
195 "not specified, the output will be\n directed to stdout.\n"
197 fprintf(stderr,
"\nIncluded decoders:\n\n");
199 for (i = 0; i < get_vpx_decoder_count(); ++i) {
200 const VpxInterface *
const decoder = get_vpx_decoder_by_index(i);
201 fprintf(stderr,
" %-6s - %s\n",
208 static int raw_read_frame(FILE *infile, uint8_t **buffer,
209 size_t *bytes_read,
size_t *buffer_size) {
210 char raw_hdr[RAW_FRAME_HDR_SZ];
211 size_t frame_size = 0;
213 if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) {
215 warn(
"Failed to read RAW frame size\n");
217 const size_t kCorruptFrameThreshold = 256 * 1024 * 1024;
218 const size_t kFrameTooSmallThreshold = 256 * 1024;
219 frame_size = mem_get_le32(raw_hdr);
221 if (frame_size > kCorruptFrameThreshold) {
222 warn(
"Read invalid frame size (%u)\n", (
unsigned int)frame_size);
226 if (frame_size < kFrameTooSmallThreshold) {
227 warn(
"Warning: Read invalid frame size (%u) - not a raw file?\n",
228 (
unsigned int)frame_size);
231 if (frame_size > *buffer_size) {
232 uint8_t *new_buf = realloc(*buffer, 2 * frame_size);
235 *buffer_size = 2 * frame_size;
237 warn(
"Failed to allocate compressed data buffer\n");
244 if (fread(*buffer, 1, frame_size, infile) != frame_size) {
245 warn(
"Failed to read full frame\n");
248 *bytes_read = frame_size;
254 static int read_frame(
struct VpxDecInputContext *input, uint8_t **buf,
255 size_t *bytes_in_buffer,
size_t *buffer_size) {
256 switch (input->vpx_input_ctx->file_type) {
259 return webm_read_frame(input->webm_ctx,
260 buf, bytes_in_buffer, buffer_size);
263 return raw_read_frame(input->vpx_input_ctx->file,
264 buf, bytes_in_buffer, buffer_size);
266 return ivf_read_frame(input->vpx_input_ctx->file,
267 buf, bytes_in_buffer, buffer_size);
273 static void update_image_md5(
const vpx_image_t *img,
const int planes[3],
277 for (i = 0; i < 3; ++i) {
278 const int plane = planes[i];
279 const unsigned char *buf = img->
planes[plane];
280 const int stride = img->
stride[plane];
281 const int w = vpx_img_plane_width(img, plane) *
283 const int h = vpx_img_plane_height(img, plane);
285 for (y = 0; y < h; ++y) {
286 MD5Update(md5, buf, w);
292 static void write_image_file(
const vpx_image_t *img,
const int planes[3],
295 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
298 const int bytes_per_sample = 1;
301 for (i = 0; i < 3; ++i) {
302 const int plane = planes[i];
303 const unsigned char *buf = img->
planes[plane];
304 const int stride = img->
stride[plane];
305 const int w = vpx_img_plane_width(img, plane);
306 const int h = vpx_img_plane_height(img, plane);
308 for (y = 0; y < h; ++y) {
309 fwrite(buf, bytes_per_sample, w, file);
315 int file_is_raw(
struct VpxInputContext *input) {
322 if (fread(buf, 1, 32, input->file) == 32) {
325 if (mem_get_le32(buf) < 256 * 1024 * 1024) {
326 for (i = 0; i < get_vpx_decoder_count(); ++i) {
327 const VpxInterface *
const decoder = get_vpx_decoder_by_index(i);
329 buf + 4, 32 - 4, &si)) {
331 input->fourcc = decoder->fourcc;
333 input->height = si.
h;
334 input->framerate.numerator = 30;
335 input->framerate.denominator = 1;
346 void show_progress(
int frame_in,
int frame_out, uint64_t dx_time) {
348 "%d decoded frames/%d showed frames in %"PRId64
" us (%.2f fps)\r",
349 frame_in, frame_out, dx_time,
350 (
double)frame_out * 1000000.0 / (
double)dx_time);
353 struct ExternalFrameBuffer {
359 struct ExternalFrameBufferList {
360 int num_external_frame_buffers;
361 struct ExternalFrameBuffer *ext_fb;
368 int get_vp9_frame_buffer(
void *cb_priv,
size_t min_size,
371 struct ExternalFrameBufferList *
const ext_fb_list =
372 (
struct ExternalFrameBufferList *)cb_priv;
373 if (ext_fb_list == NULL)
377 for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) {
378 if (!ext_fb_list->ext_fb[i].in_use)
382 if (i == ext_fb_list->num_external_frame_buffers)
385 if (ext_fb_list->ext_fb[i].size < min_size) {
386 free(ext_fb_list->ext_fb[i].data);
387 ext_fb_list->ext_fb[i].data = (uint8_t *)calloc(min_size,
sizeof(uint8_t));
388 if (!ext_fb_list->ext_fb[i].data)
391 ext_fb_list->ext_fb[i].size = min_size;
394 fb->
data = ext_fb_list->ext_fb[i].data;
395 fb->
size = ext_fb_list->ext_fb[i].size;
396 ext_fb_list->ext_fb[i].in_use = 1;
399 fb->
priv = &ext_fb_list->ext_fb[i];
406 int release_vp9_frame_buffer(
void *cb_priv,
408 struct ExternalFrameBuffer *
const ext_fb =
409 (
struct ExternalFrameBuffer *)fb->
priv;
415 void generate_filename(
const char *pattern,
char *out,
size_t q_len,
416 unsigned int d_w,
unsigned int d_h,
417 unsigned int frame_in) {
418 const char *p = pattern;
422 char *next_pat = strchr(p,
'%');
431 snprintf(q, q_len - 1,
"%d", d_w);
434 snprintf(q, q_len - 1,
"%d", d_h);
437 snprintf(q, q_len - 1,
"%d", frame_in);
440 snprintf(q, q_len - 1,
"%02d", frame_in);
443 snprintf(q, q_len - 1,
"%03d", frame_in);
446 snprintf(q, q_len - 1,
"%04d", frame_in);
449 snprintf(q, q_len - 1,
"%05d", frame_in);
452 snprintf(q, q_len - 1,
"%06d", frame_in);
455 snprintf(q, q_len - 1,
"%07d", frame_in);
458 snprintf(q, q_len - 1,
"%08d", frame_in);
461 snprintf(q, q_len - 1,
"%09d", frame_in);
464 die(
"Unrecognized pattern %%%c\n", p[1]);
469 if (pat_len >= q_len - 1)
470 die(
"Output filename too long.\n");
479 copy_len = strlen(p);
481 copy_len = next_pat - p;
483 if (copy_len >= q_len - 1)
484 die(
"Output filename too long.\n");
486 memcpy(q, p, copy_len);
495 static int is_single_file(
const char *outfile_pattern) {
496 const char *p = outfile_pattern;
500 if (p && p[1] >=
'1' && p[1] <=
'9')
509 static void print_md5(
unsigned char digest[16],
const char *filename) {
512 for (i = 0; i < 16; ++i)
513 printf(
"%02x", digest[i]);
514 printf(
" %s\n", filename);
517 static FILE *open_outfile(
const char *name) {
518 if (strcmp(
"-", name) == 0) {
519 set_binary_mode(stdout);
522 FILE *file = fopen(name,
"wb");
524 fatal(
"Failed to open output file '%s'", name);
529 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
530 static int img_shifted_realloc_required(
const vpx_image_t *img,
533 return img->
d_w != shifted->
d_w ||
534 img->
d_h != shifted->
d_h ||
535 required_fmt != shifted->
fmt;
539 int main_loop(
int argc,
const char **argv_) {
544 size_t bytes_in_buffer = 0, buffer_size = 0;
546 int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0;
547 int do_md5 = 0, progress = 0, frame_parallel = 0;
548 int stop_after = 0, postproc = 0, summary = 0, quiet = 1;
552 const VpxInterface *
interface = NULL;
553 const VpxInterface *fourcc_interface = NULL;
554 uint64_t dx_time = 0;
556 char **argv, **argi, **argj;
563 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
564 int output_bit_depth = 0;
566 #if CONFIG_VP8_DECODER
568 int vp8_dbg_color_ref_frame = 0;
569 int vp8_dbg_color_mb_modes = 0;
570 int vp8_dbg_color_b_modes = 0;
571 int vp8_dbg_display_mv = 0;
573 int frames_corrupted = 0;
577 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
580 int frame_avail, got_data, flush_decoder = 0;
581 int num_external_frame_buffers = 0;
582 struct ExternalFrameBufferList ext_fb_list = {0, NULL};
584 const char *outfile_pattern = NULL;
585 char outfile_name[PATH_MAX] = {0};
586 FILE *outfile = NULL;
589 unsigned char md5_digest[16];
591 struct VpxDecInputContext input = {NULL, NULL};
592 struct VpxInputContext vpx_input_ctx;
594 struct WebmInputContext webm_ctx;
595 memset(&(webm_ctx), 0,
sizeof(webm_ctx));
596 input.webm_ctx = &webm_ctx;
598 input.vpx_input_ctx = &vpx_input_ctx;
601 exec_name = argv_[0];
602 argv = argv_dup(argc - 1, argv_ + 1);
604 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
605 memset(&arg, 0,
sizeof(arg));
608 if (arg_match(&arg, &codecarg, argi)) {
609 interface = get_vpx_decoder_by_name(arg.val);
611 die(
"Error: Unrecognized argument (%s) to --codec\n", arg.val);
612 }
else if (arg_match(&arg, &looparg, argi)) {
614 }
else if (arg_match(&arg, &outputfile, argi))
615 outfile_pattern = arg.val;
616 else if (arg_match(&arg, &use_yv12, argi)) {
620 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
621 output_bit_depth = 8;
623 }
else if (arg_match(&arg, &use_i420, argi)) {
627 }
else if (arg_match(&arg, &rawvideo, argi)) {
629 }
else if (arg_match(&arg, &flipuvarg, argi))
631 else if (arg_match(&arg, &noblitarg, argi))
633 else if (arg_match(&arg, &progressarg, argi))
635 else if (arg_match(&arg, &limitarg, argi))
636 stop_after = arg_parse_uint(&arg);
637 else if (arg_match(&arg, &skiparg, argi))
638 arg_skip = arg_parse_uint(&arg);
639 else if (arg_match(&arg, &postprocarg, argi))
641 else if (arg_match(&arg, &md5arg, argi))
643 else if (arg_match(&arg, &summaryarg, argi))
645 else if (arg_match(&arg, &threadsarg, argi))
646 cfg.
threads = arg_parse_uint(&arg);
647 #if CONFIG_VP9_DECODER
648 else if (arg_match(&arg, &frameparallelarg, argi))
651 else if (arg_match(&arg, &verbosearg, argi))
653 else if (arg_match(&arg, &scalearg, argi))
655 else if (arg_match(&arg, &fb_arg, argi))
656 num_external_frame_buffers = arg_parse_uint(&arg);
657 else if (arg_match(&arg, &continuearg, argi))
659 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
660 else if (arg_match(&arg, &outbitdeptharg, argi)) {
661 output_bit_depth = arg_parse_uint(&arg);
664 #if CONFIG_VP8_DECODER
665 else if (arg_match(&arg, &addnoise_level, argi)) {
669 }
else if (arg_match(&arg, &demacroblock_level, argi)) {
673 }
else if (arg_match(&arg, &deblock, argi)) {
676 }
else if (arg_match(&arg, &mfqe, argi)) {
679 }
else if (arg_match(&arg, &pp_debug_info, argi)) {
680 unsigned int level = arg_parse_uint(&arg);
687 }
else if (arg_match(&arg, &pp_disp_ref_frame, argi)) {
688 unsigned int flags = arg_parse_int(&arg);
691 vp8_dbg_color_ref_frame = flags;
693 }
else if (arg_match(&arg, &pp_disp_mb_modes, argi)) {
694 unsigned int flags = arg_parse_int(&arg);
697 vp8_dbg_color_mb_modes = flags;
699 }
else if (arg_match(&arg, &pp_disp_b_modes, argi)) {
700 unsigned int flags = arg_parse_int(&arg);
703 vp8_dbg_color_b_modes = flags;
705 }
else if (arg_match(&arg, &pp_disp_mvs, argi)) {
706 unsigned int flags = arg_parse_int(&arg);
709 vp8_dbg_display_mv = flags;
711 }
else if (arg_match(&arg, &error_concealment, argi)) {
714 #endif // CONFIG_VP8_DECODER
720 for (argi = argv; *argi; argi++)
721 if (argi[0][0] ==
'-' && strlen(argi[0]) > 1)
722 die(
"Error: Unrecognized option %s\n", *argi);
732 infile = strcmp(fn,
"-") ? fopen(fn,
"rb") : set_binary_mode(stdin);
735 fatal(
"Failed to open input file '%s'", strcmp(fn,
"-") ? fn :
"stdin");
737 #if CONFIG_OS_SUPPORT
739 if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) {
741 "Not dumping raw video to your terminal. Use '-o -' to "
746 input.vpx_input_ctx->file = infile;
747 if (file_is_ivf(input.vpx_input_ctx))
748 input.vpx_input_ctx->file_type = FILE_TYPE_IVF;
750 else if (file_is_webm(input.webm_ctx, input.vpx_input_ctx))
751 input.vpx_input_ctx->file_type = FILE_TYPE_WEBM;
753 else if (file_is_raw(input.vpx_input_ctx))
754 input.vpx_input_ctx->file_type = FILE_TYPE_RAW;
756 fprintf(stderr,
"Unrecognized input file type.\n");
758 fprintf(stderr,
"vpxdec was built without WebM container support.\n");
763 outfile_pattern = outfile_pattern ? outfile_pattern :
"-";
764 single_file = is_single_file(outfile_pattern);
766 if (!noblit && single_file) {
767 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
768 vpx_input_ctx.width, vpx_input_ctx.height, 0);
772 outfile = open_outfile(outfile_name);
775 if (use_y4m && !noblit) {
777 fprintf(stderr,
"YUV4MPEG2 not supported with output patterns,"
778 " try --i420 or --yv12 or --rawvideo.\n");
783 if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) {
784 if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) {
785 fprintf(stderr,
"Failed to guess framerate -- error parsing "
793 fourcc_interface = get_vpx_decoder_by_fourcc(vpx_input_ctx.fourcc);
794 if (interface && fourcc_interface && interface != fourcc_interface)
795 warn(
"Header indicates codec: %s\n", fourcc_interface->name);
797 interface = fourcc_interface;
800 interface = get_vpx_decoder_by_index(0);
803 (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0) |
807 fprintf(stderr,
"Failed to initialize decoder: %s\n",
813 fprintf(stderr,
"%s\n", decoder.
name);
815 #if CONFIG_VP8_DECODER
819 fprintf(stderr,
"Failed to configure postproc: %s\n",
vpx_codec_error(&decoder));
823 if (vp8_dbg_color_ref_frame
825 fprintf(stderr,
"Failed to configure reference block visualizer: %s\n",
vpx_codec_error(&decoder));
829 if (vp8_dbg_color_mb_modes
831 fprintf(stderr,
"Failed to configure macro block visualizer: %s\n",
vpx_codec_error(&decoder));
835 if (vp8_dbg_color_b_modes
837 fprintf(stderr,
"Failed to configure block visualizer: %s\n",
vpx_codec_error(&decoder));
841 if (vp8_dbg_display_mv
843 fprintf(stderr,
"Failed to configure motion vector visualizer: %s\n",
vpx_codec_error(&decoder));
850 fprintf(stderr,
"Skipping first %d frames.\n", arg_skip);
852 if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size))
857 if (num_external_frame_buffers > 0) {
858 ext_fb_list.num_external_frame_buffers = num_external_frame_buffers;
859 ext_fb_list.ext_fb = (
struct ExternalFrameBuffer *)calloc(
860 num_external_frame_buffers,
sizeof(*ext_fb_list.ext_fb));
862 &decoder, get_vp9_frame_buffer, release_vp9_frame_buffer,
864 fprintf(stderr,
"Failed to configure external frame buffers: %s\n",
874 while (frame_avail || got_data) {
877 struct vpx_usec_timer timer;
881 if (!stop_after || frame_in < stop_after) {
882 if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) {
886 vpx_usec_timer_start(&timer);
891 warn(
"Failed to decode frame %d: %s",
895 warn(
"Additional information: %s", detail);
900 vpx_usec_timer_mark(&timer);
901 dx_time += vpx_usec_timer_elapsed(&timer);
909 vpx_usec_timer_start(&timer);
924 vpx_usec_timer_mark(&timer);
925 dx_time += (
unsigned int)vpx_usec_timer_elapsed(&timer);
927 if (!frame_parallel &&
933 frames_corrupted += corrupted;
936 show_progress(frame_in, frame_out, dx_time);
938 if (!noblit && img) {
941 const int *planes = flipuv ? PLANES_YVU : PLANES_YUV;
944 if (frame_out == 1) {
950 int display_width = vpx_input_ctx.width;
951 int display_height = vpx_input_ctx.height;
952 if (!display_width || !display_height) {
957 display_width = img->
d_w;
958 display_height = img->
d_h;
960 display_width = display_size[0];
961 display_height = display_size[1];
969 if (img->
d_w != scaled_img->
d_w || img->
d_h != scaled_img->
d_h) {
971 libyuv_scale(img, scaled_img, kFilterBox);
974 fprintf(stderr,
"Failed to scale output frame: %s.\n"
975 "Scaling is disabled in this configuration. "
976 "To enable scaling, configure with --enable-libyuv\n",
982 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
984 if (!output_bit_depth) {
988 if (output_bit_depth != img->
bit_depth) {
993 img_shifted_realloc_required(img, img_shifted, shifted_fmt)) {
1000 img_shifted->
bit_depth = output_bit_depth;
1002 if (output_bit_depth > img->
bit_depth) {
1003 vpx_img_upshift(img_shifted, img,
1006 vpx_img_downshift(img_shifted, img,
1015 char buf[Y4M_BUFFER_SIZE] = {0};
1018 fprintf(stderr,
"Cannot produce y4m output for 440 sampling.\n");
1021 if (frame_out == 1) {
1023 len = y4m_write_file_header(buf,
sizeof(buf),
1024 vpx_input_ctx.width,
1025 vpx_input_ctx.height,
1026 &vpx_input_ctx.framerate,
1029 MD5Update(&md5_ctx, (md5byte *)buf, (
unsigned int)len);
1031 fputs(buf, outfile);
1036 len = y4m_write_frame_header(buf,
sizeof(buf));
1038 MD5Update(&md5_ctx, (md5byte *)buf, (
unsigned int)len);
1040 fputs(buf, outfile);
1043 if (frame_out == 1) {
1048 img->
fmt != VPX_IMG_FMT_I42016) {
1049 fprintf(stderr,
"Cannot produce i420 output for bit-stream.\n");
1056 fprintf(stderr,
"Cannot produce yv12 output for bit-stream.\n");
1064 update_image_md5(img, planes, &md5_ctx);
1066 write_image_file(img, planes, outfile);
1069 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
1070 img->
d_w, img->
d_h, frame_in);
1073 update_image_md5(img, planes, &md5_ctx);
1074 MD5Final(md5_digest, &md5_ctx);
1075 print_md5(md5_digest, outfile_name);
1077 outfile = open_outfile(outfile_name);
1078 write_image_file(img, planes, outfile);
1084 if (stop_after && frame_in >= stop_after)
1088 if (summary || progress) {
1089 show_progress(frame_in, frame_out, dx_time);
1090 fprintf(stderr,
"\n");
1093 if (frames_corrupted)
1094 fprintf(stderr,
"WARNING: %d frames corrupted.\n", frames_corrupted);
1099 fprintf(stderr,
"Failed to destroy decoder: %s\n",
1101 return EXIT_FAILURE;
1104 if (!noblit && single_file) {
1106 MD5Final(md5_digest, &md5_ctx);
1107 print_md5(md5_digest, outfile_name);
1114 if (input.vpx_input_ctx->file_type == FILE_TYPE_WEBM)
1115 webm_free(input.webm_ctx);
1118 if (input.vpx_input_ctx->file_type != FILE_TYPE_WEBM)
1122 #if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
1126 for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) {
1127 free(ext_fb_list.ext_fb[i].data);
1129 free(ext_fb_list.ext_fb);
1134 return frames_corrupted ? EXIT_FAILURE : EXIT_SUCCESS;
1137 int main(
int argc,
const char **argv_) {
1138 unsigned int loops = 1, i;
1139 char **argv, **argi, **argj;
1143 argv = argv_dup(argc - 1, argv_ + 1);
1144 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
1145 memset(&arg, 0,
sizeof(arg));
1148 if (arg_match(&arg, &looparg, argi)) {
1149 loops = arg_parse_uint(&arg);
1154 for (i = 0; !error && i < loops; i++)
1155 error = main_loop(argc, argv_);
Definition: vpx_image.h:66
Image Descriptor.
Definition: vpx_image.h:82
Describes the decoder algorithm interface to applications.
const char * vpx_codec_iface_name(vpx_codec_iface_t *iface)
Return the name for a given interface.
Definition: vpx_image.h:55
unsigned int threads
Definition: vpx_decoder.h:116
unsigned int sz
Definition: vpx_decoder.h:97
Stream properties.
Definition: vpx_decoder.h:96
int noise_level
Definition: vp8.h:88
unsigned int bit_depth
Definition: vpx_image.h:89
Provides definitions for using VP8 or VP9 within the vpx Decoder interface.
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.
#define VPX_PLANE_Y
Definition: vpx_image.h:101
uint8_t * data
Definition: vpx_frame_buffer.h:40
const char * name
Definition: vpx_codec.h:200
#define VPX_PLANE_V
Definition: vpx_image.h:103
#define VPX_IMG_FMT_HIGHBITDEPTH
Definition: vpx_image.h:37
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.
Definition: vpx_image.h:56
unsigned int d_w
Definition: vpx_image.h:92
#define vpx_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_dec_init_ver()
Definition: vpx_decoder.h:154
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.
enum vpx_img_fmt vpx_img_fmt_t
List of supported image formats.
size_t size
Definition: vpx_frame_buffer.h:41
int stride[4]
Definition: vpx_image.h:106
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.
vpx_img_fmt_t fmt
Definition: vpx_image.h:83
unsigned char * planes[4]
Definition: vpx_image.h:105
#define VPX_CODEC_USE_POSTPROC
Definition: vpx_decoder.h:77
#define VPX_CODEC_USE_FRAME_THREADING
Definition: vpx_decoder.h:86
const char * vpx_codec_error_detail(vpx_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
void * priv
Definition: vpx_frame_buffer.h:42
#define VPX_PLANE_U
Definition: vpx_image.h:102
int deblocking_level
Definition: vp8.h:87
unsigned int w
Definition: vpx_decoder.h:98
External frame buffer.
Definition: vpx_frame_buffer.h:39
#define vpx_codec_control(ctx, id, data)
vpx_codec_control wrapper macro
Definition: vpx_codec.h:407
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
Destroy a codec instance.
unsigned int d_h
Definition: vpx_image.h:93
post process flags
Definition: vp8.h:85
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.
unsigned int h
Definition: vpx_decoder.h:99
const char * vpx_codec_error(vpx_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
Initialization Configurations.
Definition: vpx_decoder.h:115
Definition: vpx_image.h:61
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:188
vpx_image_t * vpx_codec_get_frame(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Decoded frames iterator.
int post_proc_flag
Definition: vp8.h:86
Codec context structure.
Definition: vpx_codec.h:199