AOMedia Codec SDK: aomenc

AOMedia Codec SDK

aomenc
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
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.
10 */
11
12 #include "apps/aomenc.h"
13
14 #include "config/aom_config.h"
15
16 #include <assert.h>
17 #include <limits.h>
18 #include <math.h>
19 #include <stdarg.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #if CONFIG_AV1_DECODER
25 #include "aom/aom_decoder.h"
26 #include "aom/aomdx.h"
27 #endif
28
29 #include "aom/aom_encoder.h"
30 #include "aom/aom_integer.h"
31 #include "aom/aomcx.h"
32 #include "aom_dsp/aom_dsp_common.h"
33 #include "aom_ports/aom_timer.h"
34 #include "aom_ports/mem_ops.h"
35 #include "common/args.h"
36 #include "common/ivfenc.h"
37 #include "common/tools_common.h"
38 #include "common/warnings.h"
39
40 #if CONFIG_WEBM_IO
41 #include "common/webmenc.h"
42 #endif
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
52
53 /* Swallow warnings about unused results of fread/fwrite */
54 static size_t wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
55 return fread(ptr, size, nmemb, stream);
56 }
57 #define fread wrap_fread
58
59 static size_t wrap_fwrite(const void *ptr, size_t size, size_t nmemb,
60 FILE *stream) {
61 return fwrite(ptr, size, nmemb, stream);
62 }
63 #define fwrite wrap_fwrite
64
65 static const char *exec_name;
66
67 static void warn_or_exit_on_errorv(aom_codec_ctx_t *ctx, int fatal,
68 const char *s, va_list ap) {
69 if (ctx->err) {
70 const char *detail = aom_codec_error_detail(ctx);
71
72 vfprintf(stderr, s, ap);
73 fprintf(stderr, ": %s\n", aom_codec_error(ctx));
74
75 if (detail) fprintf(stderr, " %s\n", detail);
76
77 if (fatal) exit(EXIT_FAILURE);
78 }
79 }
80
81 static void ctx_exit_on_error(aom_codec_ctx_t *ctx, const char *s, ...) {
82 va_list ap;
83
84 va_start(ap, s);
85 warn_or_exit_on_errorv(ctx, 1, s, ap);
86 va_end(ap);
87 }
88
89 static void warn_or_exit_on_error(aom_codec_ctx_t *ctx, int fatal,
90 const char *s, ...) {
91 va_list ap;
92
93 va_start(ap, s);
94 warn_or_exit_on_errorv(ctx, fatal, s, ap);
95 va_end(ap);
96 }
97
98 static int read_frame(struct AvxInputContext *input_ctx, aom_image_t *img) {
99 FILE *f = input_ctx->file;
100 y4m_input *y4m = &input_ctx->y4m;
101 int shortread = 0;
102
103 if (input_ctx->file_type == FILE_TYPE_Y4M) {
104 if (y4m_input_fetch_frame(y4m, f, img) < 1) return 0;
105 } else {
106 shortread = read_yuv_frame(input_ctx, img);
107 }
108
109 return !shortread;
110 }
111
112 static int file_is_y4m(const char detect[4]) {
113 if (memcmp(detect, "YUV4", 4) == 0) {
114 return 1;
115 }
116 return 0;
117 }
118
119 static int fourcc_is_ivf(const char detect[4]) {
120 if (memcmp(detect, "DKIF", 4) == 0) {
121 return 1;
122 }
123 return 0;
124 }
125
126 static const arg_def_t help =
127 ARG_DEF(NULL, "help", 0, "Show usage options and exit");
128 static const arg_def_t debugmode =
129 ARG_DEF("D", "debug", 0, "Debug mode (makes output deterministic)");
130 static const arg_def_t outputfile =
131 ARG_DEF("o", "output", 1, "Output filename");
132 static const arg_def_t use_yv12 =
133 ARG_DEF(NULL, "yv12", 0, "Input file is YV12 ");
134 static const arg_def_t use_i420 =
135 ARG_DEF(NULL, "i420", 0, "Input file is I420 (default)");
136 static const arg_def_t use_i422 =
137 ARG_DEF(NULL, "i422", 0, "Input file is I422");
138 static const arg_def_t use_i444 =
139 ARG_DEF(NULL, "i444", 0, "Input file is I444");
140 static const arg_def_t codecarg = ARG_DEF(NULL, "codec", 1, "Codec to use");
141 static const arg_def_t passes =
142 ARG_DEF("p", "passes", 1, "Number of passes (1/2)");
143 static const arg_def_t pass_arg =
144 ARG_DEF(NULL, "pass", 1, "Pass to execute (1/2)");
145 static const arg_def_t fpf_name =
146 ARG_DEF(NULL, "fpf", 1, "First pass statistics file name");
147 static const arg_def_t limit =
148 ARG_DEF(NULL, "limit", 1, "Stop encoding after n input frames");
149 static const arg_def_t skip =
150 ARG_DEF(NULL, "skip", 1, "Skip the first n input frames");
151 static const arg_def_t good_dl =
152 ARG_DEF(NULL, "good", 0, "Use Good Quality Deadline");
153 static const arg_def_t rt_dl =
154 ARG_DEF(NULL, "rt", 0, "Use Realtime Quality Deadline");
155 static const arg_def_t quietarg =
156 ARG_DEF("q", "quiet", 0, "Do not print encode progress");
157 static const arg_def_t verbosearg =
158 ARG_DEF("v", "verbose", 0, "Show encoder parameters");
159 static const arg_def_t psnrarg =
160 ARG_DEF(NULL, "psnr", 0, "Show PSNR in status line");
161 static const arg_def_t use_cfg = ARG_DEF("c", "cfg", 1, "Config file to use");
162
163 static const struct arg_enum_list test_decode_enum[] = {
164 { "off", TEST_DECODE_OFF },
165 { "fatal", TEST_DECODE_FATAL },
166 { "warn", TEST_DECODE_WARN },
167 { NULL, 0 }
168 };
169 static const arg_def_t recontest = ARG_DEF_ENUM(
170 NULL, "test-decode", 1, "Test encode/decode mismatch", test_decode_enum);
171 static const arg_def_t framerate =
172 ARG_DEF(NULL, "fps", 1, "Stream frame rate (rate/scale)");
173 static const arg_def_t use_webm =
174 ARG_DEF(NULL, "webm", 0, "Output WebM (default when WebM IO is enabled)");
175 static const arg_def_t use_ivf = ARG_DEF(NULL, "ivf", 0, "Output IVF");
176 static const arg_def_t use_obu = ARG_DEF(NULL, "obu", 0, "Output OBU");
177 static const arg_def_t q_hist_n =
178 ARG_DEF(NULL, "q-hist", 1, "Show quantizer histogram (n-buckets)");
179 static const arg_def_t rate_hist_n =
180 ARG_DEF(NULL, "rate-hist", 1, "Show rate histogram (n-buckets)");
181 static const arg_def_t disable_warnings =
182 ARG_DEF(NULL, "disable-warnings", 0,
183 "Disable warnings about potentially incorrect encode settings.");
184 static const arg_def_t disable_warning_prompt =
185 ARG_DEF("y", "disable-warning-prompt", 0,
186 "Display warnings, but do not prompt user to continue.");
187 static const struct arg_enum_list bitdepth_enum[] = {
188 { "8", AOM_BITS_8 }, { "10", AOM_BITS_10 }, { "12", AOM_BITS_12 }, { NULL, 0 }
189 };
190
191 static const arg_def_t bitdeptharg = ARG_DEF_ENUM(
192 "b", "bit-depth", 1,
193 "Bit depth for codec (8 for version <=1, 10 or 12 for version 2)",
194 bitdepth_enum);
195 static const arg_def_t inbitdeptharg =
196 ARG_DEF(NULL, "input-bit-depth", 1, "Bit depth of input");
197
198 static const arg_def_t input_chroma_subsampling_x = ARG_DEF(
199 NULL, "input-chroma-subsampling-x", 1, "chroma subsampling x value.");
200 static const arg_def_t input_chroma_subsampling_y = ARG_DEF(
201 NULL, "input-chroma-subsampling-y", 1, "chroma subsampling y value.");
202
203 static const arg_def_t *main_args[] = { &help,
204 &use_cfg,
205 &debugmode,
206 &outputfile,
207 &codecarg,
208 &passes,
209 &pass_arg,
210 &fpf_name,
211 &limit,
212 &skip,
213 &good_dl,
214 &rt_dl,
215 &quietarg,
216 &verbosearg,
217 &psnrarg,
218 &use_webm,
219 &use_ivf,
220 &use_obu,
221 &q_hist_n,
222 &rate_hist_n,
223 &disable_warnings,
224 &disable_warning_prompt,
225 &recontest,
226 NULL };
227
228 static const arg_def_t usage =
229 ARG_DEF("u", "usage", 1, "Usage profile number to use");
230 static const arg_def_t threads =
231 ARG_DEF("t", "threads", 1, "Max number of threads to use");
232 static const arg_def_t profile =
233 ARG_DEF(NULL, "profile", 1, "Bitstream profile number to use");
234 static const arg_def_t width = ARG_DEF("w", "width", 1, "Frame width");
235 static const arg_def_t height = ARG_DEF("h", "height", 1, "Frame height");
236 static const arg_def_t forced_max_frame_width = ARG_DEF(
237 NULL, "forced_max_frame_width", 1, "Maximum frame width value to force");
238 static const arg_def_t forced_max_frame_height = ARG_DEF(
239 NULL, "forced_max_frame_height", 1, "Maximum frame height value to force");
240 #if CONFIG_WEBM_IO
241 static const struct arg_enum_list stereo_mode_enum[] = {
242 { "mono", STEREO_FORMAT_MONO },
243 { "left-right", STEREO_FORMAT_LEFT_RIGHT },
244 { "bottom-top", STEREO_FORMAT_BOTTOM_TOP },
245 { "top-bottom", STEREO_FORMAT_TOP_BOTTOM },
246 { "right-left", STEREO_FORMAT_RIGHT_LEFT },
247 { NULL, 0 }
248 };
249 static const arg_def_t stereo_mode = ARG_DEF_ENUM(
250 NULL, "stereo-mode", 1, "Stereo 3D video format", stereo_mode_enum);
251 #endif
252 static const arg_def_t timebase = ARG_DEF(
253 NULL, "timebase", 1, "Output timestamp precision (fractional seconds)");
254 static const arg_def_t global_error_resilient =
255 ARG_DEF(NULL, "global-error-resilient", 1,
256 "Enable global error resiliency features");
257 static const arg_def_t lag_in_frames =
258 ARG_DEF(NULL, "lag-in-frames", 1, "Max number of frames to lag");
259 static const arg_def_t large_scale_tile = ARG_DEF(
260 NULL, "large-scale-tile", 1,
261 "Large scale tile coding (0: off (default), 1: on (ivf output only))");
262 static const arg_def_t monochrome =
263 ARG_DEF(NULL, "monochrome", 0, "Monochrome video (no chroma planes)");
264 static const arg_def_t full_still_picture_hdr = ARG_DEF(
265 NULL, "full-still-picture-hdr", 0, "Use full header for still picture");
266
267 static const arg_def_t *global_args[] = { &use_yv12,
268 &use_i420,
269 &use_i422,
270 &use_i444,
271 &usage,
272 &threads,
273 &profile,
274 &width,
275 &height,
276 &forced_max_frame_width,
277 &forced_max_frame_height,
278 #if CONFIG_WEBM_IO
279 &stereo_mode,
280 #endif
281 &timebase,
282 &framerate,
283 &global_error_resilient,
284 &bitdeptharg,
285 &lag_in_frames,
286 &large_scale_tile,
287 &monochrome,
288 &full_still_picture_hdr,
289 NULL };
290
291 static const arg_def_t dropframe_thresh =
292 ARG_DEF(NULL, "drop-frame", 1, "Temporal resampling threshold (buf %)");
293 static const arg_def_t resize_mode =
294 ARG_DEF(NULL, "resize-mode", 1, "Frame resize mode");
295 static const arg_def_t resize_denominator =
296 ARG_DEF(NULL, "resize-denominator", 1, "Frame resize denominator");
297 static const arg_def_t resize_kf_denominator = ARG_DEF(
298 NULL, "resize-kf-denominator", 1, "Frame resize keyframe denominator");
299 static const arg_def_t superres_mode =
300 ARG_DEF(NULL, "superres-mode", 1, "Frame super-resolution mode");
301 static const arg_def_t superres_denominator = ARG_DEF(
302 NULL, "superres-denominator", 1, "Frame super-resolution denominator");
303 static const arg_def_t superres_kf_denominator =
304 ARG_DEF(NULL, "superres-kf-denominator", 1,
305 "Frame super-resolution keyframe denominator");
306 static const arg_def_t superres_qthresh = ARG_DEF(
307 NULL, "superres-qthresh", 1, "Frame super-resolution qindex threshold");
308 static const arg_def_t superres_kf_qthresh =
309 ARG_DEF(NULL, "superres-kf-qthresh", 1,
310 "Frame super-resolution keyframe qindex threshold");
311 static const struct arg_enum_list end_usage_enum[] = { { "vbr", AOM_VBR },
312 { "cbr", AOM_CBR },
313 { "cq", AOM_CQ },
314 { "q", AOM_Q },
315 { NULL, 0 } };
316 static const arg_def_t end_usage =
317 ARG_DEF_ENUM(NULL, "end-usage", 1, "Rate control mode", end_usage_enum);
318 static const arg_def_t target_bitrate =
319 ARG_DEF(NULL, "target-bitrate", 1, "Bitrate (kbps)");
320 static const arg_def_t min_quantizer =
321 ARG_DEF(NULL, "min-q", 1, "Minimum (best) quantizer");
322 static const arg_def_t max_quantizer =
323 ARG_DEF(NULL, "max-q", 1, "Maximum (worst) quantizer");
324 static const arg_def_t undershoot_pct =
325 ARG_DEF(NULL, "undershoot-pct", 1, "Datarate undershoot (min) target (%)");
326 static const arg_def_t overshoot_pct =
327 ARG_DEF(NULL, "overshoot-pct", 1, "Datarate overshoot (max) target (%)");
328 static const arg_def_t buf_sz =
329 ARG_DEF(NULL, "buf-sz", 1, "Client buffer size (ms)");
330 static const arg_def_t buf_initial_sz =
331 ARG_DEF(NULL, "buf-initial-sz", 1, "Client initial buffer size (ms)");
332 static const arg_def_t buf_optimal_sz =
333 ARG_DEF(NULL, "buf-optimal-sz", 1, "Client optimal buffer size (ms)");
334 static const arg_def_t *rc_args[] = { &dropframe_thresh,
335 &resize_mode,
336 &resize_denominator,
337 &resize_kf_denominator,
338 &superres_mode,
339 &superres_denominator,
340 &superres_kf_denominator,
341 &superres_qthresh,
342 &superres_kf_qthresh,
343 &end_usage,
344 &target_bitrate,
345 &min_quantizer,
346 &max_quantizer,
347 &undershoot_pct,
348 &overshoot_pct,
349 &buf_sz,
350 &buf_initial_sz,
351 &buf_optimal_sz,
352 NULL };
353
354 static const arg_def_t bias_pct =
355 ARG_DEF(NULL, "bias-pct", 1, "CBR/VBR bias (0=CBR, 100=VBR)");
356 static const arg_def_t minsection_pct =
357 ARG_DEF(NULL, "minsection-pct", 1, "GOP min bitrate (% of target)");
358 static const arg_def_t maxsection_pct =
359 ARG_DEF(NULL, "maxsection-pct", 1, "GOP max bitrate (% of target)");
360 static const arg_def_t *rc_twopass_args[] = { &bias_pct, &minsection_pct,
361 &maxsection_pct, NULL };
362 static const arg_def_t fwd_kf_enabled =
363 ARG_DEF(NULL, "enable-fwd-kf", 1, "Enable forward reference keyframes");
364 static const arg_def_t kf_min_dist =
365 ARG_DEF(NULL, "kf-min-dist", 1, "Minimum keyframe interval (frames)");
366 static const arg_def_t kf_max_dist =
367 ARG_DEF(NULL, "kf-max-dist", 1, "Maximum keyframe interval (frames)");
368 static const arg_def_t kf_disabled =
369 ARG_DEF(NULL, "disable-kf", 0, "Disable keyframe placement");
370 static const arg_def_t *kf_args[] = { &fwd_kf_enabled, &kf_min_dist,
371 &kf_max_dist, &kf_disabled, NULL };
372 static const arg_def_t sframe_dist =
373 ARG_DEF(NULL, "sframe-dist", 1, "S-Frame interval (frames)");
374 static const arg_def_t sframe_mode =
375 ARG_DEF(NULL, "sframe-mode", 1, "S-Frame insertion mode (1..2)");
376 static const arg_def_t save_as_annexb =
377 ARG_DEF(NULL, "annexb", 1, "Save as Annex-B");
378 static const arg_def_t noise_sens =
379 ARG_DEF(NULL, "noise-sensitivity", 1, "Noise sensitivity (frames to blur)");
380 static const arg_def_t sharpness =
381 ARG_DEF(NULL, "sharpness", 1, "Loop filter sharpness (0..7)");
382 static const arg_def_t static_thresh =
383 ARG_DEF(NULL, "static-thresh", 1, "Motion detection threshold");
384 static const arg_def_t auto_altref =
385 ARG_DEF(NULL, "auto-alt-ref", 1, "Enable automatic alt reference frames");
386 static const arg_def_t arnr_maxframes =
387 ARG_DEF(NULL, "arnr-maxframes", 1, "AltRef max frames (0..15)");
388 static const arg_def_t arnr_strength =
389 ARG_DEF(NULL, "arnr-strength", 1, "AltRef filter strength (0..6)");
390 static const struct arg_enum_list tuning_enum[] = {
391 { "psnr", AOM_TUNE_PSNR },
392 { "ssim", AOM_TUNE_SSIM },
393 #if CONFIG_DIST_8X8
394 { "cdef-dist", AOM_TUNE_CDEF_DIST },
395 { "daala-dist", AOM_TUNE_DAALA_DIST },
396 #endif
397 { NULL, 0 }
398 };
399 static const arg_def_t tune_metric =
400 ARG_DEF_ENUM(NULL, "tune", 1, "Distortion metric tuned with", tuning_enum);
401 static const arg_def_t cq_level =
402 ARG_DEF(NULL, "cq-level", 1, "Constant/Constrained Quality level");
403 static const arg_def_t max_intra_rate_pct =
404 ARG_DEF(NULL, "max-intra-rate", 1, "Max I-frame bitrate (pct)");
405
406 #if CONFIG_AV1_ENCODER
407 static const arg_def_t cpu_used_av1 =
408 ARG_DEF(NULL, "cpu-used", 1, "CPU Used (0..5)");
409 static const arg_def_t rowmtarg =
410 ARG_DEF(NULL, "row-mt", 1,
411 "Enable row based multi-threading (0: off, 1: on (default))");
412 static const arg_def_t tile_cols =
413 ARG_DEF(NULL, "tile-columns", 1, "Number of tile columns to use, log2");
414 static const arg_def_t tile_rows =
415 ARG_DEF(NULL, "tile-rows", 1, "Number of tile rows to use, log2");
416 static const arg_def_t enable_tpl_model =
417 ARG_DEF(NULL, "enable-tpl-model", 1,
418 "RDO based on frame temporal dependency "
419 "(0: off, 1: backward source based, 2: forward 2-pass). "
420 "This is required for deltaq mode.");
421 static const arg_def_t enable_keyframe_filtering =
422 ARG_DEF(NULL, "enable-keyframe-filtering", 1,
423 "Apply temporal filtering on key frame "
424 "(0: false, 1: true (default)");
425 static const arg_def_t tile_width =
426 ARG_DEF(NULL, "tile-width", 1, "Tile widths (comma separated)");
427 static const arg_def_t tile_height =
428 ARG_DEF(NULL, "tile-height", 1, "Tile heights (command separated)");
429 static const arg_def_t lossless =
430 ARG_DEF(NULL, "lossless", 1, "Lossless mode (0: false (default), 1: true)");
431 static const arg_def_t enable_cdef =
432 ARG_DEF(NULL, "enable-cdef", 1,
433 "Enable the constrained directional enhancement filter (0: false, "
434 "1: true (default))");
435 static const arg_def_t enable_restoration = ARG_DEF(
436 NULL, "enable-restoration", 1,
437 "Enable the loop restoration filter (0: false (default in Realtime mode), "
438 "1: true (default in Non-realtime mode))");
439 static const arg_def_t enable_rect_partitions =
440 ARG_DEF(NULL, "enable-rect-partitions", 1,
441 "Enable rectangular partitions "
442 "(0: false, 1: true (default))");
443 static const arg_def_t enable_ab_partitions =
444 ARG_DEF(NULL, "enable-ab-partitions", 1,
445 "Enable ab partitions (0: false, 1: true (default))");
446 static const arg_def_t enable_1to4_partitions =
447 ARG_DEF(NULL, "enable-1to4-partitions", 1,
448 "Enable 1:4 and 4:1 partitions "
449 "(0: false, 1: true (default))");
450 static const arg_def_t min_partition_size =
451 ARG_DEF(NULL, "min-partition-size", 4,
452 "Set min partition size "
453 "(4:4x4, 8:8x8, 16:16x16, 32:32x32, 64:64x64, 128:128x128). "
454 "On frame with 4k+ resolutions or higher speed settings, the min "
455 "partition size will have a minimum of 8.");
456 static const arg_def_t max_partition_size =
457 ARG_DEF(NULL, "max-partition-size", 128,
458 "Set max partition size "
459 "(4:4x4, 8:8x8, 16:16x16, 32:32x32, 64:64x64, 128:128x128)");
460 static const arg_def_t enable_dual_filter =
461 ARG_DEF(NULL, "enable-dual-filter", 1,
462 "Enable dual filter "
463 "(0: false, 1: true (default))");
464 static const arg_def_t enable_chroma_deltaq =
465 ARG_DEF(NULL, "enable-chroma-deltaq", 1,
466 "Enable chroma delta quant "
467 "(0: false (default), 1: true)");
468 static const arg_def_t enable_intra_edge_filter =
469 ARG_DEF(NULL, "enable-intra-edge-filter", 1,
470 "Enable intra edge filtering "
471 "(0: false, 1: true (default))");
472 static const arg_def_t enable_order_hint =
473 ARG_DEF(NULL, "enable-order-hint", 1,
474 "Enable order hint "
475 "(0: false, 1: true (default))");
476 static const arg_def_t enable_tx64 =
477 ARG_DEF(NULL, "enable-tx64", 1,
478 "Enable 64-pt transform (0: false, 1: true (default))");
479 static const arg_def_t enable_flip_idtx =
480 ARG_DEF(NULL, "enable-flip-idtx", 1,
481 "Enable extended transform type (0: false, 1: true (default)) "
482 "including FLIPADST_DCT, DCT_FLIPADST, FLIPADST_FLIPADST, "
483 "ADST_FLIPADST, FLIPADST_ADST, IDTX, V_DCT, H_DCT, V_ADST, "
484 "H_ADST, V_FLIPADST, H_FLIPADST");
485 static const arg_def_t enable_dist_wtd_comp =
486 ARG_DEF(NULL, "enable-dist-wtd-comp", 1,
487 "Enable distance-weighted compound "
488 "(0: false, 1: true (default))");
489 static const arg_def_t enable_masked_comp =
490 ARG_DEF(NULL, "enable-masked-comp", 1,
491 "Enable masked (wedge/diff-wtd) compound "
492 "(0: false, 1: true (default))");
493 static const arg_def_t enable_onesided_comp =
494 ARG_DEF(NULL, "enable-onesided-comp", 1,
495 "Enable one sided compound "
496 "(0: false, 1: true (default))");
497 static const arg_def_t enable_interintra_comp =
498 ARG_DEF(NULL, "enable-interintra-comp", 1,
499 "Enable interintra compound "
500 "(0: false, 1: true (default))");
501 static const arg_def_t enable_smooth_interintra =
502 ARG_DEF(NULL, "enable-smooth-interintra", 1,
503 "Enable smooth interintra mode "
504 "(0: false, 1: true (default))");
505 static const arg_def_t enable_diff_wtd_comp =
506 ARG_DEF(NULL, "enable-diff-wtd-comp", 1,
507 "Enable difference-weighted compound "
508 "(0: false, 1: true (default))");
509 static const arg_def_t enable_interinter_wedge =
510 ARG_DEF(NULL, "enable-interinter-wedge", 1,
511 "Enable interinter wedge compound "
512 "(0: false, 1: true (default))");
513 static const arg_def_t enable_interintra_wedge =
514 ARG_DEF(NULL, "enable-interintra-wedge", 1,
515 "Enable interintra wedge compound "
516 "(0: false, 1: true (default))");
517 static const arg_def_t enable_global_motion =
518 ARG_DEF(NULL, "enable-global-motion", 1,
519 "Enable global motion "
520 "(0: false, 1: true (default))");
521 static const arg_def_t enable_warped_motion =
522 ARG_DEF(NULL, "enable-warped-motion", 1,
523 "Enable local warped motion "
524 "(0: false, 1: true (default))");
525 static const arg_def_t enable_filter_intra =
526 ARG_DEF(NULL, "enable-filter-intra", 1,
527 "Enable filter intra prediction mode "
528 "(0: false, 1: true (default))");
529 static const arg_def_t enable_smooth_intra =
530 ARG_DEF(NULL, "enable-smooth-intra", 1,
531 "Enable smooth intra prediction modes "
532 "(0: false, 1: true (default))");
533 static const arg_def_t enable_paeth_intra =
534 ARG_DEF(NULL, "enable-paeth-intra", 1,
535 "Enable Paeth intra prediction mode (0: false, 1: true (default))");
536 static const arg_def_t enable_cfl_intra =
537 ARG_DEF(NULL, "enable-cfl-intra", 1,
538 "Enable chroma from luma intra prediction mode "
539 "(0: false, 1: true (default))");
540 static const arg_def_t force_video_mode =
541 ARG_DEF(NULL, "force-video-mode", 1,
542 "Force video mode (0: false, 1: true (default))");
543 static const arg_def_t enable_obmc = ARG_DEF(
544 NULL, "enable-obmc", 1, "Enable OBMC (0: false, 1: true (default))");
545 static const arg_def_t enable_overlay =
546 ARG_DEF(NULL, "enable-overlay", 1,
547 "Enable coding overlay frames (0: false, 1: true (default))");
548 static const arg_def_t enable_palette =
549 ARG_DEF(NULL, "enable-palette", 1,
550 "Enable palette prediction mode (0: false, 1: true (default))");
551 static const arg_def_t enable_intrabc =
552 ARG_DEF(NULL, "enable-intrabc", 1,
553 "Enable intra block copy prediction mode "
554 "(0: false, 1: true (default))");
555 static const arg_def_t enable_angle_delta =
556 ARG_DEF(NULL, "enable-angle-delta", 1,
557 "Enable intra angle delta (0: false, 1: true (default))");
558 static const arg_def_t disable_trellis_quant =
559 ARG_DEF(NULL, "disable-trellis-quant", 1,
560 "Disable trellis optimization of quantized coefficients (0: false "
561 "1: true 2: true for rd search 3: true for estimate yrd serch "
562 "(default))");
563 static const arg_def_t enable_qm =
564 ARG_DEF(NULL, "enable-qm", 1,
565 "Enable quantisation matrices (0: false (default), 1: true)");
566 static const arg_def_t qm_min = ARG_DEF(
567 NULL, "qm-min", 1, "Min quant matrix flatness (0..15), default is 8");
568 static const arg_def_t qm_max = ARG_DEF(
569 NULL, "qm-max", 1, "Max quant matrix flatness (0..15), default is 15");
570 static const arg_def_t reduced_tx_type_set = ARG_DEF(
571 NULL, "reduced-tx-type-set", 1, "Use reduced set of transform types");
572 static const arg_def_t use_intra_dct_only =
573 ARG_DEF(NULL, "use-intra-dct-only", 1, "Use DCT only for INTRA modes");
574 static const arg_def_t use_inter_dct_only =
575 ARG_DEF(NULL, "use-inter-dct-only", 1, "Use DCT only for INTER modes");
576 static const arg_def_t use_intra_default_tx_only =
577 ARG_DEF(NULL, "use-intra-default-tx-only", 1,
578 "Use Default-transform only for INTRA modes");
579 static const arg_def_t quant_b_adapt =
580 ARG_DEF(NULL, "quant-b-adapt", 1, "Use adaptive quantize_b");
581 static const arg_def_t coeff_cost_upd_freq =
582 ARG_DEF(NULL, "coeff-cost-upd-freq", 1,
583 "Update freq for coeff costs"
584 "0: SB, 1: SB Row per Tile, 2: Tile");
585 static const arg_def_t mode_cost_upd_freq =
586 ARG_DEF(NULL, "mode-cost-upd-freq", 1,
587 "Update freq for mode costs"
588 "0: SB, 1: SB Row per Tile, 2: Tile");
589 static const arg_def_t mv_cost_upd_freq =
590 ARG_DEF(NULL, "mv-cost-upd-freq", 1,
591 "Update freq for mv costs"
592 "0: SB, 1: SB Row per Tile, 2: Tile, 3: Off");
593 #if CONFIG_DIST_8X8
594 static const arg_def_t enable_dist_8x8 =
595 ARG_DEF(NULL, "enable-dist-8x8", 1,
596 "Enable dist-8x8 (0: false (default), 1: true)");
597 #endif // CONFIG_DIST_8X8
598 static const arg_def_t num_tg = ARG_DEF(
599 NULL, "num-tile-groups", 1, "Maximum number of tile groups, default is 1");
600 static const arg_def_t mtu_size =
601 ARG_DEF(NULL, "mtu-size", 1,
602 "MTU size for a tile group, default is 0 (no MTU targeting), "
603 "overrides maximum number of tile groups");
604 static const struct arg_enum_list timing_info_enum[] = {
605 { "unspecified", AOM_TIMING_UNSPECIFIED },
606 { "constant", AOM_TIMING_EQUAL },
607 { "model", AOM_TIMING_DEC_MODEL },
608 { NULL, 0 }
609 };
610 static const arg_def_t timing_info =
611 ARG_DEF_ENUM(NULL, "timing-info", 1,
612 "Signal timing info in the bitstream (model unly works for no "
613 "hidden frames, no super-res yet):",
614 timing_info_enum);
615 static const arg_def_t film_grain_test =
616 ARG_DEF(NULL, "film-grain-test", 1,
617 "Film grain test vectors (0: none (default), 1: test-1 2: test-2, "
618 "... 16: test-16)");
619 static const arg_def_t film_grain_table =
620 ARG_DEF(NULL, "film-grain-table", 1,
621 "Path to file containing film grain parameters");
622 #if CONFIG_DENOISE
623 static const arg_def_t denoise_noise_level =
624 ARG_DEF(NULL, "denoise-noise-level", 1,
625 "Amount of noise (from 0 = don't denoise, to 50)");
626 static const arg_def_t denoise_block_size =
627 ARG_DEF(NULL, "denoise-block-size", 1, "Denoise block size (default = 32)");
628 #endif
629 static const arg_def_t enable_ref_frame_mvs =
630 ARG_DEF(NULL, "enable-ref-frame-mvs", 1,
631 "Enable temporal mv prediction (default is 1)");
632 static const arg_def_t frame_parallel_decoding =
633 ARG_DEF(NULL, "frame-parallel", 1,
634 "Enable frame parallel decodability features "
635 "(0: false (default), 1: true)");
636 static const arg_def_t error_resilient_mode =
637 ARG_DEF(NULL, "error-resilient", 1,
638 "Enable error resilient features "
639 "(0: false (default), 1: true)");
640 static const arg_def_t aq_mode = ARG_DEF(
641 NULL, "aq-mode", 1,
642 "Adaptive quantization mode (0: off (default), 1: variance 2: complexity, "
643 "3: cyclic refresh)");
644 static const arg_def_t deltaq_mode =
645 ARG_DEF(NULL, "deltaq-mode", 1,
646 "Delta qindex mode (0: off, 1: deltaq objective (default), "
647 "2: deltaq perceptual). "
648 "Currently this requires enable-tpl-model as a prerequisite.");
649 static const arg_def_t deltalf_mode = ARG_DEF(
650 NULL, "delta-lf-mode", 1, "Enable delta-lf-mode (0: off (default), 1: on)");
651 static const arg_def_t frame_periodic_boost =
652 ARG_DEF(NULL, "frame-boost", 1,
653 "Enable frame periodic boost (0: off (default), 1: on)");
654 static const arg_def_t gf_cbr_boost_pct = ARG_DEF(
655 NULL, "gf-cbr-boost", 1, "Boost for Golden Frame in CBR mode (pct)");
656 static const arg_def_t max_inter_rate_pct =
657 ARG_DEF(NULL, "max-inter-rate", 1, "Max P-frame bitrate (pct)");
658 static const arg_def_t min_gf_interval = ARG_DEF(
659 NULL, "min-gf-interval", 1,
660 "min gf/arf frame interval (default 0, indicating in-built behavior)");
661 static const arg_def_t max_gf_interval = ARG_DEF(
662 NULL, "max-gf-interval", 1,
663 "max gf/arf frame interval (default 0, indicating in-built behavior)");
664 static const arg_def_t gf_max_pyr_height =
665 ARG_DEF(NULL, "gf-max-pyr-height", 1,
666 "maximum height for GF group pyramid structure (0 to 4 (default))");
667 static const arg_def_t max_reference_frames = ARG_DEF(
668 NULL, "max-reference-frames", 1,
669 "maximum number of reference frames allowed per frame (3 to 7 (default))");
670 static const arg_def_t reduced_reference_set =
671 ARG_DEF(NULL, "reduced-reference-set", 1,
672 "Use reduced set of single and compound references (0: off "
673 "(default), 1: on)");
674 static const arg_def_t target_seq_level_idx =
675 ARG_DEF(NULL, "target-seq-level-idx", 1,
676 "Target sequence level index. "
677 "Possible values are in the form of \"ABxy\"(pad leading zeros if "
678 "less than 4 digits). "
679 "AB: Operating point(OP) index; "
680 "xy: Target level index for the OP. "
681 "E.g. \"0\" means target level index 0 for the 0th OP; "
682 "\"1021\" means target level index 21 for the 10th OP.");
683 static const arg_def_t set_min_cr =
684 ARG_DEF(NULL, "min-cr", 1,
685 "Set minimum compression ratio. Take integer values. Default is 0. "
686 "If non-zero, encoder will try to keep the compression ratio of "
687 "each frame to be higher than the given value divided by 100.");
688
689 static const struct arg_enum_list color_primaries_enum[] = {
690 { "bt709", AOM_CICP_CP_BT_709 },
691 { "unspecified", AOM_CICP_CP_UNSPECIFIED },
692 { "bt601", AOM_CICP_CP_BT_601 },
693 { "bt470m", AOM_CICP_CP_BT_470_M },
694 { "bt470bg", AOM_CICP_CP_BT_470_B_G },
695 { "smpte240", AOM_CICP_CP_SMPTE_240 },
696 { "film", AOM_CICP_CP_GENERIC_FILM },
697 { "bt2020", AOM_CICP_CP_BT_2020 },
698 { "xyz", AOM_CICP_CP_XYZ },
699 { "smpte431", AOM_CICP_CP_SMPTE_431 },
700 { "smpte432", AOM_CICP_CP_SMPTE_432 },
701 { "ebu3213", AOM_CICP_CP_EBU_3213 },
702 { NULL, 0 }
703 };
704
705 static const arg_def_t input_color_primaries = ARG_DEF_ENUM(
706 NULL, "color-primaries", 1,
707 "Color primaries (CICP) of input content:", color_primaries_enum);
708
709 static const struct arg_enum_list transfer_characteristics_enum[] = {
710 { "unspecified", AOM_CICP_CP_UNSPECIFIED },
711 { "bt709", AOM_CICP_TC_BT_709 },
712 { "bt470m", AOM_CICP_TC_BT_470_M },
713 { "bt470bg", AOM_CICP_TC_BT_470_B_G },
714 { "bt601", AOM_CICP_TC_BT_601 },
715 { "smpte240", AOM_CICP_TC_SMPTE_240 },
716 { "lin", AOM_CICP_TC_LINEAR },
717 { "log100", AOM_CICP_TC_LOG_100 },
718 { "log100sq10", AOM_CICP_TC_LOG_100_SQRT10 },
719 { "iec61966", AOM_CICP_TC_IEC_61966 },
720 { "bt1361", AOM_CICP_TC_BT_1361 },
721 { "srgb", AOM_CICP_TC_SRGB },
722 { "bt2020-10bit", AOM_CICP_TC_BT_2020_10_BIT },
723 { "bt2020-12bit", AOM_CICP_TC_BT_2020_12_BIT },
724 { "smpte2084", AOM_CICP_TC_SMPTE_2084 },
725 { "hlg", AOM_CICP_TC_HLG },
726 { "smpte428", AOM_CICP_TC_SMPTE_428 },
727 { NULL, 0 }
728 };
729
730 static const arg_def_t input_transfer_characteristics =
731 ARG_DEF_ENUM(NULL, "transfer-characteristics", 1,
732 "Transfer characteristics (CICP) of input content:",
733 transfer_characteristics_enum);
734
735 static const struct arg_enum_list matrix_coefficients_enum[] = {
736 { "identity", AOM_CICP_MC_IDENTITY },
737 { "bt709", AOM_CICP_MC_BT_709 },
738 { "unspecified", AOM_CICP_MC_UNSPECIFIED },
739 { "fcc73", AOM_CICP_MC_FCC },
740 { "bt470bg", AOM_CICP_MC_BT_470_B_G },
741 { "bt601", AOM_CICP_MC_BT_601 },
742 { "smpte240", AOM_CICP_CP_SMPTE_240 },
743 { "ycgco", AOM_CICP_MC_SMPTE_YCGCO },
744 { "bt2020ncl", AOM_CICP_MC_BT_2020_NCL },
745 { "bt2020cl", AOM_CICP_MC_BT_2020_CL },
746 { "smpte2085", AOM_CICP_MC_SMPTE_2085 },
747 { "chromncl", AOM_CICP_MC_CHROMAT_NCL },
748 { "chromcl", AOM_CICP_MC_CHROMAT_CL },
749 { "ictcp", AOM_CICP_MC_ICTCP },
750 { NULL, 0 }
751 };
752
753 static const arg_def_t input_matrix_coefficients = ARG_DEF_ENUM(
754 NULL, "matrix-coefficients", 1,
755 "Matrix coefficients (CICP) of input content:", matrix_coefficients_enum);
756
757 static const struct arg_enum_list chroma_sample_position_enum[] = {
758 { "unknown", AOM_CSP_UNKNOWN },
759 { "vertical", AOM_CSP_VERTICAL },
760 { "colocated", AOM_CSP_COLOCATED },
761 { NULL, 0 }
762 };
763
764 static const arg_def_t input_chroma_sample_position =
765 ARG_DEF_ENUM(NULL, "chroma-sample-position", 1,
766 "The chroma sample position when chroma 4:2:0 is signaled:",
767 chroma_sample_position_enum);
768
769 static const struct arg_enum_list tune_content_enum[] = {
770 { "default", AOM_CONTENT_DEFAULT },
771 { "screen", AOM_CONTENT_SCREEN },
772 { NULL, 0 }
773 };
774
775 static const arg_def_t tune_content = ARG_DEF_ENUM(
776 NULL, "tune-content", 1, "Tune content type", tune_content_enum);
777
778 static const arg_def_t cdf_update_mode =
779 ARG_DEF(NULL, "cdf-update-mode", 1,
780 "CDF update mode for entropy coding "
781 "(0: no CDF update; 1: update CDF on all frames(default); "
782 "2: selectively update CDF on some frames");
783
784 static const struct arg_enum_list superblock_size_enum[] = {
785 { "dynamic", AOM_SUPERBLOCK_SIZE_DYNAMIC },
786 { "64", AOM_SUPERBLOCK_SIZE_64X64 },
787 { "128", AOM_SUPERBLOCK_SIZE_128X128 },
788 { NULL, 0 }
789 };
790 static const arg_def_t superblock_size = ARG_DEF_ENUM(
791 NULL, "sb-size", 1, "Superblock size to use", superblock_size_enum);
792
793 static const arg_def_t set_tier_mask =
794 ARG_DEF(NULL, "set-tier-mask", 1,
795 "Set bit mask to specify which tier each of the 32 possible "
796 "operating points conforms to. "
797 "Bit value 0(defualt): Main Tier; 1: High Tier.");
798
799 static const arg_def_t *av1_args[] = { &cpu_used_av1,
800 &auto_altref,
801 &sharpness,
802 &static_thresh,
803 &rowmtarg,
804 &tile_cols,
805 &tile_rows,
806 &enable_tpl_model,
807 &enable_keyframe_filtering,
808 &arnr_maxframes,
809 &arnr_strength,
810 &tune_metric,
811 &cq_level,
812 &max_intra_rate_pct,
813 &max_inter_rate_pct,
814 &gf_cbr_boost_pct,
815 &lossless,
816 &enable_cdef,
817 &enable_restoration,
818 &enable_rect_partitions,
819 &enable_ab_partitions,
820 &enable_1to4_partitions,
821 &min_partition_size,
822 &max_partition_size,
823 &enable_dual_filter,
824 &enable_chroma_deltaq,
825 &enable_intra_edge_filter,
826 &enable_order_hint,
827 &enable_tx64,
828 &enable_flip_idtx,
829 &enable_dist_wtd_comp,
830 &enable_masked_comp,
831 &enable_onesided_comp,
832 &enable_interintra_comp,
833 &enable_smooth_interintra,
834 &enable_diff_wtd_comp,
835 &enable_interinter_wedge,
836 &enable_interintra_wedge,
837 &enable_global_motion,
838 &enable_warped_motion,
839 &enable_filter_intra,
840 &enable_smooth_intra,
841 &enable_paeth_intra,
842 &enable_cfl_intra,
843 &force_video_mode,
844 &enable_obmc,
845 &enable_overlay,
846 &enable_palette,
847 &enable_intrabc,
848 &enable_angle_delta,
849 &disable_trellis_quant,
850 &enable_qm,
851 &qm_min,
852 &qm_max,
853 &reduced_tx_type_set,
854 &use_intra_dct_only,
855 &use_inter_dct_only,
856 &use_intra_default_tx_only,
857 &quant_b_adapt,
858 &coeff_cost_upd_freq,
859 &mode_cost_upd_freq,
860 &mv_cost_upd_freq,
861 #if CONFIG_DIST_8X8
862 &enable_dist_8x8,
863 #endif
864 &frame_parallel_decoding,
865 &error_resilient_mode,
866 &aq_mode,
867 &deltaq_mode,
868 &deltalf_mode,
869 &frame_periodic_boost,
870 &noise_sens,
871 &tune_content,
872 &cdf_update_mode,
873 &input_color_primaries,
874 &input_transfer_characteristics,
875 &input_matrix_coefficients,
876 &input_chroma_sample_position,
877 &min_gf_interval,
878 &max_gf_interval,
879 &gf_max_pyr_height,
880 &superblock_size,
881 &num_tg,
882 &mtu_size,
883 &timing_info,
884 &film_grain_test,
885 &film_grain_table,
886 #if CONFIG_DENOISE
887 &denoise_noise_level,
888 &denoise_block_size,
889 #endif // CONFIG_DENOISE
890 &max_reference_frames,
891 &reduced_reference_set,
892 &enable_ref_frame_mvs,
893 &target_seq_level_idx,
894 &set_tier_mask,
895 &set_min_cr,
896 &bitdeptharg,
897 &inbitdeptharg,
898 &input_chroma_subsampling_x,
899 &input_chroma_subsampling_y,
900 &sframe_dist,
901 &sframe_mode,
902 &save_as_annexb,
903 NULL };
904 static const int av1_arg_ctrl_map[] = { AOME_SET_CPUUSED,
905 AOME_SET_ENABLEAUTOALTREF,
906 AOME_SET_SHARPNESS,
907 AOME_SET_STATIC_THRESHOLD,
908 AV1E_SET_ROW_MT,
909 AV1E_SET_TILE_COLUMNS,
910 AV1E_SET_TILE_ROWS,
911 AV1E_SET_ENABLE_TPL_MODEL,
912 AV1E_SET_ENABLE_KEYFRAME_FILTERING,
913 AOME_SET_ARNR_MAXFRAMES,
914 AOME_SET_ARNR_STRENGTH,
915 AOME_SET_TUNING,
916 AOME_SET_CQ_LEVEL,
917 AOME_SET_MAX_INTRA_BITRATE_PCT,
918 AV1E_SET_MAX_INTER_BITRATE_PCT,
919 AV1E_SET_GF_CBR_BOOST_PCT,
920 AV1E_SET_LOSSLESS,
921 AV1E_SET_ENABLE_CDEF,
922 AV1E_SET_ENABLE_RESTORATION,
923 AV1E_SET_ENABLE_RECT_PARTITIONS,
924 AV1E_SET_ENABLE_AB_PARTITIONS,
925 AV1E_SET_ENABLE_1TO4_PARTITIONS,
926 AV1E_SET_MIN_PARTITION_SIZE,
927 AV1E_SET_MAX_PARTITION_SIZE,
928 AV1E_SET_ENABLE_DUAL_FILTER,
929 AV1E_SET_ENABLE_CHROMA_DELTAQ,
930 AV1E_SET_ENABLE_INTRA_EDGE_FILTER,
931 AV1E_SET_ENABLE_ORDER_HINT,
932 AV1E_SET_ENABLE_TX64,
933 AV1E_SET_ENABLE_FLIP_IDTX,
934 AV1E_SET_ENABLE_DIST_WTD_COMP,
935 AV1E_SET_ENABLE_MASKED_COMP,
936 AV1E_SET_ENABLE_ONESIDED_COMP,
937 AV1E_SET_ENABLE_INTERINTRA_COMP,
938 AV1E_SET_ENABLE_SMOOTH_INTERINTRA,
939 AV1E_SET_ENABLE_DIFF_WTD_COMP,
940 AV1E_SET_ENABLE_INTERINTER_WEDGE,
941 AV1E_SET_ENABLE_INTERINTRA_WEDGE,
942 AV1E_SET_ENABLE_GLOBAL_MOTION,
943 AV1E_SET_ENABLE_WARPED_MOTION,
944 AV1E_SET_ENABLE_FILTER_INTRA,
945 AV1E_SET_ENABLE_SMOOTH_INTRA,
946 AV1E_SET_ENABLE_PAETH_INTRA,
947 AV1E_SET_ENABLE_CFL_INTRA,
948 AV1E_SET_FORCE_VIDEO_MODE,
949 AV1E_SET_ENABLE_OBMC,
950 AV1E_SET_ENABLE_OVERLAY,
951 AV1E_SET_ENABLE_PALETTE,
952 AV1E_SET_ENABLE_INTRABC,
953 AV1E_SET_ENABLE_ANGLE_DELTA,
954 AV1E_SET_DISABLE_TRELLIS_QUANT,
955 AV1E_SET_ENABLE_QM,
956 AV1E_SET_QM_MIN,
957 AV1E_SET_QM_MAX,
958 AV1E_SET_REDUCED_TX_TYPE_SET,
959 AV1E_SET_INTRA_DCT_ONLY,
960 AV1E_SET_INTER_DCT_ONLY,
961 AV1E_SET_INTRA_DEFAULT_TX_ONLY,
962 AV1E_SET_QUANT_B_ADAPT,
963 AV1E_SET_COEFF_COST_UPD_FREQ,
964 AV1E_SET_MODE_COST_UPD_FREQ,
965 AV1E_SET_MV_COST_UPD_FREQ,
966 #if CONFIG_DIST_8X8
967 AV1E_SET_ENABLE_DIST_8X8,
968 #endif
969 AV1E_SET_FRAME_PARALLEL_DECODING,
970 AV1E_SET_ERROR_RESILIENT_MODE,
971 AV1E_SET_AQ_MODE,
972 AV1E_SET_DELTAQ_MODE,
973 AV1E_SET_DELTALF_MODE,
974 AV1E_SET_FRAME_PERIODIC_BOOST,
975 AV1E_SET_NOISE_SENSITIVITY,
976 AV1E_SET_TUNE_CONTENT,
977 AV1E_SET_CDF_UPDATE_MODE,
978 AV1E_SET_COLOR_PRIMARIES,
979 AV1E_SET_TRANSFER_CHARACTERISTICS,
980 AV1E_SET_MATRIX_COEFFICIENTS,
981 AV1E_SET_CHROMA_SAMPLE_POSITION,
982 AV1E_SET_MIN_GF_INTERVAL,
983 AV1E_SET_MAX_GF_INTERVAL,
984 AV1E_SET_GF_MAX_PYRAMID_HEIGHT,
985 AV1E_SET_SUPERBLOCK_SIZE,
986 AV1E_SET_NUM_TG,
987 AV1E_SET_MTU,
988 AV1E_SET_TIMING_INFO_TYPE,
989 AV1E_SET_FILM_GRAIN_TEST_VECTOR,
990 AV1E_SET_FILM_GRAIN_TABLE,
991 #if CONFIG_DENOISE
992 AV1E_SET_DENOISE_NOISE_LEVEL,
993 AV1E_SET_DENOISE_BLOCK_SIZE,
994 #endif // CONFIG_DENOISE
995 AV1E_SET_MAX_REFERENCE_FRAMES,
996 AV1E_SET_REDUCED_REFERENCE_SET,
997 AV1E_SET_ENABLE_REF_FRAME_MVS,
998 AV1E_SET_TARGET_SEQ_LEVEL_IDX,
999 AV1E_SET_TIER_MASK,
1000 AV1E_SET_MIN_CR,
1001 0 };
1002 #endif // CONFIG_AV1_ENCODER
1003
1004 static const arg_def_t *no_args[] = { NULL };
1005
1006 static void show_help(FILE *fout, int shorthelp) {
1007 fprintf(fout, "Usage: %s <options> -o dst_filename src_filename \n",
1008 exec_name);
1009
1010 if (shorthelp) {
1011 fprintf(fout, "Use --help to see the full list of options.\n");
1012 return;
1013 }
1014
1015 fprintf(fout, "\nOptions:\n");
1016 arg_show_usage(fout, main_args);
1017 fprintf(fout, "\nEncoder Global Options:\n");
1018 arg_show_usage(fout, global_args);
1019 fprintf(fout, "\nRate Control Options:\n");
1020 arg_show_usage(fout, rc_args);
1021 fprintf(fout, "\nTwopass Rate Control Options:\n");
1022 arg_show_usage(fout, rc_twopass_args);
1023 fprintf(fout, "\nKeyframe Placement Options:\n");
1024 arg_show_usage(fout, kf_args);
1025 #if CONFIG_AV1_ENCODER
1026 fprintf(fout, "\nAV1 Specific Options:\n");
1027 arg_show_usage(fout, av1_args);
1028 #endif
1029 fprintf(fout,
1030 "\nStream timebase (--timebase):\n"
1031 " The desired precision of timestamps in the output, expressed\n"
1032 " in fractional seconds. Default is 1/1000.\n");
1033 fprintf(fout, "\nIncluded encoders:\n\n");
1034
1035 const int num_encoder = get_aom_encoder_count();
1036 for (int i = 0; i < num_encoder; ++i) {
1037 const AvxInterface *const encoder = get_aom_encoder_by_index(i);
1038 const char *defstr = (i == (num_encoder - 1)) ? "(default)" : "";
1039 fprintf(fout, " %-6s - %s %s\n", encoder->name,
1040 aom_codec_iface_name(encoder->codec_interface()), defstr);
1041 }
1042 fprintf(fout, "\n ");
1043 fprintf(fout, "Use --codec to switch to a non-default encoder.\n\n");
1044 }
1045
1046 void usage_exit(void) {
1047 show_help(stderr, 1);
1048 exit(EXIT_FAILURE);
1049 }
1050
1051 #if CONFIG_AV1_ENCODER
1052 #define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map)
1053 #endif
1054
1055 #if !CONFIG_WEBM_IO
1056 typedef int stereo_format_t;
1057 struct WebmOutputContext {
1058 int debug;
1059 };
1060 #endif
1061
1062 /* Per-stream configuration */
1063 struct stream_config {
1064 struct aom_codec_enc_cfg cfg;
1065 const char *out_fn;
1066 const char *stats_fn;
1067 stereo_format_t stereo_fmt;
1068 int arg_ctrls[ARG_CTRL_CNT_MAX][2];
1069 int arg_ctrl_cnt;
1070 int write_webm;
1071 const char *film_grain_filename;
1072 int write_ivf;
1073 // whether to use 16bit internal buffers
1074 int use_16bit_internal;
1075 };
1076
1077 struct stream_state {
1078 int index;
1079 struct stream_state *next;
1080 struct stream_config config;
1081 FILE *file;
1082 struct rate_hist *rate_hist;
1083 struct WebmOutputContext webm_ctx;
1084 uint64_t psnr_sse_total;
1085 uint64_t psnr_samples_total;
1086 double psnr_totals[4];
1087 int psnr_count;
1088 int counts[64];
1089 aom_codec_ctx_t encoder;
1090 unsigned int frames_out;
1091 uint64_t cx_time;
1092 size_t nbytes;
1093 stats_io_t stats;
1094 struct aom_image *img;
1095 aom_codec_ctx_t decoder;
1096 int mismatch_seen;
1097 unsigned int chroma_subsampling_x;
1098 unsigned int chroma_subsampling_y;
1099 };
1100
1101 static void validate_positive_rational(const char *msg,
1102 struct aom_rational *rat) {
1103 if (rat->den < 0) {
1104 rat->num *= -1;
1105 rat->den *= -1;
1106 }
1107
1108 if (rat->num < 0) die("Error: %s must be positive\n", msg);
1109
1110 if (!rat->den) die("Error: %s has zero denominator\n", msg);
1111 }
1112
1113 static void init_config(cfg_options_t *config) {
1114 memset(config, 0, sizeof(cfg_options_t));
1115 config->super_block_size = 0; // Dynamic
1116 config->max_partition_size = 128;
1117 config->min_partition_size = 4;
1118 config->disable_trellis_quant = 3;
1119 }
1120
1121 /* Parses global config arguments into the AvxEncoderConfig. Note that
1122 * argv is modified and overwrites all parsed arguments.
1123 */
1124 static void parse_global_config(struct AvxEncoderConfig *global, char ***argv) {
1125 char **argi, **argj;
1126 struct arg arg;
1127 const int num_encoder = get_aom_encoder_count();
1128 char **argv_local = (char **)*argv;
1129 if (num_encoder < 1) die("Error: no valid encoder available\n");
1130
1131 /* Initialize default parameters */
1132 memset(global, 0, sizeof(*global));
1133 global->codec = get_aom_encoder_by_index(num_encoder - 1);
1134 global->passes = 0;
1135 global->color_type = I420;
1136 global->csp = AOM_CSP_UNKNOWN;
1137
1138 int cfg_included = 0;
1139 init_config(&global->encoder_config);
1140
1141 for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) {
1142 arg.argv_step = 1;
1143
1144 if (arg_match(&arg, &use_cfg, argi)) {
1145 if (cfg_included) continue;
1146 parse_cfg(arg.val, &global->encoder_config);
1147 cfg_included = 1;
1148 continue;
1149 }
1150 if (arg_match(&arg, &help, argi)) {
1151 show_help(stdout, 0);
1152 exit(EXIT_SUCCESS);
1153 } else if (arg_match(&arg, &codecarg, argi)) {
1154 global->codec = get_aom_encoder_by_name(arg.val);
1155 if (!global->codec)
1156 die("Error: Unrecognized argument (%s) to --codec\n", arg.val);
1157 } else if (arg_match(&arg, &passes, argi)) {
1158 global->passes = arg_parse_uint(&arg);
1159
1160 if (global->passes < 1 || global->passes > 2)
1161 die("Error: Invalid number of passes (%d)\n", global->passes);
1162 } else if (arg_match(&arg, &pass_arg, argi)) {
1163 global->pass = arg_parse_uint(&arg);
1164
1165 if (global->pass < 1 || global->pass > 2)
1166 die("Error: Invalid pass selected (%d)\n", global->pass);
1167 } else if (arg_match(&arg, &input_chroma_sample_position, argi)) {
1168 global->csp = arg_parse_enum(&arg);
1169 /* Flag is used by later code as well, preserve it. */
1170 argj++;
1171 } else if (arg_match(&arg, &usage, argi))
1172 global->usage = arg_parse_uint(&arg);
1173 else if (arg_match(&arg, &good_dl, argi))
1174 global->usage = AOM_USAGE_GOOD_QUALITY; // Good quality usage
1175 else if (arg_match(&arg, &rt_dl, argi))
1176 global->usage = AOM_USAGE_REALTIME; // Real-time usage
1177 else if (arg_match(&arg, &use_yv12, argi))
1178 global->color_type = YV12;
1179 else if (arg_match(&arg, &use_i420, argi))
1180 global->color_type = I420;
1181 else if (arg_match(&arg, &use_i422, argi))
1182 global->color_type = I422;
1183 else if (arg_match(&arg, &use_i444, argi))
1184 global->color_type = I444;
1185 else if (arg_match(&arg, &quietarg, argi))
1186 global->quiet = 1;
1187 else if (arg_match(&arg, &verbosearg, argi))
1188 global->verbose = 1;
1189 else if (arg_match(&arg, &limit, argi))
1190 global->limit = arg_parse_uint(&arg);
1191 else if (arg_match(&arg, &skip, argi))
1192 global->skip_frames = arg_parse_uint(&arg);
1193 else if (arg_match(&arg, &psnrarg, argi))
1194 global->show_psnr = 1;
1195 else if (arg_match(&arg, &recontest, argi))
1196 global->test_decode = arg_parse_enum_or_int(&arg);
1197 else if (arg_match(&arg, &framerate, argi)) {
1198 global->framerate = arg_parse_rational(&arg);
1199 validate_positive_rational(arg.name, &global->framerate);
1200 global->have_framerate = 1;
1201 } else if (arg_match(&arg, &debugmode, argi))
1202 global->debug = 1;
1203 else if (arg_match(&arg, &q_hist_n, argi))
1204 global->show_q_hist_buckets = arg_parse_uint(&arg);
1205 else if (arg_match(&arg, &rate_hist_n, argi))
1206 global->show_rate_hist_buckets = arg_parse_uint(&arg);
1207 else if (arg_match(&arg, &disable_warnings, argi))
1208 global->disable_warnings = 1;
1209 else if (arg_match(&arg, &disable_warning_prompt, argi))
1210 global->disable_warning_prompt = 1;
1211 else
1212 argj++;
1213 }
1214
1215 if (global->pass) {
1216 /* DWIM: Assume the user meant passes=2 if pass=2 is specified */
1217 if (global->pass > global->passes) {
1218 warn("Assuming --pass=%d implies --passes=%d\n", global->pass,
1219 global->pass);
1220 global->passes = global->pass;
1221 }
1222 }
1223 /* Validate global config */
1224 if (global->passes == 0) {
1225 #if CONFIG_AV1_ENCODER
1226 // Make default AV1 passes = 2 until there is a better quality 1-pass
1227 // encoder
1228 if (global->codec != NULL && global->codec->name != NULL)
1229 global->passes = (strcmp(global->codec->name, "av1") == 0 &&
1230 global->usage != AOM_USAGE_REALTIME)
1231 ? 2
1232 : 1;
1233 #else
1234 global->passes = 1;
1235 #endif
1236 }
1237
1238 if (global->usage == AOM_USAGE_REALTIME && global->passes > 1) {
1239 warn("Enforcing one-pass encoding in realtime mode\n");
1240 global->passes = 1;
1241 }
1242 }
1243
1244 static void open_input_file(struct AvxInputContext *input,
1245 aom_chroma_sample_position_t csp) {
1246 /* Parse certain options from the input file, if possible */
1247 input->file = strcmp(input->filename, "-") ? fopen(input->filename, "rb")
1248 : set_binary_mode(stdin);
1249
1250 if (!input->file) fatal("Failed to open input file");
1251
1252 if (!fseeko(input->file, 0, SEEK_END)) {
1253 /* Input file is seekable. Figure out how long it is, so we can get
1254 * progress info.
1255 */
1256 input->length = ftello(input->file);
1257 rewind(input->file);
1258 }
1259
1260 /* Default to 1:1 pixel aspect ratio. */
1261 input->pixel_aspect_ratio.numerator = 1;
1262 input->pixel_aspect_ratio.denominator = 1;
1263
1264 /* For RAW input sources, these bytes will applied on the first frame
1265 * in read_frame().
1266 */
1267 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
1268 input->detect.position = 0;
1269
1270 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
1271 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
1272 input->only_i420) >= 0) {
1273 input->file_type = FILE_TYPE_Y4M;
1274 input->width = input->y4m.pic_w;
1275 input->height = input->y4m.pic_h;
1276 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
1277 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
1278 input->framerate.numerator = input->y4m.fps_n;
1279 input->framerate.denominator = input->y4m.fps_d;
1280 input->fmt = input->y4m.aom_fmt;
1281 input->bit_depth = input->y4m.bit_depth;
1282 } else
1283 fatal("Unsupported Y4M stream.");
1284 } else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
1285 fatal("IVF is not supported as input.");
1286 } else {
1287 input->file_type = FILE_TYPE_RAW;
1288 }
1289 }
1290
1291 static void close_input_file(struct AvxInputContext *input) {
1292 fclose(input->file);
1293 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
1294 }
1295
1296 static struct stream_state *new_stream(struct AvxEncoderConfig *global,
1297 struct stream_state *prev) {
1298 struct stream_state *stream;
1299
1300 stream = calloc(1, sizeof(*stream));
1301 if (stream == NULL) {
1302 fatal("Failed to allocate new stream.");
1303 }
1304
1305 if (prev) {
1306 memcpy(stream, prev, sizeof(*stream));
1307 stream->index++;
1308 prev->next = stream;
1309 } else {
1310 aom_codec_err_t res;
1311
1312 /* Populate encoder configuration */
1313 res = aom_codec_enc_config_default(global->codec->codec_interface(),
1314 &stream->config.cfg, global->usage);
1315 if (res) fatal("Failed to get config: %s\n", aom_codec_err_to_string(res));
1316
1317 /* Change the default timebase to a high enough value so that the
1318 * encoder will always create strictly increasing timestamps.
1319 */
1320 stream->config.cfg.g_timebase.den = 1000;
1321
1322 /* Never use the library's default resolution, require it be parsed
1323 * from the file or set on the command line.
1324 */
1325 stream->config.cfg.g_w = 0;
1326 stream->config.cfg.g_h = 0;
1327
1328 /* Initialize remaining stream parameters */
1329 stream->config.write_webm = 1;
1330 stream->config.write_ivf = 0;
1331
1332 #if CONFIG_WEBM_IO
1333 stream->config.stereo_fmt = STEREO_FORMAT_MONO;
1334 stream->webm_ctx.last_pts_ns = -1;
1335 stream->webm_ctx.writer = NULL;
1336 stream->webm_ctx.segment = NULL;
1337 #endif
1338
1339 /* Allows removal of the application version from the EBML tags */
1340 stream->webm_ctx.debug = global->debug;
1341 memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config,
1342 sizeof(stream->config.cfg.encoder_cfg));
1343 }
1344
1345 /* Output files must be specified for each stream */
1346 stream->config.out_fn = NULL;
1347
1348 stream->next = NULL;
1349 return stream;
1350 }
1351
1352 static void set_config_arg_ctrls(struct stream_config *config, int key,
1353 const struct arg *arg) {
1354 int j;
1355 if (key == AV1E_SET_FILM_GRAIN_TABLE) {
1356 config->film_grain_filename = arg->val;
1357 return;
1358 }
1359
1360 // For target level, the settings should accumulate rather than overwrite,
1361 // so we simply append it.
1362 if (key == AV1E_SET_TARGET_SEQ_LEVEL_IDX) {
1363 j = config->arg_ctrl_cnt;
1364 assert(j < (int)ARG_CTRL_CNT_MAX);
1365 config->arg_ctrls[j][0] = key;
1366 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
1367 ++config->arg_ctrl_cnt;
1368 return;
1369 }
1370
1371 /* Point either to the next free element or the first instance of this
1372 * control.
1373 */
1374 for (j = 0; j < config->arg_ctrl_cnt; j++)
1375 if (config->arg_ctrls[j][0] == key) break;
1376
1377 /* Update/insert */
1378 assert(j < (int)ARG_CTRL_CNT_MAX);
1379 config->arg_ctrls[j][0] = key;
1380 config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
1381
1382 if (key == AOME_SET_ENABLEAUTOALTREF && config->arg_ctrls[j][1] > 1) {
1383 warn("auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
1384 config->arg_ctrls[j][1] = 1;
1385 }
1386 if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
1387 }
1388
1389 static int parse_stream_params(struct AvxEncoderConfig *global,
1390 struct stream_state *stream, char **argv) {
1391 char **argi, **argj;
1392 struct arg arg;
1393 static const arg_def_t **ctrl_args = no_args;
1394 static const int *ctrl_args_map = NULL;
1395 struct stream_config *config = &stream->config;
1396 int eos_mark_found = 0;
1397 int webm_forced = 0;
1398
1399 // Handle codec specific options
1400 if (0) {
1401 #if CONFIG_AV1_ENCODER
1402 } else if (strcmp(global->codec->name, "av1") == 0) {
1403 // TODO(jingning): Reuse AV1 specific encoder configuration parameters.
1404 // Consider to expand this set for AV1 encoder control.
1405 ctrl_args = av1_args;
1406 ctrl_args_map = av1_arg_ctrl_map;
1407 #endif
1408 }
1409
1410 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
1411 arg.argv_step = 1;
1412
1413 /* Once we've found an end-of-stream marker (--) we want to continue
1414 * shifting arguments but not consuming them.
1415 */
1416 if (eos_mark_found) {
1417 argj++;
1418 continue;
1419 } else if (!strcmp(*argj, "--")) {
1420 eos_mark_found = 1;
1421 continue;
1422 }
1423
1424 if (arg_match(&arg, &outputfile, argi)) {
1425 config->out_fn = arg.val;
1426 if (!webm_forced) {
1427 const size_t out_fn_len = strlen(config->out_fn);
1428 if (out_fn_len >= 4 &&
1429 !strcmp(config->out_fn + out_fn_len - 4, ".ivf")) {
1430 config->write_webm = 0;
1431 config->write_ivf = 1;
1432 } else if (out_fn_len >= 4 &&
1433 !strcmp(config->out_fn + out_fn_len - 4, ".obu")) {
1434 config->write_webm = 0;
1435 config->write_ivf = 0;
1436 }
1437 }
1438 } else if (arg_match(&arg, &fpf_name, argi)) {
1439 config->stats_fn = arg.val;
1440 } else if (arg_match(&arg, &use_webm, argi)) {
1441 #if CONFIG_WEBM_IO
1442 config->write_webm = 1;
1443 webm_forced = 1;
1444 #else
1445 die("Error: --webm specified but webm is disabled.");
1446 #endif
1447 } else if (arg_match(&arg, &use_ivf, argi)) {
1448 config->write_webm = 0;
1449 config->write_ivf = 1;
1450 } else if (arg_match(&arg, &use_obu, argi)) {
1451 config->write_webm = 0;
1452 config->write_ivf = 0;
1453 } else if (arg_match(&arg, &threads, argi)) {
1454 config->cfg.g_threads = arg_parse_uint(&arg);
1455 } else if (arg_match(&arg, &profile, argi)) {
1456 config->cfg.g_profile = arg_parse_uint(&arg);
1457 } else if (arg_match(&arg, &width, argi)) {
1458 config->cfg.g_w = arg_parse_uint(&arg);
1459 } else if (arg_match(&arg, &height, argi)) {
1460 config->cfg.g_h = arg_parse_uint(&arg);
1461 } else if (arg_match(&arg, &forced_max_frame_width, argi)) {
1462 config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg);
1463 } else if (arg_match(&arg, &forced_max_frame_height, argi)) {
1464 config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg);
1465 } else if (arg_match(&arg, &bitdeptharg, argi)) {
1466 config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg);
1467 } else if (arg_match(&arg, &inbitdeptharg, argi)) {
1468 config->cfg.g_input_bit_depth = arg_parse_uint(&arg);
1469 } else if (arg_match(&arg, &input_chroma_subsampling_x, argi)) {
1470 stream->chroma_subsampling_x = arg_parse_uint(&arg);
1471 } else if (arg_match(&arg, &input_chroma_subsampling_y, argi)) {
1472 stream->chroma_subsampling_y = arg_parse_uint(&arg);
1473 #if CONFIG_WEBM_IO
1474 } else if (arg_match(&arg, &stereo_mode, argi)) {
1475 config->stereo_fmt = arg_parse_enum_or_int(&arg);
1476 #endif
1477 } else if (arg_match(&arg, &timebase, argi)) {
1478 config->cfg.g_timebase = arg_parse_rational(&arg);
1479 validate_positive_rational(arg.name, &config->cfg.g_timebase);
1480 } else if (arg_match(&arg, &global_error_resilient, argi)) {
1481 config->cfg.g_error_resilient = arg_parse_uint(&arg);
1482 } else if (arg_match(&arg, &lag_in_frames, argi)) {
1483 config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
1484 if (global->usage == AOM_USAGE_REALTIME &&
1485 config->cfg.rc_end_usage == AOM_CBR &&
1486 config->cfg.g_lag_in_frames != 0) {
1487 warn("non-zero %s option ignored in realtime CBR mode.\n", arg.name);
1488 config->cfg.g_lag_in_frames = 0;
1489 }
1490 } else if (arg_match(&arg, &large_scale_tile, argi)) {
1491 config->cfg.large_scale_tile = arg_parse_uint(&arg);
1492 if (config->cfg.large_scale_tile) global->codec = get_aom_lst_encoder();
1493 } else if (arg_match(&arg, &monochrome, argi)) {
1494 config->cfg.monochrome = 1;
1495 } else if (arg_match(&arg, &full_still_picture_hdr, argi)) {
1496 config->cfg.full_still_picture_hdr = 1;
1497 } else if (arg_match(&arg, &dropframe_thresh, argi)) {
1498 config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
1499 } else if (arg_match(&arg, &resize_mode, argi)) {
1500 config->cfg.rc_resize_mode = arg_parse_uint(&arg);
1501 } else if (arg_match(&arg, &resize_denominator, argi)) {
1502 config->cfg.rc_resize_denominator = arg_parse_uint(&arg);
1503 } else if (arg_match(&arg, &resize_kf_denominator, argi)) {
1504 config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg);
1505 } else if (arg_match(&arg, &superres_mode, argi)) {
1506 config->cfg.rc_superres_mode = arg_parse_uint(&arg);
1507 } else if (arg_match(&arg, &superres_denominator, argi)) {
1508 config->cfg.rc_superres_denominator = arg_parse_uint(&arg);
1509 } else if (arg_match(&arg, &superres_kf_denominator, argi)) {
1510 config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg);
1511 } else if (arg_match(&arg, &superres_qthresh, argi)) {
1512 config->cfg.rc_superres_qthresh = arg_parse_uint(&arg);
1513 } else if (arg_match(&arg, &superres_kf_qthresh, argi)) {
1514 config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg);
1515 } else if (arg_match(&arg, &end_usage, argi)) {
1516 config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
1517 } else if (arg_match(&arg, &target_bitrate, argi)) {
1518 config->cfg.rc_target_bitrate = arg_parse_uint(&arg);
1519 } else if (arg_match(&arg, &min_quantizer, argi)) {
1520 config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
1521 } else if (arg_match(&arg, &max_quantizer, argi)) {
1522 config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
1523 } else if (arg_match(&arg, &undershoot_pct, argi)) {
1524 config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
1525 } else if (arg_match(&arg, &overshoot_pct, argi)) {
1526 config->cfg.rc_overshoot_pct = arg_parse_uint(&arg);
1527 } else if (arg_match(&arg, &buf_sz, argi)) {
1528 config->cfg.rc_buf_sz = arg_parse_uint(&arg);
1529 } else if (arg_match(&arg, &buf_initial_sz, argi)) {
1530 config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg);
1531 } else if (arg_match(&arg, &buf_optimal_sz, argi)) {
1532 config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg);
1533 } else if (arg_match(&arg, &bias_pct, argi)) {
1534 config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg);
1535 if (global->passes < 2)
1536 warn("option %s ignored in one-pass mode.\n", arg.name);
1537 } else if (arg_match(&arg, &minsection_pct, argi)) {
1538 config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg);
1539
1540 if (global->passes < 2)
1541 warn("option %s ignored in one-pass mode.\n", arg.name);
1542 } else if (arg_match(&arg, &maxsection_pct, argi)) {
1543 config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg);
1544
1545 if (global->passes < 2)
1546 warn("option %s ignored in one-pass mode.\n", arg.name);
1547 } else if (arg_match(&arg, &fwd_kf_enabled, argi)) {
1548 config->cfg.fwd_kf_enabled = arg_parse_uint(&arg);
1549 } else if (arg_match(&arg, &kf_min_dist, argi)) {
1550 config->cfg.kf_min_dist = arg_parse_uint(&arg);
1551 } else if (arg_match(&arg, &kf_max_dist, argi)) {
1552 config->cfg.kf_max_dist = arg_parse_uint(&arg);
1553 } else if (arg_match(&arg, &kf_disabled, argi)) {
1554 config->cfg.kf_mode = AOM_KF_DISABLED;
1555 } else if (arg_match(&arg, &sframe_dist, argi)) {
1556 config->cfg.sframe_dist = arg_parse_uint(&arg);
1557 } else if (arg_match(&arg, &sframe_mode, argi)) {
1558 config->cfg.sframe_mode = arg_parse_uint(&arg);
1559 } else if (arg_match(&arg, &save_as_annexb, argi)) {
1560 config->cfg.save_as_annexb = arg_parse_uint(&arg);
1561 } else if (arg_match(&arg, &tile_width, argi)) {
1562 config->cfg.tile_width_count =
1563 arg_parse_list(&arg, config->cfg.tile_widths, MAX_TILE_WIDTHS);
1564 } else if (arg_match(&arg, &tile_height, argi)) {
1565 config->cfg.tile_height_count =
1566 arg_parse_list(&arg, config->cfg.tile_heights, MAX_TILE_HEIGHTS);
1567 } else if (global->usage == AOM_USAGE_REALTIME &&
1568 arg_match(&arg, &enable_restoration, argi)) {
1569 if (arg_parse_uint(&arg) == 1) {
1570 warn("non-zero %s option ignored in realtime mode.\n", arg.name);
1571 }
1572 } else {
1573 int i, match = 0;
1574 for (i = 0; ctrl_args[i]; i++) {
1575 if (arg_match(&arg, ctrl_args[i], argi)) {
1576 match = 1;
1577 if (ctrl_args_map) {
1578 set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
1579 }
1580 }
1581 }
1582 if (!match) argj++;
1583 }
1584 }
1585 config->use_16bit_internal =
1586 config->cfg.g_bit_depth > AOM_BITS_8 || FORCE_HIGHBITDEPTH_DECODING;
1587 return eos_mark_found;
1588 }
1589
1590 #define FOREACH_STREAM(iterator, list) \
1591 for (struct stream_state *iterator = list; iterator; \
1592 iterator = iterator->next)
1593
1594 static void validate_stream_config(const struct stream_state *stream,
1595 const struct AvxEncoderConfig *global) {
1596 const struct stream_state *streami;
1597 (void)global;
1598
1599 if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
1600 fatal(
1601 "Stream %d: Specify stream dimensions with --width (-w) "
1602 " and --height (-h)",
1603 stream->index);
1604
1605 /* Even if bit depth is set on the command line flag to be lower,
1606 * it is upgraded to at least match the input bit depth.
1607 */
1608 assert(stream->config.cfg.g_input_bit_depth <=
1609 (unsigned int)stream->config.cfg.g_bit_depth);
1610
1611 for (streami = stream; streami; streami = streami->next) {
1612 /* All streams require output files */
1613 if (!streami->config.out_fn)
1614 fatal("Stream %d: Output file is required (specify with -o)",
1615 streami->index);
1616
1617 /* Check for two streams outputting to the same file */
1618 if (streami != stream) {
1619 const char *a = stream->config.out_fn;
1620 const char *b = streami->config.out_fn;
1621 if (!strcmp(a, b) && strcmp(a, "/dev/null") && strcmp(a, ":nul"))
1622 fatal("Stream %d: duplicate output file (from stream %d)",
1623 streami->index, stream->index);
1624 }
1625
1626 /* Check for two streams sharing a stats file. */
1627 if (streami != stream) {
1628 const char *a = stream->config.stats_fn;
1629 const char *b = streami->config.stats_fn;
1630 if (a && b && !strcmp(a, b))
1631 fatal("Stream %d: duplicate stats file (from stream %d)",
1632 streami->index, stream->index);
1633 }
1634 }
1635 }
1636
1637 static void set_stream_dimensions(struct stream_state *stream, unsigned int w,
1638 unsigned int h) {
1639 if (!stream->config.cfg.g_w) {
1640 if (!stream->config.cfg.g_h)
1641 stream->config.cfg.g_w = w;
1642 else
1643 stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
1644 }
1645 if (!stream->config.cfg.g_h) {
1646 stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
1647 }
1648 }
1649
1650 static const char *file_type_to_string(enum VideoFileType t) {
1651 switch (t) {
1652 case FILE_TYPE_RAW: return "RAW";
1653 case FILE_TYPE_Y4M: return "Y4M";
1654 default: return "Other";
1655 }
1656 }
1657
1658 static const char *image_format_to_string(aom_img_fmt_t f) {
1659 switch (f) {
1660 case AOM_IMG_FMT_I420: return "I420";
1661 case AOM_IMG_FMT_I422: return "I422";
1662 case AOM_IMG_FMT_I444: return "I444";
1663 case AOM_IMG_FMT_YV12: return "YV12";
1664 case AOM_IMG_FMT_YV1216: return "YV1216";
1665 case AOM_IMG_FMT_I42016: return "I42016";
1666 case AOM_IMG_FMT_I42216: return "I42216";
1667 case AOM_IMG_FMT_I44416: return "I44416";
1668 default: return "Other";
1669 }
1670 }
1671
1672 static void show_stream_config(struct stream_state *stream,
1673 struct AvxEncoderConfig *global,
1674 struct AvxInputContext *input) {
1675 #define SHOW(field) \
1676 fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field)
1677
1678 if (stream->index == 0) {
1679 fprintf(stderr, "Codec: %s\n",
1680 aom_codec_iface_name(global->codec->codec_interface()));
1681 fprintf(stderr, "Source file: %s File Type: %s Format: %s\n",
1682 input->filename, file_type_to_string(input->file_type),
1683 image_format_to_string(input->fmt));
1684 }
1685 if (stream->next || stream->index)
1686 fprintf(stderr, "\nStream Index: %d\n", stream->index);
1687 fprintf(stderr, "Destination file: %s\n", stream->config.out_fn);
1688 fprintf(stderr, "Coding path: %s\n",
1689 stream->config.use_16bit_internal ? "HBD" : "LBD");
1690 fprintf(stderr, "Encoder parameters:\n");
1691
1692 SHOW(g_usage);
1693 SHOW(g_threads);
1694 SHOW(g_profile);
1695 SHOW(g_w);
1696 SHOW(g_h);
1697 SHOW(g_bit_depth);
1698 SHOW(g_input_bit_depth);
1699 SHOW(g_timebase.num);
1700 SHOW(g_timebase.den);
1701 SHOW(g_error_resilient);
1702 SHOW(g_pass);
1703 SHOW(g_lag_in_frames);
1704 SHOW(large_scale_tile);
1705 SHOW(rc_dropframe_thresh);
1706 SHOW(rc_resize_mode);
1707 SHOW(rc_resize_denominator);
1708 SHOW(rc_resize_kf_denominator);
1709 SHOW(rc_superres_mode);
1710 SHOW(rc_superres_denominator);
1711 SHOW(rc_superres_kf_denominator);
1712 SHOW(rc_superres_qthresh);
1713 SHOW(rc_superres_kf_qthresh);
1714 SHOW(rc_end_usage);
1715 SHOW(rc_target_bitrate);
1716 SHOW(rc_min_quantizer);
1717 SHOW(rc_max_quantizer);
1718 SHOW(rc_undershoot_pct);
1719 SHOW(rc_overshoot_pct);
1720 SHOW(rc_buf_sz);
1721 SHOW(rc_buf_initial_sz);
1722 SHOW(rc_buf_optimal_sz);
1723 SHOW(rc_2pass_vbr_bias_pct);
1724 SHOW(rc_2pass_vbr_minsection_pct);
1725 SHOW(rc_2pass_vbr_maxsection_pct);
1726 SHOW(fwd_kf_enabled);
1727 SHOW(kf_mode);
1728 SHOW(kf_min_dist);
1729 SHOW(kf_max_dist);
1730
1731 #define SHOW_PARAMS(field) \
1732 fprintf(stderr, " %-28s = %d\n", #field, \
1733 stream->config.cfg.encoder_cfg.field)
1734 SHOW_PARAMS(super_block_size);
1735 SHOW_PARAMS(max_partition_size);
1736 SHOW_PARAMS(min_partition_size);
1737 SHOW_PARAMS(disable_ab_partition_type);
1738 SHOW_PARAMS(disable_rect_partition_type);
1739 SHOW_PARAMS(disable_1to4_partition_type);
1740 SHOW_PARAMS(disable_flip_idtx);
1741 SHOW_PARAMS(disable_cdef);
1742 SHOW_PARAMS(disable_lr);
1743 SHOW_PARAMS(disable_obmc);
1744 SHOW_PARAMS(disable_warp_motion);
1745 SHOW_PARAMS(disable_global_motion);
1746 SHOW_PARAMS(disable_dist_wtd_comp);
1747 SHOW_PARAMS(disable_diff_wtd_comp);
1748 SHOW_PARAMS(disable_inter_intra_comp);
1749 SHOW_PARAMS(disable_masked_comp);
1750 SHOW_PARAMS(disable_one_sided_comp);
1751 SHOW_PARAMS(disable_palette);
1752 SHOW_PARAMS(disable_intrabc);
1753 SHOW_PARAMS(disable_cfl);
1754 SHOW_PARAMS(disable_smooth_intra);
1755 SHOW_PARAMS(disable_filter_intra);
1756 SHOW_PARAMS(disable_dual_filter);
1757 SHOW_PARAMS(disable_intra_angle_delta);
1758 SHOW_PARAMS(disable_intra_edge_filter);
1759 SHOW_PARAMS(disable_tx_64x64);
1760 SHOW_PARAMS(disable_smooth_inter_intra);
1761 SHOW_PARAMS(disable_inter_inter_wedge);
1762 SHOW_PARAMS(disable_inter_intra_wedge);
1763 SHOW_PARAMS(disable_paeth_intra);
1764 SHOW_PARAMS(disable_trellis_quant);
1765 SHOW_PARAMS(disable_ref_frame_mv);
1766 SHOW_PARAMS(reduced_reference_set);
1767 SHOW_PARAMS(reduced_tx_type_set);
1768 }
1769
1770 static void open_output_file(struct stream_state *stream,
1771 struct AvxEncoderConfig *global,
1772 const struct AvxRational *pixel_aspect_ratio) {
1773 const char *fn = stream->config.out_fn;
1774 const struct aom_codec_enc_cfg *const cfg = &stream->config.cfg;
1775
1776 if (cfg->g_pass == AOM_RC_FIRST_PASS) return;
1777
1778 stream->file = strcmp(fn, "-") ? fopen(fn, "wb") : set_binary_mode(stdout);
1779
1780 if (!stream->file) fatal("Failed to open output file");
1781
1782 if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1783 fatal("WebM output to pipes not supported.");
1784
1785 #if CONFIG_WEBM_IO
1786 if (stream->config.write_webm) {
1787 stream->webm_ctx.stream = stream->file;
1788 if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg,
1789 stream->config.stereo_fmt, global->codec->fourcc,
1790 pixel_aspect_ratio) != 0) {
1791 fatal("WebM writer initialization failed.");
1792 }
1793 }
1794 #else
1795 (void)pixel_aspect_ratio;
1796 #endif
1797
1798 if (!stream->config.write_webm && stream->config.write_ivf) {
1799 ivf_write_file_header(stream->file, cfg, global->codec->fourcc, 0);
1800 }
1801 }
1802
1803 static void close_output_file(struct stream_state *stream,
1804 unsigned int fourcc) {
1805 const struct aom_codec_enc_cfg *const cfg = &stream->config.cfg;
1806
1807 if (cfg->g_pass == AOM_RC_FIRST_PASS) return;
1808
1809 #if CONFIG_WEBM_IO
1810 if (stream->config.write_webm) {
1811 if (write_webm_file_footer(&stream->webm_ctx) != 0) {
1812 fatal("WebM writer finalization failed.");
1813 }
1814 }
1815 #endif
1816
1817 if (!stream->config.write_webm && stream->config.write_ivf) {
1818 if (!fseek(stream->file, 0, SEEK_SET))
1819 ivf_write_file_header(stream->file, &stream->config.cfg, fourcc,
1820 stream->frames_out);
1821 }
1822
1823 fclose(stream->file);
1824 }
1825
1826 static void setup_pass(struct stream_state *stream,
1827 struct AvxEncoderConfig *global, int pass) {
1828 if (stream->config.stats_fn) {
1829 if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass))
1830 fatal("Failed to open statistics store");
1831 } else {
1832 if (!stats_open_mem(&stream->stats, pass))
1833 fatal("Failed to open statistics store");
1834 }
1835
1836 stream->config.cfg.g_pass = global->passes == 2
1837 ? pass ? AOM_RC_LAST_PASS : AOM_RC_FIRST_PASS
1838 : AOM_RC_ONE_PASS;
1839 if (pass) {
1840 stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats);
1841 }
1842
1843 stream->cx_time = 0;
1844 stream->nbytes = 0;
1845 stream->frames_out = 0;
1846 }
1847
1848 static void initialize_encoder(struct stream_state *stream,
1849 struct AvxEncoderConfig *global) {
1850 int i;
1851 int flags = 0;
1852
1853 flags |= global->show_psnr ? AOM_CODEC_USE_PSNR : 0;
1854 flags |= stream->config.use_16bit_internal ? AOM_CODEC_USE_HIGHBITDEPTH : 0;
1855
1856 /* Construct Encoder Context */
1857 aom_codec_enc_init(&stream->encoder, global->codec->codec_interface(),
1858 &stream->config.cfg, flags);
1859 ctx_exit_on_error(&stream->encoder, "Failed to initialize encoder");
1860
1861 /* Note that we bypass the aom_codec_control wrapper macro because
1862 * we're being clever to store the control IDs in an array. Real
1863 * applications will want to make use of the enumerations directly
1864 */
1865 for (i = 0; i < stream->config.arg_ctrl_cnt; i++) {
1866 int ctrl = stream->config.arg_ctrls[i][0];
1867 int value = stream->config.arg_ctrls[i][1];
1868 if (aom_codec_control_(&stream->encoder, ctrl, value))
1869 fprintf(stderr, "Error: Tried to set control %d = %d\n", ctrl, value);
1870
1871 ctx_exit_on_error(&stream->encoder, "Failed to control codec");
1872 }
1873 if (stream->config.film_grain_filename) {
1874 aom_codec_control_(&stream->encoder, AV1E_SET_FILM_GRAIN_TABLE,
1875 stream->config.film_grain_filename);
1876 }
1877
1878 #if CONFIG_AV1_DECODER
1879 if (global->test_decode != TEST_DECODE_OFF) {
1880 const AvxInterface *decoder = get_aom_decoder_by_name(global->codec->name);
1881 aom_codec_dec_cfg_t cfg = { 0, 0, 0, !FORCE_HIGHBITDEPTH_DECODING };
1882 aom_codec_dec_init(&stream->decoder, decoder->codec_interface(), &cfg, 0);
1883
1884 if (strcmp(global->codec->name, "av1") == 0) {
1885 aom_codec_control(&stream->decoder, AV1_SET_TILE_MODE,
1886 stream->config.cfg.large_scale_tile);
1887 ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_mode");
1888
1889 aom_codec_control(&stream->decoder, AV1D_SET_IS_ANNEXB,
1890 stream->config.cfg.save_as_annexb);
1891 ctx_exit_on_error(&stream->decoder, "Failed to set is_annexb");
1892
1893 aom_codec_control(&stream->decoder, AV1_SET_DECODE_TILE_ROW, -1);
1894 ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_row");
1895
1896 aom_codec_control(&stream->decoder, AV1_SET_DECODE_TILE_COL, -1);
1897 ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_col");
1898 }
1899 }
1900 #endif
1901 }
1902
1903 static void encode_frame(struct stream_state *stream,
1904 struct AvxEncoderConfig *global, struct aom_image *img,
1905 unsigned int frames_in) {
1906 aom_codec_pts_t frame_start, next_frame_start;
1907 struct aom_codec_enc_cfg *cfg = &stream->config.cfg;
1908 struct aom_usec_timer timer;
1909
1910 frame_start =
1911 (cfg->g_timebase.den * (int64_t)(frames_in - 1) * global->framerate.den) /
1912 cfg->g_timebase.num / global->framerate.num;
1913 next_frame_start =
1914 (cfg->g_timebase.den * (int64_t)(frames_in)*global->framerate.den) /
1915 cfg->g_timebase.num / global->framerate.num;
1916
1917 /* Scale if necessary */
1918 if (img) {
1919 if ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) &&
1920 (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) {
1921 if (img->fmt != AOM_IMG_FMT_I42016) {
1922 fprintf(stderr, "%s can only scale 4:2:0 inputs\n", exec_name);
1923 exit(EXIT_FAILURE);
1924 }
1925 #if CONFIG_LIBYUV
1926 if (!stream->img) {
1927 stream->img =
1928 aom_img_alloc(NULL, AOM_IMG_FMT_I42016, cfg->g_w, cfg->g_h, 16);
1929 }
1930 I420Scale_16(
1931 (uint16_t *)img->planes[AOM_PLANE_Y], img->stride[AOM_PLANE_Y] / 2,
1932 (uint16_t *)img->planes[AOM_PLANE_U], img->stride[AOM_PLANE_U] / 2,
1933 (uint16_t *)img->planes[AOM_PLANE_V], img->stride[AOM_PLANE_V] / 2,
1934 img->d_w, img->d_h, (uint16_t *)stream->img->planes[AOM_PLANE_Y],
1935 stream->img->stride[AOM_PLANE_Y] / 2,
1936 (uint16_t *)stream->img->planes[AOM_PLANE_U],
1937 stream->img->stride[AOM_PLANE_U] / 2,
1938 (uint16_t *)stream->img->planes[AOM_PLANE_V],
1939 stream->img->stride[AOM_PLANE_V] / 2, stream->img->d_w,
1940 stream->img->d_h, kFilterBox);
1941 img = stream->img;
1942 #else
1943 stream->encoder.err = 1;
1944 ctx_exit_on_error(&stream->encoder,
1945 "Stream %d: Failed to encode frame.\n"
1946 "libyuv is required for scaling but is currently "
1947 "disabled.\n"
1948 "Be sure to specify -DCONFIG_LIBYUV=1 when running "
1949 "cmake.\n",
1950 stream->index);
1951 #endif
1952 }
1953 }
1954 if (img && (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) {
1955 if (img->fmt != AOM_IMG_FMT_I420 && img->fmt != AOM_IMG_FMT_YV12) {
1956 fprintf(stderr, "%s can only scale 4:2:0 8bpp inputs\n", exec_name);
1957 exit(EXIT_FAILURE);
1958 }
1959 #if CONFIG_LIBYUV
1960 if (!stream->img)
1961 stream->img =
1962 aom_img_alloc(NULL, AOM_IMG_FMT_I420, cfg->g_w, cfg->g_h, 16);
1963 I420Scale(
1964 img->planes[AOM_PLANE_Y], img->stride[AOM_PLANE_Y],
1965 img->planes[AOM_PLANE_U], img->stride[AOM_PLANE_U],
1966 img->planes[AOM_PLANE_V], img->stride[AOM_PLANE_V], img->d_w, img->d_h,
1967 stream->img->planes[AOM_PLANE_Y], stream->img->stride[AOM_PLANE_Y],
1968 stream->img->planes[AOM_PLANE_U], stream->img->stride[AOM_PLANE_U],
1969 stream->img->planes[AOM_PLANE_V], stream->img->stride[AOM_PLANE_V],
1970 stream->img->d_w, stream->img->d_h, kFilterBox);
1971 img = stream->img;
1972 #else
1973 stream->encoder.err = 1;
1974 ctx_exit_on_error(&stream->encoder,
1975 "Stream %d: Failed to encode frame.\n"
1976 "Scaling disabled in this configuration. \n"
1977 "To enable, configure with --enable-libyuv\n",
1978 stream->index);
1979 #endif
1980 }
1981
1982 aom_usec_timer_start(&timer);
1983 aom_codec_encode(&stream->encoder, img, frame_start,
1984 (uint32_t)(next_frame_start - frame_start), 0);
1985 aom_usec_timer_mark(&timer);
1986 stream->cx_time += aom_usec_timer_elapsed(&timer);
1987 ctx_exit_on_error(&stream->encoder, "Stream %d: Failed to encode frame",
1988 stream->index);
1989 }
1990
1991 static void update_quantizer_histogram(struct stream_state *stream) {
1992 if (stream->config.cfg.g_pass != AOM_RC_FIRST_PASS) {
1993 int q;
1994
1995 aom_codec_control(&stream->encoder, AOME_GET_LAST_QUANTIZER_64, &q);
1996 ctx_exit_on_error(&stream->encoder, "Failed to read quantizer");
1997 stream->counts[q]++;
1998 }
1999 }
2000
2001 static void get_cx_data(struct stream_state *stream,
2002 struct AvxEncoderConfig *global, int *got_data) {
2003 const aom_codec_cx_pkt_t *pkt;
2004 const struct aom_codec_enc_cfg *cfg = &stream->config.cfg;
2005 aom_codec_iter_t iter = NULL;
2006
2007 *got_data = 0;
2008 while ((pkt = aom_codec_get_cx_data(&stream->encoder, &iter))) {
2009 static size_t fsize = 0;
2010 static FileOffset ivf_header_pos = 0;
2011
2012 switch (pkt->kind) {
2013 case AOM_CODEC_CX_FRAME_PKT:
2014 ++stream->frames_out;
2015 if (!global->quiet)
2016 fprintf(stderr, " %6luF", (unsigned long)pkt->data.frame.sz);
2017
2018 update_rate_histogram(stream->rate_hist, cfg, pkt);
2019 #if CONFIG_WEBM_IO
2020 if (stream->config.write_webm) {
2021 if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) {
2022 fatal("WebM writer failed.");
2023 }
2024 }
2025 #endif
2026 if (!stream->config.write_webm) {
2027 if (stream->config.write_ivf) {
2028 if (pkt->data.frame.partition_id <= 0) {
2029 ivf_header_pos = ftello(stream->file);
2030 fsize = pkt->data.frame.sz;
2031
2032 ivf_write_frame_header(stream->file, pkt->data.frame.pts, fsize);
2033 } else {
2034 fsize += pkt->data.frame.sz;
2035
2036 const FileOffset currpos = ftello(stream->file);
2037 fseeko(stream->file, ivf_header_pos, SEEK_SET);
2038 ivf_write_frame_size(stream->file, fsize);
2039 fseeko(stream->file, currpos, SEEK_SET);
2040 }
2041 }
2042
2043 (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz,
2044 stream->file);
2045 }
2046 stream->nbytes += pkt->data.raw.sz;
2047
2048 *got_data = 1;
2049 #if CONFIG_AV1_DECODER
2050 if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) {
2051 aom_codec_decode(&stream->decoder, pkt->data.frame.buf,
2052 pkt->data.frame.sz, NULL);
2053 if (stream->decoder.err) {
2054 warn_or_exit_on_error(&stream->decoder,
2055 global->test_decode == TEST_DECODE_FATAL,
2056 "Failed to decode frame %d in stream %d",
2057 stream->frames_out + 1, stream->index);
2058 stream->mismatch_seen = stream->frames_out + 1;
2059 }
2060 }
2061 #endif
2062 break;
2063 case AOM_CODEC_STATS_PKT:
2064 stream->frames_out++;
2065 stats_write(&stream->stats, pkt->data.twopass_stats.buf,
2066 pkt->data.twopass_stats.sz);
2067 stream->nbytes += pkt->data.raw.sz;
2068 break;
2069 case AOM_CODEC_PSNR_PKT:
2070
2071 if (global->show_psnr) {
2072 int i;
2073
2074 stream->psnr_sse_total += pkt->data.psnr.sse[0];
2075 stream->psnr_samples_total += pkt->data.psnr.samples[0];
2076 for (i = 0; i < 4; i++) {
2077 if (!global->quiet)
2078 fprintf(stderr, "%.3f ", pkt->data.psnr.psnr[i]);
2079 stream->psnr_totals[i] += pkt->data.psnr.psnr[i];
2080 }
2081 stream->psnr_count++;
2082 }
2083
2084 break;
2085 default: break;
2086 }
2087 }
2088 }
2089
2090 static void show_psnr(struct stream_state *stream, double peak, int64_t bps) {
2091 int i;
2092 double ovpsnr;
2093
2094 if (!stream->psnr_count) return;
2095
2096 fprintf(stderr, "Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
2097 ovpsnr = sse_to_psnr((double)stream->psnr_samples_total, peak,
2098 (double)stream->psnr_sse_total);
2099 fprintf(stderr, " %.3f", ovpsnr);
2100
2101 for (i = 0; i < 4; i++) {
2102 fprintf(stderr, " %.3f", stream->psnr_totals[i] / stream->psnr_count);
2103 }
2104 if (bps > 0) {
2105 fprintf(stderr, " %7" PRId64 " bps", bps);
2106 }
2107 fprintf(stderr, " %7" PRId64 " ms", stream->cx_time / 1000);
2108 fprintf(stderr, "\n");
2109 }
2110
2111 static float usec_to_fps(uint64_t usec, unsigned int frames) {
2112 return (float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
2113 }
2114
2115 static void test_decode(struct stream_state *stream,
2116 enum TestDecodeFatality fatal) {
2117 aom_image_t enc_img, dec_img;
2118
2119 if (stream->mismatch_seen) return;
2120
2121 /* Get the internal reference frame */
2122 aom_codec_control(&stream->encoder, AV1_GET_NEW_FRAME_IMAGE, &enc_img);
2123 aom_codec_control(&stream->decoder, AV1_GET_NEW_FRAME_IMAGE, &dec_img);
2124
2125 if ((enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) !=
2126 (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH)) {
2127 if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
2128 aom_image_t enc_hbd_img;
2129 aom_img_alloc(&enc_hbd_img, enc_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH,
2130 enc_img.d_w, enc_img.d_h, 16);
2131 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
2132 enc_img = enc_hbd_img;
2133 }
2134 if (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
2135 aom_image_t dec_hbd_img;
2136 aom_img_alloc(&dec_hbd_img, dec_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH,
2137 dec_img.d_w, dec_img.d_h, 16);
2138 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
2139 dec_img = dec_hbd_img;
2140 }
2141 }
2142
2143 ctx_exit_on_error(&stream->encoder, "Failed to get encoder reference frame");
2144 ctx_exit_on_error(&stream->decoder, "Failed to get decoder reference frame");
2145
2146 if (!aom_compare_img(&enc_img, &dec_img)) {
2147 int y[4], u[4], v[4];
2148 if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
2149 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
2150 } else {
2151 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
2152 }
2153 stream->decoder.err = 1;
2154 warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL,
2155 "Stream %d: Encode/decode mismatch on frame %d at"
2156 " Y[%d, %d] {%d/%d},"
2157 " U[%d, %d] {%d/%d},"
2158 " V[%d, %d] {%d/%d}",
2159 stream->index, stream->frames_out, y[0], y[1], y[2],
2160 y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]);
2161 stream->mismatch_seen = stream->frames_out;
2162 }
2163
2164 aom_img_free(&enc_img);
2165 aom_img_free(&dec_img);
2166 }
2167
2168 static void print_time(const char *label, int64_t etl) {
2169 int64_t hours;
2170 int64_t mins;
2171 int64_t secs;
2172
2173 if (etl >= 0) {
2174 hours = etl / 3600;
2175 etl -= hours * 3600;
2176 mins = etl / 60;
2177 etl -= mins * 60;
2178 secs = etl;
2179
2180 fprintf(stderr, "[%3s %2" PRId64 ":%02" PRId64 ":%02" PRId64 "] ", label,
2181 hours, mins, secs);
2182 } else {
2183 fprintf(stderr, "[%3s unknown] ", label);
2184 }
2185 }
2186
2187 int main(int argc, const char **argv_) {
2188 int pass;
2189 aom_image_t raw;
2190 aom_image_t raw_shift;
2191 int allocated_raw_shift = 0;
2192 int use_16bit_internal = 0;
2193 int input_shift = 0;
2194 int frame_avail, got_data;
2195
2196 struct AvxInputContext input;
2197 struct AvxEncoderConfig global;
2198 struct stream_state *streams = NULL;
2199 char **argv, **argi;
2200 uint64_t cx_time = 0;
2201 int stream_cnt = 0;
2202 int res = 0;
2203 int profile_updated = 0;
2204
2205 memset(&input, 0, sizeof(input));
2206 exec_name = argv_[0];
2207
2208 /* Setup default input stream settings */
2209 input.framerate.numerator = 30;
2210 input.framerate.denominator = 1;
2211 input.only_i420 = 1;
2212 input.bit_depth = 0;
2213
2214 /* First parse the global configuration values, because we want to apply
2215 * other parameters on top of the default configuration provided by the
2216 * codec.
2217 */
2218 argv = argv_dup(argc - 1, argv_ + 1);
2219 parse_global_config(&global, &argv);
2220
2221 if (argc < 2) usage_exit();
2222
2223 switch (global.color_type) {
2224 case I420: input.fmt = AOM_IMG_FMT_I420; break;
2225 case I422: input.fmt = AOM_IMG_FMT_I422; break;
2226 case I444: input.fmt = AOM_IMG_FMT_I444; break;
2227 case YV12: input.fmt = AOM_IMG_FMT_YV12; break;
2228 }
2229
2230 {
2231 /* Now parse each stream's parameters. Using a local scope here
2232 * due to the use of 'stream' as loop variable in FOREACH_STREAM
2233 * loops
2234 */
2235 struct stream_state *stream = NULL;
2236
2237 do {
2238 stream = new_stream(&global, stream);
2239 stream_cnt++;
2240 if (!streams) streams = stream;
2241 } while (parse_stream_params(&global, stream, argv));
2242 }
2243
2244 /* Check for unrecognized options */
2245 for (argi = argv; *argi; argi++)
2246 if (argi[0][0] == '-' && argi[0][1])
2247 die("Error: Unrecognized option %s\n", *argi);
2248
2249 FOREACH_STREAM(stream, streams) {
2250 check_encoder_config(global.disable_warning_prompt, &global,
2251 &stream->config.cfg);
2252
2253 // If large_scale_tile = 1, only support to output to ivf format.
2254 if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf)
2255 die("only support ivf output format while large-scale-tile=1\n");
2256 }
2257
2258 /* Handle non-option arguments */
2259 input.filename = argv[0];
2260
2261 if (!input.filename) {
2262 fprintf(stderr, "No input file specified!\n");
2263 usage_exit();
2264 }
2265
2266 /* Decide if other chroma subsamplings than 4:2:0 are supported */
2267 if (global.codec->fourcc == AV1_FOURCC) input.only_i420 = 0;
2268
2269 for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) {
2270 int frames_in = 0, seen_frames = 0;
2271 int64_t estimated_time_left = -1;
2272 int64_t average_rate = -1;
2273 int64_t lagged_count = 0;
2274
2275 open_input_file(&input, global.csp);
2276
2277 /* If the input file doesn't specify its w/h (raw files), try to get
2278 * the data from the first stream's configuration.
2279 */
2280 if (!input.width || !input.height) {
2281 FOREACH_STREAM(stream, streams) {
2282 if (stream->config.cfg.g_w && stream->config.cfg.g_h) {
2283 input.width = stream->config.cfg.g_w;
2284 input.height = stream->config.cfg.g_h;
2285 break;
2286 }
2287 };
2288 }
2289
2290 /* Update stream configurations from the input file's parameters */
2291 if (!input.width || !input.height)
2292 fatal(
2293 "Specify stream dimensions with --width (-w) "
2294 " and --height (-h)");
2295
2296 /* If input file does not specify bit-depth but input-bit-depth parameter
2297 * exists, assume that to be the input bit-depth. However, if the
2298 * input-bit-depth paramter does not exist, assume the input bit-depth
2299 * to be the same as the codec bit-depth.
2300 */
2301 if (!input.bit_depth) {
2302 FOREACH_STREAM(stream, streams) {
2303 if (stream->config.cfg.g_input_bit_depth)
2304 input.bit_depth = stream->config.cfg.g_input_bit_depth;
2305 else
2306 input.bit_depth = stream->config.cfg.g_input_bit_depth =
2307 (int)stream->config.cfg.g_bit_depth;
2308 }
2309 if (input.bit_depth > 8) input.fmt |= AOM_IMG_FMT_HIGHBITDEPTH;
2310 } else {
2311 FOREACH_STREAM(stream, streams) {
2312 stream->config.cfg.g_input_bit_depth = input.bit_depth;
2313 }
2314 }
2315
2316 FOREACH_STREAM(stream, streams) {
2317 if (input.fmt != AOM_IMG_FMT_I420 && input.fmt != AOM_IMG_FMT_I42016) {
2318 /* Automatically upgrade if input is non-4:2:0 but a 4:2:0 profile
2319 was selected. */
2320 switch (stream->config.cfg.g_profile) {
2321 case 0:
2322 if (input.bit_depth < 12 && (input.fmt == AOM_IMG_FMT_I444 ||
2323 input.fmt == AOM_IMG_FMT_I44416)) {
2324 if (!stream->config.cfg.monochrome) {
2325 stream->config.cfg.g_profile = 1;
2326 profile_updated = 1;
2327 }
2328 } else if (input.bit_depth == 12 || input.fmt == AOM_IMG_FMT_I422 ||
2329 input.fmt == AOM_IMG_FMT_I42216) {
2330 stream->config.cfg.g_profile = 2;
2331 profile_updated = 1;
2332 }
2333 break;
2334 case 1:
2335 if (input.bit_depth == 12 || input.fmt == AOM_IMG_FMT_I422 ||
2336 input.fmt == AOM_IMG_FMT_I42216) {
2337 stream->config.cfg.g_profile = 2;
2338 profile_updated = 1;
2339 } else if (input.bit_depth < 12 &&
2340 (input.fmt == AOM_IMG_FMT_I420 ||
2341 input.fmt == AOM_IMG_FMT_I42016)) {
2342 stream->config.cfg.g_profile = 0;
2343 profile_updated = 1;
2344 }
2345 break;
2346 case 2:
2347 if (input.bit_depth < 12 && (input.fmt == AOM_IMG_FMT_I444 ||
2348 input.fmt == AOM_IMG_FMT_I44416)) {
2349 stream->config.cfg.g_profile = 1;
2350 profile_updated = 1;
2351 } else if (input.bit_depth < 12 &&
2352 (input.fmt == AOM_IMG_FMT_I420 ||
2353 input.fmt == AOM_IMG_FMT_I42016)) {
2354 stream->config.cfg.g_profile = 0;
2355 profile_updated = 1;
2356 } else if (input.bit_depth == 12 &&
2357 input.file_type == FILE_TYPE_Y4M) {
2358 // Note that here the input file values for chroma subsampling
2359 // are used instead of those from the command line.
2360 aom_codec_control(&stream->encoder, AV1E_SET_CHROMA_SUBSAMPLING_X,
2361 input.y4m.dst_c_dec_h >> 1);
2362 aom_codec_control(&stream->encoder, AV1E_SET_CHROMA_SUBSAMPLING_Y,
2363 input.y4m.dst_c_dec_v >> 1);
2364 } else if (input.bit_depth == 12 &&
2365 input.file_type == FILE_TYPE_RAW) {
2366 aom_codec_control(&stream->encoder, AV1E_SET_CHROMA_SUBSAMPLING_X,
2367 stream->chroma_subsampling_x);
2368 aom_codec_control(&stream->encoder, AV1E_SET_CHROMA_SUBSAMPLING_Y,
2369 stream->chroma_subsampling_y);
2370 }
2371 break;
2372 default: break;
2373 }
2374 }
2375 /* Automatically set the codec bit depth to match the input bit depth.
2376 * Upgrade the profile if required. */
2377 if (stream->config.cfg.g_input_bit_depth >
2378 (unsigned int)stream->config.cfg.g_bit_depth) {
2379 stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth;
2380 if (!global.quiet) {
2381 fprintf(stderr,
2382 "Warning: automatically updating bit depth to %d to "
2383 "match input format.\n",
2384 stream->config.cfg.g_input_bit_depth);
2385 }
2386 }
2387 if (stream->config.cfg.g_bit_depth > 10) {
2388 switch (stream->config.cfg.g_profile) {
2389 case 0:
2390 case 1:
2391 stream->config.cfg.g_profile = 2;
2392 profile_updated = 1;
2393 break;
2394 default: break;
2395 }
2396 }
2397 if (stream->config.cfg.g_bit_depth > 8) {
2398 stream->config.use_16bit_internal = 1;
2399 }
2400 if (profile_updated && !global.quiet) {
2401 fprintf(stderr,
2402 "Warning: automatically updating to profile %d to "
2403 "match input format.\n",
2404 stream->config.cfg.g_profile);
2405 }
2406 /* Set limit */
2407 stream->config.cfg.g_limit = global.limit;
2408 }
2409
2410 FOREACH_STREAM(stream, streams) {
2411 set_stream_dimensions(stream, input.width, input.height);
2412 }
2413 FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); }
2414
2415 /* Ensure that --passes and --pass are consistent. If --pass is set and
2416 * --passes=2, ensure --fpf was set.
2417 */
2418 if (global.pass && global.passes == 2) {
2419 FOREACH_STREAM(stream, streams) {
2420 if (!stream->config.stats_fn)
2421 die("Stream %d: Must specify --fpf when --pass=%d"
2422 " and --passes=2\n",
2423 stream->index, global.pass);
2424 }
2425 }
2426
2427 #if !CONFIG_WEBM_IO
2428 FOREACH_STREAM(stream, streams) {
2429 if (stream->config.write_webm) {
2430 stream->config.write_webm = 0;
2431 stream->config.write_ivf = 0;
2432 warn("aomenc compiled w/o WebM support. Writing OBU stream.");
2433 }
2434 }
2435 #endif
2436
2437 /* Use the frame rate from the file only if none was specified
2438 * on the command-line.
2439 */
2440 if (!global.have_framerate) {
2441 global.framerate.num = input.framerate.numerator;
2442 global.framerate.den = input.framerate.denominator;
2443 }
2444 FOREACH_STREAM(stream, streams) {
2445 stream->config.cfg.g_timebase.den = global.framerate.num;
2446 stream->config.cfg.g_timebase.num = global.framerate.den;
2447 }
2448 /* Show configuration */
2449 if (global.verbose && pass == 0) {
2450 FOREACH_STREAM(stream, streams) {
2451 show_stream_config(stream, &global, &input);
2452 }
2453 }
2454
2455 if (pass == (global.pass ? global.pass - 1 : 0)) {
2456 if (input.file_type == FILE_TYPE_Y4M)
2457 /*The Y4M reader does its own allocation.
2458 Just initialize this here to avoid problems if we never read any
2459 frames.*/
2460 memset(&raw, 0, sizeof(raw));
2461 else
2462 aom_img_alloc(&raw, input.fmt, input.width, input.height, 32);
2463
2464 FOREACH_STREAM(stream, streams) {
2465 stream->rate_hist =
2466 init_rate_histogram(&stream->config.cfg, &global.framerate);
2467 }
2468 }
2469
2470 FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); }
2471 FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); }
2472 FOREACH_STREAM(stream, streams) {
2473 open_output_file(stream, &global, &input.pixel_aspect_ratio);
2474 }
2475
2476 if (strcmp(global.codec->name, "av1") == 0 ||
2477 strcmp(global.codec->name, "av1") == 0) {
2478 // Check to see if at least one stream uses 16 bit internal.
2479 // Currently assume that the bit_depths for all streams using
2480 // highbitdepth are the same.
2481 FOREACH_STREAM(stream, streams) {
2482 if (stream->config.use_16bit_internal) {
2483 use_16bit_internal = 1;
2484 }
2485 input_shift = (int)stream->config.cfg.g_bit_depth -
2486 stream->config.cfg.g_input_bit_depth;
2487 };
2488 }
2489
2490 frame_avail = 1;
2491 got_data = 0;
2492
2493 while (frame_avail || got_data) {
2494 struct aom_usec_timer timer;
2495
2496 if (!global.limit || frames_in < global.limit) {
2497 frame_avail = read_frame(&input, &raw);
2498
2499 if (frame_avail) frames_in++;
2500 seen_frames =
2501 frames_in > global.skip_frames ? frames_in - global.skip_frames : 0;
2502
2503 if (!global.quiet) {
2504 float fps = usec_to_fps(cx_time, seen_frames);
2505 fprintf(stderr, "\rPass %d/%d ", pass + 1, global.passes);
2506
2507 if (stream_cnt == 1)
2508 fprintf(stderr, "frame %4d/%-4d %7" PRId64 "B ", frames_in,
2509 streams->frames_out, (int64_t)streams->nbytes);
2510 else
2511 fprintf(stderr, "frame %4d ", frames_in);
2512
2513 fprintf(stderr, "%7" PRId64 " %s %.2f %s ",
2514 cx_time > 9999999 ? cx_time / 1000 : cx_time,
2515 cx_time > 9999999 ? "ms" : "us", fps >= 1.0 ? fps : fps * 60,
2516 fps >= 1.0 ? "fps" : "fpm");
2517 print_time("ETA", estimated_time_left);
2518 }
2519
2520 } else {
2521 frame_avail = 0;
2522 }
2523
2524 if (frames_in > global.skip_frames) {
2525 aom_image_t *frame_to_encode;
2526 if (input_shift || (use_16bit_internal && input.bit_depth == 8)) {
2527 assert(use_16bit_internal);
2528 // Input bit depth and stream bit depth do not match, so up
2529 // shift frame to stream bit depth
2530 if (!allocated_raw_shift) {
2531 aom_img_alloc(&raw_shift, raw.fmt | AOM_IMG_FMT_HIGHBITDEPTH,
2532 input.width, input.height, 32);
2533 allocated_raw_shift = 1;
2534 }
2535 aom_img_upshift(&raw_shift, &raw, input_shift);
2536 frame_to_encode = &raw_shift;
2537 } else {
2538 frame_to_encode = &raw;
2539 }
2540 aom_usec_timer_start(&timer);
2541 if (use_16bit_internal) {
2542 assert(frame_to_encode->fmt & AOM_IMG_FMT_HIGHBITDEPTH);
2543 FOREACH_STREAM(stream, streams) {
2544 if (stream->config.use_16bit_internal)
2545 encode_frame(stream, &global,
2546 frame_avail ? frame_to_encode : NULL, frames_in);
2547 else
2548 assert(0);
2549 };
2550 } else {
2551 assert((frame_to_encode->fmt & AOM_IMG_FMT_HIGHBITDEPTH) == 0);
2552 FOREACH_STREAM(stream, streams) {
2553 encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL,
2554 frames_in);
2555 }
2556 }
2557 aom_usec_timer_mark(&timer);
2558 cx_time += aom_usec_timer_elapsed(&timer);
2559
2560 FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); }
2561
2562 got_data = 0;
2563 FOREACH_STREAM(stream, streams) {
2564 get_cx_data(stream, &global, &got_data);
2565 }
2566
2567 if (!got_data && input.length && streams != NULL &&
2568 !streams->frames_out) {
2569 lagged_count = global.limit ? seen_frames : ftello(input.file);
2570 } else if (input.length) {
2571 int64_t remaining;
2572 int64_t rate;
2573
2574 if (global.limit) {
2575 const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000;
2576
2577 rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0;
2578 remaining = 1000 * (global.limit - global.skip_frames -
2579 seen_frames + lagged_count);
2580 } else {
2581 const int64_t input_pos = ftello(input.file);
2582 const int64_t input_pos_lagged = input_pos - lagged_count;
2583 const int64_t input_limit = input.length;
2584
2585 rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0;
2586 remaining = input_limit - input_pos + lagged_count;
2587 }
2588
2589 average_rate =
2590 (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8;
2591 estimated_time_left = average_rate ? remaining / average_rate : -1;
2592 }
2593
2594 if (got_data && global.test_decode != TEST_DECODE_OFF) {
2595 FOREACH_STREAM(stream, streams) {
2596 test_decode(stream, global.test_decode);
2597 }
2598 }
2599 }
2600
2601 fflush(stdout);
2602 if (!global.quiet) fprintf(stderr, "\033[K");
2603 }
2604
2605 if (stream_cnt > 1) fprintf(stderr, "\n");
2606
2607 if (!global.quiet) {
2608 FOREACH_STREAM(stream, streams) {
2609 const int64_t bpf =
2610 seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0;
2611 const int64_t bps = bpf * global.framerate.num / global.framerate.den;
2612 fprintf(stderr,
2613 "\rPass %d/%d frame %4d/%-4d %7" PRId64 "B %7" PRId64
2614 "b/f %7" PRId64
2615 "b/s"
2616 " %7" PRId64 " %s (%.2f fps)\033[K\n",
2617 pass + 1, global.passes, frames_in, stream->frames_out,
2618 (int64_t)stream->nbytes, bpf, bps,
2619 stream->cx_time > 9999999 ? stream->cx_time / 1000
2620 : stream->cx_time,
2621 stream->cx_time > 9999999 ? "ms" : "us",
2622 usec_to_fps(stream->cx_time, seen_frames));
2623 }
2624 }
2625
2626 if (global.show_psnr) {
2627 if (global.codec->fourcc == AV1_FOURCC) {
2628 FOREACH_STREAM(stream, streams) {
2629 int64_t bps = 0;
2630 if (stream->psnr_count && seen_frames && global.framerate.den) {
2631 bps = (int64_t)stream->nbytes * 8 * (int64_t)global.framerate.num /
2632 global.framerate.den / seen_frames;
2633 }
2634 show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1,
2635 bps);
2636 }
2637 } else {
2638 FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); }
2639 }
2640 }
2641
2642 FOREACH_STREAM(stream, streams) { aom_codec_destroy(&stream->encoder); }
2643
2644 if (global.test_decode != TEST_DECODE_OFF) {
2645 FOREACH_STREAM(stream, streams) { aom_codec_destroy(&stream->decoder); }
2646 }
2647
2648 close_input_file(&input);
2649
2650 if (global.test_decode == TEST_DECODE_FATAL) {
2651 FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; }
2652 }
2653 FOREACH_STREAM(stream, streams) {
2654 close_output_file(stream, global.codec->fourcc);
2655 }
2656
2657 FOREACH_STREAM(stream, streams) {
2658 stats_close(&stream->stats, global.passes - 1);
2659 }
2660
2661 if (global.pass) break;
2662 }
2663
2664 if (global.show_q_hist_buckets) {
2665 FOREACH_STREAM(stream, streams) {
2666 show_q_histogram(stream->counts, global.show_q_hist_buckets);
2667 }
2668 }
2669
2670 if (global.show_rate_hist_buckets) {
2671 FOREACH_STREAM(stream, streams) {
2672 show_rate_histogram(stream->rate_hist, &stream->config.cfg,
2673 global.show_rate_hist_buckets);
2674 }
2675 }
2676 FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); }
2677
2678 #if CONFIG_INTERNAL_STATS
2679 /* TODO(jkoleszar): This doesn't belong in this executable. Do it for now,
2680 * to match some existing utilities.
2681 */
2682 if (!(global.pass == 1 && global.passes == 2)) {
2683 FOREACH_STREAM(stream, streams) {
2684 FILE *f = fopen("opsnr.stt", "a");
2685 if (stream->mismatch_seen) {
2686 fprintf(f, "First mismatch occurred in frame %d\n",
2687 stream->mismatch_seen);
2688 } else {
2689 fprintf(f, "No mismatch detected in recon buffers\n");
2690 }
2691 fclose(f);
2692 }
2693 }
2694 #endif
2695
2696 if (allocated_raw_shift) aom_img_free(&raw_shift);
2697 aom_img_free(&raw);
2698 free(argv);
2699 free(streams);
2700 return res ? EXIT_FAILURE : EXIT_SUCCESS;
2701 }
AOME_GET_LAST_QUANTIZER_64
@ AOME_GET_LAST_QUANTIZER_64
Codec control function to get last quantizer chosen by the encoder.
Definition: aomcx.h:213
AOM_IMG_FMT_I420
@ AOM_IMG_FMT_I420
Definition: aom_image.h:45
aom_image::fmt
aom_img_fmt_t fmt
Definition: aom_image.h:152
AOM_CICP_TC_IEC_61966
@ AOM_CICP_TC_IEC_61966
Definition: aom_image.h:92
AOM_IMG_FMT_YV12
@ AOM_IMG_FMT_YV12
Definition: aom_image.h:43
AOM_CICP_TC_BT_2020_12_BIT
@ AOM_CICP_TC_BT_2020_12_BIT
Definition: aom_image.h:96
AV1E_SET_ENABLE_DIFF_WTD_COMP
@ AV1E_SET_ENABLE_DIFF_WTD_COMP
Codec control function to turn on / off difference weighted compound.
Definition: aomcx.h:930
AOM_CICP_CP_BT_2020
@ AOM_CICP_CP_BT_2020
Definition: aom_image.h:69
AOM_CICP_CP_SMPTE_431
@ AOM_CICP_CP_SMPTE_431
Definition: aom_image.h:71
AV1E_SET_MV_COST_UPD_FREQ
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors Possible values are: 0: Update at SB ...
Definition: aomcx.h:1151
AV1E_SET_TIER_MASK
@ AV1E_SET_TIER_MASK
Control to set bit mask that specifies which tier each of the 32 possible operating points conforms t...
Definition: aomcx.h:1157
AOM_USAGE_REALTIME
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition: aom_encoder.h:1008
aom_codec_decode
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, size_t data_sz, void *user_priv)
Decode data.
AV1E_SET_ENABLE_OVERLAY
@ AV1E_SET_ENABLE_OVERLAY
Codec control function to turn on / off overlay frames for fitlered ALTREF frames.
Definition: aomcx.h:1023
AV1E_SET_DELTALF_MODE
@ AV1E_SET_DELTALF_MODE
Codec control function to turn on/off loopfilter modulation when delta q modulation is enabled....
Definition: aomcx.h:1051
aom_codec_pts_t
int64_t aom_codec_pts_t
Time Stamp Type.
Definition: aom_codec.h:181
aom_codec_enc_cfg
Encoder configuration structure.
Definition: aom_encoder.h:369
MAX_TILE_WIDTHS
#define MAX_TILE_WIDTHS
Maximum number of tile widths in tile widths array.
Definition: aom_encoder.h:846
AOME_SET_CPUUSED
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings.
Definition: aomcx.h:184
AOM_CICP_TC_SMPTE_240
@ AOM_CICP_TC_SMPTE_240
Definition: aom_image.h:87
aom_image::planes
unsigned char * planes[3]
Definition: aom_image.h:182
AOM_SUPERBLOCK_SIZE_DYNAMIC
@ AOM_SUPERBLOCK_SIZE_DYNAMIC
Definition: aom_codec.h:246
AOM_PLANE_Y
#define AOM_PLANE_Y
Definition: aom_image.h:179
AV1E_SET_FORCE_VIDEO_MODE
@ AV1E_SET_FORCE_VIDEO_MODE
Codec control function to force video mode.
Definition: aomcx.h:599
AV1E_SET_ENABLE_DIST_WTD_COMP
@ AV1E_SET_ENABLE_DIST_WTD_COMP
enum value 82 is empty.
Definition: aomcx.h:849
aom_chroma_sample_position_t
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
AV1E_SET_ENABLE_TX64
@ AV1E_SET_ENABLE_TX64
Codec control function to turn on / off 64-length transforms.
Definition: aomcx.h:824
aom_img_fmt_t
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
AOM_CICP_CP_BT_601
@ AOM_CICP_CP_BT_601
Definition: aom_image.h:65
AOM_CICP_TC_BT_709
@ AOM_CICP_TC_BT_709
Definition: aom_image.h:81
AOM_IMG_FMT_I444
@ AOM_IMG_FMT_I444
Definition: aom_image.h:50
AV1E_SET_AQ_MODE
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode.
Definition: aomcx.h:388
AV1E_SET_MAX_GF_INTERVAL
@ AV1E_SET_MAX_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames.
Definition: aomcx.h:512
AV1E_SET_ENABLE_OBMC
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode.
Definition: aomcx.h:609
AOM_BITS_8
@ AOM_BITS_8
Definition: aom_codec.h:232
AV1E_SET_QUANT_B_ADAPT
@ AV1E_SET_QUANT_B_ADAPT
Control to use adaptive quantize_b.
Definition: aomcx.h:1112
aom_image::d_h
unsigned int d_h
Definition: aom_image.h:167
AV1E_SET_GF_CBR_BOOST_PCT
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode.
Definition: aomcx.h:278
MAX_TILE_HEIGHTS
#define MAX_TILE_HEIGHTS
Maximum number of tile heights in tile heights array.
Definition: aom_encoder.h:859
AOM_PLANE_U
#define AOM_PLANE_U
Definition: aom_image.h:180
AV1E_SET_ENABLE_1TO4_PARTITIONS
@ AV1E_SET_ENABLE_1TO4_PARTITIONS
Codec control function to enable/disable 1:4 and 4:1 partitions.
Definition: aomcx.h:774
aom_codec_ctx
Codec context structure.
Definition: aom_codec.h:211
AV1_SET_TILE_MODE
@ AV1_SET_TILE_MODE
Definition: aomdx.h:196
AOM_CICP_MC_ICTCP
@ AOM_CICP_MC_ICTCP
Definition: aom_image.h:121
cfg_options::super_block_size
unsigned int super_block_size
Superblock size 0, 64 or 128.
Definition: aom_encoder.h:218
AOM_CICP_CP_BT_470_B_G
@ AOM_CICP_CP_BT_470_B_G
Definition: aom_image.h:64
aom_rational
Rational Number.
Definition: aom_encoder.h:171
aom_codec_iter_t
const typedef void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:201
AOME_SET_STATIC_THRESHOLD
@ AOME_SET_STATIC_THRESHOLD
Codec control function to set the threshold for MBs treated static.
Definition: aomcx.h:198
AOM_CQ
@ AOM_CQ
Definition: aom_encoder.h:187
AOM_CSP_UNKNOWN
@ AOM_CSP_UNKNOWN
Definition: aom_image.h:133
aomcx.h
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
AOM_CICP_MC_SMPTE_2085
@ AOM_CICP_MC_SMPTE_2085
Definition: aom_image.h:117
AV1E_SET_ENABLE_PALETTE
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode.
Definition: aomcx.h:1026
AV1E_SET_MODE_COST_UPD_FREQ
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode Possible values are: 0: Update at SB level (def...
Definition: aomcx.h:1142
aom_codec_err_to_string
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
cfg_options::disable_trellis_quant
unsigned int disable_trellis_quant
disable trellis quantization
Definition: aom_encoder.h:338
AOM_CODEC_USE_HIGHBITDEPTH
#define AOM_CODEC_USE_HIGHBITDEPTH
Make the encoder output one partition at a time.
Definition: aom_encoder.h:70
AOM_CICP_CP_BT_709
@ AOM_CICP_CP_BT_709
Definition: aom_image.h:60
AV1E_SET_ROW_MT
@ AV1E_SET_ROW_MT
Definition: aomcx.h:299
cfg_options::min_partition_size
unsigned int min_partition_size
min partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:226
AOM_CICP_CP_SMPTE_240
@ AOM_CICP_CP_SMPTE_240
Definition: aom_image.h:66
AOM_IMG_FMT_I422
@ AOM_IMG_FMT_I422
Definition: aom_image.h:49
AV1E_SET_DELTAQ_MODE
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode.
Definition: aomcx.h:1045
AOM_RC_FIRST_PASS
@ AOM_RC_FIRST_PASS
Definition: aom_encoder.h:179
AV1E_SET_COLOR_PRIMARIES
@ AV1E_SET_COLOR_PRIMARIES
Codec control function to set color space info.
Definition: aomcx.h:443
AOM_CICP_MC_BT_2020_NCL
@ AOM_CICP_MC_BT_2020_NCL
Definition: aom_image.h:114
AV1E_SET_TUNE_CONTENT
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type.
Definition: aomcx.h:414
aom_img_free
void aom_img_free(aom_image_t *img)
Close an image descriptor.
AOM_CODEC_PSNR_PKT
@ AOM_CODEC_PSNR_PKT
Definition: aom_encoder.h:122
AV1E_SET_QM_MAX
@ AV1E_SET_QM_MAX
Codec control function to set the max quant matrix flatness.
Definition: aomcx.h:663
aom_codec_control_
aom_codec_err_t aom_codec_control_(aom_codec_ctx_t *ctx, int ctrl_id,...)
Control algorithm.
AOME_SET_ARNR_STRENGTH
@ AOME_SET_ARNR_STRENGTH
Codec control function to set the filter strength for the arf.
Definition: aomcx.h:221
AOM_CBR
@ AOM_CBR
Definition: aom_encoder.h:186
AOME_SET_ENABLEAUTOALTREF
@ AOME_SET_ENABLEAUTOALTREF
Codec control function to enable automatic set and use alf frames.
Definition: aomcx.h:188
aom_codec_iface_name
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_ctx::err
aom_codec_err_t err
Definition: aom_codec.h:214
AV1_SET_DECODE_TILE_ROW
@ AV1_SET_DECODE_TILE_ROW
Definition: aomdx.h:190
aom_rational::den
int den
Definition: aom_encoder.h:173
aom_codec_destroy
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
AOM_CICP_TC_LOG_100
@ AOM_CICP_TC_LOG_100
Definition: aom_image.h:89
AV1E_SET_TRANSFER_CHARACTERISTICS
@ AV1E_SET_TRANSFER_CHARACTERISTICS
Codec control function to set transfer function info.
Definition: aomcx.h:469
AV1E_SET_ENABLE_ANGLE_DELTA
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta.
Definition: aomcx.h:1032
AOM_CICP_CP_SMPTE_432
@ AOM_CICP_CP_SMPTE_432
Definition: aom_image.h:72
AOM_RC_LAST_PASS
@ AOM_RC_LAST_PASS
Definition: aom_encoder.h:180
AV1E_SET_MAX_PARTITION_SIZE
@ AV1E_SET_MAX_PARTITION_SIZE
Codec control function to set max partition size.
Definition: aomcx.h:795
aom_img_alloc
aom_image_t * aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
aom_codec_control
#define aom_codec_control(ctx, id, data)
aom_codec_control wrapper macro
Definition: aom_codec.h:421
aom_codec_cx_pkt::twopass_stats
aom_fixed_buf_t twopass_stats
Definition: aom_encoder.h:149
AV1E_SET_TIMING_INFO_TYPE
@ AV1E_SET_TIMING_INFO_TYPE
Codec control function to signal picture timing info in the bitstream.
Definition: aomcx.h:1074
AV1E_SET_ENABLE_SMOOTH_INTRA
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage.
Definition: aomcx.h:990
AOM_CICP_MC_BT_470_B_G
@ AOM_CICP_MC_BT_470_B_G
Definition: aom_image.h:110
AOM_IMG_FMT_I42216
@ AOM_IMG_FMT_I42216
Definition: aom_image.h:53
AV1E_SET_TILE_ROWS
@ AV1E_SET_TILE_ROWS
Codec control function to set number of tile rows.
Definition: aomcx.h:332
aom_codec_dec_cfg
Initialization Configurations.
Definition: aom_decoder.h:96
AOM_IMG_FMT_I44416
@ AOM_IMG_FMT_I44416
Definition: aom_image.h:54
AOM_CICP_TC_SMPTE_428
@ AOM_CICP_TC_SMPTE_428
Definition: aom_image.h:98
AOM_CICP_MC_BT_601
@ AOM_CICP_MC_BT_601
Definition: aom_image.h:111
AV1E_SET_COEFF_COST_UPD_FREQ
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients Possible values are: 0: Update at SB le...
Definition: aomcx.h:1134
AOM_CICP_CP_XYZ
@ AOM_CICP_CP_XYZ
Definition: aom_image.h:70
AOM_CICP_TC_LINEAR
@ AOM_CICP_TC_LINEAR
Definition: aom_image.h:88
AV1E_SET_FRAME_PERIODIC_BOOST
@ AV1E_SET_FRAME_PERIODIC_BOOST
Codec control function to enable/disable periodic Q boost.
Definition: aomcx.h:401
AOM_SUPERBLOCK_SIZE_64X64
@ AOM_SUPERBLOCK_SIZE_64X64
Definition: aom_codec.h:244
AOM_IMG_FMT_YV1216
@ AOM_IMG_FMT_YV1216
Definition: aom_image.h:52
AV1E_SET_NUM_TG
@ AV1E_SET_NUM_TG
Codec control function to set a maximum number of tile groups.
Definition: aomcx.h:726
AOME_SET_ARNR_MAXFRAMES
@ AOME_SET_ARNR_MAXFRAMES
Codec control function to set the max no of frames to create arf.
Definition: aomcx.h:217
AV1E_SET_ENABLE_CHROMA_DELTAQ
@ AV1E_SET_ENABLE_CHROMA_DELTAQ
Codec control function to turn on / off delta quantization in chroma planes usage for a sequence.
Definition: aomcx.h:885
AOM_CICP_TC_BT_1361
@ AOM_CICP_TC_BT_1361
Definition: aom_image.h:93
AOM_CSP_VERTICAL
@ AOM_CSP_VERTICAL
Definition: aom_image.h:134
AV1E_SET_FRAME_PARALLEL_DECODING
@ AV1E_SET_FRAME_PARALLEL_DECODING
Codec control function to enable frame parallel decoding feature.
Definition: aomcx.h:357
AV1E_SET_INTER_DCT_ONLY
@ AV1E_SET_INTER_DCT_ONLY
Control to use dct only for inter modes.
Definition: aomcx.h:1106
aom_codec_enc_cfg::g_pass
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: aom_encoder.h:481
AV1E_SET_INTRA_DCT_ONLY
@ AV1E_SET_INTRA_DCT_ONLY
Control to use dct only for intra modes.
Definition: aomcx.h:1103
AV1E_SET_ENABLE_PAETH_INTRA
@ AV1E_SET_ENABLE_PAETH_INTRA
Codec control function to turn on / off Paeth intra mode usage.
Definition: aomcx.h:998
AOM_CICP_MC_UNSPECIFIED
@ AOM_CICP_MC_UNSPECIFIED
Definition: aom_image.h:107
AV1E_SET_MTU
@ AV1E_SET_MTU
Codec control function to set an MTU size for a tile group.
Definition: aomcx.h:738
aom_codec_enc_cfg::g_w
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:408
AOM_CICP_MC_SMPTE_YCGCO
@ AOM_CICP_MC_SMPTE_YCGCO
Definition: aom_image.h:113
AV1E_SET_MIN_CR
@ AV1E_SET_MIN_CR
Control to set minimum compression ratio. Take integer values. If non-zero, encoder will try to keep ...
Definition: aomcx.h:1164
AV1E_SET_CDF_UPDATE_MODE
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode.
Definition: aomcx.h:421
AOM_CSP_COLOCATED
@ AOM_CSP_COLOCATED
Definition: aom_image.h:136
AOM_BITS_12
@ AOM_BITS_12
Definition: aom_codec.h:234
AOM_SUPERBLOCK_SIZE_128X128
@ AOM_SUPERBLOCK_SIZE_128X128
Definition: aom_codec.h:245
AOM_USAGE_GOOD_QUALITY
#define AOM_USAGE_GOOD_QUALITY
usage parameter analogous to AV1 GOOD QUALITY mode.
Definition: aom_encoder.h:1006
AOM_VBR
@ AOM_VBR
Definition: aom_encoder.h:185
AV1E_SET_NOISE_SENSITIVITY
@ AV1E_SET_NOISE_SENSITIVITY
Codec control function to set noise sensitivity.
Definition: aomcx.h:407
AOM_CICP_TC_BT_2020_10_BIT
@ AOM_CICP_TC_BT_2020_10_BIT
Definition: aom_image.h:95
aom_codec_cx_pkt::raw
aom_fixed_buf_t raw
Definition: aom_encoder.h:156
AOM_CICP_CP_EBU_3213
@ AOM_CICP_CP_EBU_3213
Definition: aom_image.h:74
AOM_CICP_TC_LOG_100_SQRT10
@ AOM_CICP_TC_LOG_100_SQRT10
Definition: aom_image.h:90
AV1E_SET_SUPERBLOCK_SIZE
@ AV1E_SET_SUPERBLOCK_SIZE
Codec control function to set intended superblock size.
Definition: aomcx.h:560
AV1E_SET_INTRA_DEFAULT_TX_ONLY
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes.
Definition: aomcx.h:1109
AV1E_SET_CHROMA_SAMPLE_POSITION
@ AV1E_SET_CHROMA_SAMPLE_POSITION
Codec control function to set chroma 4:2:0 sample position info.
Definition: aomcx.h:500
aom_codec_err_t
aom_codec_err_t
Algorithm return codes.
Definition: aom_codec.h:101
aom_decoder.h
Describes the decoder algorithm interface to applications.
AOM_RC_ONE_PASS
@ AOM_RC_ONE_PASS
Definition: aom_encoder.h:178
aom_encoder.h
Describes the encoder algorithm interface to applications.
AV1E_SET_MIN_PARTITION_SIZE
@ AV1E_SET_MIN_PARTITION_SIZE
Codec control function to set min partition size.
Definition: aomcx.h:785
AV1E_SET_TARGET_SEQ_LEVEL_IDX
@ AV1E_SET_TARGET_SEQ_LEVEL_IDX
Control to set target sequence level index for a certain operating point(OP). Possible values are in ...
Definition: aomcx.h:545
AV1E_SET_DISABLE_TRELLIS_QUANT
@ AV1E_SET_DISABLE_TRELLIS_QUANT
Codec control function to encode without trellis quantization.
Definition: aomcx.h:622
AV1D_SET_IS_ANNEXB
@ AV1D_SET_IS_ANNEXB
Definition: aomdx.h:222
AOM_CICP_TC_HLG
@ AOM_CICP_TC_HLG
Definition: aom_image.h:99
aom_codec_get_cx_data
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
AOM_CICP_MC_BT_2020_CL
@ AOM_CICP_MC_BT_2020_CL
Definition: aom_image.h:116
aom_codec_encode
aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img, aom_codec_pts_t pts, unsigned long duration, aom_enc_frame_flags_t flags)
Encode a frame.
aom_codec_dec_init
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition: aom_decoder.h:134
AV1E_SET_ENABLE_INTRABC
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode.
Definition: aomcx.h:1029
AV1E_SET_ENABLE_WARPED_MOTION
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level.
Definition: aomcx.h:964
AV1E_SET_REDUCED_REFERENCE_SET
@ AV1E_SET_REDUCED_REFERENCE_SET
Control to use reduced set of single and compound references.
Definition: aomcx.h:1123
AV1E_SET_ENABLE_INTERINTER_WEDGE
@ AV1E_SET_ENABLE_INTERINTER_WEDGE
Codec control function to turn on / off interinter wedge compound.
Definition: aomcx.h:939
AV1E_SET_QM_MIN
@ AV1E_SET_QM_MIN
Codec control function to set the min quant matrix flatness.
Definition: aomcx.h:650
AV1E_SET_MIN_GF_INTERVAL
@ AV1E_SET_MIN_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames.
Definition: aomcx.h:506
AV1E_SET_ENABLE_CFL_INTRA
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage.
Definition: aomcx.h:1006
AV1E_SET_ENABLE_FLIP_IDTX
@ AV1E_SET_ENABLE_FLIP_IDTX
Codec control function to turn on / off flip and identity transforms.
Definition: aomcx.h:835
AOM_IMG_FMT_I42016
@ AOM_IMG_FMT_I42016
Definition: aom_image.h:51
AOME_SET_MAX_INTRA_BITRATE_PCT
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set Max data rate for Intra frames.
Definition: aomcx.h:248
AOM_BITS_10
@ AOM_BITS_10
Definition: aom_codec.h:233
AV1E_SET_MATRIX_COEFFICIENTS
@ AV1E_SET_MATRIX_COEFFICIENTS
Codec control function to set transfer function info.
Definition: aomcx.h:491
AOM_CICP_MC_FCC
@ AOM_CICP_MC_FCC
Definition: aom_image.h:109
AOM_Q
@ AOM_Q
Definition: aom_encoder.h:188
aom_codec_cx_pkt::data
union aom_codec_cx_pkt::@1 data
AV1E_SET_ENABLE_CDEF
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF.
Definition: aomcx.h:579
AV1E_SET_FILM_GRAIN_TABLE
@ AV1E_SET_FILM_GRAIN_TABLE
Codec control function to set the path to the film grain parameters.
Definition: aomcx.h:1085
AOM_CICP_MC_IDENTITY
@ AOM_CICP_MC_IDENTITY
Definition: aom_image.h:105
AV1E_SET_FILM_GRAIN_TEST_VECTOR
@ AV1E_SET_FILM_GRAIN_TEST_VECTOR
Codec control function to add film grain parameters (one of several preset types) info in the bitstre...
Definition: aomcx.h:1081
AV1E_SET_MAX_INTER_BITRATE_PCT
@ AV1E_SET_MAX_INTER_BITRATE_PCT
Codec control function to set max data rate for Inter frames.
Definition: aomcx.h:265
AOM_KF_DISABLED
@ AOM_KF_DISABLED
Definition: aom_encoder.h:202
AV1E_SET_ENABLE_GLOBAL_MOTION
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence.
Definition: aomcx.h:956
aom_codec_cx_pkt::frame
struct aom_codec_cx_pkt::@1::@2 frame
AOM_CICP_CP_BT_470_M
@ AOM_CICP_CP_BT_470_M
Definition: aom_image.h:63
aom_codec_cx_pkt
Encoder output packet.
Definition: aom_encoder.h:131
AV1E_SET_ENABLE_ORDER_HINT
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint for a few tools:
Definition: aomcx.h:816
AOM_CICP_MC_CHROMAT_CL
@ AOM_CICP_MC_CHROMAT_CL
Definition: aom_image.h:120
aom_image::d_w
unsigned int d_w
Definition: aom_image.h:166
aom_codec_error
const char * aom_codec_error(aom_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
AV1E_SET_TILE_COLUMNS
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns.
Definition: aomcx.h:316
AOM_CICP_MC_CHROMAT_NCL
@ AOM_CICP_MC_CHROMAT_NCL
Definition: aom_image.h:118
AOM_CICP_TC_SMPTE_2084
@ AOM_CICP_TC_SMPTE_2084
Definition: aom_image.h:97
AOM_PLANE_V
#define AOM_PLANE_V
Definition: aom_image.h:181
AV1E_SET_ENABLE_QM
@ AV1E_SET_ENABLE_QM
Codec control function to encode with quantisation matrices.
Definition: aomcx.h:636
AOM_CICP_TC_BT_470_M
@ AOM_CICP_TC_BT_470_M
Definition: aom_image.h:84
AV1E_SET_ENABLE_INTERINTRA_COMP
@ AV1E_SET_ENABLE_INTERINTRA_COMP
Codec control function to turn on / off interintra compound for a sequence.
Definition: aomcx.h:912
AOM_CODEC_STATS_PKT
@ AOM_CODEC_STATS_PKT
Definition: aom_encoder.h:120
AV1E_SET_ENABLE_DIST_8X8
@ AV1E_SET_ENABLE_DIST_8X8
Codec control function to encode with dist_8x8.
Definition: aomcx.h:717
AOME_SET_SHARPNESS
@ AOME_SET_SHARPNESS
Codec control function to set sharpness.
Definition: aomcx.h:194
aom_codec_enc_cfg::g_h
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:417
AV1E_SET_ENABLE_INTERINTRA_WEDGE
@ AV1E_SET_ENABLE_INTERINTRA_WEDGE
Codec control function to turn on / off interintra wedge compound.
Definition: aomcx.h:948
AV1E_SET_DENOISE_BLOCK_SIZE
@ AV1E_SET_DENOISE_BLOCK_SIZE
Sets the denoisers block size.
Definition: aomcx.h:1091
AOM_CICP_TC_SRGB
@ AOM_CICP_TC_SRGB
Definition: aom_image.h:94
AV1_GET_NEW_FRAME_IMAGE
@ AV1_GET_NEW_FRAME_IMAGE
Definition: aom.h:65
aomdx.h
Provides definitions for using AOM or AV1 within the aom Decoder interface.
AOM_CODEC_CX_FRAME_PKT
@ AOM_CODEC_CX_FRAME_PKT
Definition: aom_encoder.h:119
AV1E_SET_DENOISE_NOISE_LEVEL
@ AV1E_SET_DENOISE_NOISE_LEVEL
Sets the noise level.
Definition: aomcx.h:1088
AV1E_SET_ENABLE_SMOOTH_INTERINTRA
@ AV1E_SET_ENABLE_SMOOTH_INTERINTRA
Codec control function to turn on / off smooth inter-intra mode for a sequence.
Definition: aomcx.h:921
AOM_CICP_MC_BT_709
@ AOM_CICP_MC_BT_709
Definition: aom_image.h:106
aom_codec_enc_init
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition: aom_encoder.h:905
AOME_SET_CQ_LEVEL
@ AOME_SET_CQ_LEVEL
Codec control function to set constrained / constant quality level.
Definition: aomcx.h:235
aom_codec_cx_pkt::psnr
double psnr[4]
Definition: aom_encoder.h:154
aom_image
Image Descriptor.
Definition: aom_image.h:151
AV1E_SET_ENABLE_KEYFRAME_FILTERING
@ AV1E_SET_ENABLE_KEYFRAME_FILTERING
Codec control function to enable temporal filtering on key frame.
Definition: aomcx.h:345
aom_image::stride
int stride[3]
Definition: aom_image.h:183
AV1E_SET_LOSSLESS
@ AV1E_SET_LOSSLESS
Codec control function to set lossless encoding mode.
Definition: aomcx.h:293
aom_fixed_buf::sz
size_t sz
Definition: aom_encoder.h:78
AOM_CICP_TC_BT_601
@ AOM_CICP_TC_BT_601
Definition: aom_image.h:86
aom_codec_cx_pkt::kind
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:132
aom_codec_enc_cfg::g_timebase
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:466
AOM_CODEC_USE_PSNR
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition: aom_encoder.h:68
AV1E_SET_ENABLE_TPL_MODEL
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency.
Definition: aomcx.h:339
AOM_CICP_TC_BT_470_B_G
@ AOM_CICP_TC_BT_470_B_G
Definition: aom_image.h:85
AV1E_SET_ERROR_RESILIENT_MODE
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode.
Definition: aomcx.h:367
AV1E_SET_ENABLE_RESTORATION
@ AV1E_SET_ENABLE_RESTORATION
Codec control function to encode with Loop Restoration Filter.
Definition: aomcx.h:589
cfg_options
Encoder Config Options.
Definition: aom_encoder.h:210
AV1E_SET_ENABLE_RECT_PARTITIONS
@ AV1E_SET_ENABLE_RECT_PARTITIONS
Codec control function to enable/disable rectangular partitions.
Definition: aomcx.h:758
AV1E_SET_ENABLE_DUAL_FILTER
@ AV1E_SET_ENABLE_DUAL_FILTER
Codec control function to turn on / off dual filter usage for a sequence.
Definition: aomcx.h:876
aom_codec_error_detail
const char * aom_codec_error_detail(aom_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
AOME_SET_TUNING
@ AOME_SET_TUNING
Codec control function to set visual tuning.
Definition: aomcx.h:227
AOM_CICP_CP_GENERIC_FILM
@ AOM_CICP_CP_GENERIC_FILM
Definition: aom_image.h:67
AV1E_SET_ENABLE_AB_PARTITIONS
@ AV1E_SET_ENABLE_AB_PARTITIONS
Codec control function to enable/disable AB partitions.
Definition: aomcx.h:766
cfg_options::max_partition_size
unsigned int max_partition_size
max partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:222
AV1E_SET_GF_MAX_PYRAMID_HEIGHT
@ AV1E_SET_GF_MAX_PYRAMID_HEIGHT
Control to select maximum height for the GF group pyramid structure (valid values: 0 - 4)
Definition: aomcx.h:1116
AOM_IMG_FMT_HIGHBITDEPTH
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
AV1E_SET_ENABLE_ONESIDED_COMP
@ AV1E_SET_ENABLE_ONESIDED_COMP
Codec control function to turn on / off one sided compound usage for a sequence.
Definition: aomcx.h:903
aom_fixed_buf::buf
void * buf
Definition: aom_encoder.h:77
AV1E_SET_CHROMA_SUBSAMPLING_Y
@ AV1E_SET_CHROMA_SUBSAMPLING_Y
Sets the chroma subsampling y value.
Definition: aomcx.h:1097
AV1E_SET_ENABLE_MASKED_COMP
@ AV1E_SET_ENABLE_MASKED_COMP
Codec control function to turn on / off masked compound usage for a sequence.
Definition: aomcx.h:894
AV1E_SET_ENABLE_FILTER_INTRA
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level.
Definition: aomcx.h:982
aom_codec_enc_config_default
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg, unsigned int reserved)
Get a default configuration.
AV1E_SET_ENABLE_INTRA_EDGE_FILTER
@ AV1E_SET_ENABLE_INTRA_EDGE_FILTER
Codec control function to turn on / off intra edge filter at sequence level.
Definition: aomcx.h:804
AV1E_SET_REDUCED_TX_TYPE_SET
@ AV1E_SET_REDUCED_TX_TYPE_SET
Control to use a reduced tx type set.
Definition: aomcx.h:1100
aom_rational::num
int num
Definition: aom_encoder.h:172
AV1E_SET_CHROMA_SUBSAMPLING_X
@ AV1E_SET_CHROMA_SUBSAMPLING_X
Sets the chroma subsampling x value.
Definition: aomcx.h:1094
AV1E_SET_MAX_REFERENCE_FRAMES
@ AV1E_SET_MAX_REFERENCE_FRAMES
Control to select maximum reference frames allowed per frame (valid values: 3 - 7)
Definition: aomcx.h:1120
AV1E_SET_ENABLE_REF_FRAME_MVS
@ AV1E_SET_ENABLE_REF_FRAME_MVS
Codec control function to turn on / off ref frame mvs (mfmv) usage at sequence level.
Definition: aomcx.h:858
AOM_CICP_CP_UNSPECIFIED
@ AOM_CICP_CP_UNSPECIFIED
Definition: aom_image.h:61