2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
18 #include "third_party/libyuv/include/libyuv/scale.h"
23 #define VPX_CODEC_DISABLE_COMPAT 1
24 #include "./vpx_config.h"
25 #include "vpx/vpx_decoder.h"
26 #include "vpx_ports/vpx_timer.h"
28 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
29 #include "vpx/vp8dx.h"
32 #include "./md5_utils.h"
34 #include "./tools_common.h"
35 #include "./webmdec.h"
38 static const char *exec_name;
40 struct VpxDecInputContext {
41 struct VpxInputContext *vpx_input_ctx;
42 struct WebmInputContext *webm_ctx;
45 static const arg_def_t looparg = ARG_DEF(NULL, "loops", 1,
46 "Number of times to decode the file");
47 static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1,
49 static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0,
50 "Output raw YV12 frames");
51 static const arg_def_t use_i420 = ARG_DEF(NULL, "i420", 0,
52 "Output raw I420 frames");
53 static const arg_def_t flipuvarg = ARG_DEF(NULL, "flipuv", 0,
54 "Flip the chroma planes in the output");
55 static const arg_def_t noblitarg = ARG_DEF(NULL, "noblit", 0,
56 "Don't process the decoded frames");
57 static const arg_def_t progressarg = ARG_DEF(NULL, "progress", 0,
58 "Show progress after each frame decodes");
59 static const arg_def_t limitarg = ARG_DEF(NULL, "limit", 1,
60 "Stop decoding after n frames");
61 static const arg_def_t skiparg = ARG_DEF(NULL, "skip", 1,
62 "Skip the first n input frames");
63 static const arg_def_t postprocarg = ARG_DEF(NULL, "postproc", 0,
64 "Postprocess decoded frames");
65 static const arg_def_t summaryarg = ARG_DEF(NULL, "summary", 0,
66 "Show timing summary");
67 static const arg_def_t outputfile = ARG_DEF("o", "output", 1,
68 "Output file name pattern (see below)");
69 static const arg_def_t threadsarg = ARG_DEF("t", "threads", 1,
70 "Max threads to use");
71 static const arg_def_t verbosearg = ARG_DEF("v", "verbose", 0,
72 "Show version string");
73 static const arg_def_t error_concealment = ARG_DEF(NULL, "error-concealment", 0,
74 "Enable decoder error-concealment");
75 static const arg_def_t scalearg = ARG_DEF("S", "scale", 0,
76 "Scale output frames uniformly");
79 static const arg_def_t md5arg = ARG_DEF(NULL, "md5", 0,
80 "Compute the MD5 sum of the decoded frame");
82 static const arg_def_t *all_args[] = {
83 &codecarg, &use_yv12, &use_i420, &flipuvarg, &noblitarg,
84 &progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile,
85 &threadsarg, &verbosearg, &scalearg,
91 #if CONFIG_VP8_DECODER
92 static const arg_def_t addnoise_level = ARG_DEF(NULL, "noise-level", 1,
93 "Enable VP8 postproc add noise");
94 static const arg_def_t deblock = ARG_DEF(NULL, "deblock", 0,
95 "Enable VP8 deblocking");
96 static const arg_def_t demacroblock_level = ARG_DEF(NULL, "demacroblock-level", 1,
97 "Enable VP8 demacroblocking, w/ level");
98 static const arg_def_t pp_debug_info = ARG_DEF(NULL, "pp-debug-info", 1,
99 "Enable VP8 visible debug info");
100 static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL, "pp-dbg-ref-frame", 1,
101 "Display only selected reference frame per macro block");
102 static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL, "pp-dbg-mb-modes", 1,
103 "Display only selected macro block modes");
104 static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL, "pp-dbg-b-modes", 1,
105 "Display only selected block modes");
106 static const arg_def_t pp_disp_mvs = ARG_DEF(NULL, "pp-dbg-mvs", 1,
107 "Draw only selected motion vectors");
108 static const arg_def_t mfqe = ARG_DEF(NULL, "mfqe", 0,
109 "Enable multiframe quality enhancement");
111 static const arg_def_t *vp8_pp_args[] = {
112 &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info,
113 &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe,
118 static int vpx_image_scale(vpx_image_t *src, vpx_image_t *dst,
120 assert(src->fmt == VPX_IMG_FMT_I420);
121 assert(dst->fmt == VPX_IMG_FMT_I420);
122 return I420Scale(src->planes[VPX_PLANE_Y], src->stride[VPX_PLANE_Y],
123 src->planes[VPX_PLANE_U], src->stride[VPX_PLANE_U],
124 src->planes[VPX_PLANE_V], src->stride[VPX_PLANE_V],
126 dst->planes[VPX_PLANE_Y], dst->stride[VPX_PLANE_Y],
127 dst->planes[VPX_PLANE_U], dst->stride[VPX_PLANE_U],
128 dst->planes[VPX_PLANE_V], dst->stride[VPX_PLANE_V],
136 fprintf(stderr, "Usage: %s <options> filename\n\n"
137 "Options:\n", exec_name);
138 arg_show_usage(stderr, all_args);
139 #if CONFIG_VP8_DECODER
140 fprintf(stderr, "\nVP8 Postprocessing Options:\n");
141 arg_show_usage(stderr, vp8_pp_args);
144 "\nOutput File Patterns:\n\n"
145 " The -o argument specifies the name of the file(s) to "
146 "write to. If the\n argument does not include any escape "
147 "characters, the output will be\n written to a single file. "
148 "Otherwise, the filename will be calculated by\n expanding "
149 "the following escape characters:\n");
151 "\n\t%%w - Frame width"
152 "\n\t%%h - Frame height"
153 "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
154 "\n\n Pattern arguments are only supported in conjunction "
155 "with the --yv12 and\n --i420 options. If the -o option is "
156 "not specified, the output will be\n directed to stdout.\n"
158 fprintf(stderr, "\nIncluded decoders:\n\n");
160 for (i = 0; i < get_vpx_decoder_count(); ++i) {
161 const VpxInterface *const decoder = get_vpx_decoder_by_index(i);
162 fprintf(stderr, " %-6s - %s\n",
163 decoder->name, vpx_codec_iface_name(decoder->interface()));
169 static int raw_read_frame(FILE *infile, uint8_t **buffer,
170 size_t *bytes_read, size_t *buffer_size) {
171 char raw_hdr[RAW_FRAME_HDR_SZ];
172 size_t frame_size = 0;
174 if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) {
176 warn("Failed to read RAW frame size\n");
178 const size_t kCorruptFrameThreshold = 256 * 1024 * 1024;
179 const size_t kFrameTooSmallThreshold = 256 * 1024;
180 frame_size = mem_get_le32(raw_hdr);
182 if (frame_size > kCorruptFrameThreshold) {
183 warn("Read invalid frame size (%u)\n", (unsigned int)frame_size);
187 if (frame_size < kFrameTooSmallThreshold) {
188 warn("Warning: Read invalid frame size (%u) - not a raw file?\n",
189 (unsigned int)frame_size);
192 if (frame_size > *buffer_size) {
193 uint8_t *new_buf = realloc(*buffer, 2 * frame_size);
196 *buffer_size = 2 * frame_size;
198 warn("Failed to allocate compressed data buffer\n");
205 if (fread(*buffer, 1, frame_size, infile) != frame_size) {
206 warn("Failed to read full frame\n");
209 *bytes_read = frame_size;
215 static int read_frame(struct VpxDecInputContext *input, uint8_t **buf,
216 size_t *bytes_in_buffer, size_t *buffer_size) {
217 switch (input->vpx_input_ctx->file_type) {
219 return webm_read_frame(input->webm_ctx,
220 buf, bytes_in_buffer, buffer_size);
222 return raw_read_frame(input->vpx_input_ctx->file,
223 buf, bytes_in_buffer, buffer_size);
225 return ivf_read_frame(input->vpx_input_ctx->file,
226 buf, bytes_in_buffer, buffer_size);
232 static void update_image_md5(const vpx_image_t *img, const int planes[3],
236 for (i = 0; i < 3; ++i) {
237 const int plane = planes[i];
238 const unsigned char *buf = img->planes[plane];
239 const int stride = img->stride[plane];
240 const int w = vpx_img_plane_width(img, plane);
241 const int h = vpx_img_plane_height(img, plane);
243 for (y = 0; y < h; ++y) {
244 MD5Update(md5, buf, w);
250 static void write_image_file(const vpx_image_t *img, const int planes[3],
254 for (i = 0; i < 3; ++i) {
255 const int plane = planes[i];
256 const unsigned char *buf = img->planes[plane];
257 const int stride = img->stride[plane];
258 const int w = vpx_img_plane_width(img, plane);
259 const int h = vpx_img_plane_height(img, plane);
261 for (y = 0; y < h; ++y) {
262 fwrite(buf, 1, w, file);
268 int file_is_raw(struct VpxInputContext *input) {
271 vpx_codec_stream_info_t si;
275 if (fread(buf, 1, 32, input->file) == 32) {
278 if (mem_get_le32(buf) < 256 * 1024 * 1024) {
279 for (i = 0; i < get_vpx_decoder_count(); ++i) {
280 const VpxInterface *const decoder = get_vpx_decoder_by_index(i);
281 if (!vpx_codec_peek_stream_info(decoder->interface(),
282 buf + 4, 32 - 4, &si)) {
284 input->fourcc = decoder->fourcc;
286 input->height = si.h;
287 input->framerate.numerator = 30;
288 input->framerate.denominator = 1;
299 void show_progress(int frame_in, int frame_out, unsigned long dx_time) {
300 fprintf(stderr, "%d decoded frames/%d showed frames in %lu us (%.2f fps)\r",
301 frame_in, frame_out, dx_time,
302 (float)frame_out * 1000000.0 / (float)dx_time);
305 void generate_filename(const char *pattern, char *out, size_t q_len,
306 unsigned int d_w, unsigned int d_h,
307 unsigned int frame_in) {
308 const char *p = pattern;
312 char *next_pat = strchr(p, '%');
317 /* parse the pattern */
321 snprintf(q, q_len - 1, "%d", d_w);
324 snprintf(q, q_len - 1, "%d", d_h);
327 snprintf(q, q_len - 1, "%d", frame_in);
330 snprintf(q, q_len - 1, "%02d", frame_in);
333 snprintf(q, q_len - 1, "%03d", frame_in);
336 snprintf(q, q_len - 1, "%04d", frame_in);
339 snprintf(q, q_len - 1, "%05d", frame_in);
342 snprintf(q, q_len - 1, "%06d", frame_in);
345 snprintf(q, q_len - 1, "%07d", frame_in);
348 snprintf(q, q_len - 1, "%08d", frame_in);
351 snprintf(q, q_len - 1, "%09d", frame_in);
354 die("Unrecognized pattern %%%c\n", p[1]);
358 if (pat_len >= q_len - 1)
359 die("Output filename too long.\n");
366 /* copy the next segment */
368 copy_len = strlen(p);
370 copy_len = next_pat - p;
372 if (copy_len >= q_len - 1)
373 die("Output filename too long.\n");
375 memcpy(q, p, copy_len);
384 static int is_single_file(const char *outfile_pattern) {
385 const char *p = outfile_pattern;
389 if (p && p[1] >= '1' && p[1] <= '9')
390 return 0; // pattern contains sequence number, so it's not unique
398 static void print_md5(unsigned char digest[16], const char *filename) {
401 for (i = 0; i < 16; ++i)
402 printf("%02x", digest[i]);
403 printf(" %s\n", filename);
406 static FILE *open_outfile(const char *name) {
407 if (strcmp("-", name) == 0) {
408 set_binary_mode(stdout);
411 FILE *file = fopen(name, "wb");
413 fatal("Failed to output file %s", name);
418 int main_loop(int argc, const char **argv_) {
419 vpx_codec_ctx_t decoder;
422 size_t bytes_in_buffer = 0, buffer_size = 0;
424 int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0;
425 int do_md5 = 0, progress = 0;
426 int stop_after = 0, postproc = 0, summary = 0, quiet = 1;
429 const VpxInterface *interface = NULL;
430 const VpxInterface *fourcc_interface = NULL;
431 unsigned long dx_time = 0;
433 char **argv, **argi, **argj;
437 vpx_codec_dec_cfg_t cfg = {0};
438 #if CONFIG_VP8_DECODER
439 vp8_postproc_cfg_t vp8_pp_cfg = {0};
440 int vp8_dbg_color_ref_frame = 0;
441 int vp8_dbg_color_mb_modes = 0;
442 int vp8_dbg_color_b_modes = 0;
443 int vp8_dbg_display_mv = 0;
445 int frames_corrupted = 0;
448 vpx_image_t *scaled_img = NULL;
449 int frame_avail, got_data;
451 const char *outfile_pattern = NULL;
452 char outfile_name[PATH_MAX] = {0};
453 FILE *outfile = NULL;
456 unsigned char md5_digest[16];
458 struct VpxDecInputContext input = {0};
459 struct VpxInputContext vpx_input_ctx = {0};
460 struct WebmInputContext webm_ctx = {0};
461 input.vpx_input_ctx = &vpx_input_ctx;
462 input.webm_ctx = &webm_ctx;
464 /* Parse command line */
465 exec_name = argv_[0];
466 argv = argv_dup(argc - 1, argv_ + 1);
468 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
469 memset(&arg, 0, sizeof(arg));
472 if (arg_match(&arg, &codecarg, argi)) {
473 interface = get_vpx_decoder_by_name(arg.val);
475 die("Error: Unrecognized argument (%s) to --codec\n", arg.val);
476 } else if (arg_match(&arg, &looparg, argi)) {
478 } else if (arg_match(&arg, &outputfile, argi))
479 outfile_pattern = arg.val;
480 else if (arg_match(&arg, &use_yv12, argi)) {
483 } else if (arg_match(&arg, &use_i420, argi)) {
486 } else if (arg_match(&arg, &flipuvarg, argi))
488 else if (arg_match(&arg, &noblitarg, argi))
490 else if (arg_match(&arg, &progressarg, argi))
492 else if (arg_match(&arg, &limitarg, argi))
493 stop_after = arg_parse_uint(&arg);
494 else if (arg_match(&arg, &skiparg, argi))
495 arg_skip = arg_parse_uint(&arg);
496 else if (arg_match(&arg, &postprocarg, argi))
498 else if (arg_match(&arg, &md5arg, argi))
500 else if (arg_match(&arg, &summaryarg, argi))
502 else if (arg_match(&arg, &threadsarg, argi))
503 cfg.threads = arg_parse_uint(&arg);
504 else if (arg_match(&arg, &verbosearg, argi))
506 else if (arg_match(&arg, &scalearg, argi))
509 #if CONFIG_VP8_DECODER
510 else if (arg_match(&arg, &addnoise_level, argi)) {
512 vp8_pp_cfg.post_proc_flag |= VP8_ADDNOISE;
513 vp8_pp_cfg.noise_level = arg_parse_uint(&arg);
514 } else if (arg_match(&arg, &demacroblock_level, argi)) {
516 vp8_pp_cfg.post_proc_flag |= VP8_DEMACROBLOCK;
517 vp8_pp_cfg.deblocking_level = arg_parse_uint(&arg);
518 } else if (arg_match(&arg, &deblock, argi)) {
520 vp8_pp_cfg.post_proc_flag |= VP8_DEBLOCK;
521 } else if (arg_match(&arg, &mfqe, argi)) {
523 vp8_pp_cfg.post_proc_flag |= VP8_MFQE;
524 } else if (arg_match(&arg, &pp_debug_info, argi)) {
525 unsigned int level = arg_parse_uint(&arg);
528 vp8_pp_cfg.post_proc_flag &= ~0x7;
531 vp8_pp_cfg.post_proc_flag |= level;
532 } else if (arg_match(&arg, &pp_disp_ref_frame, argi)) {
533 unsigned int flags = arg_parse_int(&arg);
536 vp8_dbg_color_ref_frame = flags;
538 } else if (arg_match(&arg, &pp_disp_mb_modes, argi)) {
539 unsigned int flags = arg_parse_int(&arg);
542 vp8_dbg_color_mb_modes = flags;
544 } else if (arg_match(&arg, &pp_disp_b_modes, argi)) {
545 unsigned int flags = arg_parse_int(&arg);
548 vp8_dbg_color_b_modes = flags;
550 } else if (arg_match(&arg, &pp_disp_mvs, argi)) {
551 unsigned int flags = arg_parse_int(&arg);
554 vp8_dbg_display_mv = flags;
556 } else if (arg_match(&arg, &error_concealment, argi)) {
565 /* Check for unrecognized options */
566 for (argi = argv; *argi; argi++)
567 if (argi[0][0] == '-' && strlen(argi[0]) > 1)
568 die("Error: Unrecognized option %s\n", *argi);
570 /* Handle non-option arguments */
577 infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin);
580 fprintf(stderr, "Failed to open file '%s'", strcmp(fn, "-") ? fn : "stdin");
583 #if CONFIG_OS_SUPPORT
584 /* Make sure we don't dump to the terminal, unless forced to with -o - */
585 if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) {
587 "Not dumping raw video to your terminal. Use '-o -' to "
592 input.vpx_input_ctx->file = infile;
593 if (file_is_ivf(input.vpx_input_ctx))
594 input.vpx_input_ctx->file_type = FILE_TYPE_IVF;
595 else if (file_is_webm(input.webm_ctx, input.vpx_input_ctx))
596 input.vpx_input_ctx->file_type = FILE_TYPE_WEBM;
597 else if (file_is_raw(input.vpx_input_ctx))
598 input.vpx_input_ctx->file_type = FILE_TYPE_RAW;
600 fprintf(stderr, "Unrecognized input file type.\n");
604 outfile_pattern = outfile_pattern ? outfile_pattern : "-";
605 single_file = is_single_file(outfile_pattern);
607 if (!noblit && single_file) {
608 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
609 vpx_input_ctx.width, vpx_input_ctx.height, 0);
613 outfile = open_outfile(outfile_name);
616 if (use_y4m && !noblit) {
618 fprintf(stderr, "YUV4MPEG2 not supported with output patterns,"
619 " try --i420 or --yv12.\n");
623 if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) {
624 if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) {
625 fprintf(stderr, "Failed to guess framerate -- error parsing "
632 fourcc_interface = get_vpx_decoder_by_fourcc(vpx_input_ctx.fourcc);
633 if (interface && fourcc_interface && interface != fourcc_interface)
634 warn("Header indicates codec: %s\n", fourcc_interface->name);
636 interface = fourcc_interface;
639 interface = get_vpx_decoder_by_index(0);
641 dec_flags = (postproc ? VPX_CODEC_USE_POSTPROC : 0) |
642 (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0);
643 if (vpx_codec_dec_init(&decoder, interface->interface(), &cfg, dec_flags)) {
644 fprintf(stderr, "Failed to initialize decoder: %s\n",
645 vpx_codec_error(&decoder));
650 fprintf(stderr, "%s\n", decoder.name);
652 #if CONFIG_VP8_DECODER
654 if (vp8_pp_cfg.post_proc_flag
655 && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) {
656 fprintf(stderr, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder));
660 if (vp8_dbg_color_ref_frame
661 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, vp8_dbg_color_ref_frame)) {
662 fprintf(stderr, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder));
666 if (vp8_dbg_color_mb_modes
667 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, vp8_dbg_color_mb_modes)) {
668 fprintf(stderr, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder));
672 if (vp8_dbg_color_b_modes
673 && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, vp8_dbg_color_b_modes)) {
674 fprintf(stderr, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder));
678 if (vp8_dbg_display_mv
679 && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, vp8_dbg_display_mv)) {
680 fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder));
687 fprintf(stderr, "Skipping first %d frames.\n", arg_skip);
689 if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size))
698 while (frame_avail || got_data) {
699 vpx_codec_iter_t iter = NULL;
701 struct vpx_usec_timer timer;
705 if (!stop_after || frame_in < stop_after) {
706 if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) {
710 vpx_usec_timer_start(&timer);
712 if (vpx_codec_decode(&decoder, buf, bytes_in_buffer, NULL, 0)) {
713 const char *detail = vpx_codec_error_detail(&decoder);
714 warn("Failed to decode frame %d: %s",
715 frame_in, vpx_codec_error(&decoder));
718 warn("Additional information: %s", detail);
722 vpx_usec_timer_mark(&timer);
723 dx_time += (unsigned int)vpx_usec_timer_elapsed(&timer);
727 vpx_usec_timer_start(&timer);
730 if ((img = vpx_codec_get_frame(&decoder, &iter))) {
735 vpx_usec_timer_mark(&timer);
736 dx_time += (unsigned int)vpx_usec_timer_elapsed(&timer);
738 if (vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) {
739 warn("Failed VP8_GET_FRAME_CORRUPTED: %s", vpx_codec_error(&decoder));
742 frames_corrupted += corrupted;
745 show_progress(frame_in, frame_out, dx_time);
747 if (!noblit && img) {
748 const int PLANES_YUV[] = {VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V};
749 const int PLANES_YVU[] = {VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U};
750 const int *planes = flipuv ? PLANES_YVU : PLANES_YUV;
753 if (frame_out == 1) {
754 // If the output frames are to be scaled to a fixed display size then
755 // use the width and height specified in the container. If either of
756 // these is set to 0, use the display size set in the first frame
757 // header. If that is unavailable, use the raw decoded size of the
758 // first decoded frame.
759 int display_width = vpx_input_ctx.width;
760 int display_height = vpx_input_ctx.height;
761 if (!display_width || !display_height) {
763 if (vpx_codec_control(&decoder, VP9D_GET_DISPLAY_SIZE,
765 // As last resort use size of first frame as display size.
766 display_width = img->d_w;
767 display_height = img->d_h;
769 display_width = display_size[0];
770 display_height = display_size[1];
773 scaled_img = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, display_width,
777 if (img->d_w != scaled_img->d_w || img->d_h != scaled_img->d_h) {
778 vpx_image_scale(img, scaled_img, kFilterBox);
785 char buf[Y4M_BUFFER_SIZE] = {0};
787 if (frame_out == 1) {
789 len = y4m_write_file_header(buf, sizeof(buf),
791 vpx_input_ctx.height,
792 &vpx_input_ctx.framerate, img->fmt);
794 MD5Update(&md5_ctx, (md5byte *)buf, len);
801 len = y4m_write_frame_header(buf, sizeof(buf));
803 MD5Update(&md5_ctx, (md5byte *)buf, len);
810 update_image_md5(img, planes, &md5_ctx);
812 write_image_file(img, planes, outfile);
815 generate_filename(outfile_pattern, outfile_name, PATH_MAX,
816 img->d_w, img->d_h, frame_in);
819 update_image_md5(img, planes, &md5_ctx);
820 MD5Final(md5_digest, &md5_ctx);
821 print_md5(md5_digest, outfile_name);
823 outfile = open_outfile(outfile_name);
824 write_image_file(img, planes, outfile);
830 if (stop_after && frame_in >= stop_after)
834 if (summary || progress) {
835 show_progress(frame_in, frame_out, dx_time);
836 fprintf(stderr, "\n");
839 if (frames_corrupted)
840 fprintf(stderr, "WARNING: %d frames corrupted.\n", frames_corrupted);
844 if (vpx_codec_destroy(&decoder)) {
845 fprintf(stderr, "Failed to destroy decoder: %s\n",
846 vpx_codec_error(&decoder));
850 if (!noblit && single_file) {
852 MD5Final(md5_digest, &md5_ctx);
853 print_md5(md5_digest, outfile_name);
859 if (input.vpx_input_ctx->file_type == FILE_TYPE_WEBM)
860 webm_free(input.webm_ctx);
864 if (scaled_img) vpx_img_free(scaled_img);
869 return frames_corrupted ? EXIT_FAILURE : EXIT_SUCCESS;
872 int main(int argc, const char **argv_) {
873 unsigned int loops = 1, i;
874 char **argv, **argi, **argj;
878 argv = argv_dup(argc - 1, argv_ + 1);
879 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
880 memset(&arg, 0, sizeof(arg));
883 if (arg_match(&arg, &looparg, argi)) {
884 loops = arg_parse_uint(&arg);
889 for (i = 0; !error && i < loops; i++)
890 error = main_loop(argc, argv_);