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