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