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