John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
James Zern | b7c05bd | 2024-06-11 19:15:10 -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 | |
Tom Finegan | c65bf06 | 2018-05-21 15:50:57 -0700 | [diff] [blame] | 12 | #include "apps/aomenc.h" |
| 13 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 14 | #include "config/aom_config.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 15 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 16 | #include <assert.h> |
| 17 | #include <limits.h> |
Tom Finegan | 78cb2e6 | 2013-11-07 21:28:45 -0800 | [diff] [blame] | 18 | #include <math.h> |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 19 | #include <stdarg.h> |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 22 | #include <string.h> |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 23 | |
Tom Finegan | ba02c24 | 2017-05-16 15:01:54 -0700 | [diff] [blame] | 24 | #if CONFIG_AV1_DECODER |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 25 | #include "aom/aom_decoder.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 26 | #include "aom/aomdx.h" |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 27 | #endif |
| 28 | |
Tom Finegan | 7790213 | 2018-05-21 10:19:15 -0700 | [diff] [blame] | 29 | #include "aom/aom_encoder.h" |
Thomas Daede | c0dca3c | 2016-02-25 17:23:17 -0800 | [diff] [blame] | 30 | #include "aom/aom_integer.h" |
Tom Finegan | 7790213 | 2018-05-21 10:19:15 -0700 | [diff] [blame] | 31 | #include "aom/aomcx.h" |
hui su | efdad1f | 2017-05-16 18:01:25 -0700 | [diff] [blame] | 32 | #include "aom_dsp/aom_dsp_common.h" |
Thomas Daede | c0dca3c | 2016-02-25 17:23:17 -0800 | [diff] [blame] | 33 | #include "aom_ports/aom_timer.h" |
| 34 | #include "aom_ports/mem_ops.h" |
Tom Finegan | 7790213 | 2018-05-21 10:19:15 -0700 | [diff] [blame] | 35 | #include "common/args.h" |
| 36 | #include "common/ivfenc.h" |
| 37 | #include "common/tools_common.h" |
| 38 | #include "common/warnings.h" |
| 39 | |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 40 | #if CONFIG_WEBM_IO |
Tom Finegan | 7790213 | 2018-05-21 10:19:15 -0700 | [diff] [blame] | 41 | #include "common/webmenc.h" |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 42 | #endif |
Tom Finegan | 7790213 | 2018-05-21 10:19:15 -0700 | [diff] [blame] | 43 | |
| 44 | #include "common/y4minput.h" |
| 45 | #include "examples/encoder_util.h" |
| 46 | #include "stats/aomstats.h" |
| 47 | #include "stats/rate_hist.h" |
| 48 | |
| 49 | #if CONFIG_LIBYUV |
| 50 | #include "third_party/libyuv/include/libyuv/scale.h" |
| 51 | #endif |
Tom Finegan | 03848f5 | 2013-11-05 10:02:18 -0800 | [diff] [blame] | 52 | |
John Koleszar | 6291dd4 | 2012-06-19 21:05:36 -0700 | [diff] [blame] | 53 | /* Swallow warnings about unused results of fread/fwrite */ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 54 | 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] | 55 | return fread(ptr, size, nmemb, stream); |
John Koleszar | 6291dd4 | 2012-06-19 21:05:36 -0700 | [diff] [blame] | 56 | } |
| 57 | #define fread wrap_fread |
| 58 | |
| 59 | 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] | 60 | FILE *stream) { |
| 61 | return fwrite(ptr, size, nmemb, stream); |
John Koleszar | 6291dd4 | 2012-06-19 21:05:36 -0700 | [diff] [blame] | 62 | } |
| 63 | #define fwrite wrap_fwrite |
| 64 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 65 | static const char *exec_name; |
| 66 | |
James Zern | 20660e5 | 2021-11-02 17:19:10 -0700 | [diff] [blame] | 67 | static AOM_TOOLS_FORMAT_PRINTF(3, 0) void warn_or_exit_on_errorv( |
| 68 | aom_codec_ctx_t *ctx, int fatal, const char *s, va_list ap) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 69 | if (ctx->err) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | const char *detail = aom_codec_error_detail(ctx); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 71 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 72 | vfprintf(stderr, s, ap); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | fprintf(stderr, ": %s\n", aom_codec_error(ctx)); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 74 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 75 | if (detail) fprintf(stderr, " %s\n", detail); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 76 | |
Mudassir Galaganath | 6062c09 | 2023-07-18 14:01:21 +0530 | [diff] [blame] | 77 | if (fatal) { |
| 78 | aom_codec_destroy(ctx); |
| 79 | exit(EXIT_FAILURE); |
| 80 | } |
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 | |
James Zern | 20660e5 | 2021-11-02 17:19:10 -0700 | [diff] [blame] | 84 | static AOM_TOOLS_FORMAT_PRINTF(2, |
| 85 | 3) void ctx_exit_on_error(aom_codec_ctx_t *ctx, |
| 86 | const char *s, ...) { |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 87 | va_list ap; |
| 88 | |
| 89 | va_start(ap, s); |
| 90 | warn_or_exit_on_errorv(ctx, 1, s, ap); |
| 91 | va_end(ap); |
| 92 | } |
| 93 | |
James Zern | 20660e5 | 2021-11-02 17:19:10 -0700 | [diff] [blame] | 94 | static AOM_TOOLS_FORMAT_PRINTF(3, 4) void warn_or_exit_on_error( |
| 95 | aom_codec_ctx_t *ctx, int fatal, const char *s, ...) { |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 96 | va_list ap; |
| 97 | |
| 98 | va_start(ap, s); |
| 99 | warn_or_exit_on_errorv(ctx, fatal, s, ap); |
| 100 | va_end(ap); |
| 101 | } |
| 102 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 103 | static int read_frame(struct AvxInputContext *input_ctx, aom_image_t *img) { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 104 | FILE *f = input_ctx->file; |
| 105 | y4m_input *y4m = &input_ctx->y4m; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 106 | int shortread = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 107 | |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 108 | if (input_ctx->file_type == FILE_TYPE_Y4M) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 109 | if (y4m_input_fetch_frame(y4m, f, img) < 1) return 0; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 110 | } else { |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 111 | shortread = read_yuv_frame(input_ctx, img); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | return !shortread; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 115 | } |
| 116 | |
James Zern | 5c337fd | 2015-05-09 10:42:58 -0700 | [diff] [blame] | 117 | static int file_is_y4m(const char detect[4]) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 118 | if (memcmp(detect, "YUV4", 4) == 0) { |
| 119 | return 1; |
| 120 | } |
| 121 | return 0; |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 122 | } |
| 123 | |
James Zern | 5c337fd | 2015-05-09 10:42:58 -0700 | [diff] [blame] | 124 | static int fourcc_is_ivf(const char detect[4]) { |
Alex Converse | 64b89f1 | 2014-01-06 16:29:09 -0800 | [diff] [blame] | 125 | if (memcmp(detect, "DKIF", 4) == 0) { |
| 126 | return 1; |
| 127 | } |
| 128 | return 0; |
| 129 | } |
John Koleszar | dc66630 | 2010-10-20 12:05:48 -0400 | [diff] [blame] | 130 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 131 | static const int av1_arg_ctrl_map[] = { AOME_SET_CPUUSED, |
| 132 | AOME_SET_ENABLEAUTOALTREF, |
| 133 | AOME_SET_SHARPNESS, |
| 134 | AOME_SET_STATIC_THRESHOLD, |
Ravi Chaudhary | 0ec03a4 | 2018-08-17 18:53:28 +0530 | [diff] [blame] | 135 | AV1E_SET_ROW_MT, |
Remya Prakasan | 93c1c37 | 2021-10-25 14:36:07 +0530 | [diff] [blame] | 136 | AV1E_SET_FP_MT, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 137 | AV1E_SET_TILE_COLUMNS, |
| 138 | AV1E_SET_TILE_ROWS, |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 139 | AV1E_SET_ENABLE_TPL_MODEL, |
Cheng Chen | 0fcf6f8 | 2019-10-11 11:41:19 -0700 | [diff] [blame] | 140 | AV1E_SET_ENABLE_KEYFRAME_FILTERING, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 141 | AOME_SET_ARNR_MAXFRAMES, |
| 142 | AOME_SET_ARNR_STRENGTH, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 143 | AOME_SET_TUNING, |
| 144 | AOME_SET_CQ_LEVEL, |
| 145 | AOME_SET_MAX_INTRA_BITRATE_PCT, |
| 146 | AV1E_SET_MAX_INTER_BITRATE_PCT, |
| 147 | AV1E_SET_GF_CBR_BOOST_PCT, |
| 148 | AV1E_SET_LOSSLESS, |
Steinar Midtskogen | e44c622 | 2017-11-09 13:22:09 +0100 | [diff] [blame] | 149 | AV1E_SET_ENABLE_CDEF, |
Sebastien Alaiwan | 1ed2024 | 2018-02-20 14:47:18 +0100 | [diff] [blame] | 150 | AV1E_SET_ENABLE_RESTORATION, |
Debargha Mukherjee | 9d9cf19 | 2018-12-17 11:24:21 -0800 | [diff] [blame] | 151 | AV1E_SET_ENABLE_RECT_PARTITIONS, |
Ryan Lei | 9543c70 | 2019-03-11 11:06:14 -0700 | [diff] [blame] | 152 | AV1E_SET_ENABLE_AB_PARTITIONS, |
| 153 | AV1E_SET_ENABLE_1TO4_PARTITIONS, |
| 154 | AV1E_SET_MIN_PARTITION_SIZE, |
| 155 | AV1E_SET_MAX_PARTITION_SIZE, |
Debargha Mukherjee | 4ad0113 | 2018-12-10 17:37:47 -0800 | [diff] [blame] | 156 | AV1E_SET_ENABLE_DUAL_FILTER, |
Yue Chen | c5806c2 | 2019-07-19 17:32:57 -0700 | [diff] [blame] | 157 | AV1E_SET_ENABLE_CHROMA_DELTAQ, |
Debargha Mukherjee | 03c43ba | 2018-12-14 13:08:08 -0800 | [diff] [blame] | 158 | AV1E_SET_ENABLE_INTRA_EDGE_FILTER, |
Debargha Mukherjee | 4ad0113 | 2018-12-10 17:37:47 -0800 | [diff] [blame] | 159 | AV1E_SET_ENABLE_ORDER_HINT, |
Debargha Mukherjee | 8c917b0 | 2018-12-17 13:45:50 -0800 | [diff] [blame] | 160 | AV1E_SET_ENABLE_TX64, |
Ryan Lei | 9543c70 | 2019-03-11 11:06:14 -0700 | [diff] [blame] | 161 | AV1E_SET_ENABLE_FLIP_IDTX, |
Josh Verdejo | b7897b4 | 2020-08-13 18:17:30 +0000 | [diff] [blame] | 162 | AV1E_SET_ENABLE_RECT_TX, |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 163 | AV1E_SET_ENABLE_DIST_WTD_COMP, |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame] | 164 | AV1E_SET_ENABLE_MASKED_COMP, |
Ryan Lei | 9543c70 | 2019-03-11 11:06:14 -0700 | [diff] [blame] | 165 | AV1E_SET_ENABLE_ONESIDED_COMP, |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame] | 166 | AV1E_SET_ENABLE_INTERINTRA_COMP, |
Yue Chen | 8cbee6c | 2018-12-14 11:54:39 -0800 | [diff] [blame] | 167 | AV1E_SET_ENABLE_SMOOTH_INTERINTRA, |
Debargha Mukherjee | 78e6b2c | 2018-12-11 07:50:57 -0800 | [diff] [blame] | 168 | AV1E_SET_ENABLE_DIFF_WTD_COMP, |
| 169 | AV1E_SET_ENABLE_INTERINTER_WEDGE, |
| 170 | AV1E_SET_ENABLE_INTERINTRA_WEDGE, |
Debargha Mukherjee | d2e53ca | 2018-12-10 11:34:59 -0800 | [diff] [blame] | 171 | AV1E_SET_ENABLE_GLOBAL_MOTION, |
| 172 | AV1E_SET_ENABLE_WARPED_MOTION, |
Yue Chen | 8f9ca58 | 2018-12-12 15:11:47 -0800 | [diff] [blame] | 173 | AV1E_SET_ENABLE_FILTER_INTRA, |
Debargha Mukherjee | 078ae86 | 2018-12-18 11:05:43 -0800 | [diff] [blame] | 174 | AV1E_SET_ENABLE_SMOOTH_INTRA, |
| 175 | AV1E_SET_ENABLE_PAETH_INTRA, |
Debargha Mukherjee | 8e25678 | 2018-12-18 13:44:13 -0800 | [diff] [blame] | 176 | AV1E_SET_ENABLE_CFL_INTRA, |
Fyodor Kyslov | c491c66 | 2021-03-09 11:11:20 -0800 | [diff] [blame] | 177 | AV1E_SET_ENABLE_DIAGONAL_INTRA, |
Yaowu Xu | 2a9ac43 | 2019-08-06 14:21:17 -0700 | [diff] [blame] | 178 | AV1E_SET_FORCE_VIDEO_MODE, |
Yue Chen | 5e12951e | 2018-12-10 10:48:54 -0800 | [diff] [blame] | 179 | AV1E_SET_ENABLE_OBMC, |
Debargha Mukherjee | a2074dd | 2019-09-04 10:03:44 -0700 | [diff] [blame] | 180 | AV1E_SET_ENABLE_OVERLAY, |
Hui Su | a9e3d14 | 2018-12-14 15:21:21 -0800 | [diff] [blame] | 181 | AV1E_SET_ENABLE_PALETTE, |
Hui Su | 440e6d4 | 2018-12-17 11:47:07 -0800 | [diff] [blame] | 182 | AV1E_SET_ENABLE_INTRABC, |
Hui Su | 94b3817 | 2018-12-19 10:40:29 -0800 | [diff] [blame] | 183 | AV1E_SET_ENABLE_ANGLE_DELTA, |
Yue Chen | 4835dc0 | 2018-05-11 15:57:43 -0700 | [diff] [blame] | 184 | AV1E_SET_DISABLE_TRELLIS_QUANT, |
Yaowu Xu | 6c8ec65 | 2016-11-09 13:58:25 -0800 | [diff] [blame] | 185 | AV1E_SET_ENABLE_QM, |
| 186 | AV1E_SET_QM_MIN, |
| 187 | AV1E_SET_QM_MAX, |
Sarah Parker | 0b7e590 | 2018-12-10 13:35:25 -0800 | [diff] [blame] | 188 | AV1E_SET_REDUCED_TX_TYPE_SET, |
Debargha Mukherjee | db45815 | 2019-01-25 11:04:09 -0800 | [diff] [blame] | 189 | AV1E_SET_INTRA_DCT_ONLY, |
| 190 | AV1E_SET_INTER_DCT_ONLY, |
Debargha Mukherjee | 042af92 | 2019-02-07 05:58:26 -0800 | [diff] [blame] | 191 | AV1E_SET_INTRA_DEFAULT_TX_ONLY, |
Sarah Parker | 740e839 | 2019-01-23 15:47:53 -0800 | [diff] [blame] | 192 | AV1E_SET_QUANT_B_ADAPT, |
Debargha Mukherjee | 03ad12d | 2019-02-07 11:17:59 -0800 | [diff] [blame] | 193 | AV1E_SET_COEFF_COST_UPD_FREQ, |
| 194 | AV1E_SET_MODE_COST_UPD_FREQ, |
Debargha Mukherjee | 8d27341 | 2019-09-11 10:36:50 -0700 | [diff] [blame] | 195 | AV1E_SET_MV_COST_UPD_FREQ, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 196 | AV1E_SET_FRAME_PARALLEL_DECODING, |
Debargha Mukherjee | 921cc4c | 2018-03-24 12:01:12 -0700 | [diff] [blame] | 197 | AV1E_SET_ERROR_RESILIENT_MODE, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | AV1E_SET_AQ_MODE, |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 199 | AV1E_SET_DELTAQ_MODE, |
Sai Deng | a62022d | 2021-10-01 10:27:57 -0700 | [diff] [blame] | 200 | AV1E_SET_DELTAQ_STRENGTH, |
Debargha Mukherjee | 4fef7a5 | 2019-04-04 01:02:06 -0700 | [diff] [blame] | 201 | AV1E_SET_DELTALF_MODE, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 202 | AV1E_SET_FRAME_PERIODIC_BOOST, |
| 203 | AV1E_SET_NOISE_SENSITIVITY, |
| 204 | AV1E_SET_TUNE_CONTENT, |
Hui Su | 1cb1c00 | 2018-02-05 18:21:20 -0800 | [diff] [blame] | 205 | AV1E_SET_CDF_UPDATE_MODE, |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 206 | AV1E_SET_COLOR_PRIMARIES, |
| 207 | AV1E_SET_TRANSFER_CHARACTERISTICS, |
| 208 | AV1E_SET_MATRIX_COEFFICIENTS, |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 209 | AV1E_SET_CHROMA_SAMPLE_POSITION, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 210 | AV1E_SET_MIN_GF_INTERVAL, |
| 211 | AV1E_SET_MAX_GF_INTERVAL, |
Urvang Joshi | b44f48f | 2020-01-27 11:09:48 -0800 | [diff] [blame] | 212 | AV1E_SET_GF_MIN_PYRAMID_HEIGHT, |
Urvang Joshi | f4e775c | 2018-12-14 11:33:17 -0800 | [diff] [blame] | 213 | AV1E_SET_GF_MAX_PYRAMID_HEIGHT, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 214 | AV1E_SET_SUPERBLOCK_SIZE, |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 215 | AV1E_SET_NUM_TG, |
| 216 | AV1E_SET_MTU, |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 217 | AV1E_SET_TIMING_INFO_TYPE, |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 218 | AV1E_SET_FILM_GRAIN_TEST_VECTOR, |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 219 | AV1E_SET_FILM_GRAIN_TABLE, |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 220 | #if CONFIG_DENOISE |
| 221 | AV1E_SET_DENOISE_NOISE_LEVEL, |
| 222 | AV1E_SET_DENOISE_BLOCK_SIZE, |
n9Mtq4 | 08eb1d4 | 2021-02-18 00:13:10 -0500 | [diff] [blame] | 223 | AV1E_SET_ENABLE_DNL_DENOISING, |
Urvang Joshi | 9ad9f08 | 2019-01-22 12:31:33 -0800 | [diff] [blame] | 224 | #endif // CONFIG_DENOISE |
| 225 | AV1E_SET_MAX_REFERENCE_FRAMES, |
Urvang Joshi | 1a9e27e | 2019-02-19 11:17:23 -0800 | [diff] [blame] | 226 | AV1E_SET_REDUCED_REFERENCE_SET, |
Debargha Mukherjee | 0d8368a | 2018-03-25 12:23:02 -0700 | [diff] [blame] | 227 | AV1E_SET_ENABLE_REF_FRAME_MVS, |
Hui Su | fad3856 | 2019-03-04 14:12:23 -0800 | [diff] [blame] | 228 | AV1E_SET_TARGET_SEQ_LEVEL_IDX, |
Hui Su | d909c2c | 2019-03-08 11:51:14 -0800 | [diff] [blame] | 229 | AV1E_SET_TIER_MASK, |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 230 | AV1E_SET_MIN_CR, |
Hamsalekha S | 3de77b4 | 2020-04-23 17:19:49 +0530 | [diff] [blame] | 231 | AV1E_SET_VBR_CORPUS_COMPLEXITY_LAP, |
Bohan Li | 368b918 | 2021-02-04 12:04:43 -0800 | [diff] [blame] | 232 | AV1E_SET_CHROMA_SUBSAMPLING_X, |
| 233 | AV1E_SET_CHROMA_SUBSAMPLING_Y, |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 234 | #if CONFIG_TUNE_VMAF |
| 235 | AV1E_SET_VMAF_MODEL_PATH, |
| 236 | #endif |
chiyotsai | cb037d7 | 2021-04-15 17:17:08 -0700 | [diff] [blame] | 237 | AV1E_SET_DV_COST_UPD_FREQ, |
Cheng Chen | 9164dee | 2021-04-19 23:11:38 -0700 | [diff] [blame] | 238 | AV1E_SET_PARTITION_INFO_PATH, |
Maryla | 4bb5281 | 2021-06-18 08:36:58 +0200 | [diff] [blame] | 239 | AV1E_SET_ENABLE_DIRECTIONAL_INTRA, |
Maryla | 36c2b99 | 2021-06-21 11:48:34 +0200 | [diff] [blame] | 240 | AV1E_SET_ENABLE_TX_SIZE_SEARCH, |
Fyodor Kyslov | 2372d3e | 2021-11-01 16:11:13 -0700 | [diff] [blame] | 241 | AV1E_SET_LOOPFILTER_CONTROL, |
Cheng Chen | f15d9ea | 2021-11-15 16:52:13 -0800 | [diff] [blame] | 242 | AV1E_SET_AUTO_INTRA_TOOLS_OFF, |
Cheng Chen | 567038a | 2022-12-22 16:45:02 -0800 | [diff] [blame] | 243 | AV1E_ENABLE_RATE_GUIDE_DELTAQ, |
| 244 | AV1E_SET_RATE_DISTRIBUTION_INFO, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 245 | 0 }; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 246 | |
| 247 | const arg_def_t *main_args[] = { &g_av1_codec_arg_defs.help, |
| 248 | &g_av1_codec_arg_defs.use_cfg, |
| 249 | &g_av1_codec_arg_defs.debugmode, |
| 250 | &g_av1_codec_arg_defs.outputfile, |
| 251 | &g_av1_codec_arg_defs.codecarg, |
| 252 | &g_av1_codec_arg_defs.passes, |
| 253 | &g_av1_codec_arg_defs.pass_arg, |
| 254 | &g_av1_codec_arg_defs.fpf_name, |
| 255 | &g_av1_codec_arg_defs.limit, |
| 256 | &g_av1_codec_arg_defs.skip, |
| 257 | &g_av1_codec_arg_defs.good_dl, |
| 258 | &g_av1_codec_arg_defs.rt_dl, |
Jingning Han | c5d38e0 | 2021-02-11 14:40:27 -0800 | [diff] [blame] | 259 | &g_av1_codec_arg_defs.ai_dl, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 260 | &g_av1_codec_arg_defs.quietarg, |
| 261 | &g_av1_codec_arg_defs.verbosearg, |
| 262 | &g_av1_codec_arg_defs.psnrarg, |
| 263 | &g_av1_codec_arg_defs.use_webm, |
| 264 | &g_av1_codec_arg_defs.use_ivf, |
| 265 | &g_av1_codec_arg_defs.use_obu, |
| 266 | &g_av1_codec_arg_defs.q_hist_n, |
| 267 | &g_av1_codec_arg_defs.rate_hist_n, |
| 268 | &g_av1_codec_arg_defs.disable_warnings, |
| 269 | &g_av1_codec_arg_defs.disable_warning_prompt, |
| 270 | &g_av1_codec_arg_defs.recontest, |
| 271 | NULL }; |
| 272 | |
| 273 | const arg_def_t *global_args[] = { |
Jerome Jiang | d116cab | 2022-01-21 13:17:02 -0800 | [diff] [blame] | 274 | &g_av1_codec_arg_defs.use_nv12, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 275 | &g_av1_codec_arg_defs.use_yv12, |
| 276 | &g_av1_codec_arg_defs.use_i420, |
| 277 | &g_av1_codec_arg_defs.use_i422, |
| 278 | &g_av1_codec_arg_defs.use_i444, |
| 279 | &g_av1_codec_arg_defs.usage, |
| 280 | &g_av1_codec_arg_defs.threads, |
| 281 | &g_av1_codec_arg_defs.profile, |
| 282 | &g_av1_codec_arg_defs.width, |
| 283 | &g_av1_codec_arg_defs.height, |
| 284 | &g_av1_codec_arg_defs.forced_max_frame_width, |
| 285 | &g_av1_codec_arg_defs.forced_max_frame_height, |
| 286 | #if CONFIG_WEBM_IO |
| 287 | &g_av1_codec_arg_defs.stereo_mode, |
| 288 | #endif |
| 289 | &g_av1_codec_arg_defs.timebase, |
| 290 | &g_av1_codec_arg_defs.framerate, |
| 291 | &g_av1_codec_arg_defs.global_error_resilient, |
| 292 | &g_av1_codec_arg_defs.bitdeptharg, |
Bohan Li | 368b918 | 2021-02-04 12:04:43 -0800 | [diff] [blame] | 293 | &g_av1_codec_arg_defs.inbitdeptharg, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 294 | &g_av1_codec_arg_defs.lag_in_frames, |
| 295 | &g_av1_codec_arg_defs.large_scale_tile, |
| 296 | &g_av1_codec_arg_defs.monochrome, |
| 297 | &g_av1_codec_arg_defs.full_still_picture_hdr, |
| 298 | &g_av1_codec_arg_defs.use_16bit_internal, |
Bohan Li | 368b918 | 2021-02-04 12:04:43 -0800 | [diff] [blame] | 299 | &g_av1_codec_arg_defs.save_as_annexb, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 300 | NULL |
| 301 | }; |
| 302 | |
| 303 | const arg_def_t *rc_args[] = { &g_av1_codec_arg_defs.dropframe_thresh, |
| 304 | &g_av1_codec_arg_defs.resize_mode, |
| 305 | &g_av1_codec_arg_defs.resize_denominator, |
| 306 | &g_av1_codec_arg_defs.resize_kf_denominator, |
| 307 | &g_av1_codec_arg_defs.superres_mode, |
| 308 | &g_av1_codec_arg_defs.superres_denominator, |
| 309 | &g_av1_codec_arg_defs.superres_kf_denominator, |
| 310 | &g_av1_codec_arg_defs.superres_qthresh, |
| 311 | &g_av1_codec_arg_defs.superres_kf_qthresh, |
| 312 | &g_av1_codec_arg_defs.end_usage, |
| 313 | &g_av1_codec_arg_defs.target_bitrate, |
| 314 | &g_av1_codec_arg_defs.min_quantizer, |
| 315 | &g_av1_codec_arg_defs.max_quantizer, |
| 316 | &g_av1_codec_arg_defs.undershoot_pct, |
| 317 | &g_av1_codec_arg_defs.overshoot_pct, |
| 318 | &g_av1_codec_arg_defs.buf_sz, |
| 319 | &g_av1_codec_arg_defs.buf_initial_sz, |
| 320 | &g_av1_codec_arg_defs.buf_optimal_sz, |
| 321 | &g_av1_codec_arg_defs.bias_pct, |
| 322 | &g_av1_codec_arg_defs.minsection_pct, |
| 323 | &g_av1_codec_arg_defs.maxsection_pct, |
| 324 | NULL }; |
| 325 | |
| 326 | const arg_def_t *kf_args[] = { &g_av1_codec_arg_defs.fwd_kf_enabled, |
| 327 | &g_av1_codec_arg_defs.kf_min_dist, |
| 328 | &g_av1_codec_arg_defs.kf_max_dist, |
Bohan Li | 368b918 | 2021-02-04 12:04:43 -0800 | [diff] [blame] | 329 | &g_av1_codec_arg_defs.kf_disabled, |
| 330 | &g_av1_codec_arg_defs.sframe_dist, |
| 331 | &g_av1_codec_arg_defs.sframe_mode, |
| 332 | NULL }; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 333 | |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 334 | // TODO(bohanli): Currently all options are supported by the key & value API. |
| 335 | // Consider removing the control ID usages? |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 336 | const arg_def_t *av1_ctrl_args[] = { |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 337 | &g_av1_codec_arg_defs.cpu_used_av1, |
| 338 | &g_av1_codec_arg_defs.auto_altref, |
| 339 | &g_av1_codec_arg_defs.sharpness, |
| 340 | &g_av1_codec_arg_defs.static_thresh, |
| 341 | &g_av1_codec_arg_defs.rowmtarg, |
Remya Prakasan | 93c1c37 | 2021-10-25 14:36:07 +0530 | [diff] [blame] | 342 | &g_av1_codec_arg_defs.fpmtarg, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 343 | &g_av1_codec_arg_defs.tile_cols, |
| 344 | &g_av1_codec_arg_defs.tile_rows, |
| 345 | &g_av1_codec_arg_defs.enable_tpl_model, |
| 346 | &g_av1_codec_arg_defs.enable_keyframe_filtering, |
| 347 | &g_av1_codec_arg_defs.arnr_maxframes, |
| 348 | &g_av1_codec_arg_defs.arnr_strength, |
| 349 | &g_av1_codec_arg_defs.tune_metric, |
| 350 | &g_av1_codec_arg_defs.cq_level, |
| 351 | &g_av1_codec_arg_defs.max_intra_rate_pct, |
| 352 | &g_av1_codec_arg_defs.max_inter_rate_pct, |
| 353 | &g_av1_codec_arg_defs.gf_cbr_boost_pct, |
| 354 | &g_av1_codec_arg_defs.lossless, |
| 355 | &g_av1_codec_arg_defs.enable_cdef, |
| 356 | &g_av1_codec_arg_defs.enable_restoration, |
| 357 | &g_av1_codec_arg_defs.enable_rect_partitions, |
| 358 | &g_av1_codec_arg_defs.enable_ab_partitions, |
| 359 | &g_av1_codec_arg_defs.enable_1to4_partitions, |
| 360 | &g_av1_codec_arg_defs.min_partition_size, |
| 361 | &g_av1_codec_arg_defs.max_partition_size, |
| 362 | &g_av1_codec_arg_defs.enable_dual_filter, |
| 363 | &g_av1_codec_arg_defs.enable_chroma_deltaq, |
| 364 | &g_av1_codec_arg_defs.enable_intra_edge_filter, |
| 365 | &g_av1_codec_arg_defs.enable_order_hint, |
| 366 | &g_av1_codec_arg_defs.enable_tx64, |
| 367 | &g_av1_codec_arg_defs.enable_flip_idtx, |
| 368 | &g_av1_codec_arg_defs.enable_rect_tx, |
| 369 | &g_av1_codec_arg_defs.enable_dist_wtd_comp, |
| 370 | &g_av1_codec_arg_defs.enable_masked_comp, |
| 371 | &g_av1_codec_arg_defs.enable_onesided_comp, |
| 372 | &g_av1_codec_arg_defs.enable_interintra_comp, |
| 373 | &g_av1_codec_arg_defs.enable_smooth_interintra, |
| 374 | &g_av1_codec_arg_defs.enable_diff_wtd_comp, |
| 375 | &g_av1_codec_arg_defs.enable_interinter_wedge, |
| 376 | &g_av1_codec_arg_defs.enable_interintra_wedge, |
| 377 | &g_av1_codec_arg_defs.enable_global_motion, |
| 378 | &g_av1_codec_arg_defs.enable_warped_motion, |
| 379 | &g_av1_codec_arg_defs.enable_filter_intra, |
| 380 | &g_av1_codec_arg_defs.enable_smooth_intra, |
| 381 | &g_av1_codec_arg_defs.enable_paeth_intra, |
| 382 | &g_av1_codec_arg_defs.enable_cfl_intra, |
Fyodor Kyslov | c491c66 | 2021-03-09 11:11:20 -0800 | [diff] [blame] | 383 | &g_av1_codec_arg_defs.enable_diagonal_intra, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 384 | &g_av1_codec_arg_defs.force_video_mode, |
| 385 | &g_av1_codec_arg_defs.enable_obmc, |
| 386 | &g_av1_codec_arg_defs.enable_overlay, |
| 387 | &g_av1_codec_arg_defs.enable_palette, |
| 388 | &g_av1_codec_arg_defs.enable_intrabc, |
| 389 | &g_av1_codec_arg_defs.enable_angle_delta, |
| 390 | &g_av1_codec_arg_defs.disable_trellis_quant, |
| 391 | &g_av1_codec_arg_defs.enable_qm, |
| 392 | &g_av1_codec_arg_defs.qm_min, |
| 393 | &g_av1_codec_arg_defs.qm_max, |
| 394 | &g_av1_codec_arg_defs.reduced_tx_type_set, |
| 395 | &g_av1_codec_arg_defs.use_intra_dct_only, |
| 396 | &g_av1_codec_arg_defs.use_inter_dct_only, |
| 397 | &g_av1_codec_arg_defs.use_intra_default_tx_only, |
| 398 | &g_av1_codec_arg_defs.quant_b_adapt, |
| 399 | &g_av1_codec_arg_defs.coeff_cost_upd_freq, |
| 400 | &g_av1_codec_arg_defs.mode_cost_upd_freq, |
| 401 | &g_av1_codec_arg_defs.mv_cost_upd_freq, |
| 402 | &g_av1_codec_arg_defs.frame_parallel_decoding, |
| 403 | &g_av1_codec_arg_defs.error_resilient_mode, |
| 404 | &g_av1_codec_arg_defs.aq_mode, |
| 405 | &g_av1_codec_arg_defs.deltaq_mode, |
Sai Deng | a62022d | 2021-10-01 10:27:57 -0700 | [diff] [blame] | 406 | &g_av1_codec_arg_defs.deltaq_strength, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 407 | &g_av1_codec_arg_defs.deltalf_mode, |
| 408 | &g_av1_codec_arg_defs.frame_periodic_boost, |
| 409 | &g_av1_codec_arg_defs.noise_sens, |
| 410 | &g_av1_codec_arg_defs.tune_content, |
| 411 | &g_av1_codec_arg_defs.cdf_update_mode, |
| 412 | &g_av1_codec_arg_defs.input_color_primaries, |
| 413 | &g_av1_codec_arg_defs.input_transfer_characteristics, |
| 414 | &g_av1_codec_arg_defs.input_matrix_coefficients, |
| 415 | &g_av1_codec_arg_defs.input_chroma_sample_position, |
| 416 | &g_av1_codec_arg_defs.min_gf_interval, |
| 417 | &g_av1_codec_arg_defs.max_gf_interval, |
| 418 | &g_av1_codec_arg_defs.gf_min_pyr_height, |
| 419 | &g_av1_codec_arg_defs.gf_max_pyr_height, |
| 420 | &g_av1_codec_arg_defs.superblock_size, |
| 421 | &g_av1_codec_arg_defs.num_tg, |
| 422 | &g_av1_codec_arg_defs.mtu_size, |
| 423 | &g_av1_codec_arg_defs.timing_info, |
| 424 | &g_av1_codec_arg_defs.film_grain_test, |
| 425 | &g_av1_codec_arg_defs.film_grain_table, |
| 426 | #if CONFIG_DENOISE |
| 427 | &g_av1_codec_arg_defs.denoise_noise_level, |
| 428 | &g_av1_codec_arg_defs.denoise_block_size, |
n9Mtq4 | 08eb1d4 | 2021-02-18 00:13:10 -0500 | [diff] [blame] | 429 | &g_av1_codec_arg_defs.enable_dnl_denoising, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 430 | #endif // CONFIG_DENOISE |
| 431 | &g_av1_codec_arg_defs.max_reference_frames, |
| 432 | &g_av1_codec_arg_defs.reduced_reference_set, |
| 433 | &g_av1_codec_arg_defs.enable_ref_frame_mvs, |
| 434 | &g_av1_codec_arg_defs.target_seq_level_idx, |
| 435 | &g_av1_codec_arg_defs.set_tier_mask, |
| 436 | &g_av1_codec_arg_defs.set_min_cr, |
| 437 | &g_av1_codec_arg_defs.vbr_corpus_complexity_lap, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 438 | &g_av1_codec_arg_defs.input_chroma_subsampling_x, |
| 439 | &g_av1_codec_arg_defs.input_chroma_subsampling_y, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 440 | #if CONFIG_TUNE_VMAF |
| 441 | &g_av1_codec_arg_defs.vmaf_model_path, |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 442 | #endif |
chiyotsai | cb037d7 | 2021-04-15 17:17:08 -0700 | [diff] [blame] | 443 | &g_av1_codec_arg_defs.dv_cost_upd_freq, |
Cheng Chen | 9164dee | 2021-04-19 23:11:38 -0700 | [diff] [blame] | 444 | &g_av1_codec_arg_defs.partition_info_path, |
Maryla | 4bb5281 | 2021-06-18 08:36:58 +0200 | [diff] [blame] | 445 | &g_av1_codec_arg_defs.enable_directional_intra, |
Maryla | 36c2b99 | 2021-06-21 11:48:34 +0200 | [diff] [blame] | 446 | &g_av1_codec_arg_defs.enable_tx_size_search, |
Fyodor Kyslov | 2372d3e | 2021-11-01 16:11:13 -0700 | [diff] [blame] | 447 | &g_av1_codec_arg_defs.loopfilter_control, |
Cheng Chen | f15d9ea | 2021-11-15 16:52:13 -0800 | [diff] [blame] | 448 | &g_av1_codec_arg_defs.auto_intra_tools_off, |
Cheng Chen | 97e6d48 | 2024-03-07 17:10:41 -0800 | [diff] [blame] | 449 | &g_av1_codec_arg_defs.enable_rate_guide_deltaq, |
| 450 | &g_av1_codec_arg_defs.rate_distribution_info, |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 451 | NULL, |
| 452 | }; |
| 453 | |
| 454 | const arg_def_t *av1_key_val_args[] = { |
Bohan Li | 445fdf6 | 2021-06-03 16:16:00 -0700 | [diff] [blame] | 455 | &g_av1_codec_arg_defs.passes, |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 456 | &g_av1_codec_arg_defs.two_pass_output, |
Bohan Li | edec7cd | 2021-08-26 09:17:47 -0700 | [diff] [blame] | 457 | &g_av1_codec_arg_defs.second_pass_log, |
Jingning Han | 07eda7a | 2021-06-22 13:56:57 -0700 | [diff] [blame] | 458 | &g_av1_codec_arg_defs.fwd_kf_dist, |
Bohan Li | 239351d | 2022-01-21 11:42:17 -0800 | [diff] [blame] | 459 | &g_av1_codec_arg_defs.strict_level_conformance, |
linzhen | 4907306 | 2022-10-31 00:42:59 +0000 | [diff] [blame] | 460 | &g_av1_codec_arg_defs.sb_qp_sweep, |
Luca Versari | 6807a7f | 2021-12-20 21:41:20 +0100 | [diff] [blame] | 461 | &g_av1_codec_arg_defs.dist_metric, |
Bohan Li | 4e02570 | 2022-08-18 12:05:43 -0700 | [diff] [blame] | 462 | &g_av1_codec_arg_defs.kf_max_pyr_height, |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 463 | NULL, |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 464 | }; |
hui su | 82331e0 | 2015-08-16 18:21:56 -0700 | [diff] [blame] | 465 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 466 | static const arg_def_t *no_args[] = { NULL }; |
| 467 | |
Wan-Teh Chang | dc6e2c8 | 2018-09-21 13:49:49 -0700 | [diff] [blame] | 468 | static void show_help(FILE *fout, int shorthelp) { |
Wan-Teh Chang | ca5281c | 2021-03-02 11:14:10 -0800 | [diff] [blame] | 469 | fprintf(fout, "Usage: %s <options> -o dst_filename src_filename\n", |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 470 | exec_name); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 471 | |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 472 | if (shorthelp) { |
| 473 | fprintf(fout, "Use --help to see the full list of options.\n"); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | fprintf(fout, "\nOptions:\n"); |
| 478 | arg_show_usage(fout, main_args); |
| 479 | fprintf(fout, "\nEncoder Global Options:\n"); |
| 480 | arg_show_usage(fout, global_args); |
| 481 | fprintf(fout, "\nRate Control Options:\n"); |
| 482 | arg_show_usage(fout, rc_args); |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 483 | fprintf(fout, "\nKeyframe Placement Options:\n"); |
| 484 | arg_show_usage(fout, kf_args); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 485 | #if CONFIG_AV1_ENCODER |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 486 | fprintf(fout, "\nAV1 Specific Options:\n"); |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 487 | arg_show_usage(fout, av1_ctrl_args); |
| 488 | arg_show_usage(fout, av1_key_val_args); |
hui su | 82331e0 | 2015-08-16 18:21:56 -0700 | [diff] [blame] | 489 | #endif |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 490 | fprintf(fout, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 491 | "\nStream timebase (--timebase):\n" |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 492 | " The desired precision of timestamps in the output, expressed\n" |
| 493 | " in fractional seconds. Default is 1/1000.\n"); |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 494 | fprintf(fout, "\nIncluded encoders:\n\n"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 495 | |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 496 | const int num_encoder = get_aom_encoder_count(); |
| 497 | for (int i = 0; i < num_encoder; ++i) { |
Elliott Karpilovsky | 67e84d4 | 2020-04-26 16:03:39 -0700 | [diff] [blame] | 498 | aom_codec_iface_t *encoder = get_aom_encoder_by_index(i); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 499 | const char *defstr = (i == (num_encoder - 1)) ? "(default)" : ""; |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 500 | fprintf(fout, " %-6s - %s %s\n", get_short_name_by_aom_encoder(encoder), |
| 501 | aom_codec_iface_name(encoder), defstr); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 502 | } |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 503 | fprintf(fout, "\n "); |
| 504 | fprintf(fout, "Use --codec to switch to a non-default encoder.\n\n"); |
| 505 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 506 | |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 507 | void usage_exit(void) { |
| 508 | show_help(stderr, 1); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 509 | exit(EXIT_FAILURE); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 510 | } |
| 511 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 512 | #if CONFIG_AV1_ENCODER |
| 513 | #define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map) |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 514 | #define ARG_KEY_VAL_CNT_MAX NELEMENTS(av1_key_val_args) |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 515 | #endif |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 516 | |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 517 | #if !CONFIG_WEBM_IO |
| 518 | typedef int stereo_format_t; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 519 | struct WebmOutputContext { |
| 520 | int debug; |
| 521 | }; |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 522 | #endif |
| 523 | |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 524 | /* Per-stream configuration */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 525 | struct stream_config { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 526 | struct aom_codec_enc_cfg cfg; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 527 | const char *out_fn; |
| 528 | const char *stats_fn; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 529 | stereo_format_t stereo_fmt; |
| 530 | int arg_ctrls[ARG_CTRL_CNT_MAX][2]; |
| 531 | int arg_ctrl_cnt; |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 532 | const char *arg_key_vals[ARG_KEY_VAL_CNT_MAX][2]; |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 533 | int arg_key_val_cnt; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 534 | int write_webm; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 535 | const char *film_grain_filename; |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 536 | int write_ivf; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 537 | // whether to use 16bit internal buffers |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 538 | int use_16bit_internal; |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 539 | #if CONFIG_TUNE_VMAF |
| 540 | const char *vmaf_model_path; |
| 541 | #endif |
Cheng Chen | 9164dee | 2021-04-19 23:11:38 -0700 | [diff] [blame] | 542 | const char *partition_info_path; |
Cheng Chen | 567038a | 2022-12-22 16:45:02 -0800 | [diff] [blame] | 543 | unsigned int enable_rate_guide_deltaq; |
| 544 | const char *rate_distribution_info; |
Elliott Karpilovsky | b2d8258 | 2021-02-02 22:49:56 -0800 | [diff] [blame] | 545 | aom_color_range_t color_range; |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 546 | const char *two_pass_input; |
| 547 | const char *two_pass_output; |
| 548 | int two_pass_width; |
| 549 | int two_pass_height; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 550 | }; |
| 551 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 552 | struct stream_state { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 553 | int index; |
| 554 | struct stream_state *next; |
| 555 | struct stream_config config; |
| 556 | FILE *file; |
| 557 | struct rate_hist *rate_hist; |
| 558 | struct WebmOutputContext webm_ctx; |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 559 | uint64_t psnr_sse_total[2]; |
| 560 | uint64_t psnr_samples_total[2]; |
| 561 | double psnr_totals[2][4]; |
| 562 | int psnr_count[2]; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 563 | int counts[64]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 564 | aom_codec_ctx_t encoder; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 565 | unsigned int frames_out; |
| 566 | uint64_t cx_time; |
| 567 | size_t nbytes; |
| 568 | stats_io_t stats; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 569 | struct aom_image *img; |
| 570 | aom_codec_ctx_t decoder; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 571 | int mismatch_seen; |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 572 | unsigned int chroma_subsampling_x; |
| 573 | unsigned int chroma_subsampling_y; |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 574 | const char *orig_out_fn; |
| 575 | unsigned int orig_width; |
| 576 | unsigned int orig_height; |
Bohan Li | 15b3c6d | 2021-07-27 17:27:20 -0700 | [diff] [blame] | 577 | int orig_write_webm; |
| 578 | int orig_write_ivf; |
Bohan Li | b5c7e34 | 2021-11-03 13:32:03 -0700 | [diff] [blame] | 579 | char tmp_out_fn[1000]; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 580 | }; |
| 581 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 582 | static void validate_positive_rational(const char *msg, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 583 | struct aom_rational *rat) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 584 | if (rat->den < 0) { |
| 585 | rat->num *= -1; |
| 586 | rat->den *= -1; |
| 587 | } |
John Koleszar | 1b27e93 | 2012-04-25 17:08:56 -0700 | [diff] [blame] | 588 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 589 | if (rat->num < 0) die("Error: %s must be positive\n", msg); |
John Koleszar | 1b27e93 | 2012-04-25 17:08:56 -0700 | [diff] [blame] | 590 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 591 | if (!rat->den) die("Error: %s has zero denominator\n", msg); |
John Koleszar | 1b27e93 | 2012-04-25 17:08:56 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 594 | static void init_config(cfg_options_t *config) { |
| 595 | memset(config, 0, sizeof(cfg_options_t)); |
| 596 | config->super_block_size = 0; // Dynamic |
| 597 | config->max_partition_size = 128; |
| 598 | config->min_partition_size = 4; |
| 599 | config->disable_trellis_quant = 3; |
| 600 | } |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 601 | |
elliottk | b63b571 | 2018-09-17 11:20:20 -0700 | [diff] [blame] | 602 | /* Parses global config arguments into the AvxEncoderConfig. Note that |
| 603 | * argv is modified and overwrites all parsed arguments. |
| 604 | */ |
Ryan Lei | c8b6dd6 | 2019-10-23 20:01:26 -0700 | [diff] [blame] | 605 | static void parse_global_config(struct AvxEncoderConfig *global, char ***argv) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 606 | char **argi, **argj; |
| 607 | struct arg arg; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 608 | const int num_encoder = get_aom_encoder_count(); |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 609 | char **argv_local = (char **)*argv; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 610 | if (num_encoder < 1) die("Error: no valid encoder available\n"); |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 611 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 612 | /* Initialize default parameters */ |
| 613 | memset(global, 0, sizeof(*global)); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 614 | global->codec = get_aom_encoder_by_index(num_encoder - 1); |
Deb Mukherjee | 0d8723f | 2013-08-19 14:16:26 -0700 | [diff] [blame] | 615 | global->passes = 0; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 616 | global->color_type = I420; |
elliottk | b63b571 | 2018-09-17 11:20:20 -0700 | [diff] [blame] | 617 | global->csp = AOM_CSP_UNKNOWN; |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 618 | global->show_psnr = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 619 | |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 620 | int cfg_included = 0; |
| 621 | init_config(&global->encoder_config); |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 622 | |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 623 | for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 624 | arg.argv_step = 1; |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 625 | |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 626 | if (arg_match(&arg, &g_av1_codec_arg_defs.use_cfg, argi)) { |
Wan-Teh Chang | b8804bb | 2020-09-17 12:32:40 -0700 | [diff] [blame] | 627 | if (!cfg_included) { |
| 628 | parse_cfg(arg.val, &global->encoder_config); |
| 629 | cfg_included = 1; |
| 630 | } |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 631 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.help, argi)) { |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 632 | show_help(stdout, 0); |
| 633 | exit(EXIT_SUCCESS); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 634 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.codecarg, argi)) { |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 635 | global->codec = get_aom_encoder_by_short_name(arg.val); |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 636 | if (!global->codec) |
| 637 | die("Error: Unrecognized argument (%s) to --codec\n", arg.val); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 638 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.passes, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 639 | global->passes = arg_parse_uint(&arg); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 640 | |
Bohan Li | 445fdf6 | 2021-06-03 16:16:00 -0700 | [diff] [blame] | 641 | if (global->passes < 1 || global->passes > 3) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 642 | die("Error: Invalid number of passes (%d)\n", global->passes); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 643 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.pass_arg, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 644 | global->pass = arg_parse_uint(&arg); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 645 | |
Bohan Li | 445fdf6 | 2021-06-03 16:16:00 -0700 | [diff] [blame] | 646 | if (global->pass < 1 || global->pass > 3) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 647 | die("Error: Invalid pass selected (%d)\n", global->pass); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 648 | } else if (arg_match(&arg, |
| 649 | &g_av1_codec_arg_defs.input_chroma_sample_position, |
| 650 | argi)) { |
elliottk | b63b571 | 2018-09-17 11:20:20 -0700 | [diff] [blame] | 651 | global->csp = arg_parse_enum(&arg); |
| 652 | /* Flag is used by later code as well, preserve it. */ |
| 653 | argj++; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 654 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.usage, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 655 | global->usage = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 656 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.good_dl, argi)) { |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 657 | global->usage = AOM_USAGE_GOOD_QUALITY; // Good quality usage |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 658 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.rt_dl, argi)) { |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 659 | global->usage = AOM_USAGE_REALTIME; // Real-time usage |
Jingning Han | c5d38e0 | 2021-02-11 14:40:27 -0800 | [diff] [blame] | 660 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.ai_dl, argi)) { |
| 661 | global->usage = AOM_USAGE_ALL_INTRA; // All intra usage |
Jerome Jiang | d116cab | 2022-01-21 13:17:02 -0800 | [diff] [blame] | 662 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_nv12, argi)) { |
| 663 | global->color_type = NV12; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 664 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_yv12, argi)) { |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 665 | global->color_type = YV12; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 666 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i420, argi)) { |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 667 | global->color_type = I420; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 668 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i422, argi)) { |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 669 | global->color_type = I422; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 670 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i444, argi)) { |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 671 | global->color_type = I444; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 672 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.quietarg, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 673 | global->quiet = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 674 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.verbosearg, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 675 | global->verbose = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 676 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.limit, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 677 | global->limit = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 678 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.skip, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 679 | global->skip_frames = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 680 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.psnrarg, argi)) { |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 681 | if (arg.val) |
| 682 | global->show_psnr = arg_parse_int(&arg); |
| 683 | else |
| 684 | global->show_psnr = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 685 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.recontest, argi)) { |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 686 | global->test_decode = arg_parse_enum_or_int(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 687 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.framerate, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 688 | global->framerate = arg_parse_rational(&arg); |
| 689 | validate_positive_rational(arg.name, &global->framerate); |
| 690 | global->have_framerate = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 691 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.debugmode, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 692 | global->debug = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 693 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.q_hist_n, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 694 | global->show_q_hist_buckets = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 695 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_hist_n, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 696 | global->show_rate_hist_buckets = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 697 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warnings, argi)) { |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 698 | global->disable_warnings = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 699 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warning_prompt, |
| 700 | argi)) { |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 701 | global->disable_warning_prompt = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 702 | } else { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 703 | argj++; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 704 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 705 | } |
| 706 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 707 | if (global->pass) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 708 | /* DWIM: Assume the user meant passes=2 if pass=2 is specified */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 709 | if (global->pass > global->passes) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 710 | aom_tools_warn("Assuming --pass=%d implies --passes=%d\n", global->pass, |
| 711 | global->pass); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 712 | global->passes = global->pass; |
John Koleszar | 732cb9a | 2012-02-14 12:30:17 -0800 | [diff] [blame] | 713 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 714 | } |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 715 | /* Validate global config */ |
| 716 | if (global->passes == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 717 | #if CONFIG_AV1_ENCODER |
| 718 | // 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] | 719 | // encoder |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 720 | if (global->codec != NULL) |
| 721 | global->passes = |
| 722 | (strcmp(get_short_name_by_aom_encoder(global->codec), "av1") == 0 && |
| 723 | global->usage != AOM_USAGE_REALTIME) |
| 724 | ? 2 |
| 725 | : 1; |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 726 | #else |
| 727 | global->passes = 1; |
| 728 | #endif |
| 729 | } |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 730 | |
| 731 | if (global->usage == AOM_USAGE_REALTIME && global->passes > 1) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 732 | aom_tools_warn("Enforcing one-pass encoding in realtime mode\n"); |
Wan-Teh Chang | 7a20d10 | 2021-04-13 12:18:34 -0700 | [diff] [blame] | 733 | if (global->pass > 1) |
| 734 | die("Error: Invalid --pass=%d for one-pass encoding\n", global->pass); |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 735 | global->passes = 1; |
| 736 | } |
Jingning Han | 14bfd94 | 2021-02-11 15:18:29 -0800 | [diff] [blame] | 737 | |
| 738 | if (global->usage == AOM_USAGE_ALL_INTRA && global->passes > 1) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 739 | aom_tools_warn("Enforcing one-pass encoding in all intra mode\n"); |
Jingning Han | 14bfd94 | 2021-02-11 15:18:29 -0800 | [diff] [blame] | 740 | global->passes = 1; |
| 741 | } |
John Koleszar | 732cb9a | 2012-02-14 12:30:17 -0800 | [diff] [blame] | 742 | } |
| 743 | |
elliottk | b63b571 | 2018-09-17 11:20:20 -0700 | [diff] [blame] | 744 | static void open_input_file(struct AvxInputContext *input, |
| 745 | aom_chroma_sample_position_t csp) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 746 | /* Parse certain options from the input file, if possible */ |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 747 | input->file = strcmp(input->filename, "-") ? fopen(input->filename, "rb") |
| 748 | : set_binary_mode(stdin); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 749 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 750 | if (!input->file) fatal("Failed to open input file"); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 751 | |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 752 | if (!fseeko(input->file, 0, SEEK_END)) { |
| 753 | /* Input file is seekable. Figure out how long it is, so we can get |
| 754 | * progress info. |
| 755 | */ |
| 756 | input->length = ftello(input->file); |
| 757 | rewind(input->file); |
| 758 | } |
| 759 | |
Frank Galligan | 09acd26 | 2015-06-01 10:20:58 -0700 | [diff] [blame] | 760 | /* Default to 1:1 pixel aspect ratio. */ |
| 761 | input->pixel_aspect_ratio.numerator = 1; |
| 762 | input->pixel_aspect_ratio.denominator = 1; |
| 763 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 764 | /* For RAW input sources, these bytes will applied on the first frame |
| 765 | * in read_frame(). |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 766 | */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 767 | input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file); |
| 768 | input->detect.position = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 769 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 770 | if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) { |
elliottk | b63b571 | 2018-09-17 11:20:20 -0700 | [diff] [blame] | 771 | if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp, |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 772 | input->only_i420) >= 0) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 773 | input->file_type = FILE_TYPE_Y4M; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 774 | input->width = input->y4m.pic_w; |
| 775 | input->height = input->y4m.pic_h; |
Frank Galligan | 09acd26 | 2015-06-01 10:20:58 -0700 | [diff] [blame] | 776 | input->pixel_aspect_ratio.numerator = input->y4m.par_n; |
| 777 | input->pixel_aspect_ratio.denominator = input->y4m.par_d; |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 778 | input->framerate.numerator = input->y4m.fps_n; |
| 779 | input->framerate.denominator = input->y4m.fps_d; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 780 | input->fmt = input->y4m.aom_fmt; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 781 | input->bit_depth = input->y4m.bit_depth; |
Elliott Karpilovsky | b2d8258 | 2021-02-02 22:49:56 -0800 | [diff] [blame] | 782 | input->color_range = input->y4m.color_range; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 783 | } else |
| 784 | fatal("Unsupported Y4M stream."); |
Alex Converse | 64b89f1 | 2014-01-06 16:29:09 -0800 | [diff] [blame] | 785 | } 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] | 786 | fatal("IVF is not supported as input."); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 787 | } else { |
| 788 | input->file_type = FILE_TYPE_RAW; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 789 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 790 | } |
| 791 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 792 | static void close_input_file(struct AvxInputContext *input) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 793 | fclose(input->file); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 794 | if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m); |
John Koleszar | 732cb9a | 2012-02-14 12:30:17 -0800 | [diff] [blame] | 795 | } |
| 796 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 797 | static struct stream_state *new_stream(struct AvxEncoderConfig *global, |
Tom Finegan | 6c270ed | 2013-11-08 11:32:23 -0800 | [diff] [blame] | 798 | struct stream_state *prev) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 799 | struct stream_state *stream; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 800 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 801 | stream = calloc(1, sizeof(*stream)); |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 802 | if (stream == NULL) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 803 | fatal("Failed to allocate new stream."); |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 804 | } |
| 805 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 806 | if (prev) { |
| 807 | memcpy(stream, prev, sizeof(*stream)); |
| 808 | stream->index++; |
| 809 | prev->next = stream; |
| 810 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 811 | aom_codec_err_t res; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 812 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 813 | /* Populate encoder configuration */ |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 814 | res = aom_codec_enc_config_default(global->codec, &stream->config.cfg, |
| 815 | global->usage); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 816 | 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] | 817 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 818 | /* Change the default timebase to a high enough value so that the |
| 819 | * encoder will always create strictly increasing timestamps. |
| 820 | */ |
| 821 | stream->config.cfg.g_timebase.den = 1000; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 822 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 823 | /* Never use the library's default resolution, require it be parsed |
| 824 | * from the file or set on the command line. |
| 825 | */ |
| 826 | stream->config.cfg.g_w = 0; |
| 827 | stream->config.cfg.g_h = 0; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 828 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 829 | /* Initialize remaining stream parameters */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 830 | stream->config.write_webm = 1; |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 831 | stream->config.write_ivf = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 832 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 833 | #if CONFIG_WEBM_IO |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 834 | stream->config.stereo_fmt = STEREO_FORMAT_MONO; |
Vignesh Venkatasubramanian | 9441f10 | 2016-04-25 13:28:24 -0700 | [diff] [blame] | 835 | stream->webm_ctx.last_pts_ns = -1; |
| 836 | stream->webm_ctx.writer = NULL; |
| 837 | stream->webm_ctx.segment = NULL; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 838 | #endif |
Johann | 87c40b3 | 2012-03-01 16:12:53 -0800 | [diff] [blame] | 839 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 840 | /* Allows removal of the application version from the EBML tags */ |
Vignesh Venkatasubramanian | 9441f10 | 2016-04-25 13:28:24 -0700 | [diff] [blame] | 841 | stream->webm_ctx.debug = global->debug; |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 842 | memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config, |
| 843 | sizeof(stream->config.cfg.encoder_cfg)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 844 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 845 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 846 | /* Output files must be specified for each stream */ |
| 847 | stream->config.out_fn = NULL; |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 848 | stream->config.two_pass_input = NULL; |
| 849 | stream->config.two_pass_output = NULL; |
| 850 | stream->config.two_pass_width = 0; |
| 851 | stream->config.two_pass_height = 0; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 852 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 853 | stream->next = NULL; |
| 854 | return stream; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 855 | } |
| 856 | |
Imdad Sardharwalla | 3ab64bd | 2017-12-13 15:03:53 +0000 | [diff] [blame] | 857 | static void set_config_arg_ctrls(struct stream_config *config, int key, |
| 858 | const struct arg *arg) { |
| 859 | int j; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 860 | if (key == AV1E_SET_FILM_GRAIN_TABLE) { |
| 861 | config->film_grain_filename = arg->val; |
| 862 | return; |
| 863 | } |
| 864 | |
Hui Su | 2aa492c | 2019-03-12 15:18:18 -0700 | [diff] [blame] | 865 | // For target level, the settings should accumulate rather than overwrite, |
| 866 | // so we simply append it. |
| 867 | if (key == AV1E_SET_TARGET_SEQ_LEVEL_IDX) { |
| 868 | j = config->arg_ctrl_cnt; |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 869 | assert(j < ARG_CTRL_CNT_MAX); |
Hui Su | 2aa492c | 2019-03-12 15:18:18 -0700 | [diff] [blame] | 870 | config->arg_ctrls[j][0] = key; |
| 871 | config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg); |
| 872 | ++config->arg_ctrl_cnt; |
| 873 | return; |
| 874 | } |
| 875 | |
Imdad Sardharwalla | 3ab64bd | 2017-12-13 15:03:53 +0000 | [diff] [blame] | 876 | /* Point either to the next free element or the first instance of this |
| 877 | * control. |
| 878 | */ |
| 879 | for (j = 0; j < config->arg_ctrl_cnt; j++) |
| 880 | if (config->arg_ctrls[j][0] == key) break; |
| 881 | |
| 882 | /* Update/insert */ |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 883 | assert(j < ARG_CTRL_CNT_MAX); |
Imdad Sardharwalla | 3ab64bd | 2017-12-13 15:03:53 +0000 | [diff] [blame] | 884 | config->arg_ctrls[j][0] = key; |
| 885 | config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg); |
Wei-Ting Lin | e6961e7 | 2018-08-15 17:43:33 -0700 | [diff] [blame] | 886 | |
| 887 | if (key == AOME_SET_ENABLEAUTOALTREF && config->arg_ctrls[j][1] > 1) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 888 | aom_tools_warn( |
| 889 | "auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n"); |
Wei-Ting Lin | e6961e7 | 2018-08-15 17:43:33 -0700 | [diff] [blame] | 890 | config->arg_ctrls[j][1] = 1; |
| 891 | } |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 892 | |
Imdad Sardharwalla | 3ab64bd | 2017-12-13 15:03:53 +0000 | [diff] [blame] | 893 | if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++; |
| 894 | } |
| 895 | |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 896 | static void set_config_arg_key_vals(struct stream_config *config, |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 897 | const char *name, const struct arg *arg) { |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 898 | int j; |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 899 | const char *val = arg->val; |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 900 | // For target level, the settings should accumulate rather than overwrite, |
| 901 | // so we simply append it. |
| 902 | if (strcmp(name, "target-seq-level-idx") == 0) { |
| 903 | j = config->arg_key_val_cnt; |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 904 | assert(j < ARG_KEY_VAL_CNT_MAX); |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 905 | config->arg_key_vals[j][0] = name; |
| 906 | config->arg_key_vals[j][1] = val; |
| 907 | ++config->arg_key_val_cnt; |
| 908 | return; |
| 909 | } |
| 910 | |
| 911 | /* Point either to the next free element or the first instance of this |
Bohan Li | 0b822be | 2021-04-13 13:30:05 -0700 | [diff] [blame] | 912 | * option. |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 913 | */ |
Bohan Li | 0b822be | 2021-04-13 13:30:05 -0700 | [diff] [blame] | 914 | for (j = 0; j < config->arg_key_val_cnt; j++) |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 915 | if (strcmp(name, config->arg_key_vals[j][0]) == 0) break; |
| 916 | |
| 917 | /* Update/insert */ |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 918 | assert(j < ARG_KEY_VAL_CNT_MAX); |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 919 | config->arg_key_vals[j][0] = name; |
| 920 | config->arg_key_vals[j][1] = val; |
| 921 | |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 922 | if (strcmp(name, g_av1_codec_arg_defs.auto_altref.long_name) == 0) { |
| 923 | int auto_altref = arg_parse_int(arg); |
| 924 | if (auto_altref > 1) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 925 | aom_tools_warn( |
| 926 | "auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n"); |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 927 | config->arg_key_vals[j][1] = "1"; |
| 928 | } |
| 929 | } |
| 930 | |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 931 | if (j == config->arg_key_val_cnt) config->arg_key_val_cnt++; |
| 932 | } |
| 933 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 934 | static int parse_stream_params(struct AvxEncoderConfig *global, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 935 | struct stream_state *stream, char **argv) { |
| 936 | char **argi, **argj; |
| 937 | struct arg arg; |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 938 | static const arg_def_t **ctrl_args = no_args; |
| 939 | static const arg_def_t **key_val_args = no_args; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 940 | static const int *ctrl_args_map = NULL; |
| 941 | struct stream_config *config = &stream->config; |
| 942 | int eos_mark_found = 0; |
Tristan Matthews | ed858d6 | 2017-07-24 15:33:44 -0400 | [diff] [blame] | 943 | int webm_forced = 0; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 944 | |
Dmitry Kovalev | 70d9664 | 2014-02-11 21:12:23 -0800 | [diff] [blame] | 945 | // Handle codec specific options |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 946 | if (0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 947 | #if CONFIG_AV1_ENCODER |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 948 | } else if (strcmp(get_short_name_by_aom_encoder(global->codec), "av1") == 0) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 949 | // TODO(jingning): Reuse AV1 specific encoder configuration parameters. |
| 950 | // Consider to expand this set for AV1 encoder control. |
Wan-Teh Chang | 491889e | 2022-01-10 15:25:20 -0800 | [diff] [blame] | 951 | #if __STDC_VERSION__ >= 201112L |
| 952 | _Static_assert(NELEMENTS(av1_ctrl_args) == NELEMENTS(av1_arg_ctrl_map), |
| 953 | "The av1_ctrl_args and av1_arg_ctrl_map arrays must be of " |
| 954 | "the same size."); |
| 955 | #else |
| 956 | assert(NELEMENTS(av1_ctrl_args) == NELEMENTS(av1_arg_ctrl_map)); |
| 957 | #endif |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 958 | ctrl_args = av1_ctrl_args; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 959 | ctrl_args_map = av1_arg_ctrl_map; |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 960 | key_val_args = av1_key_val_args; |
Jingning Han | 3ee6db6 | 2015-08-05 19:00:31 -0700 | [diff] [blame] | 961 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 962 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 963 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 964 | for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 965 | arg.argv_step = 1; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 966 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 967 | /* Once we've found an end-of-stream marker (--) we want to continue |
| 968 | * shifting arguments but not consuming them. |
| 969 | */ |
| 970 | if (eos_mark_found) { |
| 971 | argj++; |
| 972 | continue; |
| 973 | } else if (!strcmp(*argj, "--")) { |
| 974 | eos_mark_found = 1; |
| 975 | continue; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 976 | } |
| 977 | |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 978 | if (arg_match(&arg, &g_av1_codec_arg_defs.outputfile, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 979 | config->out_fn = arg.val; |
Tristan Matthews | ed858d6 | 2017-07-24 15:33:44 -0400 | [diff] [blame] | 980 | if (!webm_forced) { |
| 981 | const size_t out_fn_len = strlen(config->out_fn); |
| 982 | if (out_fn_len >= 4 && |
| 983 | !strcmp(config->out_fn + out_fn_len - 4, ".ivf")) { |
| 984 | config->write_webm = 0; |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 985 | config->write_ivf = 1; |
Tom Finegan | 61b71ab | 2018-03-22 15:58:38 -0700 | [diff] [blame] | 986 | } else if (out_fn_len >= 4 && |
| 987 | !strcmp(config->out_fn + out_fn_len - 4, ".obu")) { |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 988 | config->write_webm = 0; |
| 989 | config->write_ivf = 0; |
| 990 | } |
Tristan Matthews | ed858d6 | 2017-07-24 15:33:44 -0400 | [diff] [blame] | 991 | } |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 992 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.fpf_name, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 993 | config->stats_fn = arg.val; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 994 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_webm, argi)) { |
Johann | b50e518 | 2015-01-30 15:05:14 -0800 | [diff] [blame] | 995 | #if CONFIG_WEBM_IO |
| 996 | config->write_webm = 1; |
Tristan Matthews | ed858d6 | 2017-07-24 15:33:44 -0400 | [diff] [blame] | 997 | webm_forced = 1; |
Johann | b50e518 | 2015-01-30 15:05:14 -0800 | [diff] [blame] | 998 | #else |
| 999 | die("Error: --webm specified but webm is disabled."); |
| 1000 | #endif |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1001 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_ivf, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1002 | config->write_webm = 0; |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 1003 | config->write_ivf = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1004 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_obu, argi)) { |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 1005 | config->write_webm = 0; |
| 1006 | config->write_ivf = 0; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1007 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.threads, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1008 | config->cfg.g_threads = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1009 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.profile, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1010 | config->cfg.g_profile = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1011 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.width, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1012 | config->cfg.g_w = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1013 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.height, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1014 | config->cfg.g_h = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1015 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_width, |
| 1016 | argi)) { |
Imdad Sardharwalla | 102c865 | 2018-02-23 16:35:13 +0000 | [diff] [blame] | 1017 | config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1018 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_height, |
| 1019 | argi)) { |
Imdad Sardharwalla | 102c865 | 2018-02-23 16:35:13 +0000 | [diff] [blame] | 1020 | config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1021 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.bitdeptharg, argi)) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1022 | config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1023 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.inbitdeptharg, argi)) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1024 | config->cfg.g_input_bit_depth = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1025 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_x, |
| 1026 | argi)) { |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 1027 | stream->chroma_subsampling_x = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1028 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_y, |
| 1029 | argi)) { |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 1030 | stream->chroma_subsampling_y = arg_parse_uint(&arg); |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 1031 | #if CONFIG_WEBM_IO |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1032 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.stereo_mode, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1033 | config->stereo_fmt = arg_parse_enum_or_int(&arg); |
James Zern | dba7376 | 2014-05-10 17:44:12 -0700 | [diff] [blame] | 1034 | #endif |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1035 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.timebase, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1036 | config->cfg.g_timebase = arg_parse_rational(&arg); |
| 1037 | validate_positive_rational(arg.name, &config->cfg.g_timebase); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1038 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.global_error_resilient, |
| 1039 | argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1040 | config->cfg.g_error_resilient = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1041 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.lag_in_frames, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1042 | config->cfg.g_lag_in_frames = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1043 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.large_scale_tile, argi)) { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1044 | config->cfg.large_scale_tile = arg_parse_uint(&arg); |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 1045 | if (config->cfg.large_scale_tile) { |
| 1046 | global->codec = get_aom_encoder_by_short_name("av1"); |
| 1047 | } |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1048 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.monochrome, argi)) { |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 1049 | config->cfg.monochrome = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1050 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.full_still_picture_hdr, |
| 1051 | argi)) { |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 1052 | config->cfg.full_still_picture_hdr = 1; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1053 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_16bit_internal, |
| 1054 | argi)) { |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 1055 | config->use_16bit_internal = CONFIG_AV1_HIGHBITDEPTH; |
| 1056 | if (!config->use_16bit_internal) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 1057 | aom_tools_warn("%s option ignored with CONFIG_AV1_HIGHBITDEPTH=0.\n", |
| 1058 | arg.name); |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 1059 | } |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1060 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.dropframe_thresh, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1061 | config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1062 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_mode, argi)) { |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 1063 | config->cfg.rc_resize_mode = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1064 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_denominator, |
| 1065 | argi)) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1066 | config->cfg.rc_resize_denominator = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1067 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_kf_denominator, |
| 1068 | argi)) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1069 | config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1070 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_mode, argi)) { |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 1071 | config->cfg.rc_superres_mode = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1072 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_denominator, |
| 1073 | argi)) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1074 | config->cfg.rc_superres_denominator = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1075 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_denominator, |
| 1076 | argi)) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1077 | config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1078 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_qthresh, argi)) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 1079 | config->cfg.rc_superres_qthresh = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1080 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_qthresh, |
| 1081 | argi)) { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 1082 | config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1083 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.end_usage, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1084 | config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1085 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.target_bitrate, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1086 | config->cfg.rc_target_bitrate = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1087 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.min_quantizer, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1088 | config->cfg.rc_min_quantizer = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1089 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.max_quantizer, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1090 | config->cfg.rc_max_quantizer = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1091 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.undershoot_pct, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1092 | config->cfg.rc_undershoot_pct = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1093 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.overshoot_pct, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1094 | config->cfg.rc_overshoot_pct = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1095 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_sz, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1096 | config->cfg.rc_buf_sz = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1097 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_initial_sz, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1098 | config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1099 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_optimal_sz, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1100 | config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1101 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.bias_pct, argi)) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1102 | config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1103 | if (global->passes < 2) |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 1104 | aom_tools_warn("option %s ignored in one-pass mode.\n", arg.name); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1105 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.minsection_pct, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1106 | config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg); |
| 1107 | |
| 1108 | if (global->passes < 2) |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 1109 | aom_tools_warn("option %s ignored in one-pass mode.\n", arg.name); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1110 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.maxsection_pct, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1111 | config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg); |
| 1112 | |
| 1113 | if (global->passes < 2) |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 1114 | aom_tools_warn("option %s ignored in one-pass mode.\n", arg.name); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1115 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.fwd_kf_enabled, argi)) { |
Sarah Parker | 93c0314 | 2018-05-22 13:35:45 -0700 | [diff] [blame] | 1116 | config->cfg.fwd_kf_enabled = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1117 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_min_dist, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1118 | config->cfg.kf_min_dist = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1119 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_max_dist, argi)) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1120 | config->cfg.kf_max_dist = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1121 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_disabled, argi)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1122 | config->cfg.kf_mode = AOM_KF_DISABLED; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1123 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_dist, argi)) { |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 1124 | config->cfg.sframe_dist = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1125 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_mode, argi)) { |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 1126 | config->cfg.sframe_mode = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1127 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.save_as_annexb, argi)) { |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 1128 | config->cfg.save_as_annexb = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1129 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_width, argi)) { |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1130 | config->cfg.tile_width_count = |
| 1131 | arg_parse_list(&arg, config->cfg.tile_widths, MAX_TILE_WIDTHS); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1132 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_height, argi)) { |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 1133 | config->cfg.tile_height_count = |
| 1134 | arg_parse_list(&arg, config->cfg.tile_heights, MAX_TILE_HEIGHTS); |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 1135 | #if CONFIG_TUNE_VMAF |
Sai Deng | d2f082e | 2021-02-09 15:19:52 -0800 | [diff] [blame] | 1136 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.vmaf_model_path, argi)) { |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 1137 | config->vmaf_model_path = arg.val; |
| 1138 | #endif |
Cheng Chen | 9164dee | 2021-04-19 23:11:38 -0700 | [diff] [blame] | 1139 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.partition_info_path, |
| 1140 | argi)) { |
| 1141 | config->partition_info_path = arg.val; |
Cheng Chen | 567038a | 2022-12-22 16:45:02 -0800 | [diff] [blame] | 1142 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.enable_rate_guide_deltaq, |
| 1143 | argi)) { |
| 1144 | config->enable_rate_guide_deltaq = arg_parse_uint(&arg); |
| 1145 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_distribution_info, |
| 1146 | argi)) { |
| 1147 | config->rate_distribution_info = arg.val; |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1148 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_fixed_qp_offsets, |
| 1149 | argi)) { |
Urvang Joshi | d6a3d66 | 2020-01-30 12:27:38 -0800 | [diff] [blame] | 1150 | config->cfg.use_fixed_qp_offsets = arg_parse_uint(&arg); |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1151 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.fixed_qp_offsets, argi)) { |
Urvang Joshi | d6a3d66 | 2020-01-30 12:27:38 -0800 | [diff] [blame] | 1152 | config->cfg.use_fixed_qp_offsets = 1; |
kyslov | 067fdf9 | 2019-05-08 12:17:53 -0700 | [diff] [blame] | 1153 | } else if (global->usage == AOM_USAGE_REALTIME && |
Bohan Li | c1d42fe | 2020-12-21 13:27:47 -0800 | [diff] [blame] | 1154 | arg_match(&arg, &g_av1_codec_arg_defs.enable_restoration, |
| 1155 | argi)) { |
kyslov | 067fdf9 | 2019-05-08 12:17:53 -0700 | [diff] [blame] | 1156 | if (arg_parse_uint(&arg) == 1) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 1157 | aom_tools_warn("non-zero %s option ignored in realtime mode.\n", |
| 1158 | arg.name); |
kyslov | 067fdf9 | 2019-05-08 12:17:53 -0700 | [diff] [blame] | 1159 | } |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 1160 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_input, argi)) { |
| 1161 | config->two_pass_input = arg.val; |
| 1162 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_output, argi)) { |
| 1163 | config->two_pass_output = arg.val; |
| 1164 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_width, argi)) { |
| 1165 | config->two_pass_width = arg_parse_int(&arg); |
| 1166 | } else if (arg_match(&arg, &g_av1_codec_arg_defs.two_pass_height, argi)) { |
| 1167 | config->two_pass_height = arg_parse_int(&arg); |
Deb Mukherjee | 25f22d2 | 2014-02-13 15:34:42 -0800 | [diff] [blame] | 1168 | } else { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1169 | int i, match = 0; |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 1170 | // check if the control ID API supports this arg |
| 1171 | if (ctrl_args_map) { |
| 1172 | for (i = 0; ctrl_args[i]; i++) { |
| 1173 | if (arg_match(&arg, ctrl_args[i], argi)) { |
| 1174 | match = 1; |
Imdad Sardharwalla | 3ab64bd | 2017-12-13 15:03:53 +0000 | [diff] [blame] | 1175 | set_config_arg_ctrls(config, ctrl_args_map[i], &arg); |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 1176 | break; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1177 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1178 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1179 | } |
Bohan Li | 67c3ce0 | 2021-02-25 12:10:29 -0800 | [diff] [blame] | 1180 | if (!match) { |
| 1181 | // check if the key & value API supports this arg |
| 1182 | for (i = 0; key_val_args[i]; i++) { |
| 1183 | if (arg_match(&arg, key_val_args[i], argi)) { |
| 1184 | match = 1; |
| 1185 | set_config_arg_key_vals(config, key_val_args[i]->long_name, &arg); |
| 1186 | break; |
| 1187 | } |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 1188 | } |
| 1189 | } |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1190 | if (!match) argj++; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1191 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1192 | } |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 1193 | config->use_16bit_internal |= config->cfg.g_bit_depth > AOM_BITS_8; |
| 1194 | |
Fyodor Kyslov | 8fbe1b9 | 2020-07-29 15:54:14 -0700 | [diff] [blame] | 1195 | if (global->usage == AOM_USAGE_REALTIME && config->cfg.g_lag_in_frames != 0) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 1196 | aom_tools_warn("non-zero lag-in-frames option ignored in realtime mode.\n"); |
Fyodor Kyslov | 8fbe1b9 | 2020-07-29 15:54:14 -0700 | [diff] [blame] | 1197 | config->cfg.g_lag_in_frames = 0; |
| 1198 | } |
Jingning Han | 14bfd94 | 2021-02-11 15:18:29 -0800 | [diff] [blame] | 1199 | |
| 1200 | if (global->usage == AOM_USAGE_ALL_INTRA) { |
| 1201 | if (config->cfg.g_lag_in_frames != 0) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 1202 | aom_tools_warn( |
| 1203 | "non-zero lag-in-frames option ignored in all intra mode.\n"); |
Jingning Han | 14bfd94 | 2021-02-11 15:18:29 -0800 | [diff] [blame] | 1204 | config->cfg.g_lag_in_frames = 0; |
| 1205 | } |
| 1206 | if (config->cfg.kf_max_dist != 0) { |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 1207 | aom_tools_warn( |
Jingning Han | 14bfd94 | 2021-02-11 15:18:29 -0800 | [diff] [blame] | 1208 | "non-zero max key frame distance option ignored in all intra " |
| 1209 | "mode.\n"); |
| 1210 | config->cfg.kf_max_dist = 0; |
| 1211 | } |
| 1212 | } |
Bohan Li | 445fdf6 | 2021-06-03 16:16:00 -0700 | [diff] [blame] | 1213 | |
| 1214 | // set the passes field using key & val API |
| 1215 | if (config->arg_key_val_cnt >= ARG_KEY_VAL_CNT_MAX) { |
| 1216 | die("Not enough buffer for the key & value API."); |
| 1217 | } |
| 1218 | config->arg_key_vals[config->arg_key_val_cnt][0] = "passes"; |
| 1219 | switch (global->passes) { |
| 1220 | case 0: config->arg_key_vals[config->arg_key_val_cnt][1] = "0"; break; |
| 1221 | case 1: config->arg_key_vals[config->arg_key_val_cnt][1] = "1"; break; |
| 1222 | case 2: config->arg_key_vals[config->arg_key_val_cnt][1] = "2"; break; |
| 1223 | case 3: config->arg_key_vals[config->arg_key_val_cnt][1] = "3"; break; |
| 1224 | default: die("Invalid value of --passes."); |
| 1225 | } |
| 1226 | config->arg_key_val_cnt++; |
| 1227 | |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 1228 | // set the two_pass_output field |
| 1229 | if (!config->two_pass_output && global->passes == 3) { |
Bohan Li | b5c7e34 | 2021-11-03 13:32:03 -0700 | [diff] [blame] | 1230 | // If not specified, set the name of two_pass_output file here. |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 1231 | snprintf(stream->tmp_out_fn, sizeof(stream->tmp_out_fn), |
Bohan Li | b5c7e34 | 2021-11-03 13:32:03 -0700 | [diff] [blame] | 1232 | "%.980s_pass2_%d.ivf", stream->config.out_fn, stream->index); |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 1233 | stream->config.two_pass_output = stream->tmp_out_fn; |
| 1234 | } |
| 1235 | if (config->two_pass_output) { |
| 1236 | config->arg_key_vals[config->arg_key_val_cnt][0] = "two-pass-output"; |
| 1237 | config->arg_key_vals[config->arg_key_val_cnt][1] = config->two_pass_output; |
| 1238 | config->arg_key_val_cnt++; |
| 1239 | } |
| 1240 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1241 | return eos_mark_found; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 1244 | #define FOREACH_STREAM(iterator, list) \ |
| 1245 | for (struct stream_state *iterator = list; iterator; \ |
| 1246 | iterator = iterator->next) |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1247 | |
Alex Converse | d66bd22 | 2014-02-21 10:52:09 -0800 | [diff] [blame] | 1248 | static void validate_stream_config(const struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1249 | const struct AvxEncoderConfig *global) { |
Alex Converse | d66bd22 | 2014-02-21 10:52:09 -0800 | [diff] [blame] | 1250 | const struct stream_state *streami; |
Johann | 80b344d | 2014-12-16 12:22:10 -0800 | [diff] [blame] | 1251 | (void)global; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1252 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1253 | if (!stream->config.cfg.g_w || !stream->config.cfg.g_h) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1254 | fatal( |
| 1255 | "Stream %d: Specify stream dimensions with --width (-w) " |
| 1256 | " and --height (-h)", |
| 1257 | stream->index); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1258 | |
elliottk | 7a16247 | 2018-09-25 15:06:24 -0700 | [diff] [blame] | 1259 | /* Even if bit depth is set on the command line flag to be lower, |
| 1260 | * it is upgraded to at least match the input bit depth. |
| 1261 | */ |
| 1262 | assert(stream->config.cfg.g_input_bit_depth <= |
| 1263 | (unsigned int)stream->config.cfg.g_bit_depth); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1264 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1265 | for (streami = stream; streami; streami = streami->next) { |
| 1266 | /* All streams require output files */ |
| 1267 | if (!streami->config.out_fn) |
| 1268 | fatal("Stream %d: Output file is required (specify with -o)", |
| 1269 | streami->index); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1270 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1271 | /* Check for two streams outputting to the same file */ |
| 1272 | if (streami != stream) { |
| 1273 | const char *a = stream->config.out_fn; |
| 1274 | const char *b = streami->config.out_fn; |
| 1275 | if (!strcmp(a, b) && strcmp(a, "/dev/null") && strcmp(a, ":nul")) |
| 1276 | fatal("Stream %d: duplicate output file (from stream %d)", |
| 1277 | streami->index, stream->index); |
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 | |
| 1280 | /* Check for two streams sharing a stats file. */ |
| 1281 | if (streami != stream) { |
| 1282 | const char *a = stream->config.stats_fn; |
| 1283 | const char *b = streami->config.stats_fn; |
| 1284 | if (a && b && !strcmp(a, b)) |
| 1285 | fatal("Stream %d: duplicate stats file (from stream %d)", |
| 1286 | streami->index, stream->index); |
| 1287 | } |
| 1288 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1289 | } |
| 1290 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1291 | static void set_stream_dimensions(struct stream_state *stream, unsigned int w, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1292 | unsigned int h) { |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1293 | if (!stream->config.cfg.g_w) { |
| 1294 | if (!stream->config.cfg.g_h) |
| 1295 | stream->config.cfg.g_w = w; |
| 1296 | else |
| 1297 | stream->config.cfg.g_w = w * stream->config.cfg.g_h / h; |
| 1298 | } |
| 1299 | if (!stream->config.cfg.g_h) { |
| 1300 | stream->config.cfg.g_h = h * stream->config.cfg.g_w / w; |
| 1301 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1302 | } |
| 1303 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1304 | static const char *file_type_to_string(enum VideoFileType t) { |
Alex Converse | 6c2e88e | 2014-05-16 12:29:36 -0700 | [diff] [blame] | 1305 | switch (t) { |
| 1306 | case FILE_TYPE_RAW: return "RAW"; |
| 1307 | case FILE_TYPE_Y4M: return "Y4M"; |
| 1308 | default: return "Other"; |
| 1309 | } |
| 1310 | } |
| 1311 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1312 | static void show_stream_config(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1313 | struct AvxEncoderConfig *global, |
| 1314 | struct AvxInputContext *input) { |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1315 | #define SHOW(field) \ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1316 | fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field) |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1317 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1318 | if (stream->index == 0) { |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 1319 | fprintf(stderr, "Codec: %s\n", aom_codec_iface_name(global->codec)); |
Alex Converse | 6c2e88e | 2014-05-16 12:29:36 -0700 | [diff] [blame] | 1320 | fprintf(stderr, "Source file: %s File Type: %s Format: %s\n", |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1321 | input->filename, file_type_to_string(input->file_type), |
Alex Converse | 6c2e88e | 2014-05-16 12:29:36 -0700 | [diff] [blame] | 1322 | image_format_to_string(input->fmt)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1323 | } |
| 1324 | if (stream->next || stream->index) |
| 1325 | fprintf(stderr, "\nStream Index: %d\n", stream->index); |
| 1326 | fprintf(stderr, "Destination file: %s\n", stream->config.out_fn); |
Sebastien Alaiwan | 2751192 | 2017-06-05 15:25:46 +0200 | [diff] [blame] | 1327 | fprintf(stderr, "Coding path: %s\n", |
| 1328 | stream->config.use_16bit_internal ? "HBD" : "LBD"); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1329 | fprintf(stderr, "Encoder parameters:\n"); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1330 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1331 | SHOW(g_usage); |
| 1332 | SHOW(g_threads); |
| 1333 | SHOW(g_profile); |
| 1334 | SHOW(g_w); |
| 1335 | SHOW(g_h); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1336 | SHOW(g_bit_depth); |
| 1337 | SHOW(g_input_bit_depth); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1338 | SHOW(g_timebase.num); |
| 1339 | SHOW(g_timebase.den); |
| 1340 | SHOW(g_error_resilient); |
| 1341 | SHOW(g_pass); |
| 1342 | SHOW(g_lag_in_frames); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1343 | SHOW(large_scale_tile); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1344 | SHOW(rc_dropframe_thresh); |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 1345 | SHOW(rc_resize_mode); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1346 | SHOW(rc_resize_denominator); |
| 1347 | SHOW(rc_resize_kf_denominator); |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 1348 | SHOW(rc_superres_mode); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1349 | SHOW(rc_superres_denominator); |
| 1350 | SHOW(rc_superres_kf_denominator); |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 1351 | SHOW(rc_superres_qthresh); |
| 1352 | SHOW(rc_superres_kf_qthresh); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1353 | SHOW(rc_end_usage); |
| 1354 | SHOW(rc_target_bitrate); |
| 1355 | SHOW(rc_min_quantizer); |
| 1356 | SHOW(rc_max_quantizer); |
| 1357 | SHOW(rc_undershoot_pct); |
| 1358 | SHOW(rc_overshoot_pct); |
| 1359 | SHOW(rc_buf_sz); |
| 1360 | SHOW(rc_buf_initial_sz); |
| 1361 | SHOW(rc_buf_optimal_sz); |
| 1362 | SHOW(rc_2pass_vbr_bias_pct); |
| 1363 | SHOW(rc_2pass_vbr_minsection_pct); |
| 1364 | SHOW(rc_2pass_vbr_maxsection_pct); |
Sarah Parker | 93c0314 | 2018-05-22 13:35:45 -0700 | [diff] [blame] | 1365 | SHOW(fwd_kf_enabled); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1366 | SHOW(kf_mode); |
| 1367 | SHOW(kf_min_dist); |
| 1368 | SHOW(kf_max_dist); |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 1369 | |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 1370 | #define SHOW_PARAMS(field) \ |
| 1371 | fprintf(stderr, " %-28s = %d\n", #field, \ |
| 1372 | stream->config.cfg.encoder_cfg.field) |
Yaowu Xu | c851d28 | 2020-06-15 15:28:22 -0700 | [diff] [blame] | 1373 | if (global->encoder_config.init_by_cfg_file) { |
| 1374 | SHOW_PARAMS(super_block_size); |
| 1375 | SHOW_PARAMS(max_partition_size); |
| 1376 | SHOW_PARAMS(min_partition_size); |
| 1377 | SHOW_PARAMS(disable_ab_partition_type); |
| 1378 | SHOW_PARAMS(disable_rect_partition_type); |
| 1379 | SHOW_PARAMS(disable_1to4_partition_type); |
| 1380 | SHOW_PARAMS(disable_flip_idtx); |
| 1381 | SHOW_PARAMS(disable_cdef); |
| 1382 | SHOW_PARAMS(disable_lr); |
| 1383 | SHOW_PARAMS(disable_obmc); |
| 1384 | SHOW_PARAMS(disable_warp_motion); |
| 1385 | SHOW_PARAMS(disable_global_motion); |
| 1386 | SHOW_PARAMS(disable_dist_wtd_comp); |
| 1387 | SHOW_PARAMS(disable_diff_wtd_comp); |
| 1388 | SHOW_PARAMS(disable_inter_intra_comp); |
| 1389 | SHOW_PARAMS(disable_masked_comp); |
| 1390 | SHOW_PARAMS(disable_one_sided_comp); |
| 1391 | SHOW_PARAMS(disable_palette); |
| 1392 | SHOW_PARAMS(disable_intrabc); |
| 1393 | SHOW_PARAMS(disable_cfl); |
| 1394 | SHOW_PARAMS(disable_smooth_intra); |
| 1395 | SHOW_PARAMS(disable_filter_intra); |
| 1396 | SHOW_PARAMS(disable_dual_filter); |
| 1397 | SHOW_PARAMS(disable_intra_angle_delta); |
| 1398 | SHOW_PARAMS(disable_intra_edge_filter); |
| 1399 | SHOW_PARAMS(disable_tx_64x64); |
| 1400 | SHOW_PARAMS(disable_smooth_inter_intra); |
| 1401 | SHOW_PARAMS(disable_inter_inter_wedge); |
| 1402 | SHOW_PARAMS(disable_inter_intra_wedge); |
| 1403 | SHOW_PARAMS(disable_paeth_intra); |
| 1404 | SHOW_PARAMS(disable_trellis_quant); |
| 1405 | SHOW_PARAMS(disable_ref_frame_mv); |
| 1406 | SHOW_PARAMS(reduced_reference_set); |
| 1407 | SHOW_PARAMS(reduced_tx_type_set); |
| 1408 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1409 | } |
| 1410 | |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1411 | static void open_output_file(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1412 | struct AvxEncoderConfig *global, |
Elliott Karpilovsky | 4e55eb7 | 2020-05-14 14:16:24 -0700 | [diff] [blame] | 1413 | const struct AvxRational *pixel_aspect_ratio, |
| 1414 | const char *encoder_settings) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1415 | const char *fn = stream->config.out_fn; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1416 | const struct aom_codec_enc_cfg *const cfg = &stream->config.cfg; |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1417 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1418 | if (cfg->g_pass == AOM_RC_FIRST_PASS) return; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1419 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1420 | stream->file = strcmp(fn, "-") ? fopen(fn, "wb") : set_binary_mode(stdout); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1421 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1422 | if (!stream->file) fatal("Failed to open output file"); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1423 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1424 | if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR)) |
| 1425 | fatal("WebM output to pipes not supported."); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1426 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1427 | #if CONFIG_WEBM_IO |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1428 | if (stream->config.write_webm) { |
Vignesh Venkatasubramanian | 9441f10 | 2016-04-25 13:28:24 -0700 | [diff] [blame] | 1429 | stream->webm_ctx.stream = stream->file; |
Tom Finegan | bb8157b | 2018-09-20 15:33:11 -0700 | [diff] [blame] | 1430 | if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg, |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 1431 | stream->config.stereo_fmt, |
| 1432 | get_fourcc_by_aom_encoder(global->codec), |
Elliott Karpilovsky | 4e55eb7 | 2020-05-14 14:16:24 -0700 | [diff] [blame] | 1433 | pixel_aspect_ratio, encoder_settings) != 0) { |
Tom Finegan | bb8157b | 2018-09-20 15:33:11 -0700 | [diff] [blame] | 1434 | fatal("WebM writer initialization failed."); |
| 1435 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1436 | } |
James Zern | c8e5a77 | 2016-02-11 18:53:50 -0800 | [diff] [blame] | 1437 | #else |
| 1438 | (void)pixel_aspect_ratio; |
Elliott Karpilovsky | 4e55eb7 | 2020-05-14 14:16:24 -0700 | [diff] [blame] | 1439 | (void)encoder_settings; |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1440 | #endif |
| 1441 | |
Tom Finegan | 61b71ab | 2018-03-22 15:58:38 -0700 | [diff] [blame] | 1442 | if (!stream->config.write_webm && stream->config.write_ivf) { |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 1443 | ivf_write_file_header(stream->file, cfg, |
| 1444 | get_fourcc_by_aom_encoder(global->codec), 0); |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1445 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1448 | static void close_output_file(struct stream_state *stream, |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1449 | unsigned int fourcc) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1450 | const struct aom_codec_enc_cfg *const cfg = &stream->config.cfg; |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1451 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1452 | if (cfg->g_pass == AOM_RC_FIRST_PASS) return; |
Dmitry Kovalev | 096ab11 | 2014-01-13 15:21:48 -0800 | [diff] [blame] | 1453 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1454 | #if CONFIG_WEBM_IO |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1455 | if (stream->config.write_webm) { |
Tom Finegan | bb8157b | 2018-09-20 15:33:11 -0700 | [diff] [blame] | 1456 | if (write_webm_file_footer(&stream->webm_ctx) != 0) { |
| 1457 | fatal("WebM writer finalization failed."); |
| 1458 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1459 | } |
| 1460 | #endif |
| 1461 | |
Tom Finegan | 61b71ab | 2018-03-22 15:58:38 -0700 | [diff] [blame] | 1462 | if (!stream->config.write_webm && stream->config.write_ivf) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1463 | if (!fseek(stream->file, 0, SEEK_SET)) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1464 | ivf_write_file_header(stream->file, &stream->config.cfg, fourcc, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1465 | stream->frames_out); |
| 1466 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1467 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1468 | fclose(stream->file); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1469 | } |
| 1470 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1471 | static void setup_pass(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1472 | struct AvxEncoderConfig *global, int pass) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1473 | if (stream->config.stats_fn) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1474 | if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass)) |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1475 | fatal("Failed to open statistics store"); |
| 1476 | } else { |
| 1477 | if (!stats_open_mem(&stream->stats, pass)) |
| 1478 | fatal("Failed to open statistics store"); |
| 1479 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1480 | |
Bohan Li | 445fdf6 | 2021-06-03 16:16:00 -0700 | [diff] [blame] | 1481 | if (global->passes == 1) { |
| 1482 | stream->config.cfg.g_pass = AOM_RC_ONE_PASS; |
| 1483 | } else { |
| 1484 | switch (pass) { |
| 1485 | case 0: stream->config.cfg.g_pass = AOM_RC_FIRST_PASS; break; |
| 1486 | case 1: stream->config.cfg.g_pass = AOM_RC_SECOND_PASS; break; |
| 1487 | case 2: stream->config.cfg.g_pass = AOM_RC_THIRD_PASS; break; |
| 1488 | default: fatal("Failed to set pass"); |
| 1489 | } |
| 1490 | } |
| 1491 | |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1492 | if (pass) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1493 | stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats); |
Pengchong Jin | f349b07 | 2014-07-14 09:13:38 -0700 | [diff] [blame] | 1494 | } |
Yunqing Wang | aabae97 | 2012-02-29 08:24:53 -0500 | [diff] [blame] | 1495 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1496 | stream->cx_time = 0; |
| 1497 | stream->nbytes = 0; |
| 1498 | stream->frames_out = 0; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1499 | } |
| 1500 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1501 | static void initialize_encoder(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1502 | struct AvxEncoderConfig *global) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1503 | int i; |
| 1504 | int flags = 0; |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 1505 | |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1506 | flags |= (global->show_psnr >= 1) ? AOM_CODEC_USE_PSNR : 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1507 | flags |= stream->config.use_16bit_internal ? AOM_CODEC_USE_HIGHBITDEPTH : 0; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1508 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1509 | /* Construct Encoder Context */ |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 1510 | aom_codec_enc_init(&stream->encoder, global->codec, &stream->config.cfg, |
| 1511 | flags); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1512 | ctx_exit_on_error(&stream->encoder, "Failed to initialize encoder"); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1513 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1514 | for (i = 0; i < stream->config.arg_ctrl_cnt; i++) { |
| 1515 | int ctrl = stream->config.arg_ctrls[i][0]; |
| 1516 | int value = stream->config.arg_ctrls[i][1]; |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1517 | if (aom_codec_control(&stream->encoder, ctrl, value)) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1518 | fprintf(stderr, "Error: Tried to set control %d = %d\n", ctrl, value); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1519 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1520 | ctx_exit_on_error(&stream->encoder, "Failed to control codec"); |
| 1521 | } |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 1522 | |
Bohan Li | 77edd8c | 2021-02-04 16:07:34 -0800 | [diff] [blame] | 1523 | for (i = 0; i < stream->config.arg_key_val_cnt; i++) { |
| 1524 | const char *name = stream->config.arg_key_vals[i][0]; |
| 1525 | const char *val = stream->config.arg_key_vals[i][1]; |
| 1526 | if (aom_codec_set_option(&stream->encoder, name, val)) |
| 1527 | fprintf(stderr, "Error: Tried to set option %s = %s\n", name, val); |
| 1528 | |
| 1529 | ctx_exit_on_error(&stream->encoder, "Failed to set codec option"); |
| 1530 | } |
| 1531 | |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 1532 | #if CONFIG_TUNE_VMAF |
| 1533 | if (stream->config.vmaf_model_path) { |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1534 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AV1E_SET_VMAF_MODEL_PATH, |
| 1535 | stream->config.vmaf_model_path); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 1536 | ctx_exit_on_error(&stream->encoder, "Failed to set vmaf model path"); |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 1537 | } |
| 1538 | #endif |
Cheng Chen | 9164dee | 2021-04-19 23:11:38 -0700 | [diff] [blame] | 1539 | if (stream->config.partition_info_path) { |
| 1540 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, |
| 1541 | AV1E_SET_PARTITION_INFO_PATH, |
| 1542 | stream->config.partition_info_path); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 1543 | ctx_exit_on_error(&stream->encoder, "Failed to set partition info path"); |
Cheng Chen | 9164dee | 2021-04-19 23:11:38 -0700 | [diff] [blame] | 1544 | } |
Cheng Chen | 567038a | 2022-12-22 16:45:02 -0800 | [diff] [blame] | 1545 | if (stream->config.enable_rate_guide_deltaq) { |
| 1546 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, |
| 1547 | AV1E_ENABLE_RATE_GUIDE_DELTAQ, |
| 1548 | stream->config.enable_rate_guide_deltaq); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 1549 | ctx_exit_on_error(&stream->encoder, "Failed to enable rate guide deltaq"); |
Cheng Chen | 567038a | 2022-12-22 16:45:02 -0800 | [diff] [blame] | 1550 | } |
| 1551 | if (stream->config.rate_distribution_info) { |
| 1552 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, |
| 1553 | AV1E_SET_RATE_DISTRIBUTION_INFO, |
| 1554 | stream->config.rate_distribution_info); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 1555 | ctx_exit_on_error(&stream->encoder, "Failed to set rate distribution info"); |
Cheng Chen | 567038a | 2022-12-22 16:45:02 -0800 | [diff] [blame] | 1556 | } |
sdeng | 29c6215 | 2019-12-09 12:44:18 -0800 | [diff] [blame] | 1557 | |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 1558 | if (stream->config.film_grain_filename) { |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1559 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AV1E_SET_FILM_GRAIN_TABLE, |
| 1560 | stream->config.film_grain_filename); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 1561 | ctx_exit_on_error(&stream->encoder, "Failed to set film grain table"); |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 1562 | } |
Elliott Karpilovsky | b2d8258 | 2021-02-02 22:49:56 -0800 | [diff] [blame] | 1563 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AV1E_SET_COLOR_RANGE, |
| 1564 | stream->config.color_range); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 1565 | ctx_exit_on_error(&stream->encoder, "Failed to set color range"); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1566 | |
Tom Finegan | ba02c24 | 2017-05-16 15:01:54 -0700 | [diff] [blame] | 1567 | #if CONFIG_AV1_DECODER |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1568 | if (global->test_decode != TEST_DECODE_OFF) { |
Elliott Karpilovsky | 67e84d4 | 2020-04-26 16:03:39 -0700 | [diff] [blame] | 1569 | aom_codec_iface_t *decoder = get_aom_decoder_by_short_name( |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 1570 | get_short_name_by_aom_encoder(global->codec)); |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 1571 | aom_codec_dec_cfg_t cfg = { 0, 0, 0, !stream->config.use_16bit_internal }; |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 1572 | aom_codec_dec_init(&stream->decoder, decoder, &cfg, 0); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 1573 | |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 1574 | if (strcmp(get_short_name_by_aom_encoder(global->codec), "av1") == 0) { |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1575 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_SET_TILE_MODE, |
| 1576 | stream->config.cfg.large_scale_tile); |
Yunqing Wang | 8ae64a9 | 2018-01-12 12:26:44 -0800 | [diff] [blame] | 1577 | ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_mode"); |
| 1578 | |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1579 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1D_SET_IS_ANNEXB, |
| 1580 | stream->config.cfg.save_as_annexb); |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 1581 | ctx_exit_on_error(&stream->decoder, "Failed to set is_annexb"); |
| 1582 | |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1583 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_SET_DECODE_TILE_ROW, |
| 1584 | -1); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 1585 | ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_row"); |
| 1586 | |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1587 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_SET_DECODE_TILE_COL, |
| 1588 | -1); |
Yunqing Wang | 8e5e338 | 2016-05-05 16:42:57 -0700 | [diff] [blame] | 1589 | ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_col"); |
| 1590 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1591 | } |
John Koleszar | 5ebe94f | 2012-12-23 07:20:10 -0800 | [diff] [blame] | 1592 | #endif |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
Wan-Teh Chang | 5c9bc41 | 2021-04-13 10:12:20 -0700 | [diff] [blame] | 1595 | // Convert the input image 'img' to a monochrome image. The Y plane of the |
| 1596 | // output image is a shallow copy of the Y plane of the input image, therefore |
| 1597 | // the input image must remain valid for the lifetime of the output image. The U |
| 1598 | // and V planes of the output image are set to null pointers. The output image |
| 1599 | // format is AOM_IMG_FMT_I420 because libaom does not have AOM_IMG_FMT_I400. |
| 1600 | static void convert_image_to_monochrome(const struct aom_image *img, |
| 1601 | struct aom_image *monochrome_img) { |
| 1602 | *monochrome_img = *img; |
| 1603 | monochrome_img->fmt = AOM_IMG_FMT_I420; |
| 1604 | if (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
| 1605 | monochrome_img->fmt |= AOM_IMG_FMT_HIGHBITDEPTH; |
| 1606 | } |
| 1607 | monochrome_img->monochrome = 1; |
| 1608 | monochrome_img->csp = AOM_CSP_UNKNOWN; |
| 1609 | monochrome_img->x_chroma_shift = 1; |
| 1610 | monochrome_img->y_chroma_shift = 1; |
| 1611 | monochrome_img->planes[AOM_PLANE_U] = NULL; |
| 1612 | monochrome_img->planes[AOM_PLANE_V] = NULL; |
| 1613 | monochrome_img->stride[AOM_PLANE_U] = 0; |
| 1614 | monochrome_img->stride[AOM_PLANE_V] = 0; |
| 1615 | monochrome_img->sz = 0; |
| 1616 | monochrome_img->bps = (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 16 : 8; |
| 1617 | monochrome_img->img_data = NULL; |
| 1618 | monochrome_img->img_data_owner = 0; |
| 1619 | monochrome_img->self_allocd = 0; |
| 1620 | } |
| 1621 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1622 | static void encode_frame(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1623 | struct AvxEncoderConfig *global, struct aom_image *img, |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1624 | unsigned int frames_in) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1625 | aom_codec_pts_t frame_start, next_frame_start; |
| 1626 | struct aom_codec_enc_cfg *cfg = &stream->config.cfg; |
| 1627 | struct aom_usec_timer timer; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1628 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1629 | frame_start = |
| 1630 | (cfg->g_timebase.den * (int64_t)(frames_in - 1) * global->framerate.den) / |
| 1631 | cfg->g_timebase.num / global->framerate.num; |
| 1632 | next_frame_start = |
| 1633 | (cfg->g_timebase.den * (int64_t)(frames_in)*global->framerate.den) / |
| 1634 | cfg->g_timebase.num / global->framerate.num; |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1635 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 1636 | /* Scale if necessary */ |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1637 | if (img) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1638 | if ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) && |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1639 | (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1640 | if (img->fmt != AOM_IMG_FMT_I42016) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1641 | fprintf(stderr, "%s can only scale 4:2:0 inputs\n", exec_name); |
| 1642 | exit(EXIT_FAILURE); |
| 1643 | } |
| 1644 | #if CONFIG_LIBYUV |
| 1645 | if (!stream->img) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1646 | stream->img = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1647 | 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] | 1648 | } |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1649 | I420Scale_16( |
Mirko Bonadei | 8a63418 | 2018-08-03 23:09:09 -0700 | [diff] [blame] | 1650 | (uint16_t *)img->planes[AOM_PLANE_Y], img->stride[AOM_PLANE_Y] / 2, |
| 1651 | (uint16_t *)img->planes[AOM_PLANE_U], img->stride[AOM_PLANE_U] / 2, |
| 1652 | (uint16_t *)img->planes[AOM_PLANE_V], img->stride[AOM_PLANE_V] / 2, |
| 1653 | img->d_w, img->d_h, (uint16_t *)stream->img->planes[AOM_PLANE_Y], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1654 | stream->img->stride[AOM_PLANE_Y] / 2, |
Mirko Bonadei | 8a63418 | 2018-08-03 23:09:09 -0700 | [diff] [blame] | 1655 | (uint16_t *)stream->img->planes[AOM_PLANE_U], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1656 | stream->img->stride[AOM_PLANE_U] / 2, |
Mirko Bonadei | 8a63418 | 2018-08-03 23:09:09 -0700 | [diff] [blame] | 1657 | (uint16_t *)stream->img->planes[AOM_PLANE_V], |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1658 | stream->img->stride[AOM_PLANE_V] / 2, stream->img->d_w, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1659 | stream->img->d_h, kFilterBox); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1660 | img = stream->img; |
| 1661 | #else |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1662 | stream->encoder.err = 1; |
| 1663 | ctx_exit_on_error(&stream->encoder, |
| 1664 | "Stream %d: Failed to encode frame.\n" |
Johann | e07a675 | 2018-01-10 12:47:44 -0800 | [diff] [blame] | 1665 | "libyuv is required for scaling but is currently " |
| 1666 | "disabled.\n" |
| 1667 | "Be sure to specify -DCONFIG_LIBYUV=1 when running " |
| 1668 | "cmake.\n", |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1669 | stream->index); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1670 | #endif |
| 1671 | } |
| 1672 | } |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1673 | 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] | 1674 | 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] | 1675 | fprintf(stderr, "%s can only scale 4:2:0 8bpp inputs\n", exec_name); |
| 1676 | exit(EXIT_FAILURE); |
| 1677 | } |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 1678 | #if CONFIG_LIBYUV |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1679 | if (!stream->img) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1680 | stream->img = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1681 | 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] | 1682 | I420Scale( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1683 | img->planes[AOM_PLANE_Y], img->stride[AOM_PLANE_Y], |
| 1684 | img->planes[AOM_PLANE_U], img->stride[AOM_PLANE_U], |
| 1685 | img->planes[AOM_PLANE_V], img->stride[AOM_PLANE_V], img->d_w, img->d_h, |
| 1686 | stream->img->planes[AOM_PLANE_Y], stream->img->stride[AOM_PLANE_Y], |
| 1687 | stream->img->planes[AOM_PLANE_U], stream->img->stride[AOM_PLANE_U], |
| 1688 | stream->img->planes[AOM_PLANE_V], stream->img->stride[AOM_PLANE_V], |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1689 | stream->img->d_w, stream->img->d_h, kFilterBox); |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1690 | img = stream->img; |
Deb Mukherjee | 47031c0 | 2014-05-16 18:52:01 -0700 | [diff] [blame] | 1691 | #else |
| 1692 | stream->encoder.err = 1; |
| 1693 | ctx_exit_on_error(&stream->encoder, |
| 1694 | "Stream %d: Failed to encode frame.\n" |
| 1695 | "Scaling disabled in this configuration. \n" |
| 1696 | "To enable, configure with --enable-libyuv\n", |
| 1697 | stream->index); |
| 1698 | #endif |
John Koleszar | 34882b9 | 2012-03-01 12:50:40 -0800 | [diff] [blame] | 1699 | } |
| 1700 | |
Wan-Teh Chang | 5c9bc41 | 2021-04-13 10:12:20 -0700 | [diff] [blame] | 1701 | struct aom_image monochrome_img; |
| 1702 | if (img && cfg->monochrome) { |
| 1703 | convert_image_to_monochrome(img, &monochrome_img); |
| 1704 | img = &monochrome_img; |
| 1705 | } |
| 1706 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1707 | aom_usec_timer_start(&timer); |
| 1708 | aom_codec_encode(&stream->encoder, img, frame_start, |
Sean DuBois | 47cc255 | 2018-01-23 07:44:16 +0000 | [diff] [blame] | 1709 | (uint32_t)(next_frame_start - frame_start), 0); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1710 | aom_usec_timer_mark(&timer); |
| 1711 | stream->cx_time += aom_usec_timer_elapsed(&timer); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1712 | ctx_exit_on_error(&stream->encoder, "Stream %d: Failed to encode frame", |
| 1713 | stream->index); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1714 | } |
| 1715 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1716 | static void update_quantizer_histogram(struct stream_state *stream) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1717 | if (stream->config.cfg.g_pass != AOM_RC_FIRST_PASS) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1718 | int q; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1719 | |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1720 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AOME_GET_LAST_QUANTIZER_64, |
| 1721 | &q); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1722 | ctx_exit_on_error(&stream->encoder, "Failed to read quantizer"); |
| 1723 | stream->counts[q]++; |
| 1724 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1725 | } |
| 1726 | |
Tom Finegan | 49dc9ca | 2013-11-21 16:46:40 -0800 | [diff] [blame] | 1727 | static void get_cx_data(struct stream_state *stream, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1728 | struct AvxEncoderConfig *global, int *got_data) { |
| 1729 | const aom_codec_cx_pkt_t *pkt; |
| 1730 | const struct aom_codec_enc_cfg *cfg = &stream->config.cfg; |
| 1731 | aom_codec_iter_t iter = NULL; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1732 | |
Ronald S. Bultje | 88d703c | 2012-11-09 09:07:50 -0800 | [diff] [blame] | 1733 | *got_data = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1734 | while ((pkt = aom_codec_get_cx_data(&stream->encoder, &iter))) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1735 | static size_t fsize = 0; |
James Zern | b643036 | 2017-01-14 14:18:01 -0800 | [diff] [blame] | 1736 | static FileOffset ivf_header_pos = 0; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1737 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1738 | switch (pkt->kind) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1739 | case AOM_CODEC_CX_FRAME_PKT: |
Urvang Joshi | 22043ef | 2018-09-27 12:41:17 -0700 | [diff] [blame] | 1740 | ++stream->frames_out; |
Jingning Han | babbd5d | 2013-02-13 09:03:21 -0800 | [diff] [blame] | 1741 | if (!global->quiet) |
| 1742 | fprintf(stderr, " %6luF", (unsigned long)pkt->data.frame.sz); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1743 | |
Dmitry Kovalev | f11da2b | 2014-01-29 12:28:29 -0800 | [diff] [blame] | 1744 | update_rate_histogram(stream->rate_hist, cfg, pkt); |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1745 | #if CONFIG_WEBM_IO |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1746 | if (stream->config.write_webm) { |
Tom Finegan | bb8157b | 2018-09-20 15:33:11 -0700 | [diff] [blame] | 1747 | if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) { |
| 1748 | fatal("WebM writer failed."); |
| 1749 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 1750 | } |
| 1751 | #endif |
| 1752 | if (!stream->config.write_webm) { |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 1753 | if (stream->config.write_ivf) { |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 1754 | if (pkt->data.frame.partition_id <= 0) { |
| 1755 | ivf_header_pos = ftello(stream->file); |
| 1756 | fsize = pkt->data.frame.sz; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1757 | |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 1758 | ivf_write_frame_header(stream->file, pkt->data.frame.pts, fsize); |
| 1759 | } else { |
| 1760 | fsize += pkt->data.frame.sz; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1761 | |
Urvang Joshi | 22043ef | 2018-09-27 12:41:17 -0700 | [diff] [blame] | 1762 | const FileOffset currpos = ftello(stream->file); |
| 1763 | fseeko(stream->file, ivf_header_pos, SEEK_SET); |
| 1764 | ivf_write_frame_size(stream->file, fsize); |
| 1765 | fseeko(stream->file, currpos, SEEK_SET); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1766 | } |
| 1767 | } |
| 1768 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1769 | (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, |
| 1770 | stream->file); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1771 | } |
| 1772 | stream->nbytes += pkt->data.raw.sz; |
Attila Nagy | 52cf4dc | 2012-02-09 12:37:03 +0200 | [diff] [blame] | 1773 | |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1774 | *got_data = 1; |
Tom Finegan | ba02c24 | 2017-05-16 15:01:54 -0700 | [diff] [blame] | 1775 | #if CONFIG_AV1_DECODER |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1776 | if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1777 | aom_codec_decode(&stream->decoder, pkt->data.frame.buf, |
Wan-Teh Chang | 84b22b8 | 2018-05-16 14:56:28 -0700 | [diff] [blame] | 1778 | pkt->data.frame.sz, NULL); |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1779 | if (stream->decoder.err) { |
| 1780 | warn_or_exit_on_error(&stream->decoder, |
| 1781 | global->test_decode == TEST_DECODE_FATAL, |
| 1782 | "Failed to decode frame %d in stream %d", |
| 1783 | stream->frames_out + 1, stream->index); |
| 1784 | stream->mismatch_seen = stream->frames_out + 1; |
| 1785 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1786 | } |
John Koleszar | 5ebe94f | 2012-12-23 07:20:10 -0800 | [diff] [blame] | 1787 | #endif |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1788 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1789 | case AOM_CODEC_STATS_PKT: |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1790 | stream->frames_out++; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1791 | stats_write(&stream->stats, pkt->data.twopass_stats.buf, |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1792 | pkt->data.twopass_stats.sz); |
| 1793 | stream->nbytes += pkt->data.raw.sz; |
| 1794 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1795 | case AOM_CODEC_PSNR_PKT: |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1796 | |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1797 | if (global->show_psnr >= 1) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1798 | int i; |
| 1799 | |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1800 | stream->psnr_sse_total[0] += pkt->data.psnr.sse[0]; |
| 1801 | stream->psnr_samples_total[0] += pkt->data.psnr.samples[0]; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1802 | for (i = 0; i < 4; i++) { |
Jingning Han | babbd5d | 2013-02-13 09:03:21 -0800 | [diff] [blame] | 1803 | if (!global->quiet) |
| 1804 | fprintf(stderr, "%.3f ", pkt->data.psnr.psnr[i]); |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1805 | stream->psnr_totals[0][i] += pkt->data.psnr.psnr[i]; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1806 | } |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1807 | stream->psnr_count[0]++; |
| 1808 | |
| 1809 | #if CONFIG_AV1_HIGHBITDEPTH |
| 1810 | if (stream->config.cfg.g_input_bit_depth < |
Aasaipriya Chandran | 48d580b | 2020-08-18 14:56:25 +0530 | [diff] [blame] | 1811 | (unsigned int)stream->config.cfg.g_bit_depth) { |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1812 | stream->psnr_sse_total[1] += pkt->data.psnr.sse_hbd[0]; |
| 1813 | stream->psnr_samples_total[1] += pkt->data.psnr.samples_hbd[0]; |
| 1814 | for (i = 0; i < 4; i++) { |
| 1815 | if (!global->quiet) |
| 1816 | fprintf(stderr, "%.3f ", pkt->data.psnr.psnr_hbd[i]); |
| 1817 | stream->psnr_totals[1][i] += pkt->data.psnr.psnr_hbd[i]; |
| 1818 | } |
| 1819 | stream->psnr_count[1]++; |
| 1820 | } |
| 1821 | #endif |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | break; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1825 | default: break; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1826 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1827 | } |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1828 | } |
| 1829 | |
Peng Bin | eede835 | 2018-04-25 15:52:34 +0800 | [diff] [blame] | 1830 | static void show_psnr(struct stream_state *stream, double peak, int64_t bps) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1831 | int i; |
| 1832 | double ovpsnr; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1833 | |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1834 | if (!stream->psnr_count[0]) return; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1835 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1836 | fprintf(stderr, "Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index); |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1837 | ovpsnr = sse_to_psnr((double)stream->psnr_samples_total[0], peak, |
| 1838 | (double)stream->psnr_sse_total[0]); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1839 | fprintf(stderr, " %.3f", ovpsnr); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1840 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1841 | for (i = 0; i < 4; i++) { |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1842 | fprintf(stderr, " %.3f", stream->psnr_totals[0][i] / stream->psnr_count[0]); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1843 | } |
Peng Bin | eede835 | 2018-04-25 15:52:34 +0800 | [diff] [blame] | 1844 | if (bps > 0) { |
| 1845 | fprintf(stderr, " %7" PRId64 " bps", bps); |
| 1846 | } |
| 1847 | fprintf(stderr, " %7" PRId64 " ms", stream->cx_time / 1000); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1848 | fprintf(stderr, "\n"); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1849 | } |
| 1850 | |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 1851 | #if CONFIG_AV1_HIGHBITDEPTH |
| 1852 | static void show_psnr_hbd(struct stream_state *stream, double peak, |
| 1853 | int64_t bps) { |
| 1854 | int i; |
| 1855 | double ovpsnr; |
| 1856 | // Compute PSNR based on stream bit depth |
| 1857 | if (!stream->psnr_count[1]) return; |
| 1858 | |
| 1859 | fprintf(stderr, "Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index); |
| 1860 | ovpsnr = sse_to_psnr((double)stream->psnr_samples_total[1], peak, |
| 1861 | (double)stream->psnr_sse_total[1]); |
| 1862 | fprintf(stderr, " %.3f", ovpsnr); |
| 1863 | |
| 1864 | for (i = 0; i < 4; i++) { |
| 1865 | fprintf(stderr, " %.3f", stream->psnr_totals[1][i] / stream->psnr_count[1]); |
| 1866 | } |
| 1867 | if (bps > 0) { |
| 1868 | fprintf(stderr, " %7" PRId64 " bps", bps); |
| 1869 | } |
| 1870 | fprintf(stderr, " %7" PRId64 " ms", stream->cx_time / 1000); |
| 1871 | fprintf(stderr, "\n"); |
| 1872 | } |
| 1873 | #endif |
| 1874 | |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1875 | static float usec_to_fps(uint64_t usec, unsigned int frames) { |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1876 | return (float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0); |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1877 | } |
| 1878 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1879 | static void test_decode(struct stream_state *stream, |
Imdad Sardharwalla | b5def02 | 2017-12-14 11:20:24 +0000 | [diff] [blame] | 1880 | enum TestDecodeFatality fatal) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1881 | aom_image_t enc_img, dec_img; |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1882 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1883 | if (stream->mismatch_seen) return; |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1884 | |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1885 | /* Get the internal reference frame */ |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 1886 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AV1_GET_NEW_FRAME_IMAGE, |
| 1887 | &enc_img); |
| 1888 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_GET_NEW_FRAME_IMAGE, |
| 1889 | &dec_img); |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1890 | |
Sebastien Alaiwan | 34c9d8b | 2017-08-07 09:56:47 +0200 | [diff] [blame] | 1891 | if ((enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) != |
| 1892 | (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH)) { |
| 1893 | if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
| 1894 | aom_image_t enc_hbd_img; |
| 1895 | aom_img_alloc(&enc_hbd_img, enc_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH, |
| 1896 | enc_img.d_w, enc_img.d_h, 16); |
| 1897 | aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img); |
| 1898 | enc_img = enc_hbd_img; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1899 | } |
Sebastien Alaiwan | 34c9d8b | 2017-08-07 09:56:47 +0200 | [diff] [blame] | 1900 | if (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
| 1901 | aom_image_t dec_hbd_img; |
| 1902 | aom_img_alloc(&dec_hbd_img, dec_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH, |
| 1903 | dec_img.d_w, dec_img.d_h, 16); |
| 1904 | aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img); |
| 1905 | dec_img = dec_hbd_img; |
| 1906 | } |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1907 | } |
Sebastien Alaiwan | 34c9d8b | 2017-08-07 09:56:47 +0200 | [diff] [blame] | 1908 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1909 | ctx_exit_on_error(&stream->encoder, "Failed to get encoder reference frame"); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1910 | ctx_exit_on_error(&stream->decoder, "Failed to get decoder reference frame"); |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 1911 | |
Imdad Sardharwalla | b5def02 | 2017-12-14 11:20:24 +0000 | [diff] [blame] | 1912 | if (!aom_compare_img(&enc_img, &dec_img)) { |
Deb Mukherjee | 23144d2 | 2013-03-12 14:21:08 -0700 | [diff] [blame] | 1913 | int y[4], u[4], v[4]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1914 | if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
Urvang Joshi | 09c293e | 2017-04-20 17:56:27 -0700 | [diff] [blame] | 1915 | aom_find_mismatch_high(&enc_img, &dec_img, y, u, v); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1916 | } else { |
Urvang Joshi | 09c293e | 2017-04-20 17:56:27 -0700 | [diff] [blame] | 1917 | aom_find_mismatch(&enc_img, &dec_img, y, u, v); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1918 | } |
Ronald S. Bultje | 97dd734 | 2013-03-04 14:12:49 -0800 | [diff] [blame] | 1919 | stream->decoder.err = 1; |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 1920 | warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL, |
Deb Mukherjee | 23144d2 | 2013-03-12 14:21:08 -0700 | [diff] [blame] | 1921 | "Stream %d: Encode/decode mismatch on frame %d at" |
| 1922 | " Y[%d, %d] {%d/%d}," |
| 1923 | " U[%d, %d] {%d/%d}," |
| 1924 | " V[%d, %d] {%d/%d}", |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1925 | stream->index, stream->frames_out, y[0], y[1], y[2], |
| 1926 | 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] | 1927 | stream->mismatch_seen = stream->frames_out; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1928 | } |
John Koleszar | b3c350a | 2013-03-13 12:15:43 -0700 | [diff] [blame] | 1929 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1930 | aom_img_free(&enc_img); |
| 1931 | aom_img_free(&dec_img); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1932 | } |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 1933 | |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1934 | static void print_time(const char *label, int64_t etl) { |
Tom Finegan | 7a691f1 | 2014-02-10 14:55:25 -0800 | [diff] [blame] | 1935 | int64_t hours; |
| 1936 | int64_t mins; |
| 1937 | int64_t secs; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1938 | |
| 1939 | if (etl >= 0) { |
| 1940 | hours = etl / 3600; |
| 1941 | etl -= hours * 3600; |
| 1942 | mins = etl / 60; |
| 1943 | etl -= mins * 60; |
| 1944 | secs = etl; |
| 1945 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 1946 | fprintf(stderr, "[%3s %2" PRId64 ":%02" PRId64 ":%02" PRId64 "] ", label, |
| 1947 | hours, mins, secs); |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 1948 | } else { |
| 1949 | fprintf(stderr, "[%3s unknown] ", label); |
| 1950 | } |
| 1951 | } |
| 1952 | |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 1953 | static void clear_stream_count_state(struct stream_state *stream) { |
| 1954 | // PSNR counters |
| 1955 | for (int k = 0; k < 2; k++) { |
| 1956 | stream->psnr_sse_total[k] = 0; |
| 1957 | stream->psnr_samples_total[k] = 0; |
| 1958 | for (int i = 0; i < 4; i++) { |
| 1959 | stream->psnr_totals[k][i] = 0; |
| 1960 | } |
| 1961 | stream->psnr_count[k] = 0; |
| 1962 | } |
| 1963 | // q hist |
| 1964 | memset(stream->counts, 0, sizeof(stream->counts)); |
| 1965 | } |
| 1966 | |
| 1967 | // aomenc will downscale the second pass if: |
| 1968 | // 1. the specific pass is not given by commandline (aomenc will perform all |
| 1969 | // passes) |
| 1970 | // 2. there are more than 2 passes in total |
| 1971 | // 3. current pass is the second pass (the parameter pass starts with 0 so |
| 1972 | // pass == 1) |
| 1973 | static int pass_need_downscale(int global_pass, int global_passes, int pass) { |
| 1974 | return !global_pass && global_passes > 2 && pass == 1; |
| 1975 | } |
| 1976 | |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 1977 | int main(int argc, const char **argv_) { |
| 1978 | int pass; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1979 | aom_image_t raw; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1980 | aom_image_t raw_shift; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1981 | int allocated_raw_shift = 0; |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 1982 | int do_16bit_internal = 0; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 1983 | int input_shift = 0; |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 1984 | int frame_avail, got_data; |
| 1985 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1986 | struct AvxInputContext input; |
| 1987 | struct AvxEncoderConfig global; |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 1988 | struct stream_state *streams = NULL; |
| 1989 | char **argv, **argi; |
| 1990 | uint64_t cx_time = 0; |
| 1991 | int stream_cnt = 0; |
| 1992 | int res = 0; |
Thomas Daede | c0dca3c | 2016-02-25 17:23:17 -0800 | [diff] [blame] | 1993 | int profile_updated = 0; |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 1994 | |
Yaowu Xu | 618e7ef | 2014-07-11 16:27:21 -0700 | [diff] [blame] | 1995 | memset(&input, 0, sizeof(input)); |
Hui Su | 94bcbfe | 2021-01-12 11:50:01 -0800 | [diff] [blame] | 1996 | memset(&raw, 0, sizeof(raw)); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1997 | exec_name = argv_[0]; |
John Koleszar | 9e50ed7 | 2012-02-15 12:39:38 -0800 | [diff] [blame] | 1998 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 1999 | /* Setup default input stream settings */ |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 2000 | input.framerate.numerator = 30; |
| 2001 | input.framerate.denominator = 1; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 2002 | input.only_i420 = 1; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 2003 | input.bit_depth = 0; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2004 | |
| 2005 | /* First parse the global configuration values, because we want to apply |
| 2006 | * other parameters on top of the default configuration provided by the |
| 2007 | * codec. |
| 2008 | */ |
| 2009 | argv = argv_dup(argc - 1, argv_ + 1); |
James Zern | b79f705 | 2022-04-28 16:26:22 -0700 | [diff] [blame] | 2010 | if (!argv) { |
| 2011 | fprintf(stderr, "Error allocating argument list\n"); |
| 2012 | return EXIT_FAILURE; |
| 2013 | } |
Ryan Lei | c8b6dd6 | 2019-10-23 20:01:26 -0700 | [diff] [blame] | 2014 | parse_global_config(&global, &argv); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2015 | |
Ryan | 44276df | 2019-10-29 17:11:45 -0700 | [diff] [blame] | 2016 | if (argc < 2) usage_exit(); |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 2017 | |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 2018 | switch (global.color_type) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2019 | case I420: input.fmt = AOM_IMG_FMT_I420; break; |
| 2020 | case I422: input.fmt = AOM_IMG_FMT_I422; break; |
| 2021 | case I444: input.fmt = AOM_IMG_FMT_I444; break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2022 | case YV12: input.fmt = AOM_IMG_FMT_YV12; break; |
Jerome Jiang | d116cab | 2022-01-21 13:17:02 -0800 | [diff] [blame] | 2023 | case NV12: input.fmt = AOM_IMG_FMT_NV12; break; |
Deb Mukherjee | 090f4d4 | 2014-07-16 09:37:13 -0700 | [diff] [blame] | 2024 | } |
Tom Finegan | 44dd327 | 2013-11-20 17:18:28 -0800 | [diff] [blame] | 2025 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2026 | { |
| 2027 | /* Now parse each stream's parameters. Using a local scope here |
| 2028 | * due to the use of 'stream' as loop variable in FOREACH_STREAM |
| 2029 | * loops |
John Koleszar | efd54f8 | 2012-02-13 16:52:18 -0800 | [diff] [blame] | 2030 | */ |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2031 | struct stream_state *stream = NULL; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2032 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2033 | do { |
| 2034 | stream = new_stream(&global, stream); |
| 2035 | stream_cnt++; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2036 | if (!streams) streams = stream; |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2037 | } while (parse_stream_params(&global, stream, argv)); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2038 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2039 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2040 | /* Check for unrecognized options */ |
| 2041 | for (argi = argv; *argi; argi++) |
| 2042 | if (argi[0][0] == '-' && argi[0][1]) |
| 2043 | die("Error: Unrecognized option %s\n", *argi); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2044 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2045 | FOREACH_STREAM(stream, streams) { |
| 2046 | check_encoder_config(global.disable_warning_prompt, &global, |
| 2047 | &stream->config.cfg); |
Yunqing Wang | a879ee9 | 2019-01-30 10:27:20 -0800 | [diff] [blame] | 2048 | |
| 2049 | // If large_scale_tile = 1, only support to output to ivf format. |
| 2050 | if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf) |
| 2051 | die("only support ivf output format while large-scale-tile=1\n"); |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2052 | } |
Tom Finegan | 249366b | 2013-11-25 12:05:19 -0800 | [diff] [blame] | 2053 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2054 | /* Handle non-option arguments */ |
Tom Finegan | 00a35aa | 2013-11-14 12:37:42 -0800 | [diff] [blame] | 2055 | input.filename = argv[0]; |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2056 | const char *orig_input_filename = input.filename; |
| 2057 | FOREACH_STREAM(stream, streams) { |
| 2058 | stream->orig_out_fn = stream->config.out_fn; |
| 2059 | stream->orig_width = stream->config.cfg.g_w; |
| 2060 | stream->orig_height = stream->config.cfg.g_h; |
Bohan Li | 15b3c6d | 2021-07-27 17:27:20 -0700 | [diff] [blame] | 2061 | stream->orig_write_ivf = stream->config.write_ivf; |
| 2062 | stream->orig_write_webm = stream->config.write_webm; |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2063 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2064 | |
James Zern | fd8c78c | 2017-11-27 16:37:33 -0800 | [diff] [blame] | 2065 | if (!input.filename) { |
| 2066 | fprintf(stderr, "No input file specified!\n"); |
| 2067 | usage_exit(); |
| 2068 | } |
John Koleszar | 5329189 | 2010-10-22 14:48:21 -0400 | [diff] [blame] | 2069 | |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 2070 | /* Decide if other chroma subsamplings than 4:2:0 are supported */ |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 2071 | if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC) |
| 2072 | input.only_i420 = 0; |
John Koleszar | 8dd8287 | 2013-05-06 11:01:35 -0700 | [diff] [blame] | 2073 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2074 | for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) { |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2075 | if (pass > 1) { |
| 2076 | FOREACH_STREAM(stream, streams) { clear_stream_count_state(stream); } |
| 2077 | } |
| 2078 | |
John Koleszar | 2bf563c | 2013-03-11 15:03:00 -0700 | [diff] [blame] | 2079 | int frames_in = 0, seen_frames = 0; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2080 | int64_t estimated_time_left = -1; |
| 2081 | int64_t average_rate = -1; |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 2082 | int64_t lagged_count = 0; |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2083 | const int need_downscale = |
| 2084 | pass_need_downscale(global.pass, global.passes, pass); |
| 2085 | |
| 2086 | // Set the output to the specified two-pass output file, and |
| 2087 | // restore the width and height to the original values. |
| 2088 | FOREACH_STREAM(stream, streams) { |
| 2089 | if (need_downscale) { |
| 2090 | stream->config.out_fn = stream->config.two_pass_output; |
Bohan Li | 15b3c6d | 2021-07-27 17:27:20 -0700 | [diff] [blame] | 2091 | // Libaom currently only supports the ivf format for the third pass. |
| 2092 | stream->config.write_ivf = 1; |
| 2093 | stream->config.write_webm = 0; |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2094 | } else { |
| 2095 | stream->config.out_fn = stream->orig_out_fn; |
Bohan Li | 15b3c6d | 2021-07-27 17:27:20 -0700 | [diff] [blame] | 2096 | stream->config.write_ivf = stream->orig_write_ivf; |
| 2097 | stream->config.write_webm = stream->orig_write_webm; |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2098 | } |
| 2099 | stream->config.cfg.g_w = stream->orig_width; |
| 2100 | stream->config.cfg.g_h = stream->orig_height; |
| 2101 | } |
| 2102 | |
| 2103 | // For second pass in three-pass encoding, set the input to |
| 2104 | // the given two-pass-input file if available. If the scaled input is not |
| 2105 | // given, we will attempt to re-scale the original input. |
| 2106 | input.filename = orig_input_filename; |
| 2107 | const char *two_pass_input = NULL; |
| 2108 | if (need_downscale) { |
| 2109 | FOREACH_STREAM(stream, streams) { |
| 2110 | if (stream->config.two_pass_input) { |
| 2111 | two_pass_input = stream->config.two_pass_input; |
| 2112 | input.filename = two_pass_input; |
| 2113 | break; |
| 2114 | } |
| 2115 | } |
| 2116 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2117 | |
elliottk | b63b571 | 2018-09-17 11:20:20 -0700 | [diff] [blame] | 2118 | open_input_file(&input, global.csp); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2119 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2120 | /* If the input file doesn't specify its w/h (raw files), try to get |
| 2121 | * the data from the first stream's configuration. |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2122 | */ |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 2123 | if (!input.width || !input.height) { |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2124 | if (two_pass_input) { |
| 2125 | FOREACH_STREAM(stream, streams) { |
| 2126 | if (stream->config.two_pass_width && stream->config.two_pass_height) { |
| 2127 | input.width = stream->config.two_pass_width; |
| 2128 | input.height = stream->config.two_pass_height; |
| 2129 | break; |
| 2130 | } |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 2131 | } |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2132 | } else { |
| 2133 | FOREACH_STREAM(stream, streams) { |
| 2134 | if (stream->config.cfg.g_w && stream->config.cfg.g_h) { |
| 2135 | input.width = stream->config.cfg.g_w; |
| 2136 | input.height = stream->config.cfg.g_h; |
| 2137 | break; |
| 2138 | } |
| 2139 | } |
| 2140 | } |
Deb Mukherjee | a349ee3 | 2014-10-13 14:27:53 -0700 | [diff] [blame] | 2141 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2142 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2143 | /* Update stream configurations from the input file's parameters */ |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2144 | if (!input.width || !input.height) { |
| 2145 | if (two_pass_input) { |
| 2146 | fatal( |
| 2147 | "Specify downscaled stream dimensions with --two-pass-width " |
| 2148 | " and --two-pass-height"); |
| 2149 | } else { |
| 2150 | fatal( |
| 2151 | "Specify stream dimensions with --width (-w) " |
| 2152 | " and --height (-h)"); |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | if (need_downscale) { |
| 2157 | FOREACH_STREAM(stream, streams) { |
| 2158 | if (stream->config.two_pass_width && stream->config.two_pass_height) { |
| 2159 | stream->config.cfg.g_w = stream->config.two_pass_width; |
| 2160 | stream->config.cfg.g_h = stream->config.two_pass_height; |
| 2161 | } else if (two_pass_input) { |
| 2162 | stream->config.cfg.g_w = input.width; |
| 2163 | stream->config.cfg.g_h = input.height; |
| 2164 | } else if (stream->orig_width && stream->orig_height) { |
Angie Chiang | 958912e | 2021-12-10 17:25:57 -0800 | [diff] [blame] | 2165 | #if CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL |
| 2166 | stream->config.cfg.g_w = stream->orig_width; |
| 2167 | stream->config.cfg.g_h = stream->orig_height; |
| 2168 | #else // CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2169 | stream->config.cfg.g_w = (stream->orig_width + 1) / 2; |
| 2170 | stream->config.cfg.g_h = (stream->orig_height + 1) / 2; |
Angie Chiang | 958912e | 2021-12-10 17:25:57 -0800 | [diff] [blame] | 2171 | #endif // CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2172 | } else { |
Angie Chiang | 958912e | 2021-12-10 17:25:57 -0800 | [diff] [blame] | 2173 | #if CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL |
| 2174 | stream->config.cfg.g_w = input.width; |
| 2175 | stream->config.cfg.g_h = input.height; |
| 2176 | #else // CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2177 | stream->config.cfg.g_w = (input.width + 1) / 2; |
| 2178 | stream->config.cfg.g_h = (input.height + 1) / 2; |
Angie Chiang | 958912e | 2021-12-10 17:25:57 -0800 | [diff] [blame] | 2179 | #endif // CONFIG_BITRATE_ACCURACY || CONFIG_BITRATE_ACCURACY_BL |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2180 | } |
| 2181 | } |
| 2182 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2183 | |
| 2184 | /* If input file does not specify bit-depth but input-bit-depth parameter |
| 2185 | * exists, assume that to be the input bit-depth. However, if the |
| 2186 | * input-bit-depth paramter does not exist, assume the input bit-depth |
| 2187 | * to be the same as the codec bit-depth. |
| 2188 | */ |
| 2189 | if (!input.bit_depth) { |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2190 | FOREACH_STREAM(stream, streams) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2191 | if (stream->config.cfg.g_input_bit_depth) |
| 2192 | input.bit_depth = stream->config.cfg.g_input_bit_depth; |
| 2193 | else |
| 2194 | input.bit_depth = stream->config.cfg.g_input_bit_depth = |
| 2195 | (int)stream->config.cfg.g_bit_depth; |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2196 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2197 | if (input.bit_depth > 8) input.fmt |= AOM_IMG_FMT_HIGHBITDEPTH; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2198 | } else { |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2199 | FOREACH_STREAM(stream, streams) { |
| 2200 | stream->config.cfg.g_input_bit_depth = input.bit_depth; |
| 2201 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2204 | FOREACH_STREAM(stream, streams) { |
Jerome Jiang | d116cab | 2022-01-21 13:17:02 -0800 | [diff] [blame] | 2205 | if (input.fmt != AOM_IMG_FMT_I420 && input.fmt != AOM_IMG_FMT_I42016 && |
| 2206 | input.fmt != AOM_IMG_FMT_NV12) { |
Thomas Daede | 8ec53b2 | 2016-09-19 13:24:51 -0700 | [diff] [blame] | 2207 | /* Automatically upgrade if input is non-4:2:0 but a 4:2:0 profile |
| 2208 | was selected. */ |
| 2209 | switch (stream->config.cfg.g_profile) { |
| 2210 | case 0: |
Debargha Mukherjee | fc321aa | 2018-01-12 16:26:47 -0800 | [diff] [blame] | 2211 | if (input.bit_depth < 12 && (input.fmt == AOM_IMG_FMT_I444 || |
| 2212 | input.fmt == AOM_IMG_FMT_I44416)) { |
Yaowu Xu | c1fdb4b | 2018-03-16 08:44:13 -0700 | [diff] [blame] | 2213 | if (!stream->config.cfg.monochrome) { |
| 2214 | stream->config.cfg.g_profile = 1; |
| 2215 | profile_updated = 1; |
| 2216 | } |
Wan-Teh Chang | 5c9bc41 | 2021-04-13 10:12:20 -0700 | [diff] [blame] | 2217 | } else if (input.bit_depth == 12 || |
| 2218 | ((input.fmt == AOM_IMG_FMT_I422 || |
| 2219 | input.fmt == AOM_IMG_FMT_I42216) && |
| 2220 | !stream->config.cfg.monochrome)) { |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 2221 | stream->config.cfg.g_profile = 2; |
| 2222 | profile_updated = 1; |
| 2223 | } |
Thomas Daede | 8ec53b2 | 2016-09-19 13:24:51 -0700 | [diff] [blame] | 2224 | break; |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 2225 | case 1: |
| 2226 | if (input.bit_depth == 12 || input.fmt == AOM_IMG_FMT_I422 || |
| 2227 | input.fmt == AOM_IMG_FMT_I42216) { |
| 2228 | stream->config.cfg.g_profile = 2; |
| 2229 | profile_updated = 1; |
Debargha Mukherjee | fc321aa | 2018-01-12 16:26:47 -0800 | [diff] [blame] | 2230 | } else if (input.bit_depth < 12 && |
| 2231 | (input.fmt == AOM_IMG_FMT_I420 || |
| 2232 | input.fmt == AOM_IMG_FMT_I42016)) { |
| 2233 | stream->config.cfg.g_profile = 0; |
| 2234 | profile_updated = 1; |
| 2235 | } |
| 2236 | break; |
| 2237 | case 2: |
| 2238 | if (input.bit_depth < 12 && (input.fmt == AOM_IMG_FMT_I444 || |
| 2239 | input.fmt == AOM_IMG_FMT_I44416)) { |
| 2240 | stream->config.cfg.g_profile = 1; |
| 2241 | profile_updated = 1; |
| 2242 | } else if (input.bit_depth < 12 && |
| 2243 | (input.fmt == AOM_IMG_FMT_I420 || |
| 2244 | input.fmt == AOM_IMG_FMT_I42016)) { |
| 2245 | stream->config.cfg.g_profile = 0; |
| 2246 | profile_updated = 1; |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 2247 | } else if (input.bit_depth == 12 && |
| 2248 | input.file_type == FILE_TYPE_Y4M) { |
| 2249 | // Note that here the input file values for chroma subsampling |
| 2250 | // are used instead of those from the command line. |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 2251 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, |
| 2252 | AV1E_SET_CHROMA_SUBSAMPLING_X, |
| 2253 | input.y4m.dst_c_dec_h >> 1); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 2254 | ctx_exit_on_error(&stream->encoder, |
| 2255 | "Failed to set chroma subsampling x"); |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 2256 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, |
| 2257 | AV1E_SET_CHROMA_SUBSAMPLING_Y, |
| 2258 | input.y4m.dst_c_dec_v >> 1); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 2259 | ctx_exit_on_error(&stream->encoder, |
| 2260 | "Failed to set chroma subsampling y"); |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 2261 | } else if (input.bit_depth == 12 && |
| 2262 | input.file_type == FILE_TYPE_RAW) { |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 2263 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, |
| 2264 | AV1E_SET_CHROMA_SUBSAMPLING_X, |
| 2265 | stream->chroma_subsampling_x); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 2266 | ctx_exit_on_error(&stream->encoder, |
| 2267 | "Failed to set chroma subsampling x"); |
Elliott Karpilovsky | 60dd0f9 | 2020-04-30 19:19:27 -0700 | [diff] [blame] | 2268 | AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, |
| 2269 | AV1E_SET_CHROMA_SUBSAMPLING_Y, |
| 2270 | stream->chroma_subsampling_y); |
Satheesh Kumar | e46f3f2 | 2023-12-05 19:34:33 +0530 | [diff] [blame] | 2271 | ctx_exit_on_error(&stream->encoder, |
| 2272 | "Failed to set chroma subsampling y"); |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 2273 | } |
Thomas Daede | 8ec53b2 | 2016-09-19 13:24:51 -0700 | [diff] [blame] | 2274 | break; |
| 2275 | default: break; |
| 2276 | } |
| 2277 | } |
elliottk | 7a16247 | 2018-09-25 15:06:24 -0700 | [diff] [blame] | 2278 | /* Automatically set the codec bit depth to match the input bit depth. |
| 2279 | * Upgrade the profile if required. */ |
| 2280 | if (stream->config.cfg.g_input_bit_depth > |
| 2281 | (unsigned int)stream->config.cfg.g_bit_depth) { |
| 2282 | stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth; |
| 2283 | if (!global.quiet) { |
| 2284 | fprintf(stderr, |
| 2285 | "Warning: automatically updating bit depth to %d to " |
| 2286 | "match input format.\n", |
| 2287 | stream->config.cfg.g_input_bit_depth); |
| 2288 | } |
| 2289 | } |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 2290 | #if !CONFIG_AV1_HIGHBITDEPTH |
| 2291 | if (stream->config.cfg.g_bit_depth > 8) { |
| 2292 | fatal("Unsupported bit-depth with CONFIG_AV1_HIGHBITDEPTH=0\n"); |
| 2293 | } |
| 2294 | #endif // CONFIG_AV1_HIGHBITDEPTH |
Debargha Mukherjee | fc321aa | 2018-01-12 16:26:47 -0800 | [diff] [blame] | 2295 | if (stream->config.cfg.g_bit_depth > 10) { |
Thomas Daede | c0dca3c | 2016-02-25 17:23:17 -0800 | [diff] [blame] | 2296 | switch (stream->config.cfg.g_profile) { |
| 2297 | case 0: |
Thomas Daede | c0dca3c | 2016-02-25 17:23:17 -0800 | [diff] [blame] | 2298 | case 1: |
Debargha Mukherjee | fc321aa | 2018-01-12 16:26:47 -0800 | [diff] [blame] | 2299 | stream->config.cfg.g_profile = 2; |
Thomas Daede | c0dca3c | 2016-02-25 17:23:17 -0800 | [diff] [blame] | 2300 | profile_updated = 1; |
| 2301 | break; |
| 2302 | default: break; |
| 2303 | } |
| 2304 | } |
Debargha Mukherjee | fc321aa | 2018-01-12 16:26:47 -0800 | [diff] [blame] | 2305 | if (stream->config.cfg.g_bit_depth > 8) { |
Thomas Daede | c0dca3c | 2016-02-25 17:23:17 -0800 | [diff] [blame] | 2306 | stream->config.use_16bit_internal = 1; |
Arild Fuldseth (arilfuld) | 59622cf | 2016-10-24 10:37:37 +0200 | [diff] [blame] | 2307 | } |
Urvang Joshi | 51c048e | 2017-02-16 12:43:52 -0800 | [diff] [blame] | 2308 | if (profile_updated && !global.quiet) { |
Arild Fuldseth (arilfuld) | 59622cf | 2016-10-24 10:37:37 +0200 | [diff] [blame] | 2309 | fprintf(stderr, |
Debargha Mukherjee | fc321aa | 2018-01-12 16:26:47 -0800 | [diff] [blame] | 2310 | "Warning: automatically updating to profile %d to " |
Arild Fuldseth (arilfuld) | 59622cf | 2016-10-24 10:37:37 +0200 | [diff] [blame] | 2311 | "match input format.\n", |
| 2312 | stream->config.cfg.g_profile); |
| 2313 | } |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 2314 | if ((global.show_psnr == 2) && (stream->config.cfg.g_input_bit_depth == |
| 2315 | stream->config.cfg.g_bit_depth)) { |
| 2316 | fprintf(stderr, |
| 2317 | "Warning: --psnr==2 and --psnr==1 will provide same " |
| 2318 | "results when input bit-depth == stream bit-depth, " |
| 2319 | "falling back to default psnr value\n"); |
| 2320 | global.show_psnr = 1; |
| 2321 | } |
| 2322 | if (global.show_psnr < 0 || global.show_psnr > 2) { |
| 2323 | fprintf(stderr, |
| 2324 | "Warning: --psnr can take only 0,1,2 as values," |
| 2325 | "falling back to default psnr value\n"); |
| 2326 | global.show_psnr = 1; |
| 2327 | } |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 2328 | /* Set limit */ |
| 2329 | stream->config.cfg.g_limit = global.limit; |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2330 | } |
Thomas Daede | c0dca3c | 2016-02-25 17:23:17 -0800 | [diff] [blame] | 2331 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2332 | FOREACH_STREAM(stream, streams) { |
| 2333 | set_stream_dimensions(stream, input.width, input.height); |
Elliott Karpilovsky | b2d8258 | 2021-02-02 22:49:56 -0800 | [diff] [blame] | 2334 | stream->config.color_range = input.color_range; |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2335 | } |
| 2336 | FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); } |
John Koleszar | 77e6b45 | 2010-11-03 13:58:40 -0400 | [diff] [blame] | 2337 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2338 | /* Ensure that --passes and --pass are consistent. If --pass is set and |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2339 | * --passes >= 2, ensure --fpf was set. |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2340 | */ |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2341 | if (global.pass > 0 && global.pass <= 3 && global.passes >= 2) { |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2342 | FOREACH_STREAM(stream, streams) { |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2343 | if (!stream->config.stats_fn) |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 2344 | die("Stream %d: Must specify --fpf when --pass=%d" |
Bohan Li | 8611781 | 2021-07-14 14:08:59 -0700 | [diff] [blame] | 2345 | " and --passes=%d\n", |
| 2346 | stream->index, global.pass, global.passes); |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2347 | } |
| 2348 | } |
John Koleszar | 3245d46 | 2010-06-10 17:10:12 -0400 | [diff] [blame] | 2349 | |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 2350 | #if !CONFIG_WEBM_IO |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2351 | FOREACH_STREAM(stream, streams) { |
Ronald S. Bultje | 3977507 | 2015-12-16 13:35:43 -0500 | [diff] [blame] | 2352 | if (stream->config.write_webm) { |
| 2353 | stream->config.write_webm = 0; |
Cyril Concolato | 6c78883 | 2017-10-30 16:30:35 -0700 | [diff] [blame] | 2354 | stream->config.write_ivf = 0; |
Wan-Teh Chang | 3668fed | 2021-08-30 15:57:37 -0700 | [diff] [blame] | 2355 | aom_tools_warn("aomenc compiled w/o WebM support. Writing OBU stream."); |
Ronald S. Bultje | 3977507 | 2015-12-16 13:35:43 -0500 | [diff] [blame] | 2356 | } |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2357 | } |
Vignesh Venkatasubramanian | 0ffa383 | 2014-03-14 08:10:35 -0700 | [diff] [blame] | 2358 | #endif |
| 2359 | |
Debargha Mukherjee | 4a707a8 | 2018-03-02 11:19:43 -0800 | [diff] [blame] | 2360 | /* Use the frame rate from the file only if none was specified |
| 2361 | * on the command-line. |
| 2362 | */ |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 2363 | if (!global.have_framerate) { |
| 2364 | global.framerate.num = input.framerate.numerator; |
| 2365 | global.framerate.den = input.framerate.denominator; |
| 2366 | } |
| 2367 | FOREACH_STREAM(stream, streams) { |
| 2368 | stream->config.cfg.g_timebase.den = global.framerate.num; |
| 2369 | stream->config.cfg.g_timebase.num = global.framerate.den; |
| 2370 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2371 | /* Show configuration */ |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2372 | if (global.verbose && pass == 0) { |
| 2373 | FOREACH_STREAM(stream, streams) { |
| 2374 | show_stream_config(stream, &global, &input); |
| 2375 | } |
| 2376 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2377 | |
| 2378 | if (pass == (global.pass ? global.pass - 1 : 0)) { |
Hui Su | 94bcbfe | 2021-01-12 11:50:01 -0800 | [diff] [blame] | 2379 | // The Y4M reader does its own allocation. |
| 2380 | if (input.file_type != FILE_TYPE_Y4M) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2381 | aom_img_alloc(&raw, input.fmt, input.width, input.height, 32); |
Hui Su | 94bcbfe | 2021-01-12 11:50:01 -0800 | [diff] [blame] | 2382 | } |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2383 | FOREACH_STREAM(stream, streams) { |
| 2384 | stream->rate_hist = |
| 2385 | init_rate_histogram(&stream->config.cfg, &global.framerate); |
| 2386 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2387 | } |
Timothy B. Terriberry | 44d8949 | 2010-05-26 18:27:51 -0400 | [diff] [blame] | 2388 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2389 | FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); } |
Tom Finegan | ec0833f | 2018-09-19 14:28:20 -0700 | [diff] [blame] | 2390 | FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); } |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2391 | FOREACH_STREAM(stream, streams) { |
Elliott Karpilovsky | 4e55eb7 | 2020-05-14 14:16:24 -0700 | [diff] [blame] | 2392 | char *encoder_settings = NULL; |
| 2393 | #if CONFIG_WEBM_IO |
Elliott Karpilovsky | e4d1bba | 2020-05-19 16:51:41 -0700 | [diff] [blame] | 2394 | // Test frameworks may compare outputs from different versions, but only |
| 2395 | // wish to check for bitstream changes. The encoder-settings tag, however, |
| 2396 | // can vary if the version is updated, even if no encoder algorithm |
| 2397 | // changes were made. To work around this issue, do not output |
| 2398 | // the encoder-settings tag when --debug is enabled (which is the flag |
| 2399 | // that test frameworks should use, when they want deterministic output |
| 2400 | // from the container format). |
| 2401 | if (stream->config.write_webm && !stream->webm_ctx.debug) { |
Elliott Karpilovsky | 4e55eb7 | 2020-05-14 14:16:24 -0700 | [diff] [blame] | 2402 | encoder_settings = extract_encoder_settings( |
| 2403 | aom_codec_version_str(), argv_, argc, input.filename); |
| 2404 | if (encoder_settings == NULL) { |
| 2405 | fprintf( |
| 2406 | stderr, |
| 2407 | "Warning: unable to extract encoder settings. Continuing...\n"); |
| 2408 | } |
| 2409 | } |
| 2410 | #endif |
| 2411 | open_output_file(stream, &global, &input.pixel_aspect_ratio, |
| 2412 | encoder_settings); |
| 2413 | free(encoder_settings); |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2414 | } |
Tom Finegan | ec0833f | 2018-09-19 14:28:20 -0700 | [diff] [blame] | 2415 | |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 2416 | if (strcmp(get_short_name_by_aom_encoder(global.codec), "av1") == 0) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2417 | // Check to see if at least one stream uses 16 bit internal. |
| 2418 | // Currently assume that the bit_depths for all streams using |
| 2419 | // highbitdepth are the same. |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2420 | FOREACH_STREAM(stream, streams) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2421 | if (stream->config.use_16bit_internal) { |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 2422 | do_16bit_internal = 1; |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2423 | } |
Yaowu Xu | 913867b | 2018-01-23 18:27:59 -0800 | [diff] [blame] | 2424 | input_shift = (int)stream->config.cfg.g_bit_depth - |
| 2425 | stream->config.cfg.g_input_bit_depth; |
James Zern | f2658a3 | 2022-02-09 10:18:38 -0800 | [diff] [blame] | 2426 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2427 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2428 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2429 | frame_avail = 1; |
| 2430 | got_data = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2431 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2432 | while (frame_avail || got_data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2433 | struct aom_usec_timer timer; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2434 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2435 | if (!global.limit || frames_in < global.limit) { |
| 2436 | frame_avail = read_frame(&input, &raw); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2437 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2438 | if (frame_avail) frames_in++; |
| 2439 | seen_frames = |
| 2440 | frames_in > global.skip_frames ? frames_in - global.skip_frames : 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2441 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2442 | if (!global.quiet) { |
John Koleszar | 2bf563c | 2013-03-11 15:03:00 -0700 | [diff] [blame] | 2443 | float fps = usec_to_fps(cx_time, seen_frames); |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2444 | fprintf(stderr, "\rPass %d/%d ", pass + 1, global.passes); |
| 2445 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2446 | if (stream_cnt == 1) |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2447 | fprintf(stderr, "frame %4d/%-4d %7" PRId64 "B ", frames_in, |
| 2448 | streams->frames_out, (int64_t)streams->nbytes); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2449 | else |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2450 | fprintf(stderr, "frame %4d ", frames_in); |
| 2451 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2452 | fprintf(stderr, "%7" PRId64 " %s %.2f %s ", |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2453 | cx_time > 9999999 ? cx_time / 1000 : cx_time, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2454 | cx_time > 9999999 ? "ms" : "us", fps >= 1.0 ? fps : fps * 60, |
Yaowu Xu | 014acfa | 2013-09-17 16:31:46 -0700 | [diff] [blame] | 2455 | fps >= 1.0 ? "fps" : "fpm"); |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2456 | print_time("ETA", estimated_time_left); |
Christopher Degawa | eda9c45 | 2021-07-23 11:04:48 -0500 | [diff] [blame] | 2457 | // mingw-w64 gcc does not match msvc for stderr buffering behavior |
| 2458 | // and uses line buffering, thus the progress output is not |
| 2459 | // real-time. The fflush() is here to make sure the progress output |
| 2460 | // is sent out while the clip is being processed. |
Christopher Degawa | 697613f | 2021-07-15 10:41:44 -0500 | [diff] [blame] | 2461 | fflush(stderr); |
John Koleszar | 3245d46 | 2010-06-10 17:10:12 -0400 | [diff] [blame] | 2462 | } |
| 2463 | |
hui su | 251e151 | 2016-10-03 15:48:43 -0700 | [diff] [blame] | 2464 | } else { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2465 | frame_avail = 0; |
hui su | 251e151 | 2016-10-03 15:48:43 -0700 | [diff] [blame] | 2466 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2467 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2468 | if (frames_in > global.skip_frames) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2469 | aom_image_t *frame_to_encode; |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 2470 | if (input_shift || (do_16bit_internal && input.bit_depth == 8)) { |
| 2471 | assert(do_16bit_internal); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2472 | // Input bit depth and stream bit depth do not match, so up |
| 2473 | // shift frame to stream bit depth |
| 2474 | if (!allocated_raw_shift) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2475 | aom_img_alloc(&raw_shift, raw.fmt | AOM_IMG_FMT_HIGHBITDEPTH, |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2476 | input.width, input.height, 32); |
| 2477 | allocated_raw_shift = 1; |
| 2478 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2479 | aom_img_upshift(&raw_shift, &raw, input_shift); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2480 | frame_to_encode = &raw_shift; |
| 2481 | } else { |
| 2482 | frame_to_encode = &raw; |
| 2483 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2484 | aom_usec_timer_start(&timer); |
Debargha Mukherjee | 4821571 | 2020-05-14 15:51:10 -0700 | [diff] [blame] | 2485 | if (do_16bit_internal) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2486 | assert(frame_to_encode->fmt & AOM_IMG_FMT_HIGHBITDEPTH); |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2487 | FOREACH_STREAM(stream, streams) { |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2488 | if (stream->config.use_16bit_internal) |
| 2489 | encode_frame(stream, &global, |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2490 | frame_avail ? frame_to_encode : NULL, frames_in); |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2491 | else |
| 2492 | assert(0); |
James Zern | f2658a3 | 2022-02-09 10:18:38 -0800 | [diff] [blame] | 2493 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2494 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2495 | assert((frame_to_encode->fmt & AOM_IMG_FMT_HIGHBITDEPTH) == 0); |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2496 | FOREACH_STREAM(stream, streams) { |
| 2497 | encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL, |
| 2498 | frames_in); |
| 2499 | } |
Deb Mukherjee | 5acfafb | 2014-08-26 12:35:15 -0700 | [diff] [blame] | 2500 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2501 | aom_usec_timer_mark(&timer); |
| 2502 | cx_time += aom_usec_timer_elapsed(&timer); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2503 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2504 | FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2505 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2506 | got_data = 0; |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2507 | FOREACH_STREAM(stream, streams) { |
| 2508 | get_cx_data(stream, &global, &got_data); |
| 2509 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2510 | |
Jim Bankoski | c901a4f | 2014-08-21 07:18:07 -0700 | [diff] [blame] | 2511 | if (!got_data && input.length && streams != NULL && |
| 2512 | !streams->frames_out) { |
John Koleszar | 2bf563c | 2013-03-11 15:03:00 -0700 | [diff] [blame] | 2513 | lagged_count = global.limit ? seen_frames : ftello(input.file); |
John Koleszar | ebf8b9f | 2013-02-27 11:14:23 -0800 | [diff] [blame] | 2514 | } else if (input.length) { |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2515 | int64_t remaining; |
| 2516 | int64_t rate; |
| 2517 | |
| 2518 | if (global.limit) { |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 2519 | const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2520 | |
| 2521 | rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0; |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2522 | remaining = 1000 * (global.limit - global.skip_frames - |
| 2523 | seen_frames + lagged_count); |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2524 | } else { |
James Zern | e3578af | 2014-04-17 10:47:08 -0700 | [diff] [blame] | 2525 | const int64_t input_pos = ftello(input.file); |
| 2526 | const int64_t input_pos_lagged = input_pos - lagged_count; |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 2527 | const int64_t input_limit = input.length; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2528 | |
| 2529 | rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0; |
Urvang Joshi | 4145bf0 | 2016-10-17 14:53:33 -0700 | [diff] [blame] | 2530 | remaining = input_limit - input_pos + lagged_count; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2531 | } |
| 2532 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2533 | average_rate = |
| 2534 | (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8; |
John Koleszar | 25b6e9f | 2013-02-12 21:17:56 -0800 | [diff] [blame] | 2535 | estimated_time_left = average_rate ? remaining / average_rate : -1; |
| 2536 | } |
| 2537 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2538 | if (got_data && global.test_decode != TEST_DECODE_OFF) { |
| 2539 | FOREACH_STREAM(stream, streams) { |
Imdad Sardharwalla | b5def02 | 2017-12-14 11:20:24 +0000 | [diff] [blame] | 2540 | test_decode(stream, global.test_decode); |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2541 | } |
| 2542 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2543 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2544 | |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2545 | fflush(stdout); |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2546 | if (!global.quiet) fprintf(stderr, "\033[K"); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2547 | } |
| 2548 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2549 | if (stream_cnt > 1) fprintf(stderr, "\n"); |
John Koleszar | 3fde996 | 2011-06-20 17:09:29 -0400 | [diff] [blame] | 2550 | |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2551 | if (!global.quiet) { |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2552 | FOREACH_STREAM(stream, streams) { |
Peng Bin | eede835 | 2018-04-25 15:52:34 +0800 | [diff] [blame] | 2553 | const int64_t bpf = |
| 2554 | seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0; |
| 2555 | const int64_t bps = bpf * global.framerate.num / global.framerate.den; |
Johann | 3c30fb4 | 2018-02-08 14:33:20 -0800 | [diff] [blame] | 2556 | fprintf(stderr, |
| 2557 | "\rPass %d/%d frame %4d/%-4d %7" PRId64 "B %7" PRId64 |
| 2558 | "b/f %7" PRId64 |
| 2559 | "b/s" |
| 2560 | " %7" PRId64 " %s (%.2f fps)\033[K\n", |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2561 | pass + 1, global.passes, frames_in, stream->frames_out, |
Peng Bin | eede835 | 2018-04-25 15:52:34 +0800 | [diff] [blame] | 2562 | (int64_t)stream->nbytes, bpf, bps, |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2563 | stream->cx_time > 9999999 ? stream->cx_time / 1000 |
| 2564 | : stream->cx_time, |
| 2565 | stream->cx_time > 9999999 ? "ms" : "us", |
| 2566 | usec_to_fps(stream->cx_time, seen_frames)); |
Christopher Degawa | eda9c45 | 2021-07-23 11:04:48 -0500 | [diff] [blame] | 2567 | // This instance of cr does not need fflush as it is followed by a |
| 2568 | // newline in the same string. |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2569 | } |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2570 | } |
John Koleszar | c96f8e2 | 2011-06-21 16:42:33 -0400 | [diff] [blame] | 2571 | |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 2572 | if (global.show_psnr >= 1) { |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 2573 | if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC) { |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2574 | FOREACH_STREAM(stream, streams) { |
Peng Bin | eede835 | 2018-04-25 15:52:34 +0800 | [diff] [blame] | 2575 | int64_t bps = 0; |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 2576 | if (global.show_psnr == 1) { |
| 2577 | if (stream->psnr_count[0] && seen_frames && global.framerate.den) { |
| 2578 | bps = (int64_t)stream->nbytes * 8 * |
| 2579 | (int64_t)global.framerate.num / global.framerate.den / |
| 2580 | seen_frames; |
| 2581 | } |
| 2582 | show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1, |
| 2583 | bps); |
Peng Bin | eede835 | 2018-04-25 15:52:34 +0800 | [diff] [blame] | 2584 | } |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 2585 | if (global.show_psnr == 2) { |
| 2586 | #if CONFIG_AV1_HIGHBITDEPTH |
| 2587 | if (stream->config.cfg.g_input_bit_depth < |
Aasaipriya Chandran | 48d580b | 2020-08-18 14:56:25 +0530 | [diff] [blame] | 2588 | (unsigned int)stream->config.cfg.g_bit_depth) |
Aasaipriya Chandran | 4c2b30e | 2020-08-07 12:13:49 +0530 | [diff] [blame] | 2589 | show_psnr_hbd(stream, (1 << stream->config.cfg.g_bit_depth) - 1, |
| 2590 | bps); |
| 2591 | #endif |
| 2592 | } |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2593 | } |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2594 | } else { |
Peng Bin | eede835 | 2018-04-25 15:52:34 +0800 | [diff] [blame] | 2595 | FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); } |
Deb Mukherjee | a160d72 | 2014-09-30 21:56:33 -0700 | [diff] [blame] | 2596 | } |
| 2597 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2598 | |
Bohan Li | e803343 | 2022-01-21 13:46:49 -0800 | [diff] [blame] | 2599 | if (pass == global.passes - 1) { |
| 2600 | FOREACH_STREAM(stream, streams) { |
Wan-Teh Chang | 977be33 | 2022-06-06 17:35:19 -0700 | [diff] [blame] | 2601 | int num_operating_points; |
| 2602 | int levels[32]; |
| 2603 | int target_levels[32]; |
| 2604 | aom_codec_control(&stream->encoder, AV1E_GET_NUM_OPERATING_POINTS, |
| 2605 | &num_operating_points); |
Bohan Li | e803343 | 2022-01-21 13:46:49 -0800 | [diff] [blame] | 2606 | aom_codec_control(&stream->encoder, AV1E_GET_SEQ_LEVEL_IDX, levels); |
| 2607 | aom_codec_control(&stream->encoder, AV1E_GET_TARGET_SEQ_LEVEL_IDX, |
| 2608 | target_levels); |
| 2609 | |
Wan-Teh Chang | 977be33 | 2022-06-06 17:35:19 -0700 | [diff] [blame] | 2610 | for (int i = 0; i < num_operating_points; i++) { |
Bohan Li | e803343 | 2022-01-21 13:46:49 -0800 | [diff] [blame] | 2611 | if (levels[i] > target_levels[i]) { |
Bohan Li | debf086 | 2022-11-21 09:55:53 -0800 | [diff] [blame] | 2612 | if (levels[i] == 31) { |
| 2613 | aom_tools_warn( |
| 2614 | "Failed to encode to target level %d.%d for operating point " |
| 2615 | "%d. The output level is SEQ_LEVEL_MAX", |
| 2616 | 2 + (target_levels[i] >> 2), target_levels[i] & 3, i); |
| 2617 | } else { |
| 2618 | aom_tools_warn( |
| 2619 | "Failed to encode to target level %d.%d for operating point " |
| 2620 | "%d. The output level is %d.%d", |
| 2621 | 2 + (target_levels[i] >> 2), target_levels[i] & 3, i, |
| 2622 | 2 + (levels[i] >> 2), levels[i] & 3); |
| 2623 | } |
Bohan Li | e803343 | 2022-01-21 13:46:49 -0800 | [diff] [blame] | 2624 | } |
| 2625 | } |
| 2626 | } |
| 2627 | } |
| 2628 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2629 | FOREACH_STREAM(stream, streams) { aom_codec_destroy(&stream->encoder); } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2630 | |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 2631 | if (global.test_decode != TEST_DECODE_OFF) { |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2632 | FOREACH_STREAM(stream, streams) { aom_codec_destroy(&stream->decoder); } |
Yaowu Xu | f798f9e | 2012-03-07 12:25:50 -0800 | [diff] [blame] | 2633 | } |
| 2634 | |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2635 | close_input_file(&input); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2636 | |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 2637 | if (global.test_decode == TEST_DECODE_FATAL) { |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2638 | FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; } |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 2639 | } |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2640 | FOREACH_STREAM(stream, streams) { |
Elliott Karpilovsky | cbe219b | 2020-04-22 16:21:06 -0700 | [diff] [blame] | 2641 | close_output_file(stream, get_fourcc_by_aom_encoder(global.codec)); |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2642 | } |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2643 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2644 | FOREACH_STREAM(stream, streams) { |
| 2645 | stats_close(&stream->stats, global.passes - 1); |
| 2646 | } |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2647 | |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 2648 | if (global.pass) break; |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2651 | if (global.show_q_hist_buckets) { |
| 2652 | FOREACH_STREAM(stream, streams) { |
| 2653 | show_q_histogram(stream->counts, global.show_q_hist_buckets); |
| 2654 | } |
| 2655 | } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2656 | |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2657 | if (global.show_rate_hist_buckets) { |
| 2658 | FOREACH_STREAM(stream, streams) { |
| 2659 | show_rate_histogram(stream->rate_hist, &stream->config.cfg, |
| 2660 | global.show_rate_hist_buckets); |
| 2661 | } |
| 2662 | } |
| 2663 | FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); } |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2664 | |
Ronald S. Bultje | 3121497 | 2012-10-11 10:13:48 -0700 | [diff] [blame] | 2665 | #if CONFIG_INTERNAL_STATS |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2666 | /* TODO(jkoleszar): This doesn't belong in this executable. Do it for now, |
| 2667 | * to match some existing utilities. |
| 2668 | */ |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2669 | if (!(global.pass == 1 && global.passes == 2)) { |
| 2670 | FOREACH_STREAM(stream, streams) { |
Yaowu Xu | 47e784e | 2013-10-16 16:29:28 -0700 | [diff] [blame] | 2671 | FILE *f = fopen("opsnr.stt", "a"); |
| 2672 | if (stream->mismatch_seen) { |
| 2673 | fprintf(f, "First mismatch occurred in frame %d\n", |
| 2674 | stream->mismatch_seen); |
| 2675 | } else { |
| 2676 | fprintf(f, "No mismatch detected in recon buffers\n"); |
| 2677 | } |
| 2678 | fclose(f); |
Sebastien Alaiwan | 0b99384 | 2017-06-09 10:28:29 +0200 | [diff] [blame] | 2679 | } |
| 2680 | } |
Ronald S. Bultje | 3121497 | 2012-10-11 10:13:48 -0700 | [diff] [blame] | 2681 | #endif |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2682 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2683 | if (allocated_raw_shift) aom_img_free(&raw_shift); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2684 | aom_img_free(&raw); |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 2685 | free(argv); |
John Koleszar | 6ad3b74 | 2012-11-06 12:02:42 -0800 | [diff] [blame] | 2686 | free(streams); |
Ronald S. Bultje | 9837bf4 | 2013-02-15 16:31:02 -0800 | [diff] [blame] | 2687 | return res ? EXIT_FAILURE : EXIT_SUCCESS; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 2688 | } |