John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
John Koleszar | c2140b8 | 2010-09-09 08:16:39 -0400 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 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 |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 7 | * in the file PATENTS. All contributing project authors may |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 8 | * be found in the AUTHORS file in the root of the source tree. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
John Koleszar | da58436 | 2013-05-06 15:52:06 -0700 | [diff] [blame] | 11 | #include <assert.h> |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <stdarg.h> |
| 15 | #include <string.h> |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 16 | #include <limits.h> |
Tero Rintaluoma | 11a222f | 2011-01-24 11:21:40 +0200 | [diff] [blame] | 17 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 18 | #include "third_party/libyuv/include/libyuv/scale.h" |
| 19 | |
| 20 | #include "./args.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 21 | #include "./ivfdec.h" |
| 22 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 23 | #define VPX_CODEC_DISABLE_COMPAT 1 |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 24 | #include "./vpx_config.h" |
John Koleszar | b749234 | 2010-05-24 11:39:59 -0400 | [diff] [blame] | 25 | #include "vpx/vpx_decoder.h" |
Dmitry Kovalev | 4334c07 | 2014-02-26 16:32:09 -0800 | [diff] [blame] | 26 | #include "vpx_ports/mem_ops.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 27 | #include "vpx_ports/vpx_timer.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 28 | |
John Koleszar | 7b8dfcb | 2012-11-06 16:59:01 -0800 | [diff] [blame] | 29 | #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER |
John Koleszar | b749234 | 2010-05-24 11:39:59 -0400 | [diff] [blame] | 30 | #include "vpx/vp8dx.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 31 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 32 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 33 | #include "./md5_utils.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 34 | |
| 35 | #include "./tools_common.h" |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 36 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 37 | #include "./webmdec.h" |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 38 | #endif |
Dmitry Kovalev | 5ab63583 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 39 | #include "./y4menc.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 40 | |
| 41 | static const char *exec_name; |
| 42 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 43 | struct VpxDecInputContext { |
| 44 | struct VpxInputContext *vpx_input_ctx; |
| 45 | struct WebmInputContext *webm_ctx; |
| 46 | }; |
| 47 | |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 48 | static const arg_def_t looparg = ARG_DEF(NULL, "loops", 1, |
| 49 | "Number of times to decode the file"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 50 | static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 51 | "Codec to use"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 52 | static const arg_def_t use_yv12 = ARG_DEF(NULL, "yv12", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 53 | "Output raw YV12 frames"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 54 | static const arg_def_t use_i420 = ARG_DEF(NULL, "i420", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 55 | "Output raw I420 frames"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 56 | static const arg_def_t flipuvarg = ARG_DEF(NULL, "flipuv", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 57 | "Flip the chroma planes in the output"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 58 | static const arg_def_t noblitarg = ARG_DEF(NULL, "noblit", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 59 | "Don't process the decoded frames"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 60 | static const arg_def_t progressarg = ARG_DEF(NULL, "progress", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 61 | "Show progress after each frame decodes"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 62 | static const arg_def_t limitarg = ARG_DEF(NULL, "limit", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 63 | "Stop decoding after n frames"); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 64 | static const arg_def_t skiparg = ARG_DEF(NULL, "skip", 1, |
| 65 | "Skip the first n input frames"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 66 | static const arg_def_t postprocarg = ARG_DEF(NULL, "postproc", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 67 | "Postprocess decoded frames"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 68 | static const arg_def_t summaryarg = ARG_DEF(NULL, "summary", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 69 | "Show timing summary"); |
Timothy B. Terriberry | 7f9db41 | 2010-05-26 19:36:20 -0400 | [diff] [blame] | 70 | static const arg_def_t outputfile = ARG_DEF("o", "output", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 71 | "Output file name pattern (see below)"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 72 | static const arg_def_t threadsarg = ARG_DEF("t", "threads", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 73 | "Max threads to use"); |
John Koleszar | 4b578ea | 2010-10-21 20:35:12 -0700 | [diff] [blame] | 74 | static const arg_def_t verbosearg = ARG_DEF("v", "verbose", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 75 | "Show version string"); |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 76 | static const arg_def_t error_concealment = ARG_DEF(NULL, "error-concealment", 0, |
| 77 | "Enable decoder error-concealment"); |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 78 | static const arg_def_t scalearg = ARG_DEF("S", "scale", 0, |
| 79 | "Scale output frames uniformly"); |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 80 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 81 | static const arg_def_t fb_arg = |
| 82 | ARG_DEF(NULL, "frame-buffers", 1, "Number of frame buffers to use"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 83 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 84 | static const arg_def_t md5arg = ARG_DEF(NULL, "md5", 0, |
| 85 | "Compute the MD5 sum of the decoded frame"); |
Dmitry Kovalev | d24f4e4 | 2013-12-27 16:10:18 -0800 | [diff] [blame] | 86 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 87 | static const arg_def_t *all_args[] = { |
| 88 | &codecarg, &use_yv12, &use_i420, &flipuvarg, &noblitarg, |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 89 | &progressarg, &limitarg, &skiparg, &postprocarg, &summaryarg, &outputfile, |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 90 | &threadsarg, &verbosearg, &scalearg, &fb_arg, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 91 | &md5arg, |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 92 | &error_concealment, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 93 | NULL |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 94 | }; |
| 95 | |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 96 | #if CONFIG_VP8_DECODER |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 97 | static const arg_def_t addnoise_level = ARG_DEF(NULL, "noise-level", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 98 | "Enable VP8 postproc add noise"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 99 | static const arg_def_t deblock = ARG_DEF(NULL, "deblock", 0, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 100 | "Enable VP8 deblocking"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 101 | static const arg_def_t demacroblock_level = ARG_DEF(NULL, "demacroblock-level", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 102 | "Enable VP8 demacroblocking, w/ level"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 103 | static const arg_def_t pp_debug_info = ARG_DEF(NULL, "pp-debug-info", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 104 | "Enable VP8 visible debug info"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 105 | static const arg_def_t pp_disp_ref_frame = ARG_DEF(NULL, "pp-dbg-ref-frame", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 106 | "Display only selected reference frame per macro block"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 107 | static const arg_def_t pp_disp_mb_modes = ARG_DEF(NULL, "pp-dbg-mb-modes", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 108 | "Display only selected macro block modes"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 109 | static const arg_def_t pp_disp_b_modes = ARG_DEF(NULL, "pp-dbg-b-modes", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 110 | "Display only selected block modes"); |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 111 | static const arg_def_t pp_disp_mvs = ARG_DEF(NULL, "pp-dbg-mvs", 1, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 112 | "Draw only selected motion vectors"); |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 113 | static const arg_def_t mfqe = ARG_DEF(NULL, "mfqe", 0, |
| 114 | "Enable multiframe quality enhancement"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 115 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 116 | static const arg_def_t *vp8_pp_args[] = { |
| 117 | &addnoise_level, &deblock, &demacroblock_level, &pp_debug_info, |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 118 | &pp_disp_ref_frame, &pp_disp_mb_modes, &pp_disp_b_modes, &pp_disp_mvs, &mfqe, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 119 | NULL |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 120 | }; |
| 121 | #endif |
| 122 | |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 123 | static int vpx_image_scale(vpx_image_t *src, vpx_image_t *dst, |
Deb Mukherjee | 20c3077 | 2014-04-22 11:15:19 -0700 | [diff] [blame] | 124 | FilterModeEnum mode) { |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 125 | assert(src->fmt == VPX_IMG_FMT_I420); |
| 126 | assert(dst->fmt == VPX_IMG_FMT_I420); |
| 127 | return I420Scale(src->planes[VPX_PLANE_Y], src->stride[VPX_PLANE_Y], |
| 128 | src->planes[VPX_PLANE_U], src->stride[VPX_PLANE_U], |
| 129 | src->planes[VPX_PLANE_V], src->stride[VPX_PLANE_V], |
| 130 | src->d_w, src->d_h, |
| 131 | dst->planes[VPX_PLANE_Y], dst->stride[VPX_PLANE_Y], |
| 132 | dst->planes[VPX_PLANE_U], dst->stride[VPX_PLANE_U], |
| 133 | dst->planes[VPX_PLANE_V], dst->stride[VPX_PLANE_V], |
| 134 | dst->d_w, dst->d_h, |
| 135 | mode); |
| 136 | } |
| 137 | |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 138 | void usage_exit() { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 139 | int i; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 140 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 141 | fprintf(stderr, "Usage: %s <options> filename\n\n" |
| 142 | "Options:\n", exec_name); |
| 143 | arg_show_usage(stderr, all_args); |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 144 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 145 | fprintf(stderr, "\nVP8 Postprocessing Options:\n"); |
| 146 | arg_show_usage(stderr, vp8_pp_args); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 147 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 148 | fprintf(stderr, |
| 149 | "\nOutput File Patterns:\n\n" |
| 150 | " The -o argument specifies the name of the file(s) to " |
| 151 | "write to. If the\n argument does not include any escape " |
| 152 | "characters, the output will be\n written to a single file. " |
| 153 | "Otherwise, the filename will be calculated by\n expanding " |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 154 | "the following escape characters:\n"); |
| 155 | fprintf(stderr, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 156 | "\n\t%%w - Frame width" |
| 157 | "\n\t%%h - Frame height" |
| 158 | "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)" |
| 159 | "\n\n Pattern arguments are only supported in conjunction " |
| 160 | "with the --yv12 and\n --i420 options. If the -o option is " |
| 161 | "not specified, the output will be\n directed to stdout.\n" |
| 162 | ); |
| 163 | fprintf(stderr, "\nIncluded decoders:\n\n"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 164 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 165 | for (i = 0; i < get_vpx_decoder_count(); ++i) { |
| 166 | const VpxInterface *const decoder = get_vpx_decoder_by_index(i); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 167 | fprintf(stderr, " %-6s - %s\n", |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 168 | decoder->name, vpx_codec_iface_name(decoder->interface())); |
| 169 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 170 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 171 | exit(EXIT_FAILURE); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 174 | static int raw_read_frame(FILE *infile, uint8_t **buffer, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 175 | size_t *bytes_read, size_t *buffer_size) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 176 | char raw_hdr[RAW_FRAME_HDR_SZ]; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 177 | size_t frame_size = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 178 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 179 | if (fread(raw_hdr, RAW_FRAME_HDR_SZ, 1, infile) != 1) { |
| 180 | if (!feof(infile)) |
| 181 | warn("Failed to read RAW frame size\n"); |
| 182 | } else { |
James Zern | 75d7ee3 | 2014-02-04 20:06:28 -0800 | [diff] [blame] | 183 | const size_t kCorruptFrameThreshold = 256 * 1024 * 1024; |
| 184 | const size_t kFrameTooSmallThreshold = 256 * 1024; |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 185 | frame_size = mem_get_le32(raw_hdr); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 186 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 187 | if (frame_size > kCorruptFrameThreshold) { |
| 188 | warn("Read invalid frame size (%u)\n", (unsigned int)frame_size); |
| 189 | frame_size = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 190 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 191 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 192 | if (frame_size < kFrameTooSmallThreshold) { |
| 193 | warn("Warning: Read invalid frame size (%u) - not a raw file?\n", |
| 194 | (unsigned int)frame_size); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 197 | if (frame_size > *buffer_size) { |
| 198 | uint8_t *new_buf = realloc(*buffer, 2 * frame_size); |
| 199 | if (new_buf) { |
| 200 | *buffer = new_buf; |
| 201 | *buffer_size = 2 * frame_size; |
| 202 | } else { |
| 203 | warn("Failed to allocate compressed data buffer\n"); |
| 204 | frame_size = 0; |
| 205 | } |
| 206 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 207 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 208 | |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 209 | if (!feof(infile)) { |
| 210 | if (fread(*buffer, 1, frame_size, infile) != frame_size) { |
| 211 | warn("Failed to read full frame\n"); |
| 212 | return 1; |
| 213 | } |
| 214 | *bytes_read = frame_size; |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static int read_frame(struct VpxDecInputContext *input, uint8_t **buf, |
| 221 | size_t *bytes_in_buffer, size_t *buffer_size) { |
| 222 | switch (input->vpx_input_ctx->file_type) { |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 223 | #if CONFIG_WEBM_IO |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 224 | case FILE_TYPE_WEBM: |
| 225 | return webm_read_frame(input->webm_ctx, |
| 226 | buf, bytes_in_buffer, buffer_size); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 227 | #endif |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 228 | case FILE_TYPE_RAW: |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 229 | return raw_read_frame(input->vpx_input_ctx->file, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 230 | buf, bytes_in_buffer, buffer_size); |
| 231 | case FILE_TYPE_IVF: |
Dmitry Kovalev | 0eac753 | 2014-01-13 11:57:55 -0800 | [diff] [blame] | 232 | return ivf_read_frame(input->vpx_input_ctx->file, |
Dmitry Kovalev | f0fde24 | 2014-01-13 10:54:57 -0800 | [diff] [blame] | 233 | buf, bytes_in_buffer, buffer_size); |
| 234 | default: |
| 235 | return 1; |
| 236 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 237 | } |
| 238 | |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 239 | static void update_image_md5(const vpx_image_t *img, const int planes[3], |
| 240 | MD5Context *md5) { |
| 241 | int i, y; |
| 242 | |
| 243 | for (i = 0; i < 3; ++i) { |
| 244 | const int plane = planes[i]; |
| 245 | const unsigned char *buf = img->planes[plane]; |
| 246 | const int stride = img->stride[plane]; |
Dmitry Kovalev | 2bdd43d | 2014-02-12 18:36:36 -0800 | [diff] [blame] | 247 | const int w = vpx_img_plane_width(img, plane); |
| 248 | const int h = vpx_img_plane_height(img, plane); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 249 | |
| 250 | for (y = 0; y < h; ++y) { |
| 251 | MD5Update(md5, buf, w); |
| 252 | buf += stride; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | static void write_image_file(const vpx_image_t *img, const int planes[3], |
| 258 | FILE *file) { |
| 259 | int i, y; |
| 260 | |
| 261 | for (i = 0; i < 3; ++i) { |
| 262 | const int plane = planes[i]; |
| 263 | const unsigned char *buf = img->planes[plane]; |
| 264 | const int stride = img->stride[plane]; |
Dmitry Kovalev | 2bdd43d | 2014-02-12 18:36:36 -0800 | [diff] [blame] | 265 | const int w = vpx_img_plane_width(img, plane); |
| 266 | const int h = vpx_img_plane_height(img, plane); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 267 | |
| 268 | for (y = 0; y < h; ++y) { |
| 269 | fwrite(buf, 1, w, file); |
| 270 | buf += stride; |
| 271 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 272 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 273 | } |
| 274 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 275 | int file_is_raw(struct VpxInputContext *input) { |
| 276 | uint8_t buf[32]; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 277 | int is_raw = 0; |
| 278 | vpx_codec_stream_info_t si; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 279 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 280 | si.sz = sizeof(si); |
John Koleszar | 19255b8 | 2010-11-23 13:40:31 -0500 | [diff] [blame] | 281 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 282 | if (fread(buf, 1, 32, input->file) == 32) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 283 | int i; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 284 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 285 | if (mem_get_le32(buf) < 256 * 1024 * 1024) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 286 | for (i = 0; i < get_vpx_decoder_count(); ++i) { |
| 287 | const VpxInterface *const decoder = get_vpx_decoder_by_index(i); |
| 288 | if (!vpx_codec_peek_stream_info(decoder->interface(), |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 289 | buf + 4, 32 - 4, &si)) { |
| 290 | is_raw = 1; |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 291 | input->fourcc = decoder->fourcc; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 292 | input->width = si.w; |
| 293 | input->height = si.h; |
| 294 | input->framerate.numerator = 30; |
| 295 | input->framerate.denominator = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 296 | break; |
| 297 | } |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 298 | } |
| 299 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 300 | } |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 301 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 302 | rewind(input->file); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 303 | return is_raw; |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 304 | } |
| 305 | |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 306 | void show_progress(int frame_in, int frame_out, uint64_t dx_time) { |
| 307 | fprintf(stderr, |
| 308 | "%d decoded frames/%d showed frames in %"PRId64" us (%.2f fps)\r", |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 309 | frame_in, frame_out, dx_time, |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 310 | (double)frame_out * 1000000.0 / (double)dx_time); |
John Koleszar | 5d12e04 | 2010-10-21 17:28:34 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 313 | struct ExternalFrameBuffer { |
| 314 | uint8_t* data; |
| 315 | size_t size; |
| 316 | int in_use; |
| 317 | }; |
| 318 | |
| 319 | struct ExternalFrameBufferList { |
| 320 | int num_external_frame_buffers; |
| 321 | struct ExternalFrameBuffer *ext_fb; |
| 322 | }; |
| 323 | |
| 324 | // Callback used by libvpx to request an external frame buffer. |cb_priv| |
| 325 | // Application private data passed into the set function. |min_size| is the |
| 326 | // minimum size in bytes needed to decode the next frame. |fb| pointer to the |
| 327 | // frame buffer. |
| 328 | int get_vp9_frame_buffer(void *cb_priv, size_t min_size, |
| 329 | vpx_codec_frame_buffer_t *fb) { |
| 330 | int i; |
| 331 | struct ExternalFrameBufferList *const ext_fb_list = |
| 332 | (struct ExternalFrameBufferList *)cb_priv; |
| 333 | if (ext_fb_list == NULL) |
| 334 | return -1; |
| 335 | |
| 336 | // Find a free frame buffer. |
| 337 | for (i = 0; i < ext_fb_list->num_external_frame_buffers; ++i) { |
| 338 | if (!ext_fb_list->ext_fb[i].in_use) |
| 339 | break; |
| 340 | } |
| 341 | |
| 342 | if (i == ext_fb_list->num_external_frame_buffers) |
| 343 | return -1; |
| 344 | |
| 345 | if (ext_fb_list->ext_fb[i].size < min_size) { |
| 346 | free(ext_fb_list->ext_fb[i].data); |
| 347 | ext_fb_list->ext_fb[i].data = (uint8_t *)malloc(min_size); |
| 348 | if (!ext_fb_list->ext_fb[i].data) |
| 349 | return -1; |
| 350 | |
| 351 | ext_fb_list->ext_fb[i].size = min_size; |
| 352 | } |
| 353 | |
| 354 | fb->data = ext_fb_list->ext_fb[i].data; |
| 355 | fb->size = ext_fb_list->ext_fb[i].size; |
| 356 | ext_fb_list->ext_fb[i].in_use = 1; |
| 357 | |
| 358 | // Set the frame buffer's private data to point at the external frame buffer. |
| 359 | fb->priv = &ext_fb_list->ext_fb[i]; |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | // Callback used by libvpx when there are no references to the frame buffer. |
| 364 | // |cb_priv| user private data passed into the set function. |fb| pointer |
| 365 | // to the frame buffer. |
| 366 | int release_vp9_frame_buffer(void *cb_priv, |
| 367 | vpx_codec_frame_buffer_t *fb) { |
| 368 | struct ExternalFrameBuffer *const ext_fb = |
| 369 | (struct ExternalFrameBuffer *)fb->priv; |
| 370 | (void)cb_priv; |
| 371 | ext_fb->in_use = 0; |
| 372 | return 0; |
| 373 | } |
| 374 | |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 375 | void generate_filename(const char *pattern, char *out, size_t q_len, |
| 376 | unsigned int d_w, unsigned int d_h, |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 377 | unsigned int frame_in) { |
| 378 | const char *p = pattern; |
| 379 | char *q = out; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 380 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 381 | do { |
| 382 | char *next_pat = strchr(p, '%'); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 383 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 384 | if (p == next_pat) { |
| 385 | size_t pat_len; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 386 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 387 | /* parse the pattern */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 388 | q[q_len - 1] = '\0'; |
| 389 | switch (p[1]) { |
| 390 | case 'w': |
| 391 | snprintf(q, q_len - 1, "%d", d_w); |
| 392 | break; |
| 393 | case 'h': |
| 394 | snprintf(q, q_len - 1, "%d", d_h); |
| 395 | break; |
| 396 | case '1': |
| 397 | snprintf(q, q_len - 1, "%d", frame_in); |
| 398 | break; |
| 399 | case '2': |
| 400 | snprintf(q, q_len - 1, "%02d", frame_in); |
| 401 | break; |
| 402 | case '3': |
| 403 | snprintf(q, q_len - 1, "%03d", frame_in); |
| 404 | break; |
| 405 | case '4': |
| 406 | snprintf(q, q_len - 1, "%04d", frame_in); |
| 407 | break; |
| 408 | case '5': |
| 409 | snprintf(q, q_len - 1, "%05d", frame_in); |
| 410 | break; |
| 411 | case '6': |
| 412 | snprintf(q, q_len - 1, "%06d", frame_in); |
| 413 | break; |
| 414 | case '7': |
| 415 | snprintf(q, q_len - 1, "%07d", frame_in); |
| 416 | break; |
| 417 | case '8': |
| 418 | snprintf(q, q_len - 1, "%08d", frame_in); |
| 419 | break; |
| 420 | case '9': |
| 421 | snprintf(q, q_len - 1, "%09d", frame_in); |
| 422 | break; |
| 423 | default: |
| 424 | die("Unrecognized pattern %%%c\n", p[1]); |
| 425 | } |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 426 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 427 | pat_len = strlen(q); |
| 428 | if (pat_len >= q_len - 1) |
| 429 | die("Output filename too long.\n"); |
| 430 | q += pat_len; |
| 431 | p += 2; |
| 432 | q_len -= pat_len; |
| 433 | } else { |
| 434 | size_t copy_len; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 435 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 436 | /* copy the next segment */ |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 437 | if (!next_pat) |
| 438 | copy_len = strlen(p); |
| 439 | else |
| 440 | copy_len = next_pat - p; |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 441 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 442 | if (copy_len >= q_len - 1) |
| 443 | die("Output filename too long.\n"); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 444 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 445 | memcpy(q, p, copy_len); |
| 446 | q[copy_len] = '\0'; |
| 447 | q += copy_len; |
| 448 | p += copy_len; |
| 449 | q_len -= copy_len; |
| 450 | } |
| 451 | } while (*p); |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 454 | static int is_single_file(const char *outfile_pattern) { |
| 455 | const char *p = outfile_pattern; |
| 456 | |
| 457 | do { |
| 458 | p = strchr(p, '%'); |
| 459 | if (p && p[1] >= '1' && p[1] <= '9') |
| 460 | return 0; // pattern contains sequence number, so it's not unique |
| 461 | if (p) |
| 462 | p++; |
| 463 | } while (p); |
| 464 | |
| 465 | return 1; |
| 466 | } |
| 467 | |
| 468 | static void print_md5(unsigned char digest[16], const char *filename) { |
| 469 | int i; |
| 470 | |
| 471 | for (i = 0; i < 16; ++i) |
| 472 | printf("%02x", digest[i]); |
| 473 | printf(" %s\n", filename); |
| 474 | } |
| 475 | |
| 476 | static FILE *open_outfile(const char *name) { |
| 477 | if (strcmp("-", name) == 0) { |
| 478 | set_binary_mode(stdout); |
| 479 | return stdout; |
| 480 | } else { |
| 481 | FILE *file = fopen(name, "wb"); |
| 482 | if (!file) |
| 483 | fatal("Failed to output file %s", name); |
| 484 | return file; |
| 485 | } |
| 486 | } |
| 487 | |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 488 | int main_loop(int argc, const char **argv_) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 489 | vpx_codec_ctx_t decoder; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 490 | char *fn = NULL; |
Alex Converse | 2eccbd0 | 2014-02-13 17:02:50 -0800 | [diff] [blame] | 491 | int i; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 492 | uint8_t *buf = NULL; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 493 | size_t bytes_in_buffer = 0, buffer_size = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 494 | FILE *infile; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 495 | int frame_in = 0, frame_out = 0, flipuv = 0, noblit = 0; |
| 496 | int do_md5 = 0, progress = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 497 | int stop_after = 0, postproc = 0, summary = 0, quiet = 1; |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 498 | int arg_skip = 0; |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 499 | int ec_enabled = 0; |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 500 | const VpxInterface *interface = NULL; |
| 501 | const VpxInterface *fourcc_interface = NULL; |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 502 | uint64_t dx_time = 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 503 | struct arg arg; |
| 504 | char **argv, **argi, **argj; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 505 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 506 | int single_file; |
| 507 | int use_y4m = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 508 | vpx_codec_dec_cfg_t cfg = {0}; |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 509 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 510 | vp8_postproc_cfg_t vp8_pp_cfg = {0}; |
| 511 | int vp8_dbg_color_ref_frame = 0; |
| 512 | int vp8_dbg_color_mb_modes = 0; |
| 513 | int vp8_dbg_color_b_modes = 0; |
| 514 | int vp8_dbg_display_mv = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 515 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 516 | int frames_corrupted = 0; |
| 517 | int dec_flags = 0; |
John Koleszar | 83f2a11 | 2013-03-11 12:30:29 -0700 | [diff] [blame] | 518 | int do_scale = 0; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 519 | vpx_image_t *scaled_img = NULL; |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 520 | int frame_avail, got_data; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 521 | int num_external_frame_buffers = 0; |
| 522 | struct ExternalFrameBufferList ext_fb_list = {0}; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 523 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 524 | const char *outfile_pattern = NULL; |
| 525 | char outfile_name[PATH_MAX] = {0}; |
| 526 | FILE *outfile = NULL; |
| 527 | |
| 528 | MD5Context md5_ctx; |
| 529 | unsigned char md5_digest[16]; |
| 530 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 531 | struct VpxDecInputContext input = {0}; |
| 532 | struct VpxInputContext vpx_input_ctx = {0}; |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 533 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 534 | struct WebmInputContext webm_ctx = {0}; |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 535 | input.webm_ctx = &webm_ctx; |
James Zern | b6cce76 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 536 | #endif |
| 537 | input.vpx_input_ctx = &vpx_input_ctx; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 538 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 539 | /* Parse command line */ |
| 540 | exec_name = argv_[0]; |
| 541 | argv = argv_dup(argc - 1, argv_ + 1); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 542 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 543 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 544 | memset(&arg, 0, sizeof(arg)); |
| 545 | arg.argv_step = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 546 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 547 | if (arg_match(&arg, &codecarg, argi)) { |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 548 | interface = get_vpx_decoder_by_name(arg.val); |
| 549 | if (!interface) |
| 550 | die("Error: Unrecognized argument (%s) to --codec\n", arg.val); |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 551 | } else if (arg_match(&arg, &looparg, argi)) { |
| 552 | // no-op |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 553 | } else if (arg_match(&arg, &outputfile, argi)) |
| 554 | outfile_pattern = arg.val; |
| 555 | else if (arg_match(&arg, &use_yv12, argi)) { |
| 556 | use_y4m = 0; |
| 557 | flipuv = 1; |
| 558 | } else if (arg_match(&arg, &use_i420, argi)) { |
| 559 | use_y4m = 0; |
| 560 | flipuv = 0; |
| 561 | } else if (arg_match(&arg, &flipuvarg, argi)) |
| 562 | flipuv = 1; |
| 563 | else if (arg_match(&arg, &noblitarg, argi)) |
| 564 | noblit = 1; |
| 565 | else if (arg_match(&arg, &progressarg, argi)) |
| 566 | progress = 1; |
| 567 | else if (arg_match(&arg, &limitarg, argi)) |
| 568 | stop_after = arg_parse_uint(&arg); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 569 | else if (arg_match(&arg, &skiparg, argi)) |
| 570 | arg_skip = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 571 | else if (arg_match(&arg, &postprocarg, argi)) |
| 572 | postproc = 1; |
| 573 | else if (arg_match(&arg, &md5arg, argi)) |
| 574 | do_md5 = 1; |
| 575 | else if (arg_match(&arg, &summaryarg, argi)) |
| 576 | summary = 1; |
| 577 | else if (arg_match(&arg, &threadsarg, argi)) |
| 578 | cfg.threads = arg_parse_uint(&arg); |
| 579 | else if (arg_match(&arg, &verbosearg, argi)) |
| 580 | quiet = 0; |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 581 | else if (arg_match(&arg, &scalearg, argi)) |
| 582 | do_scale = 1; |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 583 | else if (arg_match(&arg, &fb_arg, argi)) |
| 584 | num_external_frame_buffers = arg_parse_uint(&arg); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 585 | |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 586 | #if CONFIG_VP8_DECODER |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 587 | else if (arg_match(&arg, &addnoise_level, argi)) { |
| 588 | postproc = 1; |
| 589 | vp8_pp_cfg.post_proc_flag |= VP8_ADDNOISE; |
| 590 | vp8_pp_cfg.noise_level = arg_parse_uint(&arg); |
| 591 | } else if (arg_match(&arg, &demacroblock_level, argi)) { |
| 592 | postproc = 1; |
| 593 | vp8_pp_cfg.post_proc_flag |= VP8_DEMACROBLOCK; |
| 594 | vp8_pp_cfg.deblocking_level = arg_parse_uint(&arg); |
| 595 | } else if (arg_match(&arg, &deblock, argi)) { |
| 596 | postproc = 1; |
| 597 | vp8_pp_cfg.post_proc_flag |= VP8_DEBLOCK; |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 598 | } else if (arg_match(&arg, &mfqe, argi)) { |
| 599 | postproc = 1; |
| 600 | vp8_pp_cfg.post_proc_flag |= VP8_MFQE; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 601 | } else if (arg_match(&arg, &pp_debug_info, argi)) { |
| 602 | unsigned int level = arg_parse_uint(&arg); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 603 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 604 | postproc = 1; |
| 605 | vp8_pp_cfg.post_proc_flag &= ~0x7; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 606 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 607 | if (level) |
| 608 | vp8_pp_cfg.post_proc_flag |= level; |
| 609 | } else if (arg_match(&arg, &pp_disp_ref_frame, argi)) { |
| 610 | unsigned int flags = arg_parse_int(&arg); |
| 611 | if (flags) { |
| 612 | postproc = 1; |
| 613 | vp8_dbg_color_ref_frame = flags; |
| 614 | } |
| 615 | } else if (arg_match(&arg, &pp_disp_mb_modes, argi)) { |
| 616 | unsigned int flags = arg_parse_int(&arg); |
| 617 | if (flags) { |
| 618 | postproc = 1; |
| 619 | vp8_dbg_color_mb_modes = flags; |
| 620 | } |
| 621 | } else if (arg_match(&arg, &pp_disp_b_modes, argi)) { |
| 622 | unsigned int flags = arg_parse_int(&arg); |
| 623 | if (flags) { |
| 624 | postproc = 1; |
| 625 | vp8_dbg_color_b_modes = flags; |
| 626 | } |
| 627 | } else if (arg_match(&arg, &pp_disp_mvs, argi)) { |
| 628 | unsigned int flags = arg_parse_int(&arg); |
| 629 | if (flags) { |
| 630 | postproc = 1; |
| 631 | vp8_dbg_display_mv = flags; |
| 632 | } |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 633 | } else if (arg_match(&arg, &error_concealment, argi)) { |
| 634 | ec_enabled = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 635 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 636 | |
| 637 | #endif |
John Koleszar | cfe3f91 | 2010-10-20 10:49:12 -0400 | [diff] [blame] | 638 | else |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 639 | argj++; |
| 640 | } |
| 641 | |
| 642 | /* Check for unrecognized options */ |
| 643 | for (argi = argv; *argi; argi++) |
| 644 | if (argi[0][0] == '-' && strlen(argi[0]) > 1) |
| 645 | die("Error: Unrecognized option %s\n", *argi); |
| 646 | |
| 647 | /* Handle non-option arguments */ |
| 648 | fn = argv[0]; |
| 649 | |
| 650 | if (!fn) |
| 651 | usage_exit(); |
| 652 | |
| 653 | /* Open file */ |
| 654 | infile = strcmp(fn, "-") ? fopen(fn, "rb") : set_binary_mode(stdin); |
| 655 | |
| 656 | if (!infile) { |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 657 | fprintf(stderr, "Failed to open file '%s'", strcmp(fn, "-") ? fn : "stdin"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 658 | return EXIT_FAILURE; |
| 659 | } |
| 660 | #if CONFIG_OS_SUPPORT |
| 661 | /* Make sure we don't dump to the terminal, unless forced to with -o - */ |
| 662 | if (!outfile_pattern && isatty(fileno(stdout)) && !do_md5 && !noblit) { |
| 663 | fprintf(stderr, |
| 664 | "Not dumping raw video to your terminal. Use '-o -' to " |
| 665 | "override.\n"); |
| 666 | return EXIT_FAILURE; |
| 667 | } |
| 668 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 669 | input.vpx_input_ctx->file = infile; |
| 670 | if (file_is_ivf(input.vpx_input_ctx)) |
| 671 | input.vpx_input_ctx->file_type = FILE_TYPE_IVF; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 672 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 673 | else if (file_is_webm(input.webm_ctx, input.vpx_input_ctx)) |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 674 | input.vpx_input_ctx->file_type = FILE_TYPE_WEBM; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 675 | #endif |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 676 | else if (file_is_raw(input.vpx_input_ctx)) |
| 677 | input.vpx_input_ctx->file_type = FILE_TYPE_RAW; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 678 | else { |
| 679 | fprintf(stderr, "Unrecognized input file type.\n"); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 680 | #if !CONFIG_WEBM_IO |
| 681 | fprintf(stderr, "vpxdec was built without WebM container support.\n"); |
| 682 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 683 | return EXIT_FAILURE; |
| 684 | } |
| 685 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 686 | outfile_pattern = outfile_pattern ? outfile_pattern : "-"; |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 687 | single_file = is_single_file(outfile_pattern); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 688 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 689 | if (!noblit && single_file) { |
| 690 | generate_filename(outfile_pattern, outfile_name, PATH_MAX, |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 691 | vpx_input_ctx.width, vpx_input_ctx.height, 0); |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 692 | if (do_md5) |
| 693 | MD5Init(&md5_ctx); |
| 694 | else |
| 695 | outfile = open_outfile(outfile_name); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | if (use_y4m && !noblit) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 699 | if (!single_file) { |
| 700 | fprintf(stderr, "YUV4MPEG2 not supported with output patterns," |
| 701 | " try --i420 or --yv12.\n"); |
| 702 | return EXIT_FAILURE; |
| 703 | } |
| 704 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 705 | #if CONFIG_WEBM_IO |
Dmitry Kovalev | 5ab63583 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 706 | if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) { |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 707 | if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 708 | fprintf(stderr, "Failed to guess framerate -- error parsing " |
| 709 | "webm file?\n"); |
Timothy B. Terriberry | 7f9db41 | 2010-05-26 19:36:20 -0400 | [diff] [blame] | 710 | return EXIT_FAILURE; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 711 | } |
Dmitry Kovalev | 5ab63583 | 2014-01-17 17:02:37 -0800 | [diff] [blame] | 712 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 713 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 716 | fourcc_interface = get_vpx_decoder_by_fourcc(vpx_input_ctx.fourcc); |
| 717 | if (interface && fourcc_interface && interface != fourcc_interface) |
| 718 | warn("Header indicates codec: %s\n", fourcc_interface->name); |
| 719 | else |
| 720 | interface = fourcc_interface; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 721 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 722 | if (!interface) |
| 723 | interface = get_vpx_decoder_by_index(0); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 724 | |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 725 | dec_flags = (postproc ? VPX_CODEC_USE_POSTPROC : 0) | |
| 726 | (ec_enabled ? VPX_CODEC_USE_ERROR_CONCEALMENT : 0); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 727 | if (vpx_codec_dec_init(&decoder, interface->interface(), &cfg, dec_flags)) { |
| 728 | fprintf(stderr, "Failed to initialize decoder: %s\n", |
| 729 | vpx_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 730 | return EXIT_FAILURE; |
| 731 | } |
John Koleszar | 933d44b | 2010-10-21 20:40:42 -0700 | [diff] [blame] | 732 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 733 | if (!quiet) |
| 734 | fprintf(stderr, "%s\n", decoder.name); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 735 | |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 736 | #if CONFIG_VP8_DECODER |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 737 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 738 | if (vp8_pp_cfg.post_proc_flag |
| 739 | && vpx_codec_control(&decoder, VP8_SET_POSTPROC, &vp8_pp_cfg)) { |
| 740 | fprintf(stderr, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder)); |
| 741 | return EXIT_FAILURE; |
| 742 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 743 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 744 | if (vp8_dbg_color_ref_frame |
| 745 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_REF_FRAME, vp8_dbg_color_ref_frame)) { |
| 746 | fprintf(stderr, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 747 | return EXIT_FAILURE; |
| 748 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 749 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 750 | if (vp8_dbg_color_mb_modes |
| 751 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_MB_MODES, vp8_dbg_color_mb_modes)) { |
| 752 | fprintf(stderr, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 753 | return EXIT_FAILURE; |
| 754 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 755 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 756 | if (vp8_dbg_color_b_modes |
| 757 | && vpx_codec_control(&decoder, VP8_SET_DBG_COLOR_B_MODES, vp8_dbg_color_b_modes)) { |
| 758 | fprintf(stderr, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder)); |
| 759 | return EXIT_FAILURE; |
| 760 | } |
Fritz Koenig | 647df00 | 2010-11-04 16:03:36 -0700 | [diff] [blame] | 761 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 762 | if (vp8_dbg_display_mv |
| 763 | && vpx_codec_control(&decoder, VP8_SET_DBG_DISPLAY_MV, vp8_dbg_display_mv)) { |
| 764 | fprintf(stderr, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder)); |
| 765 | return EXIT_FAILURE; |
| 766 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 767 | #endif |
| 768 | |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 769 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 770 | if (arg_skip) |
Adrian Grange | 475d1d6 | 2013-11-20 09:49:33 -0800 | [diff] [blame] | 771 | fprintf(stderr, "Skipping first %d frames.\n", arg_skip); |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 772 | while (arg_skip) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 773 | if (read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) |
Yaowu Xu | c394ffc | 2012-10-11 15:12:35 -0700 | [diff] [blame] | 774 | break; |
| 775 | arg_skip--; |
| 776 | } |
| 777 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 778 | if (num_external_frame_buffers > 0) { |
| 779 | ext_fb_list.num_external_frame_buffers = num_external_frame_buffers; |
| 780 | ext_fb_list.ext_fb = (struct ExternalFrameBuffer *)calloc( |
| 781 | num_external_frame_buffers, sizeof(*ext_fb_list.ext_fb)); |
| 782 | if (vpx_codec_set_frame_buffer_functions( |
| 783 | &decoder, get_vp9_frame_buffer, release_vp9_frame_buffer, |
| 784 | &ext_fb_list)) { |
| 785 | fprintf(stderr, "Failed to configure external frame buffers: %s\n", |
| 786 | vpx_codec_error(&decoder)); |
| 787 | return EXIT_FAILURE; |
| 788 | } |
| 789 | } |
| 790 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 791 | frame_avail = 1; |
| 792 | got_data = 0; |
| 793 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 794 | /* Decode file */ |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 795 | while (frame_avail || got_data) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 796 | vpx_codec_iter_t iter = NULL; |
| 797 | vpx_image_t *img; |
| 798 | struct vpx_usec_timer timer; |
| 799 | int corrupted; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 800 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 801 | frame_avail = 0; |
| 802 | if (!stop_after || frame_in < stop_after) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 803 | if (!read_frame(&input, &buf, &bytes_in_buffer, &buffer_size)) { |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 804 | frame_avail = 1; |
| 805 | frame_in++; |
| 806 | |
| 807 | vpx_usec_timer_start(&timer); |
| 808 | |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 809 | if (vpx_codec_decode(&decoder, buf, (unsigned int)bytes_in_buffer, |
| 810 | NULL, 0)) { |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 811 | const char *detail = vpx_codec_error_detail(&decoder); |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 812 | warn("Failed to decode frame %d: %s", |
| 813 | frame_in, vpx_codec_error(&decoder)); |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 814 | |
| 815 | if (detail) |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 816 | warn("Additional information: %s", detail); |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 817 | goto fail; |
| 818 | } |
| 819 | |
| 820 | vpx_usec_timer_mark(&timer); |
James Yu | 6d15132 | 2014-02-22 14:51:11 +0800 | [diff] [blame] | 821 | dx_time += vpx_usec_timer_elapsed(&timer); |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 825 | vpx_usec_timer_start(&timer); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 826 | |
Scott LaVarnway | c3ae212 | 2013-06-07 12:39:03 -0400 | [diff] [blame] | 827 | got_data = 0; |
| 828 | if ((img = vpx_codec_get_frame(&decoder, &iter))) { |
| 829 | ++frame_out; |
| 830 | got_data = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 831 | } |
| 832 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 833 | vpx_usec_timer_mark(&timer); |
John Koleszar | 3707c34 | 2012-11-06 10:09:36 -0800 | [diff] [blame] | 834 | dx_time += (unsigned int)vpx_usec_timer_elapsed(&timer); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 835 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 836 | if (vpx_codec_control(&decoder, VP8D_GET_FRAME_CORRUPTED, &corrupted)) { |
Tom Finegan | f225b1e | 2013-11-18 15:50:58 -0800 | [diff] [blame] | 837 | warn("Failed VP8_GET_FRAME_CORRUPTED: %s", vpx_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 838 | goto fail; |
| 839 | } |
| 840 | frames_corrupted += corrupted; |
| 841 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 842 | if (progress) |
| 843 | show_progress(frame_in, frame_out, dx_time); |
| 844 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 845 | if (!noblit && img) { |
| 846 | const int PLANES_YUV[] = {VPX_PLANE_Y, VPX_PLANE_U, VPX_PLANE_V}; |
| 847 | const int PLANES_YVU[] = {VPX_PLANE_Y, VPX_PLANE_V, VPX_PLANE_U}; |
| 848 | const int *planes = flipuv ? PLANES_YVU : PLANES_YUV; |
John Koleszar | da58436 | 2013-05-06 15:52:06 -0700 | [diff] [blame] | 849 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 850 | if (do_scale) { |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 851 | if (frame_out == 1) { |
| 852 | // If the output frames are to be scaled to a fixed display size then |
| 853 | // use the width and height specified in the container. If either of |
| 854 | // these is set to 0, use the display size set in the first frame |
Adrian Grange | 82f6af6 | 2014-01-22 09:36:07 -0800 | [diff] [blame] | 855 | // header. If that is unavailable, use the raw decoded size of the |
| 856 | // first decoded frame. |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 857 | int display_width = vpx_input_ctx.width; |
| 858 | int display_height = vpx_input_ctx.height; |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 859 | if (!display_width || !display_height) { |
| 860 | int display_size[2]; |
| 861 | if (vpx_codec_control(&decoder, VP9D_GET_DISPLAY_SIZE, |
| 862 | display_size)) { |
| 863 | // As last resort use size of first frame as display size. |
| 864 | display_width = img->d_w; |
| 865 | display_height = img->d_h; |
| 866 | } else { |
| 867 | display_width = display_size[0]; |
| 868 | display_height = display_size[1]; |
| 869 | } |
Adrian Grange | 2117fe0 | 2013-11-19 14:01:44 -0800 | [diff] [blame] | 870 | } |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 871 | scaled_img = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, display_width, |
| 872 | display_height, 16); |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 873 | } |
Adrian Grange | 482c39c | 2013-12-13 10:15:03 -0800 | [diff] [blame] | 874 | |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 875 | if (img->d_w != scaled_img->d_w || img->d_h != scaled_img->d_h) { |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 876 | #if CONFIG_LIBYUV |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 877 | vpx_image_scale(img, scaled_img, kFilterBox); |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 878 | img = scaled_img; |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 879 | #else |
| 880 | fprintf(stderr, "Failed to scale output frame: %s.\n" |
| 881 | "Scaling is disabled in this configuration. " |
| 882 | "To enable scaling, configure with --enable-libyuv\n", |
| 883 | vpx_codec_error(&decoder)); |
| 884 | return EXIT_FAILURE; |
| 885 | #endif |
John Koleszar | 7d8fc26 | 2013-02-25 16:58:47 -0800 | [diff] [blame] | 886 | } |
| 887 | } |
Dmitry Kovalev | 3c05481 | 2014-01-17 12:19:19 -0800 | [diff] [blame] | 888 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 889 | if (single_file) { |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 890 | if (use_y4m) { |
| 891 | char buf[Y4M_BUFFER_SIZE] = {0}; |
| 892 | size_t len = 0; |
| 893 | if (frame_out == 1) { |
| 894 | // Y4M file header |
| 895 | len = y4m_write_file_header(buf, sizeof(buf), |
| 896 | vpx_input_ctx.width, |
| 897 | vpx_input_ctx.height, |
| 898 | &vpx_input_ctx.framerate, img->fmt); |
| 899 | if (do_md5) { |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 900 | MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 901 | } else { |
| 902 | fputs(buf, outfile); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | // Y4M frame header |
| 907 | len = y4m_write_frame_header(buf, sizeof(buf)); |
| 908 | if (do_md5) { |
Jim Bankoski | 24025c0 | 2014-02-14 07:27:10 -0800 | [diff] [blame] | 909 | MD5Update(&md5_ctx, (md5byte *)buf, (unsigned int)len); |
Dmitry Kovalev | 5260b39 | 2014-01-28 11:12:58 -0800 | [diff] [blame] | 910 | } else { |
| 911 | fputs(buf, outfile); |
| 912 | } |
| 913 | } |
| 914 | |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 915 | if (do_md5) { |
| 916 | update_image_md5(img, planes, &md5_ctx); |
Dmitry Kovalev | cf46bc7 | 2014-01-17 10:57:55 -0800 | [diff] [blame] | 917 | } else { |
Dmitry Kovalev | f2acb45 | 2014-01-23 17:20:34 -0800 | [diff] [blame] | 918 | write_image_file(img, planes, outfile); |
| 919 | } |
| 920 | } else { |
| 921 | generate_filename(outfile_pattern, outfile_name, PATH_MAX, |
| 922 | img->d_w, img->d_h, frame_in); |
| 923 | if (do_md5) { |
| 924 | MD5Init(&md5_ctx); |
| 925 | update_image_md5(img, planes, &md5_ctx); |
| 926 | MD5Final(md5_digest, &md5_ctx); |
| 927 | print_md5(md5_digest, outfile_name); |
| 928 | } else { |
| 929 | outfile = open_outfile(outfile_name); |
| 930 | write_image_file(img, planes, outfile); |
| 931 | fclose(outfile); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 932 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 933 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 934 | } |
| 935 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 936 | if (stop_after && frame_in >= stop_after) |
| 937 | break; |
| 938 | } |
| 939 | |
| 940 | if (summary || progress) { |
| 941 | show_progress(frame_in, frame_out, dx_time); |
| 942 | fprintf(stderr, "\n"); |
| 943 | } |
| 944 | |
| 945 | if (frames_corrupted) |
| 946 | fprintf(stderr, "WARNING: %d frames corrupted.\n", frames_corrupted); |
John Koleszar | 4226f0c | 2011-04-27 12:04:48 -0400 | [diff] [blame] | 947 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 948 | fail: |
| 949 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 950 | if (vpx_codec_destroy(&decoder)) { |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 951 | fprintf(stderr, "Failed to destroy decoder: %s\n", |
| 952 | vpx_codec_error(&decoder)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 953 | return EXIT_FAILURE; |
| 954 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 955 | |
Dmitry Kovalev | 347b306 | 2014-01-22 09:04:07 -0800 | [diff] [blame] | 956 | if (!noblit && single_file) { |
| 957 | if (do_md5) { |
| 958 | MD5Final(md5_digest, &md5_ctx); |
| 959 | print_md5(md5_digest, outfile_name); |
| 960 | } else { |
| 961 | fclose(outfile); |
| 962 | } |
| 963 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 964 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 965 | #if CONFIG_WEBM_IO |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 966 | if (input.vpx_input_ctx->file_type == FILE_TYPE_WEBM) |
| 967 | webm_free(input.webm_ctx); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 968 | #endif |
| 969 | |
| 970 | if (input.vpx_input_ctx->file_type != FILE_TYPE_WEBM) |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 971 | free(buf); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 972 | |
Adrian Grange | d427fab | 2013-11-21 17:19:04 -0800 | [diff] [blame] | 973 | if (scaled_img) vpx_img_free(scaled_img); |
| 974 | |
Frank Galligan | a4f30a5 | 2014-02-06 17:13:08 -0800 | [diff] [blame] | 975 | for (i = 0; i < ext_fb_list.num_external_frame_buffers; ++i) { |
| 976 | free(ext_fb_list.ext_fb[i].data); |
| 977 | } |
| 978 | free(ext_fb_list.ext_fb); |
| 979 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 980 | fclose(infile); |
| 981 | free(argv); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 982 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 983 | return frames_corrupted ? EXIT_FAILURE : EXIT_SUCCESS; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 984 | } |
John Koleszar | 9596a4c | 2013-06-12 16:08:35 -0700 | [diff] [blame] | 985 | |
| 986 | int main(int argc, const char **argv_) { |
| 987 | unsigned int loops = 1, i; |
| 988 | char **argv, **argi, **argj; |
| 989 | struct arg arg; |
| 990 | int error = 0; |
| 991 | |
| 992 | argv = argv_dup(argc - 1, argv_ + 1); |
| 993 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 994 | memset(&arg, 0, sizeof(arg)); |
| 995 | arg.argv_step = 1; |
| 996 | |
| 997 | if (arg_match(&arg, &looparg, argi)) { |
| 998 | loops = arg_parse_uint(&arg); |
| 999 | break; |
| 1000 | } |
| 1001 | } |
| 1002 | free(argv); |
| 1003 | for (i = 0; !error && i < loops; i++) |
| 1004 | error = main_loop(argc, argv_); |
| 1005 | return error; |
| 1006 | } |