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