John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #include "./aomenc.h" |
| 13 | #include "./aom_config.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 14 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 15 | #include <assert.h> |
| 16 | #include <limits.h> |
Tom Finegan | 78cb2e6 | 2013-11-07 21:28:45 -0800 | [diff] [blame] | 17 | #include <math.h> |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 18 | #include <stdarg.h> |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 21 | #include <string.h> |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 22 | |
James Zern | 5805881 | 2014-08-15 21:00:31 -0700 | [diff] [blame] | 23 | #if CONFIG_LIBYUV |
| 24 | #include "third_party/libyuv/include/libyuv/scale.h" |
| 25 | #endif |
| 26 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 27 | #include "aom/aom_encoder.h" |
John Koleszar | 5ebe94f | 2012-12-23 07:20:10 -0800 | [diff] [blame] | 28 | #if CONFIG_DECODERS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 29 | #include "aom/aom_decoder.h" |
John Koleszar | 5ebe94f | 2012-12-23 07:20:10 -0800 | [diff] [blame] | 30 | #endif |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 31 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 32 | #include "./args.h" |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 33 | #include "./ivfenc.h" |
Tom Finegan | 7a691f1 | 2014-02-10 14:55:25 -0800 | [diff] [blame] | 34 | #include "./tools_common.h" |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 35 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | #if CONFIG_AV1_ENCODER |
| 37 | #include "aom/aomcx.h" |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 38 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 39 | #if CONFIG_AV1_DECODER |
| 40 | #include "aom/aomdx.h" |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 41 | #endif |
| 42 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 43 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 44 | #include "aom_ports/mem_ops.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | #include "aom_ports/aom_timer.h" |
Dmitry Kovalev | f11da2b | 2014-01-29 12:28:29 -0800 | [diff] [blame] | 46 | #include "./rate_hist.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 47 | #include "./aomstats.h" |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 48 | #include "./warnings.h" |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 49 | #if CONFIG_WEBM_IO |
Tom Finegan | 78cb2e6 | 2013-11-07 21:28:45 -0800 | [diff] [blame] | 50 | #include "./webmenc.h" |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 51 | #endif |
Tom Finegan | 78cb2e6 | 2013-11-07 21:28:45 -0800 | [diff] [blame] | 52 | #include "./y4minput.h" |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 53 | |
John Koleszar | 6291dd4 | 2012-06-19 21:05:36 -0700 | [diff] [blame] | 54 | /* Swallow warnings about unused results of fread/fwrite */ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 55 | static size_t wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 56 | return fread(ptr, size, nmemb, stream); |
John Koleszar | 6291dd4 | 2012-06-19 21:05:36 -0700 | [diff] [blame] | 57 | } |
| 58 | #define fread wrap_fread |
| 59 | |
| 60 | static size_t wrap_fwrite(const void *ptr, size_t size, size_t nmemb, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 61 | FILE *stream) { |
| 62 | return fwrite(ptr, size, nmemb, stream); |
John Koleszar | 6291dd4 | 2012-06-19 21:05:36 -0700 | [diff] [blame] | 63 | } |
| 64 | #define fwrite wrap_fwrite |
| 65 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 66 | static const char *exec_name; |
| 67 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 68 | static void warn_or_exit_on_errorv(aom_codec_ctx_t *ctx, int fatal, |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 69 | const char *s, va_list ap) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 70 | if (ctx->err) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | const char *detail = aom_codec_error_detail(ctx); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 72 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 73 | vfprintf(stderr, s, ap); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 74 | fprintf(stderr, ": %s\n", aom_codec_error(ctx)); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 75 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 76 | if (detail) fprintf(stderr, " %s\n", detail); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 77 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 78 | if (fatal) exit(EXIT_FAILURE); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 79 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 82 | static void ctx_exit_on_error(aom_codec_ctx_t *ctx, const char *s, ...) { |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 83 | va_list ap; |
| 84 | |
| 85 | va_start(ap, s); |
| 86 | warn_or_exit_on_errorv(ctx, 1, s, ap); |
| 87 | va_end(ap); |
| 88 | } |
| 89 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 90 | static void warn_or_exit_on_error(aom_codec_ctx_t *ctx, int fatal, |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 91 | const char *s, ...) { |
| 92 | va_list ap; |
| 93 | |
| 94 | va_start(ap, s); |
| 95 | warn_or_exit_on_errorv(ctx, fatal, s, ap); |
| 96 | va_end(ap); |
| 97 | } |
| 98 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 99 | static int read_frame(struct AvxInputContext *input_ctx, aom_image_t *img) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 100 | FILE *f = input_ctx->file; |
| 101 | y4m_input *y4m = &input_ctx->y4m; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 102 | int shortread = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 103 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 104 | if (input_ctx->file_type == FILE_TYPE_Y4M) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 105 | if (y4m_input_fetch_frame(y4m, f, img) < 1) return 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 106 | } else { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 107 | shortread = read_yuv_frame(input_ctx, img); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return !shortread; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 111 | } |
| 112 | |
James Zern | 5c337fd | 2015-05-09 10:42:58 -0700 | [diff] [blame] | 113 | static int file_is_y4m(const char detect[4]) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 114 | if (memcmp(detect, "YUV4", 4) == 0) { |
| 115 | return 1; |
| 116 | } |
| 117 | return 0; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 118 | } |
| 119 | |
James Zern | 5c337fd | 2015-05-09 10:42:58 -0700 | [diff] [blame] | 120 | static int fourcc_is_ivf(const char detect[4]) { |
Alex Converse | 64b89f1 | 2014-01-06 16:29:09 -0800 | [diff] [blame] | 121 | if (memcmp(detect, "DKIF", 4) == 0) { |
| 122 | return 1; |
| 123 | } |
| 124 | return 0; |
| 125 | } |
John Koleszar | dc66630 | 2010-10-20 12:05:48 -0400 | [diff] [blame] | 126 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 127 | static const arg_def_t debugmode = |
| 128 | ARG_DEF("D", "debug", 0, "Debug mode (makes output deterministic)"); |
| 129 | static const arg_def_t outputfile = |
| 130 | ARG_DEF("o", "output", 1, "Output filename"); |
| 131 | static const arg_def_t use_yv12 = |
| 132 | ARG_DEF(NULL, "yv12", 0, "Input file is YV12 "); |
| 133 | static const arg_def_t use_i420 = |
| 134 | ARG_DEF(NULL, "i420", 0, "Input file is I420 (default)"); |
| 135 | static const arg_def_t use_i422 = |
| 136 | ARG_DEF(NULL, "i422", 0, "Input file is I422"); |
| 137 | static const arg_def_t use_i444 = |
| 138 | ARG_DEF(NULL, "i444", 0, "Input file is I444"); |
| 139 | static const arg_def_t use_i440 = |
| 140 | ARG_DEF(NULL, "i440", 0, "Input file is I440"); |
| 141 | static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, "Codec to use"); |
| 142 | static const arg_def_t passes = |
| 143 | ARG_DEF("p", "passes", 1, "Number of passes (1/2)"); |
| 144 | static const arg_def_t pass_arg = |
| 145 | ARG_DEF(NULL, "pass", 1, "Pass to execute (1/2)"); |
| 146 | static const arg_def_t fpf_name = |
| 147 | ARG_DEF(NULL, "fpf", 1, "First pass statistics file name"); |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 148 | #if CONFIG_FP_MB_STATS |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 149 | static const arg_def_t fpmbf_name = |
| 150 | ARG_DEF(NULL, "fpmbf", 1, "First pass block statistics file name"); |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 151 | #endif |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 152 | static const arg_def_t limit = |
| 153 | ARG_DEF(NULL, "limit", 1, "Stop encoding after n input frames"); |
| 154 | static const arg_def_t skip = |
| 155 | ARG_DEF(NULL, "skip", 1, "Skip the first n input frames"); |
| 156 | static const arg_def_t deadline = |
| 157 | ARG_DEF("d", "deadline", 1, "Deadline per frame (usec)"); |
| 158 | static const arg_def_t best_dl = |
| 159 | ARG_DEF(NULL, "best", 0, "Use Best Quality Deadline"); |
| 160 | static const arg_def_t good_dl = |
| 161 | ARG_DEF(NULL, "good", 0, "Use Good Quality Deadline"); |
| 162 | static const arg_def_t rt_dl = |
| 163 | ARG_DEF(NULL, "rt", 0, "Use Realtime Quality Deadline"); |
| 164 | static const arg_def_t quietarg = |
| 165 | ARG_DEF("q", "quiet", 0, "Do not print encode progress"); |
| 166 | static const arg_def_t verbosearg = |
| 167 | ARG_DEF("v", "verbose", 0, "Show encoder parameters"); |
| 168 | static const arg_def_t psnrarg = |
| 169 | ARG_DEF(NULL, "psnr", 0, "Show PSNR in status line"); |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 170 | |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 171 | static const struct arg_enum_list test_decode_enum[] = { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 172 | { "off", TEST_DECODE_OFF }, |
| 173 | { "fatal", TEST_DECODE_FATAL }, |
| 174 | { "warn", TEST_DECODE_WARN }, |
| 175 | { NULL, 0 } |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 176 | }; |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 177 | static const arg_def_t recontest = ARG_DEF_ENUM( |
| 178 | NULL, "test-decode", 1, "Test encode/decode mismatch", test_decode_enum); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 179 | static const arg_def_t framerate = |
| 180 | ARG_DEF(NULL, "fps", 1, "Stream frame rate (rate/scale)"); |
| 181 | static const arg_def_t use_webm = |
| 182 | ARG_DEF(NULL, "webm", 0, "Output WebM (default when WebM IO is enabled)"); |
| 183 | static const arg_def_t use_ivf = ARG_DEF(NULL, "ivf", 0, "Output IVF"); |
| 184 | static const arg_def_t out_part = |
| 185 | ARG_DEF("P", "output-partitions", 0, |
| 186 | "Makes encoder output partitions. Requires IVF output!"); |
| 187 | static const arg_def_t q_hist_n = |
| 188 | ARG_DEF(NULL, "q-hist", 1, "Show quantizer histogram (n-buckets)"); |
| 189 | static const arg_def_t rate_hist_n = |
| 190 | ARG_DEF(NULL, "rate-hist", 1, "Show rate histogram (n-buckets)"); |
| 191 | static const arg_def_t disable_warnings = |
| 192 | ARG_DEF(NULL, "disable-warnings", 0, |
| 193 | "Disable warnings about potentially incorrect encode settings."); |
| 194 | static const arg_def_t disable_warning_prompt = |
| 195 | ARG_DEF("y", "disable-warning-prompt", 0, |
| 196 | "Display warnings, but do not prompt user to continue."); |
Alex Converse | d66bd22 | 2014-02-21 10:52:09 -0800 | [diff] [blame] | 197 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | #if CONFIG_AOM_HIGHBITDEPTH |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 199 | static const arg_def_t test16bitinternalarg = ARG_DEF( |
| 200 | NULL, "test-16bit-internal", 0, "Force use of 16 bit internal buffer"); |
Nathan E. Egge | d1b239c | 2016-07-12 18:03:18 -0400 | [diff] [blame] | 201 | |
| 202 | static const struct arg_enum_list bitdepth_enum[] = { |
| 203 | { "8", AOM_BITS_8 }, { "10", AOM_BITS_10 }, { "12", AOM_BITS_12 }, { NULL, 0 } |
| 204 | }; |
| 205 | |
| 206 | static const arg_def_t bitdeptharg = ARG_DEF_ENUM( |
| 207 | "b", "bit-depth", 1, |
| 208 | "Bit depth for codec (8 for version <=1, 10 or 12 for version 2)", |
| 209 | bitdepth_enum); |
| 210 | static const arg_def_t inbitdeptharg = |
| 211 | ARG_DEF(NULL, "input-bit-depth", 1, "Bit depth of input"); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 212 | #endif |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 213 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 214 | static const arg_def_t *main_args[] = { &debugmode, |
| 215 | &outputfile, |
| 216 | &codecarg, |
| 217 | &passes, |
| 218 | &pass_arg, |
| 219 | &fpf_name, |
| 220 | &limit, |
| 221 | &skip, |
| 222 | &deadline, |
| 223 | &best_dl, |
| 224 | &good_dl, |
| 225 | &rt_dl, |
| 226 | &quietarg, |
| 227 | &verbosearg, |
| 228 | &psnrarg, |
| 229 | &use_webm, |
| 230 | &use_ivf, |
| 231 | &out_part, |
| 232 | &q_hist_n, |
| 233 | &rate_hist_n, |
| 234 | &disable_warnings, |
| 235 | &disable_warning_prompt, |
| 236 | &recontest, |
| 237 | NULL }; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 238 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 239 | static const arg_def_t usage = |
| 240 | ARG_DEF("u", "usage", 1, "Usage profile number to use"); |
| 241 | static const arg_def_t threads = |
| 242 | ARG_DEF("t", "threads", 1, "Max number of threads to use"); |
| 243 | static const arg_def_t profile = |
| 244 | ARG_DEF(NULL, "profile", 1, "Bitstream profile number to use"); |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 245 | static const arg_def_t width = ARG_DEF("w", "width", 1, "Frame width"); |
| 246 | static const arg_def_t height = ARG_DEF("h", "height", 1, "Frame height"); |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 247 | #if CONFIG_WEBM_IO |
Alok Ahuja | 72c76ca | 2011-04-21 00:50:07 -0700 | [diff] [blame] | 248 | static const struct arg_enum_list stereo_mode_enum[] = { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 249 | { "mono", STEREO_FORMAT_MONO }, |
| 250 | { "left-right", STEREO_FORMAT_LEFT_RIGHT }, |
| 251 | { "bottom-top", STEREO_FORMAT_BOTTOM_TOP }, |
| 252 | { "top-bottom", STEREO_FORMAT_TOP_BOTTOM }, |
| 253 | { "right-left", STEREO_FORMAT_RIGHT_LEFT }, |
| 254 | { NULL, 0 } |
Alok Ahuja | 72c76ca | 2011-04-21 00:50:07 -0700 | [diff] [blame] | 255 | }; |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 256 | static const arg_def_t stereo_mode = ARG_DEF_ENUM( |
| 257 | NULL, "stereo-mode", 1, "Stereo 3D video format", stereo_mode_enum); |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 258 | #endif |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 259 | static const arg_def_t timebase = ARG_DEF( |
| 260 | NULL, "timebase", 1, "Output timestamp precision (fractional seconds)"); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 261 | static const arg_def_t error_resilient = |
| 262 | ARG_DEF(NULL, "error-resilient", 1, "Enable error resiliency features"); |
| 263 | static const arg_def_t lag_in_frames = |
| 264 | ARG_DEF(NULL, "lag-in-frames", 1, "Max number of frames to lag"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 265 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 266 | static const arg_def_t *global_args[] = { &use_yv12, |
| 267 | &use_i420, |
| 268 | &use_i422, |
| 269 | &use_i444, |
| 270 | &use_i440, |
| 271 | &usage, |
| 272 | &threads, |
| 273 | &profile, |
| 274 | &width, |
| 275 | &height, |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 276 | #if CONFIG_WEBM_IO |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 277 | &stereo_mode, |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 278 | #endif |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 279 | &timebase, |
| 280 | &framerate, |
| 281 | &error_resilient, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 282 | #if CONFIG_AOM_HIGHBITDEPTH |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 283 | &test16bitinternalarg, |
Nathan E. Egge | d1b239c | 2016-07-12 18:03:18 -0400 | [diff] [blame] | 284 | &bitdeptharg, |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 285 | #endif |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 286 | &lag_in_frames, |
| 287 | NULL }; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 288 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 289 | static const arg_def_t dropframe_thresh = |
| 290 | ARG_DEF(NULL, "drop-frame", 1, "Temporal resampling threshold (buf %)"); |
| 291 | static const arg_def_t resize_allowed = |
| 292 | ARG_DEF(NULL, "resize-allowed", 1, "Spatial resampling enabled (bool)"); |
| 293 | static const arg_def_t resize_width = |
| 294 | ARG_DEF(NULL, "resize-width", 1, "Width of encoded frame"); |
| 295 | static const arg_def_t resize_height = |
| 296 | ARG_DEF(NULL, "resize-height", 1, "Height of encoded frame"); |
| 297 | static const arg_def_t resize_up_thresh = |
| 298 | ARG_DEF(NULL, "resize-up", 1, "Upscale threshold (buf %)"); |
| 299 | static const arg_def_t resize_down_thresh = |
| 300 | ARG_DEF(NULL, "resize-down", 1, "Downscale threshold (buf %)"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 301 | static const struct arg_enum_list end_usage_enum[] = { { "vbr", AOM_VBR }, |
| 302 | { "cbr", AOM_CBR }, |
| 303 | { "cq", AOM_CQ }, |
| 304 | { "q", AOM_Q }, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 305 | { NULL, 0 } }; |
| 306 | static const arg_def_t end_usage = |
| 307 | ARG_DEF_ENUM(NULL, "end-usage", 1, "Rate control mode", end_usage_enum); |
| 308 | static const arg_def_t target_bitrate = |
| 309 | ARG_DEF(NULL, "target-bitrate", 1, "Bitrate (kbps)"); |
| 310 | static const arg_def_t min_quantizer = |
| 311 | ARG_DEF(NULL, "min-q", 1, "Minimum (best) quantizer"); |
| 312 | static const arg_def_t max_quantizer = |
| 313 | ARG_DEF(NULL, "max-q", 1, "Maximum (worst) quantizer"); |
| 314 | static const arg_def_t undershoot_pct = |
| 315 | ARG_DEF(NULL, "undershoot-pct", 1, "Datarate undershoot (min) target (%)"); |
| 316 | static const arg_def_t overshoot_pct = |
| 317 | ARG_DEF(NULL, "overshoot-pct", 1, "Datarate overshoot (max) target (%)"); |
| 318 | static const arg_def_t buf_sz = |
| 319 | ARG_DEF(NULL, "buf-sz", 1, "Client buffer size (ms)"); |
| 320 | static const arg_def_t buf_initial_sz = |
| 321 | ARG_DEF(NULL, "buf-initial-sz", 1, "Client initial buffer size (ms)"); |
| 322 | static const arg_def_t buf_optimal_sz = |
| 323 | ARG_DEF(NULL, "buf-optimal-sz", 1, "Client optimal buffer size (ms)"); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 324 | static const arg_def_t *rc_args[] = { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 325 | &dropframe_thresh, &resize_allowed, &resize_width, &resize_height, |
| 326 | &resize_up_thresh, &resize_down_thresh, &end_usage, &target_bitrate, |
| 327 | &min_quantizer, &max_quantizer, &undershoot_pct, &overshoot_pct, |
| 328 | &buf_sz, &buf_initial_sz, &buf_optimal_sz, NULL |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 329 | }; |
| 330 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 331 | static const arg_def_t bias_pct = |
| 332 | ARG_DEF(NULL, "bias-pct", 1, "CBR/VBR bias (0=CBR, 100=VBR)"); |
| 333 | static const arg_def_t minsection_pct = |
| 334 | ARG_DEF(NULL, "minsection-pct", 1, "GOP min bitrate (% of target)"); |
| 335 | static const arg_def_t maxsection_pct = |
| 336 | ARG_DEF(NULL, "maxsection-pct", 1, "GOP max bitrate (% of target)"); |
| 337 | static const arg_def_t *rc_twopass_args[] = { &bias_pct, &minsection_pct, |
| 338 | &maxsection_pct, NULL }; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 339 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 340 | static const arg_def_t kf_min_dist = |
| 341 | ARG_DEF(NULL, "kf-min-dist", 1, "Minimum keyframe interval (frames)"); |
| 342 | static const arg_def_t kf_max_dist = |
| 343 | ARG_DEF(NULL, "kf-max-dist", 1, "Maximum keyframe interval (frames)"); |
| 344 | static const arg_def_t kf_disabled = |
| 345 | ARG_DEF(NULL, "disable-kf", 0, "Disable keyframe placement"); |
| 346 | static const arg_def_t *kf_args[] = { &kf_min_dist, &kf_max_dist, &kf_disabled, |
| 347 | NULL }; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 348 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 349 | static const arg_def_t noise_sens = |
| 350 | ARG_DEF(NULL, "noise-sensitivity", 1, "Noise sensitivity (frames to blur)"); |
| 351 | static const arg_def_t sharpness = |
| 352 | ARG_DEF(NULL, "sharpness", 1, "Loop filter sharpness (0..7)"); |
| 353 | static const arg_def_t static_thresh = |
| 354 | ARG_DEF(NULL, "static-thresh", 1, "Motion detection threshold"); |
| 355 | static const arg_def_t auto_altref = |
| 356 | ARG_DEF(NULL, "auto-alt-ref", 1, "Enable automatic alt reference frames"); |
| 357 | static const arg_def_t arnr_maxframes = |
| 358 | ARG_DEF(NULL, "arnr-maxframes", 1, "AltRef max frames (0..15)"); |
| 359 | static const arg_def_t arnr_strength = |
| 360 | ARG_DEF(NULL, "arnr-strength", 1, "AltRef filter strength (0..6)"); |
| 361 | static const arg_def_t arnr_type = ARG_DEF(NULL, "arnr-type", 1, "AltRef type"); |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 362 | static const struct arg_enum_list tuning_enum[] = { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 363 | { "psnr", AOM_TUNE_PSNR }, { "ssim", AOM_TUNE_SSIM }, { NULL, 0 } |
John Koleszar | b0da9b3 | 2010-12-17 09:43:39 -0500 | [diff] [blame] | 364 | }; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 365 | static const arg_def_t tune_ssim = |
| 366 | ARG_DEF_ENUM(NULL, "tune", 1, "Material to favor", tuning_enum); |
| 367 | static const arg_def_t cq_level = |
| 368 | ARG_DEF(NULL, "cq-level", 1, "Constant/Constrained Quality level"); |
| 369 | static const arg_def_t max_intra_rate_pct = |
| 370 | ARG_DEF(NULL, "max-intra-rate", 1, "Max I-frame bitrate (pct)"); |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 371 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 372 | #if CONFIG_AV1_ENCODER |
| 373 | static const arg_def_t cpu_used_av1 = |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 374 | ARG_DEF(NULL, "cpu-used", 1, "CPU Used (-8..8)"); |
| 375 | static const arg_def_t tile_cols = |
| 376 | ARG_DEF(NULL, "tile-columns", 1, "Number of tile columns to use, log2"); |
| 377 | static const arg_def_t tile_rows = |
| 378 | ARG_DEF(NULL, "tile-rows", 1, |
| 379 | "Number of tile rows to use, log2 (set to 0 while threads > 1)"); |
| 380 | static const arg_def_t lossless = |
| 381 | ARG_DEF(NULL, "lossless", 1, "Lossless mode (0: false (default), 1: true)"); |
Yaowu Xu | 0818a7c | 2016-08-11 09:39:47 -0700 | [diff] [blame] | 382 | #if CONFIG_AOM_QM |
| 383 | static const arg_def_t enable_qm = |
| 384 | ARG_DEF(NULL, "enable_qm", 1, |
| 385 | "Enable quantisation matrices (0: false (default), 1: true)"); |
| 386 | static const arg_def_t qm_min = ARG_DEF( |
| 387 | NULL, "qm_min", 1, "Min quant matrix flatness (0..15), default is 8"); |
| 388 | static const arg_def_t qm_max = ARG_DEF( |
| 389 | NULL, "qm_max", 1, "Max quant matrix flatness (0..15), default is 16"); |
| 390 | #endif |
Yaowu Xu | d59fb48 | 2016-09-30 15:39:53 -0700 | [diff] [blame] | 391 | static const arg_def_t frame_parallel_decoding = |
| 392 | ARG_DEF(NULL, "frame-parallel", 1, |
| 393 | "Enable frame parallel decodability features " |
| 394 | "(0: false (default), 1: true)"); |
Thomas | e28d92b | 2016-09-20 12:07:11 +0100 | [diff] [blame] | 395 | #if CONFIG_DELTA_Q |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 396 | static const arg_def_t aq_mode = ARG_DEF( |
| 397 | NULL, "aq-mode", 1, |
| 398 | "Adaptive quantization mode (0: off (default), 1: variance 2: complexity, " |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 399 | "3: cyclic refresh, 4: delta quant)"); |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 400 | #else |
Thomas | e28d92b | 2016-09-20 12:07:11 +0100 | [diff] [blame] | 401 | static const arg_def_t aq_mode = ARG_DEF( |
| 402 | NULL, "aq-mode", 1, |
| 403 | "Adaptive quantization mode (0: off (default), 1: variance 2: complexity, " |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 404 | "3: cyclic refresh)"); |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 405 | #endif |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 406 | static const arg_def_t frame_periodic_boost = |
| 407 | ARG_DEF(NULL, "frame-boost", 1, |
| 408 | "Enable frame periodic boost (0: off (default), 1: on)"); |
James Zern | f82cfc2 | 2015-06-05 16:07:20 -0700 | [diff] [blame] | 409 | static const arg_def_t gf_cbr_boost_pct = ARG_DEF( |
| 410 | NULL, "gf-cbr-boost", 1, "Boost for Golden Frame in CBR mode (pct)"); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 411 | static const arg_def_t max_inter_rate_pct = |
| 412 | ARG_DEF(NULL, "max-inter-rate", 1, "Max P-frame bitrate (pct)"); |
Debargha Mukherjee | 9852643 | 2015-04-01 16:39:06 -0700 | [diff] [blame] | 413 | static const arg_def_t min_gf_interval = ARG_DEF( |
| 414 | NULL, "min-gf-interval", 1, |
| 415 | "min gf/arf frame interval (default 0, indicating in-built behavior)"); |
| 416 | static const arg_def_t max_gf_interval = ARG_DEF( |
| 417 | NULL, "max-gf-interval", 1, |
| 418 | "max gf/arf frame interval (default 0, indicating in-built behavior)"); |
James Zern | 5248d71 | 2014-01-14 17:56:45 -0800 | [diff] [blame] | 419 | |
Yaowu Xu | fc99636 | 2015-02-10 15:03:05 -0800 | [diff] [blame] | 420 | static const struct arg_enum_list color_space_enum[] = { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 421 | { "unknown", AOM_CS_UNKNOWN }, |
| 422 | { "bt601", AOM_CS_BT_601 }, |
| 423 | { "bt709", AOM_CS_BT_709 }, |
| 424 | { "smpte170", AOM_CS_SMPTE_170 }, |
| 425 | { "smpte240", AOM_CS_SMPTE_240 }, |
| 426 | { "bt2020", AOM_CS_BT_2020 }, |
| 427 | { "reserved", AOM_CS_RESERVED }, |
| 428 | { "sRGB", AOM_CS_SRGB }, |
Yaowu Xu | fc99636 | 2015-02-10 15:03:05 -0800 | [diff] [blame] | 429 | { NULL, 0 } |
| 430 | }; |
| 431 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 432 | static const arg_def_t input_color_space = |
| 433 | ARG_DEF_ENUM(NULL, "color-space", 1, "The color space of input content:", |
| 434 | color_space_enum); |
Yaowu Xu | fc99636 | 2015-02-10 15:03:05 -0800 | [diff] [blame] | 435 | |
Alex Converse | 219f645 | 2014-08-06 11:01:18 -0700 | [diff] [blame] | 436 | static const struct arg_enum_list tune_content_enum[] = { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 437 | { "default", AOM_CONTENT_DEFAULT }, |
| 438 | { "screen", AOM_CONTENT_SCREEN }, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 439 | { NULL, 0 } |
Alex Converse | 219f645 | 2014-08-06 11:01:18 -0700 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | static const arg_def_t tune_content = ARG_DEF_ENUM( |
| 443 | NULL, "tune-content", 1, "Tune content type", tune_content_enum); |
hui su | 82331e0 | 2015-08-16 18:21:56 -0700 | [diff] [blame] | 444 | #endif |
Alex Converse | 219f645 | 2014-08-06 11:01:18 -0700 | [diff] [blame] | 445 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 446 | #if CONFIG_AV1_ENCODER |
Geza Lore | 454989f | 2016-03-24 13:56:05 +0000 | [diff] [blame] | 447 | #if CONFIG_EXT_PARTITION |
| 448 | static const struct arg_enum_list superblock_size_enum[] = { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 449 | { "dynamic", AOM_SUPERBLOCK_SIZE_DYNAMIC }, |
| 450 | { "64", AOM_SUPERBLOCK_SIZE_64X64 }, |
| 451 | { "128", AOM_SUPERBLOCK_SIZE_128X128 }, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 452 | { NULL, 0 } |
Geza Lore | 454989f | 2016-03-24 13:56:05 +0000 | [diff] [blame] | 453 | }; |
| 454 | static const arg_def_t superblock_size = ARG_DEF_ENUM( |
| 455 | NULL, "sb-size", 1, "Superblock size to use", superblock_size_enum); |
| 456 | #endif // CONFIG_EXT_PARTITION |
| 457 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 458 | static const arg_def_t *av1_args[] = { &cpu_used_av1, |
| 459 | &auto_altref, |
| 460 | &sharpness, |
| 461 | &static_thresh, |
| 462 | &tile_cols, |
| 463 | &tile_rows, |
| 464 | &arnr_maxframes, |
| 465 | &arnr_strength, |
| 466 | &arnr_type, |
| 467 | &tune_ssim, |
| 468 | &cq_level, |
| 469 | &max_intra_rate_pct, |
| 470 | &max_inter_rate_pct, |
| 471 | &gf_cbr_boost_pct, |
| 472 | &lossless, |
| 473 | &frame_parallel_decoding, |
| 474 | &aq_mode, |
| 475 | &frame_periodic_boost, |
| 476 | &noise_sens, |
| 477 | &tune_content, |
| 478 | &input_color_space, |
| 479 | &min_gf_interval, |
| 480 | &max_gf_interval, |
Geza Lore | 454989f | 2016-03-24 13:56:05 +0000 | [diff] [blame] | 481 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 482 | &superblock_size, |
Geza Lore | 454989f | 2016-03-24 13:56:05 +0000 | [diff] [blame] | 483 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 484 | #if CONFIG_AOM_HIGHBITDEPTH |
| 485 | &bitdeptharg, |
| 486 | &inbitdeptharg, |
| 487 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 488 | NULL }; |
| 489 | static const int av1_arg_ctrl_map[] = { AOME_SET_CPUUSED, |
| 490 | AOME_SET_ENABLEAUTOALTREF, |
| 491 | AOME_SET_SHARPNESS, |
| 492 | AOME_SET_STATIC_THRESHOLD, |
| 493 | AV1E_SET_TILE_COLUMNS, |
| 494 | AV1E_SET_TILE_ROWS, |
| 495 | AOME_SET_ARNR_MAXFRAMES, |
| 496 | AOME_SET_ARNR_STRENGTH, |
| 497 | AOME_SET_ARNR_TYPE, |
| 498 | AOME_SET_TUNING, |
| 499 | AOME_SET_CQ_LEVEL, |
| 500 | AOME_SET_MAX_INTRA_BITRATE_PCT, |
| 501 | AV1E_SET_MAX_INTER_BITRATE_PCT, |
| 502 | AV1E_SET_GF_CBR_BOOST_PCT, |
| 503 | AV1E_SET_LOSSLESS, |
| 504 | AV1E_SET_FRAME_PARALLEL_DECODING, |
| 505 | AV1E_SET_AQ_MODE, |
| 506 | AV1E_SET_FRAME_PERIODIC_BOOST, |
| 507 | AV1E_SET_NOISE_SENSITIVITY, |
| 508 | AV1E_SET_TUNE_CONTENT, |
| 509 | AV1E_SET_COLOR_SPACE, |
| 510 | AV1E_SET_MIN_GF_INTERVAL, |
| 511 | AV1E_SET_MAX_GF_INTERVAL, |
Geza Lore | 454989f | 2016-03-24 13:56:05 +0000 | [diff] [blame] | 512 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 513 | AV1E_SET_SUPERBLOCK_SIZE, |
Geza Lore | 454989f | 2016-03-24 13:56:05 +0000 | [diff] [blame] | 514 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 515 | 0 }; |
hui su | 82331e0 | 2015-08-16 18:21:56 -0700 | [diff] [blame] | 516 | #endif |
| 517 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 518 | static const arg_def_t *no_args[] = { NULL }; |
| 519 | |
James Zern | 59e7a47 | 2015-05-09 10:33:26 -0700 | [diff] [blame] | 520 | void usage_exit(void) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 521 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 522 | const int num_encoder = get_aom_encoder_count(); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 523 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 524 | fprintf(stderr, "Usage: %s <options> -o dst_filename src_filename \n", |
| 525 | exec_name); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 526 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 527 | fprintf(stderr, "\nOptions:\n"); |
John Koleszar | b9e2761 | 2013-06-25 09:15:07 -0700 | [diff] [blame] | 528 | arg_show_usage(stderr, main_args); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 529 | fprintf(stderr, "\nEncoder Global Options:\n"); |
John Koleszar | b9e2761 | 2013-06-25 09:15:07 -0700 | [diff] [blame] | 530 | arg_show_usage(stderr, global_args); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 531 | fprintf(stderr, "\nRate Control Options:\n"); |
John Koleszar | b9e2761 | 2013-06-25 09:15:07 -0700 | [diff] [blame] | 532 | arg_show_usage(stderr, rc_args); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 533 | fprintf(stderr, "\nTwopass Rate Control Options:\n"); |
John Koleszar | b9e2761 | 2013-06-25 09:15:07 -0700 | [diff] [blame] | 534 | arg_show_usage(stderr, rc_twopass_args); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 535 | fprintf(stderr, "\nKeyframe Placement Options:\n"); |
John Koleszar | b9e2761 | 2013-06-25 09:15:07 -0700 | [diff] [blame] | 536 | arg_show_usage(stderr, kf_args); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 537 | #if CONFIG_AV1_ENCODER |
| 538 | fprintf(stderr, "\nAV1 Specific Options:\n"); |
| 539 | arg_show_usage(stderr, av1_args); |
hui su | 82331e0 | 2015-08-16 18:21:56 -0700 | [diff] [blame] | 540 | #endif |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 541 | fprintf(stderr, |
| 542 | "\nStream timebase (--timebase):\n" |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 543 | " The desired precision of timestamps in the output, expressed\n" |
| 544 | " in fractional seconds. Default is 1/1000.\n"); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 545 | fprintf(stderr, "\nIncluded encoders:\n\n"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 546 | |
Yaowu Xu | f990b35 | 2015-06-01 09:13:59 -0700 | [diff] [blame] | 547 | for (i = 0; i < num_encoder; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 548 | const AvxInterface *const encoder = get_aom_encoder_by_index(i); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 549 | const char *defstr = (i == (num_encoder - 1)) ? "(default)" : ""; |
| 550 | fprintf(stderr, " %-6s - %s %s\n", encoder->name, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 551 | aom_codec_iface_name(encoder->codec_interface()), defstr); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 552 | } |
Yaowu Xu | f990b35 | 2015-06-01 09:13:59 -0700 | [diff] [blame] | 553 | fprintf(stderr, "\n "); |
| 554 | fprintf(stderr, "Use --codec to switch to a non-default encoder.\n\n"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 555 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 556 | exit(EXIT_FAILURE); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 557 | } |
| 558 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 559 | #define mmin(a, b) ((a) < (b) ? (a) : (b)) |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 560 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 561 | #if CONFIG_AOM_HIGHBITDEPTH |
| 562 | static void find_mismatch_high(const aom_image_t *const img1, |
| 563 | const aom_image_t *const img2, int yloc[4], |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 564 | int uloc[4], int vloc[4]) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 565 | uint16_t *plane1, *plane2; |
| 566 | uint32_t stride1, stride2; |
| 567 | const uint32_t bsize = 64; |
| 568 | const uint32_t bsizey = bsize >> img1->y_chroma_shift; |
| 569 | const uint32_t bsizex = bsize >> img1->x_chroma_shift; |
| 570 | const uint32_t c_w = |
| 571 | (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; |
| 572 | const uint32_t c_h = |
| 573 | (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; |
| 574 | int match = 1; |
| 575 | uint32_t i, j; |
| 576 | yloc[0] = yloc[1] = yloc[2] = yloc[3] = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 577 | plane1 = (uint16_t *)img1->planes[AOM_PLANE_Y]; |
| 578 | plane2 = (uint16_t *)img2->planes[AOM_PLANE_Y]; |
| 579 | stride1 = img1->stride[AOM_PLANE_Y] / 2; |
| 580 | stride2 = img2->stride[AOM_PLANE_Y] / 2; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 581 | for (i = 0, match = 1; match && i < img1->d_h; i += bsize) { |
| 582 | for (j = 0; match && j < img1->d_w; j += bsize) { |
| 583 | int k, l; |
| 584 | const int si = mmin(i + bsize, img1->d_h) - i; |
| 585 | const int sj = mmin(j + bsize, img1->d_w) - j; |
| 586 | for (k = 0; match && k < si; ++k) { |
| 587 | for (l = 0; match && l < sj; ++l) { |
| 588 | if (*(plane1 + (i + k) * stride1 + j + l) != |
| 589 | *(plane2 + (i + k) * stride2 + j + l)) { |
| 590 | yloc[0] = i + k; |
| 591 | yloc[1] = j + l; |
| 592 | yloc[2] = *(plane1 + (i + k) * stride1 + j + l); |
| 593 | yloc[3] = *(plane2 + (i + k) * stride2 + j + l); |
| 594 | match = 0; |
| 595 | break; |
| 596 | } |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | uloc[0] = uloc[1] = uloc[2] = uloc[3] = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 603 | plane1 = (uint16_t *)img1->planes[AOM_PLANE_U]; |
| 604 | plane2 = (uint16_t *)img2->planes[AOM_PLANE_U]; |
| 605 | stride1 = img1->stride[AOM_PLANE_U] / 2; |
| 606 | stride2 = img2->stride[AOM_PLANE_U] / 2; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 607 | for (i = 0, match = 1; match && i < c_h; i += bsizey) { |
| 608 | for (j = 0; match && j < c_w; j += bsizex) { |
| 609 | int k, l; |
| 610 | const int si = mmin(i + bsizey, c_h - i); |
| 611 | const int sj = mmin(j + bsizex, c_w - j); |
| 612 | for (k = 0; match && k < si; ++k) { |
| 613 | for (l = 0; match && l < sj; ++l) { |
| 614 | if (*(plane1 + (i + k) * stride1 + j + l) != |
| 615 | *(plane2 + (i + k) * stride2 + j + l)) { |
| 616 | uloc[0] = i + k; |
| 617 | uloc[1] = j + l; |
| 618 | uloc[2] = *(plane1 + (i + k) * stride1 + j + l); |
| 619 | uloc[3] = *(plane2 + (i + k) * stride2 + j + l); |
| 620 | match = 0; |
| 621 | break; |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | vloc[0] = vloc[1] = vloc[2] = vloc[3] = -1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 629 | plane1 = (uint16_t *)img1->planes[AOM_PLANE_V]; |
| 630 | plane2 = (uint16_t *)img2->planes[AOM_PLANE_V]; |
| 631 | stride1 = img1->stride[AOM_PLANE_V] / 2; |
| 632 | stride2 = img2->stride[AOM_PLANE_V] / 2; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 633 | for (i = 0, match = 1; match && i < c_h; i += bsizey) { |
| 634 | for (j = 0; match && j < c_w; j += bsizex) { |
| 635 | int k, l; |
| 636 | const int si = mmin(i + bsizey, c_h - i); |
| 637 | const int sj = mmin(j + bsizex, c_w - j); |
| 638 | for (k = 0; match && k < si; ++k) { |
| 639 | for (l = 0; match && l < sj; ++l) { |
| 640 | if (*(plane1 + (i + k) * stride1 + j + l) != |
| 641 | *(plane2 + (i + k) * stride2 + j + l)) { |
| 642 | vloc[0] = i + k; |
| 643 | vloc[1] = j + l; |
| 644 | vloc[2] = *(plane1 + (i + k) * stride1 + j + l); |
| 645 | vloc[3] = *(plane2 + (i + k) * stride2 + j + l); |
| 646 | match = 0; |
| 647 | break; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | #endif |
| 655 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 656 | static void find_mismatch(const aom_image_t *const img1, |
| 657 | const aom_image_t *const img2, int yloc[4], |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 658 | int uloc[4], int vloc[4]) { |
James Zern | 6253e8e | 2014-01-31 16:10:43 -0800 | [diff] [blame] | 659 | const uint32_t bsize = 64; |
| 660 | const uint32_t bsizey = bsize >> img1->y_chroma_shift; |
| 661 | const uint32_t bsizex = bsize >> img1->x_chroma_shift; |
| 662 | const uint32_t c_w = |
| 663 | (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; |
| 664 | const uint32_t c_h = |
| 665 | (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; |
| 666 | int match = 1; |
| 667 | uint32_t i, j; |
Deb Mukherjee | 23144d2 | 2013-03-12 14:21:08 -0700 | [diff] [blame] | 668 | yloc[0] = yloc[1] = yloc[2] = yloc[3] = -1; |
Deb Mukherjee | 01cafaa | 2013-01-15 06:43:35 -0800 | [diff] [blame] | 669 | for (i = 0, match = 1; match && i < img1->d_h; i += bsize) { |
| 670 | for (j = 0; match && j < img1->d_w; j += bsize) { |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 671 | int k, l; |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 672 | const int si = mmin(i + bsize, img1->d_h) - i; |
| 673 | const int sj = mmin(j + bsize, img1->d_w) - j; |
| 674 | for (k = 0; match && k < si; ++k) { |
| 675 | for (l = 0; match && l < sj; ++l) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 676 | if (*(img1->planes[AOM_PLANE_Y] + |
| 677 | (i + k) * img1->stride[AOM_PLANE_Y] + j + l) != |
| 678 | *(img2->planes[AOM_PLANE_Y] + |
| 679 | (i + k) * img2->stride[AOM_PLANE_Y] + j + l)) { |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 680 | yloc[0] = i + k; |
| 681 | yloc[1] = j + l; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 682 | yloc[2] = *(img1->planes[AOM_PLANE_Y] + |
| 683 | (i + k) * img1->stride[AOM_PLANE_Y] + j + l); |
| 684 | yloc[3] = *(img2->planes[AOM_PLANE_Y] + |
| 685 | (i + k) * img2->stride[AOM_PLANE_Y] + j + l); |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 686 | match = 0; |
| 687 | break; |
| 688 | } |
| 689 | } |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 690 | } |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
Jingning Han | 12bf079 | 2013-04-06 10:00:53 -0700 | [diff] [blame] | 693 | |
Deb Mukherjee | 23144d2 | 2013-03-12 14:21:08 -0700 | [diff] [blame] | 694 | uloc[0] = uloc[1] = uloc[2] = uloc[3] = -1; |
John Koleszar | beae501 | 2013-05-08 16:07:38 -0700 | [diff] [blame] | 695 | for (i = 0, match = 1; match && i < c_h; i += bsizey) { |
John Koleszar | cc0eeda | 2013-06-11 11:28:08 -0700 | [diff] [blame] | 696 | for (j = 0; match && j < c_w; j += bsizex) { |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 697 | int k, l; |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 698 | const int si = mmin(i + bsizey, c_h - i); |
| 699 | const int sj = mmin(j + bsizex, c_w - j); |
| 700 | for (k = 0; match && k < si; ++k) { |
| 701 | for (l = 0; match && l < sj; ++l) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 702 | if (*(img1->planes[AOM_PLANE_U] + |
| 703 | (i + k) * img1->stride[AOM_PLANE_U] + j + l) != |
| 704 | *(img2->planes[AOM_PLANE_U] + |
| 705 | (i + k) * img2->stride[AOM_PLANE_U] + j + l)) { |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 706 | uloc[0] = i + k; |
| 707 | uloc[1] = j + l; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 708 | uloc[2] = *(img1->planes[AOM_PLANE_U] + |
| 709 | (i + k) * img1->stride[AOM_PLANE_U] + j + l); |
| 710 | uloc[3] = *(img2->planes[AOM_PLANE_U] + |
| 711 | (i + k) * img2->stride[AOM_PLANE_U] + j + l); |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 712 | match = 0; |
| 713 | break; |
| 714 | } |
| 715 | } |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 716 | } |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 717 | } |
| 718 | } |
Deb Mukherjee | 23144d2 | 2013-03-12 14:21:08 -0700 | [diff] [blame] | 719 | vloc[0] = vloc[1] = vloc[2] = vloc[3] = -1; |
John Koleszar | beae501 | 2013-05-08 16:07:38 -0700 | [diff] [blame] | 720 | for (i = 0, match = 1; match && i < c_h; i += bsizey) { |
John Koleszar | cc0eeda | 2013-06-11 11:28:08 -0700 | [diff] [blame] | 721 | for (j = 0; match && j < c_w; j += bsizex) { |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 722 | int k, l; |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 723 | const int si = mmin(i + bsizey, c_h - i); |
| 724 | const int sj = mmin(j + bsizex, c_w - j); |
| 725 | for (k = 0; match && k < si; ++k) { |
| 726 | for (l = 0; match && l < sj; ++l) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 727 | if (*(img1->planes[AOM_PLANE_V] + |
| 728 | (i + k) * img1->stride[AOM_PLANE_V] + j + l) != |
| 729 | *(img2->planes[AOM_PLANE_V] + |
| 730 | (i + k) * img2->stride[AOM_PLANE_V] + j + l)) { |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 731 | vloc[0] = i + k; |
| 732 | vloc[1] = j + l; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 733 | vloc[2] = *(img1->planes[AOM_PLANE_V] + |
| 734 | (i + k) * img1->stride[AOM_PLANE_V] + j + l); |
| 735 | vloc[3] = *(img2->planes[AOM_PLANE_V] + |
| 736 | (i + k) * img2->stride[AOM_PLANE_V] + j + l); |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 737 | match = 0; |
| 738 | break; |
| 739 | } |
| 740 | } |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 741 | } |
Deb Mukherjee | 0742b1e | 2012-11-15 15:14:38 -0800 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 745 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 746 | static int compare_img(const aom_image_t *const img1, |
| 747 | const aom_image_t *const img2) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 748 | uint32_t l_w = img1->d_w; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 749 | uint32_t c_w = (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift; |
James Zern | 6253e8e | 2014-01-31 16:10:43 -0800 | [diff] [blame] | 750 | const uint32_t c_h = |
| 751 | (img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift; |
| 752 | uint32_t i; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 753 | int match = 1; |
Yaowu Xu | f798f9e | 2012-03-07 12:25:50 -0800 | [diff] [blame] | 754 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 755 | match &= (img1->fmt == img2->fmt); |
hkuang | 3671e62 | 2014-01-22 14:58:59 -0800 | [diff] [blame] | 756 | match &= (img1->d_w == img2->d_w); |
| 757 | match &= (img1->d_h == img2->d_h); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 758 | #if CONFIG_AOM_HIGHBITDEPTH |
| 759 | if (img1->fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 760 | l_w *= 2; |
| 761 | c_w *= 2; |
| 762 | } |
| 763 | #endif |
Yaowu Xu | f798f9e | 2012-03-07 12:25:50 -0800 | [diff] [blame] | 764 | |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 765 | for (i = 0; i < img1->d_h; ++i) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 766 | match &= (memcmp(img1->planes[AOM_PLANE_Y] + i * img1->stride[AOM_PLANE_Y], |
| 767 | img2->planes[AOM_PLANE_Y] + i * img2->stride[AOM_PLANE_Y], |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 768 | l_w) == 0); |
Yaowu Xu | f798f9e | 2012-03-07 12:25:50 -0800 | [diff] [blame] | 769 | |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 770 | for (i = 0; i < c_h; ++i) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 771 | match &= (memcmp(img1->planes[AOM_PLANE_U] + i * img1->stride[AOM_PLANE_U], |
| 772 | img2->planes[AOM_PLANE_U] + i * img2->stride[AOM_PLANE_U], |
John Koleszar | beae501 | 2013-05-08 16:07:38 -0700 | [diff] [blame] | 773 | c_w) == 0); |
Yaowu Xu | f798f9e | 2012-03-07 12:25:50 -0800 | [diff] [blame] | 774 | |
James Zern | d04112d | 2014-01-31 15:49:17 -0800 | [diff] [blame] | 775 | for (i = 0; i < c_h; ++i) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 776 | match &= (memcmp(img1->planes[AOM_PLANE_V] + i * img1->stride[AOM_PLANE_V], |
| 777 | img2->planes[AOM_PLANE_V] + i * img2->stride[AOM_PLANE_V], |
John Koleszar | beae501 | 2013-05-08 16:07:38 -0700 | [diff] [blame] | 778 | c_w) == 0); |
Yaowu Xu | f798f9e | 2012-03-07 12:25:50 -0800 | [diff] [blame] | 779 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 780 | return match; |
Yaowu Xu | f798f9e | 2012-03-07 12:25:50 -0800 | [diff] [blame] | 781 | } |
| 782 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 783 | #define NELEMENTS(x) (sizeof(x) / sizeof(x[0])) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 784 | #if CONFIG_AV1_ENCODER |
| 785 | #define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map) |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 786 | #endif |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 787 | |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 788 | #if !CONFIG_WEBM_IO |
| 789 | typedef int stereo_format_t; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 790 | struct WebmOutputContext { |
| 791 | int debug; |
| 792 | }; |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 793 | #endif |
| 794 | |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 795 | /* Per-stream configuration */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 796 | struct stream_config { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 797 | struct aom_codec_enc_cfg cfg; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 798 | const char *out_fn; |
| 799 | const char *stats_fn; |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 800 | #if CONFIG_FP_MB_STATS |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 801 | const char *fpmb_stats_fn; |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 802 | #endif |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 803 | stereo_format_t stereo_fmt; |
| 804 | int arg_ctrls[ARG_CTRL_CNT_MAX][2]; |
| 805 | int arg_ctrl_cnt; |
| 806 | int write_webm; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 807 | #if CONFIG_AOM_HIGHBITDEPTH |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 808 | // whether to use 16bit internal buffers |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 809 | int use_16bit_internal; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 810 | #endif |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 811 | }; |
| 812 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 813 | struct stream_state { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 814 | int index; |
| 815 | struct stream_state *next; |
| 816 | struct stream_config config; |
| 817 | FILE *file; |
| 818 | struct rate_hist *rate_hist; |
| 819 | struct WebmOutputContext webm_ctx; |
| 820 | uint64_t psnr_sse_total; |
| 821 | uint64_t psnr_samples_total; |
| 822 | double psnr_totals[4]; |
| 823 | int psnr_count; |
| 824 | int counts[64]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 825 | aom_codec_ctx_t encoder; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 826 | unsigned int frames_out; |
| 827 | uint64_t cx_time; |
| 828 | size_t nbytes; |
| 829 | stats_io_t stats; |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 830 | #if CONFIG_FP_MB_STATS |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 831 | stats_io_t fpmb_stats; |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 832 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 833 | struct aom_image *img; |
| 834 | aom_codec_ctx_t decoder; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 835 | int mismatch_seen; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 836 | }; |
| 837 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 838 | static void validate_positive_rational(const char *msg, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 839 | struct aom_rational *rat) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 840 | if (rat->den < 0) { |
| 841 | rat->num *= -1; |
| 842 | rat->den *= -1; |
| 843 | } |
John Koleszar | 1b27e93 | 2012-04-25 17:08:56 -0700 | [diff] [blame] | 844 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 845 | if (rat->num < 0) die("Error: %s must be positive\n", msg); |
John Koleszar | 1b27e93 | 2012-04-25 17:08:56 -0700 | [diff] [blame] | 846 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 847 | if (!rat->den) die("Error: %s has zero denominator\n", msg); |
John Koleszar | 1b27e93 | 2012-04-25 17:08:56 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 850 | static void parse_global_config(struct AvxEncoderConfig *global, char **argv) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 851 | char **argi, **argj; |
| 852 | struct arg arg; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 853 | const int num_encoder = get_aom_encoder_count(); |
Yaowu Xu | f990b35 | 2015-06-01 09:13:59 -0700 | [diff] [blame] | 854 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 855 | if (num_encoder < 1) die("Error: no valid encoder available\n"); |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 856 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 857 | /* Initialize default parameters */ |
| 858 | memset(global, 0, sizeof(*global)); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 859 | global->codec = get_aom_encoder_by_index(num_encoder - 1); |
Deb Mukherjee | 0d8723f | 2013-08-19 14:16:26 -0700 | [diff] [blame] | 860 | global->passes = 0; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 861 | global->color_type = I420; |
Deb Mukherjee | 0d8723f | 2013-08-19 14:16:26 -0700 | [diff] [blame] | 862 | /* Assign default deadline to good quality */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 863 | global->deadline = AOM_DL_GOOD_QUALITY; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 864 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 865 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
| 866 | arg.argv_step = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 867 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 868 | if (arg_match(&arg, &codecarg, argi)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 869 | global->codec = get_aom_encoder_by_name(arg.val); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 870 | if (!global->codec) |
| 871 | die("Error: Unrecognized argument (%s) to --codec\n", arg.val); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 872 | } else if (arg_match(&arg, &passes, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 873 | global->passes = arg_parse_uint(&arg); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 874 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 875 | if (global->passes < 1 || global->passes > 2) |
| 876 | die("Error: Invalid number of passes (%d)\n", global->passes); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 877 | } else if (arg_match(&arg, &pass_arg, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 878 | global->pass = arg_parse_uint(&arg); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 879 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 880 | if (global->pass < 1 || global->pass > 2) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 881 | die("Error: Invalid pass selected (%d)\n", global->pass); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 882 | } else if (arg_match(&arg, &usage, argi)) |
| 883 | global->usage = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 884 | else if (arg_match(&arg, &deadline, argi)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 885 | global->deadline = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 886 | else if (arg_match(&arg, &best_dl, argi)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 887 | global->deadline = AOM_DL_BEST_QUALITY; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 888 | else if (arg_match(&arg, &good_dl, argi)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 889 | global->deadline = AOM_DL_GOOD_QUALITY; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 890 | else if (arg_match(&arg, &rt_dl, argi)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 891 | global->deadline = AOM_DL_REALTIME; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 892 | else if (arg_match(&arg, &use_yv12, argi)) |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 893 | global->color_type = YV12; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 894 | else if (arg_match(&arg, &use_i420, argi)) |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 895 | global->color_type = I420; |
| 896 | else if (arg_match(&arg, &use_i422, argi)) |
| 897 | global->color_type = I422; |
| 898 | else if (arg_match(&arg, &use_i444, argi)) |
| 899 | global->color_type = I444; |
Deb Mukherjee | a30774c | 2014-10-01 12:17:37 -0700 | [diff] [blame] | 900 | else if (arg_match(&arg, &use_i440, argi)) |
| 901 | global->color_type = I440; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 902 | else if (arg_match(&arg, &quietarg, argi)) |
| 903 | global->quiet = 1; |
| 904 | else if (arg_match(&arg, &verbosearg, argi)) |
| 905 | global->verbose = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 906 | else if (arg_match(&arg, &limit, argi)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 907 | global->limit = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 908 | else if (arg_match(&arg, &skip, argi)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 909 | global->skip_frames = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 910 | else if (arg_match(&arg, &psnrarg, argi)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 911 | global->show_psnr = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 912 | else if (arg_match(&arg, &recontest, argi)) |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 913 | global->test_decode = arg_parse_enum_or_int(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 914 | else if (arg_match(&arg, &framerate, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 915 | global->framerate = arg_parse_rational(&arg); |
| 916 | validate_positive_rational(arg.name, &global->framerate); |
| 917 | global->have_framerate = 1; |
| 918 | } else if (arg_match(&arg, &out_part, argi)) |
| 919 | global->out_part = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 920 | else if (arg_match(&arg, &debugmode, argi)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 921 | global->debug = 1; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 922 | else if (arg_match(&arg, &q_hist_n, argi)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 923 | global->show_q_hist_buckets = arg_parse_uint(&arg); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 924 | else if (arg_match(&arg, &rate_hist_n, argi)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 925 | global->show_rate_hist_buckets = arg_parse_uint(&arg); |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 926 | else if (arg_match(&arg, &disable_warnings, argi)) |
| 927 | global->disable_warnings = 1; |
| 928 | else if (arg_match(&arg, &disable_warning_prompt, argi)) |
| 929 | global->disable_warning_prompt = 1; |
John Koleszar | 732cb9a | 2012-02-14 12:30:17 -0800 | [diff] [blame] | 930 | else |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 931 | argj++; |
| 932 | } |
| 933 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 934 | if (global->pass) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 935 | /* DWIM: Assume the user meant passes=2 if pass=2 is specified */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 936 | if (global->pass > global->passes) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 937 | warn("Assuming --pass=%d implies --passes=%d\n", global->pass, |
| 938 | global->pass); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 939 | global->passes = global->pass; |
John Koleszar | 732cb9a | 2012-02-14 12:30:17 -0800 | [diff] [blame] | 940 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 941 | } |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 942 | /* Validate global config */ |
| 943 | if (global->passes == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 944 | #if CONFIG_AV1_ENCODER |
| 945 | // Make default AV1 passes = 2 until there is a better quality 1-pass |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 946 | // encoder |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 947 | if (global->codec != NULL && global->codec->name != NULL) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 948 | global->passes = (strcmp(global->codec->name, "av1") == 0 && |
| 949 | global->deadline != AOM_DL_REALTIME) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 950 | ? 2 |
| 951 | : 1; |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 952 | #else |
| 953 | global->passes = 1; |
| 954 | #endif |
| 955 | } |
| 956 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 957 | if (global->deadline == AOM_DL_REALTIME && global->passes > 1) { |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 958 | warn("Enforcing one-pass encoding in realtime mode\n"); |
| 959 | global->passes = 1; |
| 960 | } |
John Koleszar | 732cb9a | 2012-02-14 12:30:17 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 963 | static void open_input_file(struct AvxInputContext *input) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 964 | /* Parse certain options from the input file, if possible */ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 965 | input->file = strcmp(input->filename, "-") ? fopen(input->filename, "rb") |
| 966 | : set_binary_mode(stdin); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 967 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 968 | if (!input->file) fatal("Failed to open input file"); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 969 | |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 970 | if (!fseeko(input->file, 0, SEEK_END)) { |
| 971 | /* Input file is seekable. Figure out how long it is, so we can get |
| 972 | * progress info. |
| 973 | */ |
| 974 | input->length = ftello(input->file); |
| 975 | rewind(input->file); |
| 976 | } |
| 977 | |
Frank Galligan | 09acd26 | 2015-06-01 10:20:58 -0700 | [diff] [blame] | 978 | /* Default to 1:1 pixel aspect ratio. */ |
| 979 | input->pixel_aspect_ratio.numerator = 1; |
| 980 | input->pixel_aspect_ratio.denominator = 1; |
| 981 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 982 | /* For RAW input sources, these bytes will applied on the first frame |
| 983 | * in read_frame(). |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 984 | */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 985 | input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file); |
| 986 | input->detect.position = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 987 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 988 | if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) { |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 989 | if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, |
| 990 | input->only_i420) >= 0) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 991 | input->file_type = FILE_TYPE_Y4M; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 992 | input->width = input->y4m.pic_w; |
| 993 | input->height = input->y4m.pic_h; |
Frank Galligan | 09acd26 | 2015-06-01 10:20:58 -0700 | [diff] [blame] | 994 | input->pixel_aspect_ratio.numerator = input->y4m.par_n; |
| 995 | input->pixel_aspect_ratio.denominator = input->y4m.par_d; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 996 | input->framerate.numerator = input->y4m.fps_n; |
| 997 | input->framerate.denominator = input->y4m.fps_d; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 998 | input->fmt = input->y4m.aom_fmt; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 999 | input->bit_depth = input->y4m.bit_depth; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1000 | } else |
| 1001 | fatal("Unsupported Y4M stream."); |
Alex Converse | 64b89f1 | 2014-01-06 16:29:09 -0800 | [diff] [blame] | 1002 | } else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) { |
Tom Finegan | 6c270ed | 2013-11-08 11:32:23 -0800 | [diff] [blame] | 1003 | fatal("IVF is not supported as input."); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1004 | } else { |
| 1005 | input->file_type = FILE_TYPE_RAW; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1006 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1009 | static void close_input_file(struct AvxInputContext *input) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1010 | fclose(input->file); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1011 | if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m); |
John Koleszar | 732cb9a | 2012-02-14 12:30:17 -0800 | [diff] [blame] | 1012 | } |
| 1013 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1014 | static struct stream_state *new_stream(struct AvxEncoderConfig *global, |
Tom Finegan | 6c270ed | 2013-11-08 11:32:23 -0800 | [diff] [blame] | 1015 | struct stream_state *prev) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1016 | struct stream_state *stream; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1017 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1018 | stream = calloc(1, sizeof(*stream)); |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 1019 | if (stream == NULL) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1020 | fatal("Failed to allocate new stream."); |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1023 | if (prev) { |
| 1024 | memcpy(stream, prev, sizeof(*stream)); |
| 1025 | stream->index++; |
| 1026 | prev->next = stream; |
| 1027 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1028 | aom_codec_err_t res; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1029 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1030 | /* Populate encoder configuration */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1031 | res = aom_codec_enc_config_default(global->codec->codec_interface(), |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1032 | &stream->config.cfg, global->usage); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1033 | if (res) fatal("Failed to get config: %s\n", aom_codec_err_to_string(res)); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1034 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1035 | /* Change the default timebase to a high enough value so that the |
| 1036 | * encoder will always create strictly increasing timestamps. |
| 1037 | */ |
| 1038 | stream->config.cfg.g_timebase.den = 1000; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1039 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1040 | /* Never use the library's default resolution, require it be parsed |
| 1041 | * from the file or set on the command line. |
| 1042 | */ |
| 1043 | stream->config.cfg.g_w = 0; |
| 1044 | stream->config.cfg.g_h = 0; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1045 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1046 | /* Initialize remaining stream parameters */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1047 | stream->config.write_webm = 1; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1048 | #if CONFIG_WEBM_IO |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 1049 | stream->config.stereo_fmt = STEREO_FORMAT_MONO; |
Vignesh Venkatasubramanian | 9441f10 | 2016-04-25 13:28:24 -0700 | [diff] [blame] | 1050 | stream->webm_ctx.last_pts_ns = -1; |
| 1051 | stream->webm_ctx.writer = NULL; |
| 1052 | stream->webm_ctx.segment = NULL; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1053 | #endif |
Johann | 87c40b3 | 2012-03-01 16:12:53 -0800 | [diff] [blame] | 1054 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1055 | /* Allows removal of the application version from the EBML tags */ |
Vignesh Venkatasubramanian | 9441f10 | 2016-04-25 13:28:24 -0700 | [diff] [blame] | 1056 | stream->webm_ctx.debug = global->debug; |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1057 | |
| 1058 | /* Default lag_in_frames is 0 in realtime mode */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1059 | if (global->deadline == AOM_DL_REALTIME) |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1060 | stream->config.cfg.g_lag_in_frames = 0; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1061 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1062 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1063 | /* Output files must be specified for each stream */ |
| 1064 | stream->config.out_fn = NULL; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1065 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1066 | stream->next = NULL; |
| 1067 | return stream; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1070 | static int parse_stream_params(struct AvxEncoderConfig *global, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1071 | struct stream_state *stream, char **argv) { |
| 1072 | char **argi, **argj; |
| 1073 | struct arg arg; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1074 | static const arg_def_t **ctrl_args = no_args; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1075 | static const int *ctrl_args_map = NULL; |
| 1076 | struct stream_config *config = &stream->config; |
| 1077 | int eos_mark_found = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1078 | #if CONFIG_AOM_HIGHBITDEPTH |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1079 | int test_16bit_internal = 0; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1080 | #endif |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1081 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 1082 | // Handle codec specific options |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 1083 | if (0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1084 | #if CONFIG_AV1_ENCODER |
| 1085 | } else if (strcmp(global->codec->name, "av1") == 0) { |
| 1086 | // TODO(jingning): Reuse AV1 specific encoder configuration parameters. |
| 1087 | // Consider to expand this set for AV1 encoder control. |
| 1088 | ctrl_args = av1_args; |
| 1089 | ctrl_args_map = av1_arg_ctrl_map; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 1090 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1091 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1092 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1093 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1094 | arg.argv_step = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1095 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1096 | /* Once we've found an end-of-stream marker (--) we want to continue |
| 1097 | * shifting arguments but not consuming them. |
| 1098 | */ |
| 1099 | if (eos_mark_found) { |
| 1100 | argj++; |
| 1101 | continue; |
| 1102 | } else if (!strcmp(*argj, "--")) { |
| 1103 | eos_mark_found = 1; |
| 1104 | continue; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1105 | } |
| 1106 | |
Adrian Grange | d240180 | 2015-02-13 14:51:32 -0800 | [diff] [blame] | 1107 | if (arg_match(&arg, &outputfile, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1108 | config->out_fn = arg.val; |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1109 | } else if (arg_match(&arg, &fpf_name, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1110 | config->stats_fn = arg.val; |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1111 | #if CONFIG_FP_MB_STATS |
| 1112 | } else if (arg_match(&arg, &fpmbf_name, argi)) { |
| 1113 | config->fpmb_stats_fn = arg.val; |
| 1114 | #endif |
Johann | b50e518 | 2015-01-30 15:05:14 -0800 | [diff] [blame] | 1115 | } else if (arg_match(&arg, &use_webm, argi)) { |
| 1116 | #if CONFIG_WEBM_IO |
| 1117 | config->write_webm = 1; |
| 1118 | #else |
| 1119 | die("Error: --webm specified but webm is disabled."); |
| 1120 | #endif |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1121 | } else if (arg_match(&arg, &use_ivf, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1122 | config->write_webm = 0; |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1123 | } else if (arg_match(&arg, &threads, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1124 | config->cfg.g_threads = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1125 | } else if (arg_match(&arg, &profile, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1126 | config->cfg.g_profile = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1127 | } else if (arg_match(&arg, &width, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1128 | config->cfg.g_w = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1129 | } else if (arg_match(&arg, &height, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1130 | config->cfg.g_h = arg_parse_uint(&arg); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1131 | #if CONFIG_AOM_HIGHBITDEPTH |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1132 | } else if (arg_match(&arg, &bitdeptharg, argi)) { |
| 1133 | config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg); |
| 1134 | } else if (arg_match(&arg, &inbitdeptharg, argi)) { |
| 1135 | config->cfg.g_input_bit_depth = arg_parse_uint(&arg); |
| 1136 | #endif |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 1137 | #if CONFIG_WEBM_IO |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1138 | } else if (arg_match(&arg, &stereo_mode, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1139 | config->stereo_fmt = arg_parse_enum_or_int(&arg); |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 1140 | #endif |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1141 | } else if (arg_match(&arg, &timebase, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1142 | config->cfg.g_timebase = arg_parse_rational(&arg); |
| 1143 | validate_positive_rational(arg.name, &config->cfg.g_timebase); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1144 | } else if (arg_match(&arg, &error_resilient, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1145 | config->cfg.g_error_resilient = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1146 | } else if (arg_match(&arg, &lag_in_frames, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1147 | config->cfg.g_lag_in_frames = arg_parse_uint(&arg); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1148 | if (global->deadline == AOM_DL_REALTIME && |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1149 | config->cfg.g_lag_in_frames != 0) { |
| 1150 | warn("non-zero %s option ignored in realtime mode.\n", arg.name); |
| 1151 | config->cfg.g_lag_in_frames = 0; |
| 1152 | } |
| 1153 | } else if (arg_match(&arg, &dropframe_thresh, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1154 | config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1155 | } else if (arg_match(&arg, &resize_allowed, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1156 | config->cfg.rc_resize_allowed = arg_parse_uint(&arg); |
Adrian Grange | f7bd127 | 2014-04-09 14:51:29 -0700 | [diff] [blame] | 1157 | } else if (arg_match(&arg, &resize_width, argi)) { |
| 1158 | config->cfg.rc_scaled_width = arg_parse_uint(&arg); |
| 1159 | } else if (arg_match(&arg, &resize_height, argi)) { |
| 1160 | config->cfg.rc_scaled_height = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1161 | } else if (arg_match(&arg, &resize_up_thresh, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1162 | config->cfg.rc_resize_up_thresh = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1163 | } else if (arg_match(&arg, &resize_down_thresh, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1164 | config->cfg.rc_resize_down_thresh = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1165 | } else if (arg_match(&arg, &end_usage, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1166 | config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1167 | } else if (arg_match(&arg, &target_bitrate, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1168 | config->cfg.rc_target_bitrate = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1169 | } else if (arg_match(&arg, &min_quantizer, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1170 | config->cfg.rc_min_quantizer = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1171 | } else if (arg_match(&arg, &max_quantizer, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1172 | config->cfg.rc_max_quantizer = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1173 | } else if (arg_match(&arg, &undershoot_pct, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1174 | config->cfg.rc_undershoot_pct = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1175 | } else if (arg_match(&arg, &overshoot_pct, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1176 | config->cfg.rc_overshoot_pct = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1177 | } else if (arg_match(&arg, &buf_sz, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1178 | config->cfg.rc_buf_sz = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1179 | } else if (arg_match(&arg, &buf_initial_sz, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1180 | config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1181 | } else if (arg_match(&arg, &buf_optimal_sz, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1182 | config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1183 | } else if (arg_match(&arg, &bias_pct, argi)) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1184 | config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1185 | if (global->passes < 2) |
| 1186 | warn("option %s ignored in one-pass mode.\n", arg.name); |
| 1187 | } else if (arg_match(&arg, &minsection_pct, argi)) { |
| 1188 | config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg); |
| 1189 | |
| 1190 | if (global->passes < 2) |
| 1191 | warn("option %s ignored in one-pass mode.\n", arg.name); |
| 1192 | } else if (arg_match(&arg, &maxsection_pct, argi)) { |
| 1193 | config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg); |
| 1194 | |
| 1195 | if (global->passes < 2) |
| 1196 | warn("option %s ignored in one-pass mode.\n", arg.name); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1197 | } else if (arg_match(&arg, &kf_min_dist, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1198 | config->cfg.kf_min_dist = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1199 | } else if (arg_match(&arg, &kf_max_dist, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1200 | config->cfg.kf_max_dist = arg_parse_uint(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1201 | } else if (arg_match(&arg, &kf_disabled, argi)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1202 | config->cfg.kf_mode = AOM_KF_DISABLED; |
| 1203 | #if CONFIG_AOM_HIGHBITDEPTH |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1204 | } else if (arg_match(&arg, &test16bitinternalarg, argi)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1205 | if (strcmp(global->codec->name, "av1") == 0 || |
| 1206 | strcmp(global->codec->name, "av1") == 0) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1207 | test_16bit_internal = 1; |
| 1208 | } |
| 1209 | #endif |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1210 | } else { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1211 | int i, match = 0; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1212 | for (i = 0; ctrl_args[i]; i++) { |
| 1213 | if (arg_match(&arg, ctrl_args[i], argi)) { |
| 1214 | int j; |
| 1215 | match = 1; |
| 1216 | |
| 1217 | /* Point either to the next free element or the first |
| 1218 | * instance of this control. |
| 1219 | */ |
| 1220 | for (j = 0; j < config->arg_ctrl_cnt; j++) |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 1221 | if (ctrl_args_map != NULL && |
| 1222 | config->arg_ctrls[j][0] == ctrl_args_map[i]) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1223 | break; |
| 1224 | |
| 1225 | /* Update/insert */ |
Yaowu Xu | 618e7ef | 2014-07-11 16:27:21 -0700 | [diff] [blame] | 1226 | assert(j < (int)ARG_CTRL_CNT_MAX); |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 1227 | if (ctrl_args_map != NULL && j < (int)ARG_CTRL_CNT_MAX) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1228 | config->arg_ctrls[j][0] = ctrl_args_map[i]; |
| 1229 | config->arg_ctrls[j][1] = arg_parse_enum_or_int(&arg); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1230 | if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1231 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1232 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1233 | } |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1234 | if (!match) argj++; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1235 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1236 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1237 | #if CONFIG_AOM_HIGHBITDEPTH |
| 1238 | if (strcmp(global->codec->name, "av1") == 0 || |
| 1239 | strcmp(global->codec->name, "av1") == 0) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1240 | config->use_16bit_internal = |
| 1241 | test_16bit_internal | (config->cfg.g_profile > 1); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1242 | } |
| 1243 | #endif |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1244 | return eos_mark_found; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1247 | #define FOREACH_STREAM(func) \ |
| 1248 | do { \ |
| 1249 | struct stream_state *stream; \ |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 1250 | for (stream = streams; stream; stream = stream->next) { \ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1251 | func; \ |
| 1252 | } \ |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 1253 | } while (0) |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1254 | |
Alex Converse | d66bd22 | 2014-02-21 10:52:09 -0800 | [diff] [blame] | 1255 | static void validate_stream_config(const struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1256 | const struct AvxEncoderConfig *global) { |
Alex Converse | d66bd22 | 2014-02-21 10:52:09 -0800 | [diff] [blame] | 1257 | const struct stream_state *streami; |
Johann | 80b344d | 2014-12-16 12:22:10 -0800 | [diff] [blame] | 1258 | (void)global; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1259 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1260 | if (!stream->config.cfg.g_w || !stream->config.cfg.g_h) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1261 | fatal( |
| 1262 | "Stream %d: Specify stream dimensions with --width (-w) " |
| 1263 | " and --height (-h)", |
| 1264 | stream->index); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1265 | |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1266 | // Check that the codec bit depth is greater than the input bit depth. |
| 1267 | if (stream->config.cfg.g_input_bit_depth > |
Yaowu Xu | dbdb87b | 2014-09-03 17:02:31 -0700 | [diff] [blame] | 1268 | (unsigned int)stream->config.cfg.g_bit_depth) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1269 | fatal("Stream %d: codec bit depth (%d) less than input bit depth (%d)", |
| 1270 | stream->index, (int)stream->config.cfg.g_bit_depth, |
| 1271 | stream->config.cfg.g_input_bit_depth); |
| 1272 | } |
| 1273 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1274 | for (streami = stream; streami; streami = streami->next) { |
| 1275 | /* All streams require output files */ |
| 1276 | if (!streami->config.out_fn) |
| 1277 | fatal("Stream %d: Output file is required (specify with -o)", |
| 1278 | streami->index); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1279 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1280 | /* Check for two streams outputting to the same file */ |
| 1281 | if (streami != stream) { |
| 1282 | const char *a = stream->config.out_fn; |
| 1283 | const char *b = streami->config.out_fn; |
| 1284 | if (!strcmp(a, b) && strcmp(a, "/dev/null") && strcmp(a, ":nul")) |
| 1285 | fatal("Stream %d: duplicate output file (from stream %d)", |
| 1286 | streami->index, stream->index); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1287 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1288 | |
| 1289 | /* Check for two streams sharing a stats file. */ |
| 1290 | if (streami != stream) { |
| 1291 | const char *a = stream->config.stats_fn; |
| 1292 | const char *b = streami->config.stats_fn; |
| 1293 | if (a && b && !strcmp(a, b)) |
| 1294 | fatal("Stream %d: duplicate stats file (from stream %d)", |
| 1295 | streami->index, stream->index); |
| 1296 | } |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1297 | |
| 1298 | #if CONFIG_FP_MB_STATS |
| 1299 | /* Check for two streams sharing a mb stats file. */ |
| 1300 | if (streami != stream) { |
| 1301 | const char *a = stream->config.fpmb_stats_fn; |
| 1302 | const char *b = streami->config.fpmb_stats_fn; |
| 1303 | if (a && b && !strcmp(a, b)) |
| 1304 | fatal("Stream %d: duplicate mb stats file (from stream %d)", |
| 1305 | streami->index, stream->index); |
| 1306 | } |
| 1307 | #endif |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1308 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1311 | static void set_stream_dimensions(struct stream_state *stream, unsigned int w, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1312 | unsigned int h) { |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1313 | if (!stream->config.cfg.g_w) { |
| 1314 | if (!stream->config.cfg.g_h) |
| 1315 | stream->config.cfg.g_w = w; |
| 1316 | else |
| 1317 | stream->config.cfg.g_w = w * stream->config.cfg.g_h / h; |
| 1318 | } |
| 1319 | if (!stream->config.cfg.g_h) { |
| 1320 | stream->config.cfg.g_h = h * stream->config.cfg.g_w / w; |
| 1321 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1324 | static const char *file_type_to_string(enum VideoFileType t) { |
Alex Converse | 6c2e88e | 2014-05-16 12:29:36 -0700 | [diff] [blame] | 1325 | switch (t) { |
| 1326 | case FILE_TYPE_RAW: return "RAW"; |
| 1327 | case FILE_TYPE_Y4M: return "Y4M"; |
| 1328 | default: return "Other"; |
| 1329 | } |
| 1330 | } |
| 1331 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1332 | static const char *image_format_to_string(aom_img_fmt_t f) { |
Alex Converse | 6c2e88e | 2014-05-16 12:29:36 -0700 | [diff] [blame] | 1333 | switch (f) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1334 | case AOM_IMG_FMT_I420: return "I420"; |
| 1335 | case AOM_IMG_FMT_I422: return "I422"; |
| 1336 | case AOM_IMG_FMT_I444: return "I444"; |
| 1337 | case AOM_IMG_FMT_I440: return "I440"; |
| 1338 | case AOM_IMG_FMT_YV12: return "YV12"; |
| 1339 | case AOM_IMG_FMT_I42016: return "I42016"; |
| 1340 | case AOM_IMG_FMT_I42216: return "I42216"; |
| 1341 | case AOM_IMG_FMT_I44416: return "I44416"; |
| 1342 | case AOM_IMG_FMT_I44016: return "I44016"; |
Alex Converse | 6c2e88e | 2014-05-16 12:29:36 -0700 | [diff] [blame] | 1343 | default: return "Other"; |
| 1344 | } |
| 1345 | } |
Ralph Giles | 061a16d | 2012-01-05 15:05:05 -0600 | [diff] [blame] | 1346 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1347 | static void show_stream_config(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1348 | struct AvxEncoderConfig *global, |
| 1349 | struct AvxInputContext *input) { |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1350 | #define SHOW(field) \ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1351 | fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field) |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1352 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1353 | if (stream->index == 0) { |
| 1354 | fprintf(stderr, "Codec: %s\n", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1355 | aom_codec_iface_name(global->codec->codec_interface())); |
Alex Converse | 6c2e88e | 2014-05-16 12:29:36 -0700 | [diff] [blame] | 1356 | fprintf(stderr, "Source file: %s File Type: %s Format: %s\n", |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1357 | input->filename, file_type_to_string(input->file_type), |
Alex Converse | 6c2e88e | 2014-05-16 12:29:36 -0700 | [diff] [blame] | 1358 | image_format_to_string(input->fmt)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1359 | } |
| 1360 | if (stream->next || stream->index) |
| 1361 | fprintf(stderr, "\nStream Index: %d\n", stream->index); |
| 1362 | fprintf(stderr, "Destination file: %s\n", stream->config.out_fn); |
| 1363 | fprintf(stderr, "Encoder parameters:\n"); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1364 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1365 | SHOW(g_usage); |
| 1366 | SHOW(g_threads); |
| 1367 | SHOW(g_profile); |
| 1368 | SHOW(g_w); |
| 1369 | SHOW(g_h); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1370 | SHOW(g_bit_depth); |
| 1371 | SHOW(g_input_bit_depth); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1372 | SHOW(g_timebase.num); |
| 1373 | SHOW(g_timebase.den); |
| 1374 | SHOW(g_error_resilient); |
| 1375 | SHOW(g_pass); |
| 1376 | SHOW(g_lag_in_frames); |
| 1377 | SHOW(rc_dropframe_thresh); |
| 1378 | SHOW(rc_resize_allowed); |
Adrian Grange | f7bd127 | 2014-04-09 14:51:29 -0700 | [diff] [blame] | 1379 | SHOW(rc_scaled_width); |
| 1380 | SHOW(rc_scaled_height); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1381 | SHOW(rc_resize_up_thresh); |
| 1382 | SHOW(rc_resize_down_thresh); |
| 1383 | SHOW(rc_end_usage); |
| 1384 | SHOW(rc_target_bitrate); |
| 1385 | SHOW(rc_min_quantizer); |
| 1386 | SHOW(rc_max_quantizer); |
| 1387 | SHOW(rc_undershoot_pct); |
| 1388 | SHOW(rc_overshoot_pct); |
| 1389 | SHOW(rc_buf_sz); |
| 1390 | SHOW(rc_buf_initial_sz); |
| 1391 | SHOW(rc_buf_optimal_sz); |
| 1392 | SHOW(rc_2pass_vbr_bias_pct); |
| 1393 | SHOW(rc_2pass_vbr_minsection_pct); |
| 1394 | SHOW(rc_2pass_vbr_maxsection_pct); |
| 1395 | SHOW(kf_mode); |
| 1396 | SHOW(kf_min_dist); |
| 1397 | SHOW(kf_max_dist); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1398 | } |
| 1399 | |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1400 | static void open_output_file(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1401 | struct AvxEncoderConfig *global, |
| 1402 | const struct AvxRational *pixel_aspect_ratio) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1403 | const char *fn = stream->config.out_fn; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1404 | const struct aom_codec_enc_cfg *const cfg = &stream->config.cfg; |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1405 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1406 | if (cfg->g_pass == AOM_RC_FIRST_PASS) return; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1407 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1408 | stream->file = strcmp(fn, "-") ? fopen(fn, "wb") : set_binary_mode(stdout); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1409 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1410 | if (!stream->file) fatal("Failed to open output file"); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1411 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1412 | if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR)) |
| 1413 | fatal("WebM output to pipes not supported."); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1414 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1415 | #if CONFIG_WEBM_IO |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1416 | if (stream->config.write_webm) { |
Vignesh Venkatasubramanian | 9441f10 | 2016-04-25 13:28:24 -0700 | [diff] [blame] | 1417 | stream->webm_ctx.stream = stream->file; |
Urvang Joshi | d71a231 | 2016-07-14 12:33:48 -0700 | [diff] [blame] | 1418 | write_webm_file_header(&stream->webm_ctx, cfg, stream->config.stereo_fmt, |
| 1419 | global->codec->fourcc, pixel_aspect_ratio); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1420 | } |
James Zern | c8e5a77 | 2016-02-11 18:53:50 -0800 | [diff] [blame] | 1421 | #else |
| 1422 | (void)pixel_aspect_ratio; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1423 | #endif |
| 1424 | |
| 1425 | if (!stream->config.write_webm) { |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1426 | ivf_write_file_header(stream->file, cfg, global->codec->fourcc, 0); |
| 1427 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1430 | static void close_output_file(struct stream_state *stream, |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1431 | unsigned int fourcc) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1432 | const struct aom_codec_enc_cfg *const cfg = &stream->config.cfg; |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1433 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1434 | if (cfg->g_pass == AOM_RC_FIRST_PASS) return; |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1435 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1436 | #if CONFIG_WEBM_IO |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1437 | if (stream->config.write_webm) { |
Vignesh Venkatasubramanian | 9441f10 | 2016-04-25 13:28:24 -0700 | [diff] [blame] | 1438 | write_webm_file_footer(&stream->webm_ctx); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1439 | } |
| 1440 | #endif |
| 1441 | |
| 1442 | if (!stream->config.write_webm) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1443 | if (!fseek(stream->file, 0, SEEK_SET)) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1444 | ivf_write_file_header(stream->file, &stream->config.cfg, fourcc, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1445 | stream->frames_out); |
| 1446 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1447 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1448 | fclose(stream->file); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1449 | } |
| 1450 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1451 | static void setup_pass(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1452 | struct AvxEncoderConfig *global, int pass) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1453 | if (stream->config.stats_fn) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1454 | if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1455 | fatal("Failed to open statistics store"); |
| 1456 | } else { |
| 1457 | if (!stats_open_mem(&stream->stats, pass)) |
| 1458 | fatal("Failed to open statistics store"); |
| 1459 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1460 | |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1461 | #if CONFIG_FP_MB_STATS |
| 1462 | if (stream->config.fpmb_stats_fn) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1463 | if (!stats_open_file(&stream->fpmb_stats, stream->config.fpmb_stats_fn, |
| 1464 | pass)) |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1465 | fatal("Failed to open mb statistics store"); |
| 1466 | } else { |
| 1467 | if (!stats_open_mem(&stream->fpmb_stats, pass)) |
| 1468 | fatal("Failed to open mb statistics store"); |
| 1469 | } |
| 1470 | #endif |
| 1471 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1472 | stream->config.cfg.g_pass = global->passes == 2 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1473 | ? pass ? AOM_RC_LAST_PASS : AOM_RC_FIRST_PASS |
| 1474 | : AOM_RC_ONE_PASS; |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1475 | if (pass) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1476 | stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats); |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1477 | #if CONFIG_FP_MB_STATS |
| 1478 | stream->config.cfg.rc_firstpass_mb_stats_in = |
| 1479 | stats_get(&stream->fpmb_stats); |
| 1480 | #endif |
| 1481 | } |
Yunqing Wang | aabae97 | 2012-02-29 08:24:53 -0500 | [diff] [blame] | 1482 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1483 | stream->cx_time = 0; |
| 1484 | stream->nbytes = 0; |
| 1485 | stream->frames_out = 0; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1486 | } |
| 1487 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1488 | static void initialize_encoder(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1489 | struct AvxEncoderConfig *global) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1490 | int i; |
| 1491 | int flags = 0; |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 1492 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1493 | flags |= global->show_psnr ? AOM_CODEC_USE_PSNR : 0; |
| 1494 | flags |= global->out_part ? AOM_CODEC_USE_OUTPUT_PARTITION : 0; |
| 1495 | #if CONFIG_AOM_HIGHBITDEPTH |
| 1496 | flags |= stream->config.use_16bit_internal ? AOM_CODEC_USE_HIGHBITDEPTH : 0; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1497 | #endif |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1498 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1499 | /* Construct Encoder Context */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1500 | aom_codec_enc_init(&stream->encoder, global->codec->codec_interface(), |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1501 | &stream->config.cfg, flags); |
| 1502 | ctx_exit_on_error(&stream->encoder, "Failed to initialize encoder"); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1503 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1504 | /* Note that we bypass the aom_codec_control wrapper macro because |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1505 | * we're being clever to store the control IDs in an array. Real |
| 1506 | * applications will want to make use of the enumerations directly |
| 1507 | */ |
| 1508 | for (i = 0; i < stream->config.arg_ctrl_cnt; i++) { |
| 1509 | int ctrl = stream->config.arg_ctrls[i][0]; |
| 1510 | int value = stream->config.arg_ctrls[i][1]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1511 | if (aom_codec_control_(&stream->encoder, ctrl, value)) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1512 | fprintf(stderr, "Error: Tried to set control %d = %d\n", ctrl, value); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1513 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1514 | ctx_exit_on_error(&stream->encoder, "Failed to control codec"); |
| 1515 | } |
| 1516 | |
John Koleszar | 5ebe94f | 2012-12-23 07:20:10 -0800 | [diff] [blame] | 1517 | #if CONFIG_DECODERS |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1518 | if (global->test_decode != TEST_DECODE_OFF) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1519 | const AvxInterface *decoder = get_aom_decoder_by_name(global->codec->name); |
| 1520 | aom_codec_dec_cfg_t cfg = { 0, 0, 0 }; |
| 1521 | aom_codec_dec_init(&stream->decoder, decoder->codec_interface(), &cfg, 0); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 1522 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1523 | #if CONFIG_AV1_DECODER && CONFIG_EXT_TILE |
| 1524 | if (strcmp(global->codec->name, "av1") == 0) { |
| 1525 | aom_codec_control(&stream->decoder, AV1_SET_DECODE_TILE_ROW, -1); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 1526 | ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_row"); |
| 1527 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1528 | aom_codec_control(&stream->decoder, AV1_SET_DECODE_TILE_COL, -1); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 1529 | ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_col"); |
| 1530 | } |
| 1531 | #endif |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1532 | } |
John Koleszar | 5ebe94f | 2012-12-23 07:20:10 -0800 | [diff] [blame] | 1533 | #endif |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1536 | static void encode_frame(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1537 | struct AvxEncoderConfig *global, struct aom_image *img, |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1538 | unsigned int frames_in) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1539 | aom_codec_pts_t frame_start, next_frame_start; |
| 1540 | struct aom_codec_enc_cfg *cfg = &stream->config.cfg; |
| 1541 | struct aom_usec_timer timer; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1542 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1543 | frame_start = |
| 1544 | (cfg->g_timebase.den * (int64_t)(frames_in - 1) * global->framerate.den) / |
| 1545 | cfg->g_timebase.num / global->framerate.num; |
| 1546 | next_frame_start = |
| 1547 | (cfg->g_timebase.den * (int64_t)(frames_in)*global->framerate.den) / |
| 1548 | cfg->g_timebase.num / global->framerate.num; |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1549 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1550 | /* Scale if necessary */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1551 | #if CONFIG_AOM_HIGHBITDEPTH |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1552 | if (img) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1553 | if ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) && |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1554 | (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1555 | if (img->fmt != AOM_IMG_FMT_I42016) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1556 | fprintf(stderr, "%s can only scale 4:2:0 inputs\n", exec_name); |
| 1557 | exit(EXIT_FAILURE); |
| 1558 | } |
| 1559 | #if CONFIG_LIBYUV |
| 1560 | if (!stream->img) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1561 | stream->img = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1562 | aom_img_alloc(NULL, AOM_IMG_FMT_I42016, cfg->g_w, cfg->g_h, 16); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1563 | } |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1564 | I420Scale_16( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1565 | (uint16 *)img->planes[AOM_PLANE_Y], img->stride[AOM_PLANE_Y] / 2, |
| 1566 | (uint16 *)img->planes[AOM_PLANE_U], img->stride[AOM_PLANE_U] / 2, |
| 1567 | (uint16 *)img->planes[AOM_PLANE_V], img->stride[AOM_PLANE_V] / 2, |
| 1568 | img->d_w, img->d_h, (uint16 *)stream->img->planes[AOM_PLANE_Y], |
| 1569 | stream->img->stride[AOM_PLANE_Y] / 2, |
| 1570 | (uint16 *)stream->img->planes[AOM_PLANE_U], |
| 1571 | stream->img->stride[AOM_PLANE_U] / 2, |
| 1572 | (uint16 *)stream->img->planes[AOM_PLANE_V], |
| 1573 | stream->img->stride[AOM_PLANE_V] / 2, stream->img->d_w, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1574 | stream->img->d_h, kFilterBox); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1575 | img = stream->img; |
| 1576 | #else |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1577 | stream->encoder.err = 1; |
| 1578 | ctx_exit_on_error(&stream->encoder, |
| 1579 | "Stream %d: Failed to encode frame.\n" |
| 1580 | "Scaling disabled in this configuration. \n" |
| 1581 | "To enable, configure with --enable-libyuv\n", |
| 1582 | stream->index); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1583 | #endif |
| 1584 | } |
| 1585 | } |
| 1586 | #endif |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1587 | if (img && (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1588 | if (img->fmt != AOM_IMG_FMT_I420 && img->fmt != AOM_IMG_FMT_YV12) { |
Alex Converse | 2a3092f | 2014-05-16 18:49:04 -0700 | [diff] [blame] | 1589 | fprintf(stderr, "%s can only scale 4:2:0 8bpp inputs\n", exec_name); |
| 1590 | exit(EXIT_FAILURE); |
| 1591 | } |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 1592 | #if CONFIG_LIBYUV |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1593 | if (!stream->img) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1594 | stream->img = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1595 | aom_img_alloc(NULL, AOM_IMG_FMT_I420, cfg->g_w, cfg->g_h, 16); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1596 | I420Scale( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1597 | img->planes[AOM_PLANE_Y], img->stride[AOM_PLANE_Y], |
| 1598 | img->planes[AOM_PLANE_U], img->stride[AOM_PLANE_U], |
| 1599 | img->planes[AOM_PLANE_V], img->stride[AOM_PLANE_V], img->d_w, img->d_h, |
| 1600 | stream->img->planes[AOM_PLANE_Y], stream->img->stride[AOM_PLANE_Y], |
| 1601 | stream->img->planes[AOM_PLANE_U], stream->img->stride[AOM_PLANE_U], |
| 1602 | stream->img->planes[AOM_PLANE_V], stream->img->stride[AOM_PLANE_V], |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1603 | stream->img->d_w, stream->img->d_h, kFilterBox); |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1604 | img = stream->img; |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 1605 | #else |
| 1606 | stream->encoder.err = 1; |
| 1607 | ctx_exit_on_error(&stream->encoder, |
| 1608 | "Stream %d: Failed to encode frame.\n" |
| 1609 | "Scaling disabled in this configuration. \n" |
| 1610 | "To enable, configure with --enable-libyuv\n", |
| 1611 | stream->index); |
| 1612 | #endif |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1613 | } |
| 1614 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1615 | aom_usec_timer_start(&timer); |
| 1616 | aom_codec_encode(&stream->encoder, img, frame_start, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1617 | (unsigned long)(next_frame_start - frame_start), 0, |
| 1618 | global->deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1619 | aom_usec_timer_mark(&timer); |
| 1620 | stream->cx_time += aom_usec_timer_elapsed(&timer); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1621 | ctx_exit_on_error(&stream->encoder, "Stream %d: Failed to encode frame", |
| 1622 | stream->index); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1623 | } |
| 1624 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1625 | static void update_quantizer_histogram(struct stream_state *stream) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1626 | if (stream->config.cfg.g_pass != AOM_RC_FIRST_PASS) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1627 | int q; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1628 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1629 | aom_codec_control(&stream->encoder, AOME_GET_LAST_QUANTIZER_64, &q); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1630 | ctx_exit_on_error(&stream->encoder, "Failed to read quantizer"); |
| 1631 | stream->counts[q]++; |
| 1632 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1633 | } |
| 1634 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1635 | static void get_cx_data(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1636 | struct AvxEncoderConfig *global, int *got_data) { |
| 1637 | const aom_codec_cx_pkt_t *pkt; |
| 1638 | const struct aom_codec_enc_cfg *cfg = &stream->config.cfg; |
| 1639 | aom_codec_iter_t iter = NULL; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1640 | |
Ronald S. Bultje | 88d703c | 2012-11-09 09:07:50 -0800 | [diff] [blame] | 1641 | *got_data = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1642 | while ((pkt = aom_codec_get_cx_data(&stream->encoder, &iter))) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1643 | static size_t fsize = 0; |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 1644 | static int64_t ivf_header_pos = 0; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1645 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1646 | switch (pkt->kind) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1647 | case AOM_CODEC_CX_FRAME_PKT: |
| 1648 | if (!(pkt->data.frame.flags & AOM_FRAME_IS_FRAGMENT)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1649 | stream->frames_out++; |
| 1650 | } |
Jingning Han | babbd5d | 2013-02-13 09:03:21 -0800 | [diff] [blame] | 1651 | if (!global->quiet) |
| 1652 | fprintf(stderr, " %6luF", (unsigned long)pkt->data.frame.sz); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1653 | |
Dmitry Kovalev | f11da2b | 2014-01-29 12:28:29 -0800 | [diff] [blame] | 1654 | update_rate_histogram(stream->rate_hist, cfg, pkt); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1655 | #if CONFIG_WEBM_IO |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1656 | if (stream->config.write_webm) { |
Vignesh Venkatasubramanian | 9441f10 | 2016-04-25 13:28:24 -0700 | [diff] [blame] | 1657 | write_webm_block(&stream->webm_ctx, cfg, pkt); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1658 | } |
| 1659 | #endif |
| 1660 | if (!stream->config.write_webm) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1661 | if (pkt->data.frame.partition_id <= 0) { |
| 1662 | ivf_header_pos = ftello(stream->file); |
| 1663 | fsize = pkt->data.frame.sz; |
| 1664 | |
Dmitry Kovalev | 373b0f9 | 2014-01-29 17:57:21 -0800 | [diff] [blame] | 1665 | ivf_write_frame_header(stream->file, pkt->data.frame.pts, fsize); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1666 | } else { |
| 1667 | fsize += pkt->data.frame.sz; |
| 1668 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1669 | if (!(pkt->data.frame.flags & AOM_FRAME_IS_FRAGMENT)) { |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 1670 | const int64_t currpos = ftello(stream->file); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1671 | fseeko(stream->file, ivf_header_pos, SEEK_SET); |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 1672 | ivf_write_frame_size(stream->file, fsize); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1673 | fseeko(stream->file, currpos, SEEK_SET); |
| 1674 | } |
| 1675 | } |
| 1676 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1677 | (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, |
| 1678 | stream->file); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1679 | } |
| 1680 | stream->nbytes += pkt->data.raw.sz; |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 1681 | |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1682 | *got_data = 1; |
John Koleszar | 5ebe94f | 2012-12-23 07:20:10 -0800 | [diff] [blame] | 1683 | #if CONFIG_DECODERS |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1684 | if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1685 | aom_codec_decode(&stream->decoder, pkt->data.frame.buf, |
Tom Finegan | 7a691f1 | 2014-02-10 14:55:25 -0800 | [diff] [blame] | 1686 | (unsigned int)pkt->data.frame.sz, NULL, 0); |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1687 | if (stream->decoder.err) { |
| 1688 | warn_or_exit_on_error(&stream->decoder, |
| 1689 | global->test_decode == TEST_DECODE_FATAL, |
| 1690 | "Failed to decode frame %d in stream %d", |
| 1691 | stream->frames_out + 1, stream->index); |
| 1692 | stream->mismatch_seen = stream->frames_out + 1; |
| 1693 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1694 | } |
John Koleszar | 5ebe94f | 2012-12-23 07:20:10 -0800 | [diff] [blame] | 1695 | #endif |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1696 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1697 | case AOM_CODEC_STATS_PKT: |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1698 | stream->frames_out++; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1699 | stats_write(&stream->stats, pkt->data.twopass_stats.buf, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1700 | pkt->data.twopass_stats.sz); |
| 1701 | stream->nbytes += pkt->data.raw.sz; |
| 1702 | break; |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1703 | #if CONFIG_FP_MB_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1704 | case AOM_CODEC_FPMB_STATS_PKT: |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1705 | stats_write(&stream->fpmb_stats, pkt->data.firstpass_mb_stats.buf, |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1706 | pkt->data.firstpass_mb_stats.sz); |
| 1707 | stream->nbytes += pkt->data.raw.sz; |
| 1708 | break; |
| 1709 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1710 | case AOM_CODEC_PSNR_PKT: |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1711 | |
| 1712 | if (global->show_psnr) { |
| 1713 | int i; |
| 1714 | |
| 1715 | stream->psnr_sse_total += pkt->data.psnr.sse[0]; |
| 1716 | stream->psnr_samples_total += pkt->data.psnr.samples[0]; |
| 1717 | for (i = 0; i < 4; i++) { |
Jingning Han | babbd5d | 2013-02-13 09:03:21 -0800 | [diff] [blame] | 1718 | if (!global->quiet) |
| 1719 | fprintf(stderr, "%.3f ", pkt->data.psnr.psnr[i]); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1720 | stream->psnr_totals[i] += pkt->data.psnr.psnr[i]; |
| 1721 | } |
| 1722 | stream->psnr_count++; |
| 1723 | } |
| 1724 | |
| 1725 | break; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1726 | default: break; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1727 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1728 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1729 | } |
| 1730 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1731 | static void show_psnr(struct stream_state *stream, double peak) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1732 | int i; |
| 1733 | double ovpsnr; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1734 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1735 | if (!stream->psnr_count) return; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1736 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1737 | fprintf(stderr, "Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index); |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 1738 | ovpsnr = sse_to_psnr((double)stream->psnr_samples_total, peak, |
Dmitry Kovalev | 2dad0e1 | 2014-02-27 14:00:41 -0800 | [diff] [blame] | 1739 | (double)stream->psnr_sse_total); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1740 | fprintf(stderr, " %.3f", ovpsnr); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1741 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1742 | for (i = 0; i < 4; i++) { |
| 1743 | fprintf(stderr, " %.3f", stream->psnr_totals[i] / stream->psnr_count); |
| 1744 | } |
| 1745 | fprintf(stderr, "\n"); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1746 | } |
| 1747 | |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1748 | static float usec_to_fps(uint64_t usec, unsigned int frames) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1749 | return (float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1750 | } |
| 1751 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1752 | static void test_decode(struct stream_state *stream, |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1753 | enum TestDecodeFatality fatal, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1754 | const AvxInterface *codec) { |
| 1755 | aom_image_t enc_img, dec_img; |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1756 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1757 | if (stream->mismatch_seen) return; |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1758 | |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1759 | /* Get the internal reference frame */ |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 1760 | if (strcmp(codec->name, "vp8") == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1761 | struct aom_ref_frame ref_enc, ref_dec; |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 1762 | const unsigned int frame_width = (stream->config.cfg.g_w + 15) & ~15; |
| 1763 | const unsigned int frame_height = (stream->config.cfg.g_h + 15) & ~15; |
| 1764 | aom_img_alloc(&ref_enc.img, AOM_IMG_FMT_I420, frame_width, frame_height, 1); |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1765 | enc_img = ref_enc.img; |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 1766 | aom_img_alloc(&ref_dec.img, AOM_IMG_FMT_I420, frame_width, frame_height, 1); |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1767 | dec_img = ref_dec.img; |
| 1768 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1769 | ref_enc.frame_type = AOM_LAST_FRAME; |
| 1770 | ref_dec.frame_type = AOM_LAST_FRAME; |
| 1771 | aom_codec_control(&stream->encoder, AOM_COPY_REFERENCE, &ref_enc); |
| 1772 | aom_codec_control(&stream->decoder, AOM_COPY_REFERENCE, &ref_dec); |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1773 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1774 | aom_codec_control(&stream->encoder, AV1_GET_NEW_FRAME_IMAGE, &enc_img); |
| 1775 | aom_codec_control(&stream->decoder, AV1_GET_NEW_FRAME_IMAGE, &dec_img); |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1776 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1777 | #if CONFIG_AOM_HIGHBITDEPTH |
| 1778 | if ((enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) != |
| 1779 | (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH)) { |
| 1780 | if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
| 1781 | aom_image_t enc_hbd_img; |
| 1782 | aom_img_alloc(&enc_hbd_img, enc_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH, |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1783 | enc_img.d_w, enc_img.d_h, 16); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1784 | aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img); |
Zoe Liu | a63147a | 2016-05-19 16:46:10 -0700 | [diff] [blame] | 1785 | enc_img = enc_hbd_img; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1786 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1787 | if (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
| 1788 | aom_image_t dec_hbd_img; |
| 1789 | aom_img_alloc(&dec_hbd_img, dec_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH, |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1790 | dec_img.d_w, dec_img.d_h, 16); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1791 | aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img); |
Zoe Liu | a63147a | 2016-05-19 16:46:10 -0700 | [diff] [blame] | 1792 | dec_img = dec_hbd_img; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1793 | } |
| 1794 | } |
| 1795 | #endif |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1796 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1797 | ctx_exit_on_error(&stream->encoder, "Failed to get encoder reference frame"); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1798 | ctx_exit_on_error(&stream->decoder, "Failed to get decoder reference frame"); |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 1799 | |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1800 | if (!compare_img(&enc_img, &dec_img)) { |
Deb Mukherjee | 23144d2 | 2013-03-12 14:21:08 -0700 | [diff] [blame] | 1801 | int y[4], u[4], v[4]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1802 | #if CONFIG_AOM_HIGHBITDEPTH |
| 1803 | if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1804 | find_mismatch_high(&enc_img, &dec_img, y, u, v); |
| 1805 | } else { |
| 1806 | find_mismatch(&enc_img, &dec_img, y, u, v); |
| 1807 | } |
| 1808 | #else |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1809 | find_mismatch(&enc_img, &dec_img, y, u, v); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1810 | #endif |
Ronald S. Bultje | 97dd734 | 2013-03-04 14:12:49 -0800 | [diff] [blame] | 1811 | stream->decoder.err = 1; |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1812 | warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL, |
Deb Mukherjee | 23144d2 | 2013-03-12 14:21:08 -0700 | [diff] [blame] | 1813 | "Stream %d: Encode/decode mismatch on frame %d at" |
| 1814 | " Y[%d, %d] {%d/%d}," |
| 1815 | " U[%d, %d] {%d/%d}," |
| 1816 | " V[%d, %d] {%d/%d}", |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1817 | stream->index, stream->frames_out, y[0], y[1], y[2], |
| 1818 | y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]); |
Ronald S. Bultje | 195172c | 2012-11-10 16:22:49 -0800 | [diff] [blame] | 1819 | stream->mismatch_seen = stream->frames_out; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1820 | } |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1821 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1822 | aom_img_free(&enc_img); |
| 1823 | aom_img_free(&dec_img); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1824 | } |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 1825 | |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1826 | static void print_time(const char *label, int64_t etl) { |
Tom Finegan | 7a691f1 | 2014-02-10 14:55:25 -0800 | [diff] [blame] | 1827 | int64_t hours; |
| 1828 | int64_t mins; |
| 1829 | int64_t secs; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1830 | |
| 1831 | if (etl >= 0) { |
| 1832 | hours = etl / 3600; |
| 1833 | etl -= hours * 3600; |
| 1834 | mins = etl / 60; |
| 1835 | etl -= mins * 60; |
| 1836 | secs = etl; |
| 1837 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1838 | fprintf(stderr, "[%3s %2" PRId64 ":%02" PRId64 ":%02" PRId64 "] ", label, |
| 1839 | hours, mins, secs); |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1840 | } else { |
| 1841 | fprintf(stderr, "[%3s unknown] ", label); |
| 1842 | } |
| 1843 | } |
| 1844 | |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 1845 | int main(int argc, const char **argv_) { |
| 1846 | int pass; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1847 | aom_image_t raw; |
| 1848 | #if CONFIG_AOM_HIGHBITDEPTH |
| 1849 | aom_image_t raw_shift; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1850 | int allocated_raw_shift = 0; |
| 1851 | int use_16bit_internal = 0; |
| 1852 | int input_shift = 0; |
| 1853 | #endif |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 1854 | int frame_avail, got_data; |
| 1855 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1856 | struct AvxInputContext input; |
| 1857 | struct AvxEncoderConfig global; |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 1858 | struct stream_state *streams = NULL; |
| 1859 | char **argv, **argi; |
| 1860 | uint64_t cx_time = 0; |
| 1861 | int stream_cnt = 0; |
| 1862 | int res = 0; |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 1863 | |
Yaowu Xu | 618e7ef | 2014-07-11 16:27:21 -0700 | [diff] [blame] | 1864 | memset(&input, 0, sizeof(input)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1865 | exec_name = argv_[0]; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1866 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1867 | if (argc < 3) usage_exit(); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1868 | |
| 1869 | /* Setup default input stream settings */ |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 1870 | input.framerate.numerator = 30; |
| 1871 | input.framerate.denominator = 1; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 1872 | input.only_i420 = 1; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1873 | input.bit_depth = 0; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1874 | |
| 1875 | /* First parse the global configuration values, because we want to apply |
| 1876 | * other parameters on top of the default configuration provided by the |
| 1877 | * codec. |
| 1878 | */ |
| 1879 | argv = argv_dup(argc - 1, argv_ + 1); |
| 1880 | parse_global_config(&global, argv); |
| 1881 | |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 1882 | switch (global.color_type) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1883 | case I420: input.fmt = AOM_IMG_FMT_I420; break; |
| 1884 | case I422: input.fmt = AOM_IMG_FMT_I422; break; |
| 1885 | case I444: input.fmt = AOM_IMG_FMT_I444; break; |
| 1886 | case I440: input.fmt = AOM_IMG_FMT_I440; break; |
| 1887 | case YV12: input.fmt = AOM_IMG_FMT_YV12; break; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 1888 | } |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 1889 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1890 | { |
| 1891 | /* Now parse each stream's parameters. Using a local scope here |
| 1892 | * due to the use of 'stream' as loop variable in FOREACH_STREAM |
| 1893 | * loops |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 1894 | */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1895 | struct stream_state *stream = NULL; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1896 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1897 | do { |
| 1898 | stream = new_stream(&global, stream); |
| 1899 | stream_cnt++; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1900 | if (!streams) streams = stream; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1901 | } while (parse_stream_params(&global, stream, argv)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1902 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1903 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1904 | /* Check for unrecognized options */ |
| 1905 | for (argi = argv; *argi; argi++) |
| 1906 | if (argi[0][0] == '-' && argi[0][1]) |
| 1907 | die("Error: Unrecognized option %s\n", *argi); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1908 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1909 | FOREACH_STREAM(check_encoder_config(global.disable_warning_prompt, &global, |
| 1910 | &stream->config.cfg);); |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 1911 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1912 | /* Handle non-option arguments */ |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 1913 | input.filename = argv[0]; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1914 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1915 | if (!input.filename) usage_exit(); |
John Koleszar | 5329189 | 2010-10-22 14:48:21 -0400 | [diff] [blame] | 1916 | |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 1917 | /* Decide if other chroma subsamplings than 4:2:0 are supported */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1918 | if (global.codec->fourcc == AV1_FOURCC) input.only_i420 = 0; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 1919 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1920 | for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) { |
John Koleszar | 2bf563c | 2013-03-11 15:03:00 -0700 | [diff] [blame] | 1921 | int frames_in = 0, seen_frames = 0; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1922 | int64_t estimated_time_left = -1; |
| 1923 | int64_t average_rate = -1; |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 1924 | int64_t lagged_count = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1925 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1926 | open_input_file(&input); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1927 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1928 | /* If the input file doesn't specify its w/h (raw files), try to get |
| 1929 | * the data from the first stream's configuration. |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1930 | */ |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 1931 | if (!input.width || !input.height) { |
| 1932 | FOREACH_STREAM({ |
| 1933 | if (stream->config.cfg.g_w && stream->config.cfg.g_h) { |
| 1934 | input.width = stream->config.cfg.g_w; |
| 1935 | input.height = stream->config.cfg.g_h; |
| 1936 | break; |
| 1937 | } |
| 1938 | }); |
| 1939 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 1940 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1941 | /* Update stream configurations from the input file's parameters */ |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 1942 | if (!input.width || !input.height) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1943 | fatal( |
| 1944 | "Specify stream dimensions with --width (-w) " |
| 1945 | " and --height (-h)"); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1946 | |
| 1947 | /* If input file does not specify bit-depth but input-bit-depth parameter |
| 1948 | * exists, assume that to be the input bit-depth. However, if the |
| 1949 | * input-bit-depth paramter does not exist, assume the input bit-depth |
| 1950 | * to be the same as the codec bit-depth. |
| 1951 | */ |
| 1952 | if (!input.bit_depth) { |
| 1953 | FOREACH_STREAM({ |
| 1954 | if (stream->config.cfg.g_input_bit_depth) |
| 1955 | input.bit_depth = stream->config.cfg.g_input_bit_depth; |
| 1956 | else |
| 1957 | input.bit_depth = stream->config.cfg.g_input_bit_depth = |
| 1958 | (int)stream->config.cfg.g_bit_depth; |
| 1959 | }); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1960 | if (input.bit_depth > 8) input.fmt |= AOM_IMG_FMT_HIGHBITDEPTH; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1961 | } else { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1962 | FOREACH_STREAM( |
| 1963 | { stream->config.cfg.g_input_bit_depth = input.bit_depth; }); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 1966 | FOREACH_STREAM(set_stream_dimensions(stream, input.width, input.height)); |
Alex Converse | d66bd22 | 2014-02-21 10:52:09 -0800 | [diff] [blame] | 1967 | FOREACH_STREAM(validate_stream_config(stream, &global)); |
John Koleszar | 77e6b45 | 2010-11-03 13:58:40 -0400 | [diff] [blame] | 1968 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1969 | /* Ensure that --passes and --pass are consistent. If --pass is set and |
| 1970 | * --passes=2, ensure --fpf was set. |
| 1971 | */ |
| 1972 | if (global.pass && global.passes == 2) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1973 | FOREACH_STREAM({ |
| 1974 | if (!stream->config.stats_fn) |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 1975 | die("Stream %d: Must specify --fpf when --pass=%d" |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1976 | " and --passes=2\n", |
| 1977 | stream->index, global.pass); |
| 1978 | }); |
John Koleszar | 3245d46 | 2010-06-10 17:10:12 -0400 | [diff] [blame] | 1979 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1980 | #if !CONFIG_WEBM_IO |
| 1981 | FOREACH_STREAM({ |
Ronald S. Bultje | 3977507 | 2015-12-16 13:35:43 -0500 | [diff] [blame] | 1982 | if (stream->config.write_webm) { |
| 1983 | stream->config.write_webm = 0; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1984 | warn( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1985 | "aomenc was compiled without WebM container support." |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1986 | "Producing IVF output"); |
Ronald S. Bultje | 3977507 | 2015-12-16 13:35:43 -0500 | [diff] [blame] | 1987 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1988 | }); |
| 1989 | #endif |
| 1990 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1991 | /* Use the frame rate from the file only if none was specified |
| 1992 | * on the command-line. |
| 1993 | */ |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 1994 | if (!global.have_framerate) { |
| 1995 | global.framerate.num = input.framerate.numerator; |
| 1996 | global.framerate.den = input.framerate.denominator; |
Ronald S. Bultje | 9134e9f | 2016-01-18 14:03:45 -0500 | [diff] [blame] | 1997 | FOREACH_STREAM(stream->config.cfg.g_timebase.den = global.framerate.num; |
| 1998 | stream->config.cfg.g_timebase.num = global.framerate.den); |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 1999 | } |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 2000 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2001 | /* Show configuration */ |
| 2002 | if (global.verbose && pass == 0) |
| 2003 | FOREACH_STREAM(show_stream_config(stream, &global, &input)); |
| 2004 | |
| 2005 | if (pass == (global.pass ? global.pass - 1 : 0)) { |
| 2006 | if (input.file_type == FILE_TYPE_Y4M) |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2007 | /*The Y4M reader does its own allocation. |
| 2008 | Just initialize this here to avoid problems if we never read any |
| 2009 | frames.*/ |
| 2010 | memset(&raw, 0, sizeof(raw)); |
| 2011 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2012 | aom_img_alloc(&raw, input.fmt, input.width, input.height, 32); |
John Koleszar | 05239f0 | 2011-06-29 09:53:12 -0400 | [diff] [blame] | 2013 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2014 | FOREACH_STREAM(stream->rate_hist = init_rate_histogram( |
| 2015 | &stream->config.cfg, &global.framerate)); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2016 | } |
| 2017 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2018 | FOREACH_STREAM(setup_pass(stream, &global, pass)); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2019 | FOREACH_STREAM( |
| 2020 | open_output_file(stream, &global, &input.pixel_aspect_ratio)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2021 | FOREACH_STREAM(initialize_encoder(stream, &global)); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2022 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2023 | #if CONFIG_AOM_HIGHBITDEPTH |
| 2024 | if (strcmp(global.codec->name, "av1") == 0 || |
| 2025 | strcmp(global.codec->name, "av1") == 0) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2026 | // Check to see if at least one stream uses 16 bit internal. |
| 2027 | // Currently assume that the bit_depths for all streams using |
| 2028 | // highbitdepth are the same. |
| 2029 | FOREACH_STREAM({ |
| 2030 | if (stream->config.use_16bit_internal) { |
| 2031 | use_16bit_internal = 1; |
| 2032 | } |
| 2033 | if (stream->config.cfg.g_profile == 0) { |
| 2034 | input_shift = 0; |
| 2035 | } else { |
| 2036 | input_shift = (int)stream->config.cfg.g_bit_depth - |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2037 | stream->config.cfg.g_input_bit_depth; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2038 | } |
| 2039 | }); |
| 2040 | } |
| 2041 | #endif |
| 2042 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2043 | frame_avail = 1; |
| 2044 | got_data = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2045 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2046 | while (frame_avail || got_data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2047 | struct aom_usec_timer timer; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2048 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2049 | if (!global.limit || frames_in < global.limit) { |
| 2050 | frame_avail = read_frame(&input, &raw); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2051 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2052 | if (frame_avail) frames_in++; |
| 2053 | seen_frames = |
| 2054 | frames_in > global.skip_frames ? frames_in - global.skip_frames : 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2055 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2056 | if (!global.quiet) { |
John Koleszar | 2bf563c | 2013-03-11 15:03:00 -0700 | [diff] [blame] | 2057 | float fps = usec_to_fps(cx_time, seen_frames); |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2058 | fprintf(stderr, "\rPass %d/%d ", pass + 1, global.passes); |
| 2059 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2060 | if (stream_cnt == 1) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2061 | fprintf(stderr, "frame %4d/%-4d %7" PRId64 "B ", frames_in, |
| 2062 | streams->frames_out, (int64_t)streams->nbytes); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2063 | else |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2064 | fprintf(stderr, "frame %4d ", frames_in); |
| 2065 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2066 | fprintf(stderr, "%7" PRId64 " %s %.2f %s ", |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2067 | cx_time > 9999999 ? cx_time / 1000 : cx_time, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2068 | cx_time > 9999999 ? "ms" : "us", fps >= 1.0 ? fps : fps * 60, |
Yaowu Xu | 014acfa | 2013-09-17 16:31:46 -0700 | [diff] [blame] | 2069 | fps >= 1.0 ? "fps" : "fpm"); |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2070 | print_time("ETA", estimated_time_left); |
John Koleszar | 3245d46 | 2010-06-10 17:10:12 -0400 | [diff] [blame] | 2071 | } |
| 2072 | |
hui su | 251e151 | 2016-10-03 15:48:43 -0700 | [diff] [blame] | 2073 | } else { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2074 | frame_avail = 0; |
hui su | 251e151 | 2016-10-03 15:48:43 -0700 | [diff] [blame] | 2075 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2076 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2077 | if (frames_in > global.skip_frames) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2078 | #if CONFIG_AOM_HIGHBITDEPTH |
| 2079 | aom_image_t *frame_to_encode; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2080 | if (input_shift || (use_16bit_internal && input.bit_depth == 8)) { |
| 2081 | assert(use_16bit_internal); |
| 2082 | // Input bit depth and stream bit depth do not match, so up |
| 2083 | // shift frame to stream bit depth |
| 2084 | if (!allocated_raw_shift) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2085 | aom_img_alloc(&raw_shift, raw.fmt | AOM_IMG_FMT_HIGHBITDEPTH, |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2086 | input.width, input.height, 32); |
| 2087 | allocated_raw_shift = 1; |
| 2088 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2089 | aom_img_upshift(&raw_shift, &raw, input_shift); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2090 | frame_to_encode = &raw_shift; |
| 2091 | } else { |
| 2092 | frame_to_encode = &raw; |
| 2093 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2094 | aom_usec_timer_start(&timer); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2095 | if (use_16bit_internal) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2096 | assert(frame_to_encode->fmt & AOM_IMG_FMT_HIGHBITDEPTH); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2097 | FOREACH_STREAM({ |
| 2098 | if (stream->config.use_16bit_internal) |
| 2099 | encode_frame(stream, &global, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2100 | frame_avail ? frame_to_encode : NULL, frames_in); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2101 | else |
| 2102 | assert(0); |
| 2103 | }); |
| 2104 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2105 | assert((frame_to_encode->fmt & AOM_IMG_FMT_HIGHBITDEPTH) == 0); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2106 | FOREACH_STREAM(encode_frame(stream, &global, |
| 2107 | frame_avail ? frame_to_encode : NULL, |
| 2108 | frames_in)); |
| 2109 | } |
| 2110 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2111 | aom_usec_timer_start(&timer); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2112 | FOREACH_STREAM(encode_frame(stream, &global, frame_avail ? &raw : NULL, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2113 | frames_in)); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2114 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2115 | aom_usec_timer_mark(&timer); |
| 2116 | cx_time += aom_usec_timer_elapsed(&timer); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2117 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2118 | FOREACH_STREAM(update_quantizer_histogram(stream)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2119 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2120 | got_data = 0; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2121 | FOREACH_STREAM(get_cx_data(stream, &global, &got_data)); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2122 | |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 2123 | if (!got_data && input.length && streams != NULL && |
| 2124 | !streams->frames_out) { |
John Koleszar | 2bf563c | 2013-03-11 15:03:00 -0700 | [diff] [blame] | 2125 | lagged_count = global.limit ? seen_frames : ftello(input.file); |
John Koleszar | ebf8b9f | 2013-02-27 11:14:23 -0800 | [diff] [blame] | 2126 | } else if (input.length) { |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2127 | int64_t remaining; |
| 2128 | int64_t rate; |
| 2129 | |
| 2130 | if (global.limit) { |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 2131 | const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2132 | |
| 2133 | rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2134 | remaining = 1000 * (global.limit - global.skip_frames - |
| 2135 | seen_frames + lagged_count); |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2136 | } else { |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 2137 | const int64_t input_pos = ftello(input.file); |
| 2138 | const int64_t input_pos_lagged = input_pos - lagged_count; |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 2139 | const int64_t input_limit = input.length; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2140 | |
| 2141 | rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0; |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 2142 | remaining = input_limit - input_pos + lagged_count; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2143 | } |
| 2144 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2145 | average_rate = |
| 2146 | (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2147 | estimated_time_left = average_rate ? remaining / average_rate : -1; |
| 2148 | } |
| 2149 | |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 2150 | if (got_data && global.test_decode != TEST_DECODE_OFF) |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 2151 | FOREACH_STREAM(test_decode(stream, global.test_decode, global.codec)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2152 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2153 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2154 | fflush(stdout); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2155 | if (!global.quiet) fprintf(stderr, "\033[K"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2156 | } |
| 2157 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2158 | if (stream_cnt > 1) fprintf(stderr, "\n"); |
John Koleszar | 3fde996 | 2011-06-20 17:09:29 -0400 | [diff] [blame] | 2159 | |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2160 | if (!global.quiet) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2161 | FOREACH_STREAM(fprintf( |
| 2162 | stderr, "\rPass %d/%d frame %4d/%-4d %7" PRId64 "B %7" PRId64 |
| 2163 | "b/f %7" PRId64 "b/s" |
| 2164 | " %7" PRId64 " %s (%.2f fps)\033[K\n", |
| 2165 | pass + 1, global.passes, frames_in, stream->frames_out, |
| 2166 | (int64_t)stream->nbytes, |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2167 | seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2168 | seen_frames |
| 2169 | ? (int64_t)stream->nbytes * 8 * (int64_t)global.framerate.num / |
| 2170 | global.framerate.den / seen_frames |
| 2171 | : 0, |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2172 | stream->cx_time > 9999999 ? stream->cx_time / 1000 : stream->cx_time, |
| 2173 | stream->cx_time > 9999999 ? "ms" : "us", |
| 2174 | usec_to_fps(stream->cx_time, seen_frames))); |
| 2175 | } |
John Koleszar | c96f8e2 | 2011-06-21 16:42:33 -0400 | [diff] [blame] | 2176 | |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2177 | if (global.show_psnr) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2178 | if (global.codec->fourcc == AV1_FOURCC) { |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2179 | FOREACH_STREAM( |
| 2180 | show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1)); |
| 2181 | } else { |
| 2182 | FOREACH_STREAM(show_psnr(stream, 255.0)); |
| 2183 | } |
| 2184 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2185 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2186 | FOREACH_STREAM(aom_codec_destroy(&stream->encoder)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2187 | |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 2188 | if (global.test_decode != TEST_DECODE_OFF) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2189 | FOREACH_STREAM(aom_codec_destroy(&stream->decoder)); |
Yaowu Xu | f798f9e | 2012-03-07 12:25:50 -0800 | [diff] [blame] | 2190 | } |
| 2191 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2192 | close_input_file(&input); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2193 | |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 2194 | if (global.test_decode == TEST_DECODE_FATAL) { |
| 2195 | FOREACH_STREAM(res |= stream->mismatch_seen); |
| 2196 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2197 | FOREACH_STREAM(close_output_file(stream, global.codec->fourcc)); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2198 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2199 | FOREACH_STREAM(stats_close(&stream->stats, global.passes - 1)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2200 | |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 2201 | #if CONFIG_FP_MB_STATS |
| 2202 | FOREACH_STREAM(stats_close(&stream->fpmb_stats, global.passes - 1)); |
| 2203 | #endif |
| 2204 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2205 | if (global.pass) break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2208 | if (global.show_q_hist_buckets) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2209 | FOREACH_STREAM( |
| 2210 | show_q_histogram(stream->counts, global.show_q_hist_buckets)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2211 | |
| 2212 | if (global.show_rate_hist_buckets) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2213 | FOREACH_STREAM(show_rate_histogram(stream->rate_hist, &stream->config.cfg, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2214 | global.show_rate_hist_buckets)); |
Dmitry Kovalev | f11da2b | 2014-01-29 12:28:29 -0800 | [diff] [blame] | 2215 | FOREACH_STREAM(destroy_rate_histogram(stream->rate_hist)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2216 | |
Ronald S. Bultje | 3121497 | 2012-10-11 10:13:48 -0700 | [diff] [blame] | 2217 | #if CONFIG_INTERNAL_STATS |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2218 | /* TODO(jkoleszar): This doesn't belong in this executable. Do it for now, |
| 2219 | * to match some existing utilities. |
| 2220 | */ |
Yaowu Xu | 47e784e | 2013-10-16 16:29:28 -0700 | [diff] [blame] | 2221 | if (!(global.pass == 1 && global.passes == 2)) |
| 2222 | FOREACH_STREAM({ |
| 2223 | FILE *f = fopen("opsnr.stt", "a"); |
| 2224 | if (stream->mismatch_seen) { |
| 2225 | fprintf(f, "First mismatch occurred in frame %d\n", |
| 2226 | stream->mismatch_seen); |
| 2227 | } else { |
| 2228 | fprintf(f, "No mismatch detected in recon buffers\n"); |
| 2229 | } |
| 2230 | fclose(f); |
| 2231 | }); |
Ronald S. Bultje | 3121497 | 2012-10-11 10:13:48 -0700 | [diff] [blame] | 2232 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2233 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2234 | #if CONFIG_AOM_HIGHBITDEPTH |
| 2235 | if (allocated_raw_shift) aom_img_free(&raw_shift); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2236 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2237 | aom_img_free(&raw); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2238 | free(argv); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2239 | free(streams); |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 2240 | return res ? EXIT_FAILURE : EXIT_SUCCESS; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2241 | } |