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