AOMedia AV1 Codec
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 int av1_arg_ctrl_map[] = { AOME_SET_CPUUSED,
208  AV1E_SET_MTU,
212 #if CONFIG_DENOISE
215  AV1E_SET_ENABLE_DNL_DENOISING,
216 #endif // CONFIG_DENOISE
226 #if CONFIG_TUNE_VMAF
228 #endif
229  0 };
230 
231 const arg_def_t *main_args[] = { &g_av1_codec_arg_defs.help,
232  &g_av1_codec_arg_defs.use_cfg,
233  &g_av1_codec_arg_defs.debugmode,
234  &g_av1_codec_arg_defs.outputfile,
235  &g_av1_codec_arg_defs.codecarg,
236  &g_av1_codec_arg_defs.passes,
237  &g_av1_codec_arg_defs.pass_arg,
238  &g_av1_codec_arg_defs.fpf_name,
239  &g_av1_codec_arg_defs.limit,
240  &g_av1_codec_arg_defs.skip,
241  &g_av1_codec_arg_defs.good_dl,
242  &g_av1_codec_arg_defs.rt_dl,
243  &g_av1_codec_arg_defs.quietarg,
244  &g_av1_codec_arg_defs.verbosearg,
245  &g_av1_codec_arg_defs.psnrarg,
246  &g_av1_codec_arg_defs.use_webm,
247  &g_av1_codec_arg_defs.use_ivf,
248  &g_av1_codec_arg_defs.use_obu,
249  &g_av1_codec_arg_defs.q_hist_n,
250  &g_av1_codec_arg_defs.rate_hist_n,
251  &g_av1_codec_arg_defs.disable_warnings,
252  &g_av1_codec_arg_defs.disable_warning_prompt,
253  &g_av1_codec_arg_defs.recontest,
254  NULL };
255 
256 const arg_def_t *global_args[] = {
257  &g_av1_codec_arg_defs.use_yv12,
258  &g_av1_codec_arg_defs.use_i420,
259  &g_av1_codec_arg_defs.use_i422,
260  &g_av1_codec_arg_defs.use_i444,
261  &g_av1_codec_arg_defs.usage,
262  &g_av1_codec_arg_defs.threads,
263  &g_av1_codec_arg_defs.profile,
264  &g_av1_codec_arg_defs.width,
265  &g_av1_codec_arg_defs.height,
266  &g_av1_codec_arg_defs.forced_max_frame_width,
267  &g_av1_codec_arg_defs.forced_max_frame_height,
268 #if CONFIG_WEBM_IO
269  &g_av1_codec_arg_defs.stereo_mode,
270 #endif
271  &g_av1_codec_arg_defs.timebase,
272  &g_av1_codec_arg_defs.framerate,
273  &g_av1_codec_arg_defs.global_error_resilient,
274  &g_av1_codec_arg_defs.bitdeptharg,
275  &g_av1_codec_arg_defs.inbitdeptharg,
276  &g_av1_codec_arg_defs.lag_in_frames,
277  &g_av1_codec_arg_defs.large_scale_tile,
278  &g_av1_codec_arg_defs.monochrome,
279  &g_av1_codec_arg_defs.full_still_picture_hdr,
280  &g_av1_codec_arg_defs.use_16bit_internal,
281  &g_av1_codec_arg_defs.save_as_annexb,
282  NULL
283 };
284 
285 const arg_def_t *rc_args[] = { &g_av1_codec_arg_defs.dropframe_thresh,
286  &g_av1_codec_arg_defs.resize_mode,
287  &g_av1_codec_arg_defs.resize_denominator,
288  &g_av1_codec_arg_defs.resize_kf_denominator,
289  &g_av1_codec_arg_defs.superres_mode,
290  &g_av1_codec_arg_defs.superres_denominator,
291  &g_av1_codec_arg_defs.superres_kf_denominator,
292  &g_av1_codec_arg_defs.superres_qthresh,
293  &g_av1_codec_arg_defs.superres_kf_qthresh,
294  &g_av1_codec_arg_defs.end_usage,
295  &g_av1_codec_arg_defs.target_bitrate,
296  &g_av1_codec_arg_defs.min_quantizer,
297  &g_av1_codec_arg_defs.max_quantizer,
298  &g_av1_codec_arg_defs.undershoot_pct,
299  &g_av1_codec_arg_defs.overshoot_pct,
300  &g_av1_codec_arg_defs.buf_sz,
301  &g_av1_codec_arg_defs.buf_initial_sz,
302  &g_av1_codec_arg_defs.buf_optimal_sz,
303  &g_av1_codec_arg_defs.bias_pct,
304  &g_av1_codec_arg_defs.minsection_pct,
305  &g_av1_codec_arg_defs.maxsection_pct,
306  NULL };
307 
308 const arg_def_t *kf_args[] = { &g_av1_codec_arg_defs.fwd_kf_enabled,
309  &g_av1_codec_arg_defs.kf_min_dist,
310  &g_av1_codec_arg_defs.kf_max_dist,
311  &g_av1_codec_arg_defs.kf_disabled,
312  &g_av1_codec_arg_defs.sframe_dist,
313  &g_av1_codec_arg_defs.sframe_mode,
314  NULL };
315 
316 const arg_def_t *av1_args[] = {
317  &g_av1_codec_arg_defs.cpu_used_av1,
318  &g_av1_codec_arg_defs.auto_altref,
319  &g_av1_codec_arg_defs.sharpness,
320  &g_av1_codec_arg_defs.static_thresh,
321  &g_av1_codec_arg_defs.rowmtarg,
322  &g_av1_codec_arg_defs.tile_cols,
323  &g_av1_codec_arg_defs.tile_rows,
324  &g_av1_codec_arg_defs.enable_tpl_model,
325  &g_av1_codec_arg_defs.enable_keyframe_filtering,
326  &g_av1_codec_arg_defs.arnr_maxframes,
327  &g_av1_codec_arg_defs.arnr_strength,
328  &g_av1_codec_arg_defs.tune_metric,
329  &g_av1_codec_arg_defs.cq_level,
330  &g_av1_codec_arg_defs.max_intra_rate_pct,
331  &g_av1_codec_arg_defs.max_inter_rate_pct,
332  &g_av1_codec_arg_defs.gf_cbr_boost_pct,
333  &g_av1_codec_arg_defs.lossless,
334  &g_av1_codec_arg_defs.enable_cdef,
335  &g_av1_codec_arg_defs.enable_restoration,
336  &g_av1_codec_arg_defs.enable_rect_partitions,
337  &g_av1_codec_arg_defs.enable_ab_partitions,
338  &g_av1_codec_arg_defs.enable_1to4_partitions,
339  &g_av1_codec_arg_defs.min_partition_size,
340  &g_av1_codec_arg_defs.max_partition_size,
341  &g_av1_codec_arg_defs.enable_dual_filter,
342  &g_av1_codec_arg_defs.enable_chroma_deltaq,
343  &g_av1_codec_arg_defs.enable_intra_edge_filter,
344  &g_av1_codec_arg_defs.enable_order_hint,
345  &g_av1_codec_arg_defs.enable_tx64,
346  &g_av1_codec_arg_defs.enable_flip_idtx,
347  &g_av1_codec_arg_defs.enable_rect_tx,
348  &g_av1_codec_arg_defs.enable_dist_wtd_comp,
349  &g_av1_codec_arg_defs.enable_masked_comp,
350  &g_av1_codec_arg_defs.enable_onesided_comp,
351  &g_av1_codec_arg_defs.enable_interintra_comp,
352  &g_av1_codec_arg_defs.enable_smooth_interintra,
353  &g_av1_codec_arg_defs.enable_diff_wtd_comp,
354  &g_av1_codec_arg_defs.enable_interinter_wedge,
355  &g_av1_codec_arg_defs.enable_interintra_wedge,
356  &g_av1_codec_arg_defs.enable_global_motion,
357  &g_av1_codec_arg_defs.enable_warped_motion,
358  &g_av1_codec_arg_defs.enable_filter_intra,
359  &g_av1_codec_arg_defs.enable_smooth_intra,
360  &g_av1_codec_arg_defs.enable_paeth_intra,
361  &g_av1_codec_arg_defs.enable_cfl_intra,
362  &g_av1_codec_arg_defs.force_video_mode,
363  &g_av1_codec_arg_defs.enable_obmc,
364  &g_av1_codec_arg_defs.enable_overlay,
365  &g_av1_codec_arg_defs.enable_palette,
366  &g_av1_codec_arg_defs.enable_intrabc,
367  &g_av1_codec_arg_defs.enable_angle_delta,
368  &g_av1_codec_arg_defs.disable_trellis_quant,
369  &g_av1_codec_arg_defs.enable_qm,
370  &g_av1_codec_arg_defs.qm_min,
371  &g_av1_codec_arg_defs.qm_max,
372  &g_av1_codec_arg_defs.reduced_tx_type_set,
373  &g_av1_codec_arg_defs.use_intra_dct_only,
374  &g_av1_codec_arg_defs.use_inter_dct_only,
375  &g_av1_codec_arg_defs.use_intra_default_tx_only,
376  &g_av1_codec_arg_defs.quant_b_adapt,
377  &g_av1_codec_arg_defs.coeff_cost_upd_freq,
378  &g_av1_codec_arg_defs.mode_cost_upd_freq,
379  &g_av1_codec_arg_defs.mv_cost_upd_freq,
380  &g_av1_codec_arg_defs.frame_parallel_decoding,
381  &g_av1_codec_arg_defs.error_resilient_mode,
382  &g_av1_codec_arg_defs.aq_mode,
383  &g_av1_codec_arg_defs.deltaq_mode,
384  &g_av1_codec_arg_defs.deltalf_mode,
385  &g_av1_codec_arg_defs.frame_periodic_boost,
386  &g_av1_codec_arg_defs.noise_sens,
387  &g_av1_codec_arg_defs.tune_content,
388  &g_av1_codec_arg_defs.cdf_update_mode,
389  &g_av1_codec_arg_defs.input_color_primaries,
390  &g_av1_codec_arg_defs.input_transfer_characteristics,
391  &g_av1_codec_arg_defs.input_matrix_coefficients,
392  &g_av1_codec_arg_defs.input_chroma_sample_position,
393  &g_av1_codec_arg_defs.min_gf_interval,
394  &g_av1_codec_arg_defs.max_gf_interval,
395  &g_av1_codec_arg_defs.gf_min_pyr_height,
396  &g_av1_codec_arg_defs.gf_max_pyr_height,
397  &g_av1_codec_arg_defs.superblock_size,
398  &g_av1_codec_arg_defs.num_tg,
399  &g_av1_codec_arg_defs.mtu_size,
400  &g_av1_codec_arg_defs.timing_info,
401  &g_av1_codec_arg_defs.film_grain_test,
402  &g_av1_codec_arg_defs.film_grain_table,
403 #if CONFIG_DENOISE
404  &g_av1_codec_arg_defs.denoise_noise_level,
405  &g_av1_codec_arg_defs.denoise_block_size,
406  &g_av1_codec_arg_defs.enable_dnl_denoising,
407 #endif // CONFIG_DENOISE
408  &g_av1_codec_arg_defs.max_reference_frames,
409  &g_av1_codec_arg_defs.reduced_reference_set,
410  &g_av1_codec_arg_defs.enable_ref_frame_mvs,
411  &g_av1_codec_arg_defs.target_seq_level_idx,
412  &g_av1_codec_arg_defs.set_tier_mask,
413  &g_av1_codec_arg_defs.set_min_cr,
414  &g_av1_codec_arg_defs.vbr_corpus_complexity_lap,
415  &g_av1_codec_arg_defs.input_chroma_subsampling_x,
416  &g_av1_codec_arg_defs.input_chroma_subsampling_y,
417 #if CONFIG_TUNE_VMAF
418  &g_av1_codec_arg_defs.vmaf_model_path,
419 #endif
420  NULL
421 };
422 
423 static const arg_def_t *no_args[] = { NULL };
424 
425 static void show_help(FILE *fout, int shorthelp) {
426  fprintf(fout, "Usage: %s <options> -o dst_filename src_filename \n",
427  exec_name);
428 
429  if (shorthelp) {
430  fprintf(fout, "Use --help to see the full list of options.\n");
431  return;
432  }
433 
434  fprintf(fout, "\nOptions:\n");
435  arg_show_usage(fout, main_args);
436  fprintf(fout, "\nEncoder Global Options:\n");
437  arg_show_usage(fout, global_args);
438  fprintf(fout, "\nRate Control Options:\n");
439  arg_show_usage(fout, rc_args);
440  fprintf(fout, "\nKeyframe Placement Options:\n");
441  arg_show_usage(fout, kf_args);
442 #if CONFIG_AV1_ENCODER
443  fprintf(fout, "\nAV1 Specific Options:\n");
444  arg_show_usage(fout, av1_args);
445 #endif
446  fprintf(fout,
447  "\nStream timebase (--timebase):\n"
448  " The desired precision of timestamps in the output, expressed\n"
449  " in fractional seconds. Default is 1/1000.\n");
450  fprintf(fout, "\nIncluded encoders:\n\n");
451 
452  const int num_encoder = get_aom_encoder_count();
453  for (int i = 0; i < num_encoder; ++i) {
454  aom_codec_iface_t *encoder = get_aom_encoder_by_index(i);
455  const char *defstr = (i == (num_encoder - 1)) ? "(default)" : "";
456  fprintf(fout, " %-6s - %s %s\n", get_short_name_by_aom_encoder(encoder),
457  aom_codec_iface_name(encoder), defstr);
458  }
459  fprintf(fout, "\n ");
460  fprintf(fout, "Use --codec to switch to a non-default encoder.\n\n");
461 }
462 
463 void usage_exit(void) {
464  show_help(stderr, 1);
465  exit(EXIT_FAILURE);
466 }
467 
468 #if CONFIG_AV1_ENCODER
469 #define ARG_CTRL_CNT_MAX NELEMENTS(av1_arg_ctrl_map)
470 #endif
471 
472 #if !CONFIG_WEBM_IO
473 typedef int stereo_format_t;
474 struct WebmOutputContext {
475  int debug;
476 };
477 #endif
478 
479 /* Per-stream configuration */
480 struct stream_config {
481  struct aom_codec_enc_cfg cfg;
482  const char *out_fn;
483  const char *stats_fn;
484  stereo_format_t stereo_fmt;
485  int arg_ctrls[ARG_CTRL_CNT_MAX][2];
486  int arg_ctrl_cnt;
487  int write_webm;
488  const char *film_grain_filename;
489  int write_ivf;
490  // whether to use 16bit internal buffers
491  int use_16bit_internal;
492 #if CONFIG_TUNE_VMAF
493  const char *vmaf_model_path;
494 #endif
495  aom_color_range_t color_range;
496 };
497 
498 struct stream_state {
499  int index;
500  struct stream_state *next;
501  struct stream_config config;
502  FILE *file;
503  struct rate_hist *rate_hist;
504  struct WebmOutputContext webm_ctx;
505  uint64_t psnr_sse_total[2];
506  uint64_t psnr_samples_total[2];
507  double psnr_totals[2][4];
508  int psnr_count[2];
509  int counts[64];
510  aom_codec_ctx_t encoder;
511  unsigned int frames_out;
512  uint64_t cx_time;
513  size_t nbytes;
514  stats_io_t stats;
515  struct aom_image *img;
516  aom_codec_ctx_t decoder;
517  int mismatch_seen;
518  unsigned int chroma_subsampling_x;
519  unsigned int chroma_subsampling_y;
520 };
521 
522 static void validate_positive_rational(const char *msg,
523  struct aom_rational *rat) {
524  if (rat->den < 0) {
525  rat->num *= -1;
526  rat->den *= -1;
527  }
528 
529  if (rat->num < 0) die("Error: %s must be positive\n", msg);
530 
531  if (!rat->den) die("Error: %s has zero denominator\n", msg);
532 }
533 
534 static void init_config(cfg_options_t *config) {
535  memset(config, 0, sizeof(cfg_options_t));
536  config->super_block_size = 0; // Dynamic
537  config->max_partition_size = 128;
538  config->min_partition_size = 4;
539  config->disable_trellis_quant = 3;
540 }
541 
542 /* Parses global config arguments into the AvxEncoderConfig. Note that
543  * argv is modified and overwrites all parsed arguments.
544  */
545 static void parse_global_config(struct AvxEncoderConfig *global, char ***argv) {
546  char **argi, **argj;
547  struct arg arg;
548  const int num_encoder = get_aom_encoder_count();
549  char **argv_local = (char **)*argv;
550  if (num_encoder < 1) die("Error: no valid encoder available\n");
551 
552  /* Initialize default parameters */
553  memset(global, 0, sizeof(*global));
554  global->codec = get_aom_encoder_by_index(num_encoder - 1);
555  global->passes = 0;
556  global->color_type = I420;
557  global->csp = AOM_CSP_UNKNOWN;
558  global->show_psnr = 0;
559 
560  int cfg_included = 0;
561  init_config(&global->encoder_config);
562 
563  for (argi = argj = argv_local; (*argj = *argi); argi += arg.argv_step) {
564  arg.argv_step = 1;
565 
566  if (arg_match(&arg, &g_av1_codec_arg_defs.use_cfg, argi)) {
567  if (!cfg_included) {
568  parse_cfg(arg.val, &global->encoder_config);
569  cfg_included = 1;
570  }
571  } else if (arg_match(&arg, &g_av1_codec_arg_defs.help, argi)) {
572  show_help(stdout, 0);
573  exit(EXIT_SUCCESS);
574  } else if (arg_match(&arg, &g_av1_codec_arg_defs.codecarg, argi)) {
575  global->codec = get_aom_encoder_by_short_name(arg.val);
576  if (!global->codec)
577  die("Error: Unrecognized argument (%s) to --codec\n", arg.val);
578  } else if (arg_match(&arg, &g_av1_codec_arg_defs.passes, argi)) {
579  global->passes = arg_parse_uint(&arg);
580 
581  if (global->passes < 1 || global->passes > 2)
582  die("Error: Invalid number of passes (%d)\n", global->passes);
583  } else if (arg_match(&arg, &g_av1_codec_arg_defs.pass_arg, argi)) {
584  global->pass = arg_parse_uint(&arg);
585 
586  if (global->pass < 1 || global->pass > 2)
587  die("Error: Invalid pass selected (%d)\n", global->pass);
588  } else if (arg_match(&arg,
589  &g_av1_codec_arg_defs.input_chroma_sample_position,
590  argi)) {
591  global->csp = arg_parse_enum(&arg);
592  /* Flag is used by later code as well, preserve it. */
593  argj++;
594  } else if (arg_match(&arg, &g_av1_codec_arg_defs.usage, argi)) {
595  global->usage = arg_parse_uint(&arg);
596  } else if (arg_match(&arg, &g_av1_codec_arg_defs.good_dl, argi)) {
597  global->usage = AOM_USAGE_GOOD_QUALITY; // Good quality usage
598  } else if (arg_match(&arg, &g_av1_codec_arg_defs.rt_dl, argi)) {
599  global->usage = AOM_USAGE_REALTIME; // Real-time usage
600  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_yv12, argi)) {
601  global->color_type = YV12;
602  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i420, argi)) {
603  global->color_type = I420;
604  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i422, argi)) {
605  global->color_type = I422;
606  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_i444, argi)) {
607  global->color_type = I444;
608  } else if (arg_match(&arg, &g_av1_codec_arg_defs.quietarg, argi)) {
609  global->quiet = 1;
610  } else if (arg_match(&arg, &g_av1_codec_arg_defs.verbosearg, argi)) {
611  global->verbose = 1;
612  } else if (arg_match(&arg, &g_av1_codec_arg_defs.limit, argi)) {
613  global->limit = arg_parse_uint(&arg);
614  } else if (arg_match(&arg, &g_av1_codec_arg_defs.skip, argi)) {
615  global->skip_frames = arg_parse_uint(&arg);
616  } else if (arg_match(&arg, &g_av1_codec_arg_defs.psnrarg, argi)) {
617  if (arg.val)
618  global->show_psnr = arg_parse_int(&arg);
619  else
620  global->show_psnr = 1;
621  } else if (arg_match(&arg, &g_av1_codec_arg_defs.recontest, argi)) {
622  global->test_decode = arg_parse_enum_or_int(&arg);
623  } else if (arg_match(&arg, &g_av1_codec_arg_defs.framerate, argi)) {
624  global->framerate = arg_parse_rational(&arg);
625  validate_positive_rational(arg.name, &global->framerate);
626  global->have_framerate = 1;
627  } else if (arg_match(&arg, &g_av1_codec_arg_defs.debugmode, argi)) {
628  global->debug = 1;
629  } else if (arg_match(&arg, &g_av1_codec_arg_defs.q_hist_n, argi)) {
630  global->show_q_hist_buckets = arg_parse_uint(&arg);
631  } else if (arg_match(&arg, &g_av1_codec_arg_defs.rate_hist_n, argi)) {
632  global->show_rate_hist_buckets = arg_parse_uint(&arg);
633  } else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warnings, argi)) {
634  global->disable_warnings = 1;
635  } else if (arg_match(&arg, &g_av1_codec_arg_defs.disable_warning_prompt,
636  argi)) {
637  global->disable_warning_prompt = 1;
638  } else {
639  argj++;
640  }
641  }
642 
643  if (global->pass) {
644  /* DWIM: Assume the user meant passes=2 if pass=2 is specified */
645  if (global->pass > global->passes) {
646  warn("Assuming --pass=%d implies --passes=%d\n", global->pass,
647  global->pass);
648  global->passes = global->pass;
649  }
650  }
651  /* Validate global config */
652  if (global->passes == 0) {
653 #if CONFIG_AV1_ENCODER
654  // Make default AV1 passes = 2 until there is a better quality 1-pass
655  // encoder
656  if (global->codec != NULL)
657  global->passes =
658  (strcmp(get_short_name_by_aom_encoder(global->codec), "av1") == 0 &&
659  global->usage != AOM_USAGE_REALTIME)
660  ? 2
661  : 1;
662 #else
663  global->passes = 1;
664 #endif
665  }
666 
667  if (global->usage == AOM_USAGE_REALTIME && global->passes > 1) {
668  warn("Enforcing one-pass encoding in realtime mode\n");
669  global->passes = 1;
670  }
671 }
672 
673 static void open_input_file(struct AvxInputContext *input,
675  /* Parse certain options from the input file, if possible */
676  input->file = strcmp(input->filename, "-") ? fopen(input->filename, "rb")
677  : set_binary_mode(stdin);
678 
679  if (!input->file) fatal("Failed to open input file");
680 
681  if (!fseeko(input->file, 0, SEEK_END)) {
682  /* Input file is seekable. Figure out how long it is, so we can get
683  * progress info.
684  */
685  input->length = ftello(input->file);
686  rewind(input->file);
687  }
688 
689  /* Default to 1:1 pixel aspect ratio. */
690  input->pixel_aspect_ratio.numerator = 1;
691  input->pixel_aspect_ratio.denominator = 1;
692 
693  /* For RAW input sources, these bytes will applied on the first frame
694  * in read_frame().
695  */
696  input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
697  input->detect.position = 0;
698 
699  if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
700  if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
701  input->only_i420) >= 0) {
702  input->file_type = FILE_TYPE_Y4M;
703  input->width = input->y4m.pic_w;
704  input->height = input->y4m.pic_h;
705  input->pixel_aspect_ratio.numerator = input->y4m.par_n;
706  input->pixel_aspect_ratio.denominator = input->y4m.par_d;
707  input->framerate.numerator = input->y4m.fps_n;
708  input->framerate.denominator = input->y4m.fps_d;
709  input->fmt = input->y4m.aom_fmt;
710  input->bit_depth = input->y4m.bit_depth;
711  input->color_range = input->y4m.color_range;
712  } else
713  fatal("Unsupported Y4M stream.");
714  } else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
715  fatal("IVF is not supported as input.");
716  } else {
717  input->file_type = FILE_TYPE_RAW;
718  }
719 }
720 
721 static void close_input_file(struct AvxInputContext *input) {
722  fclose(input->file);
723  if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
724 }
725 
726 static struct stream_state *new_stream(struct AvxEncoderConfig *global,
727  struct stream_state *prev) {
728  struct stream_state *stream;
729 
730  stream = calloc(1, sizeof(*stream));
731  if (stream == NULL) {
732  fatal("Failed to allocate new stream.");
733  }
734 
735  if (prev) {
736  memcpy(stream, prev, sizeof(*stream));
737  stream->index++;
738  prev->next = stream;
739  } else {
740  aom_codec_err_t res;
741 
742  /* Populate encoder configuration */
743  res = aom_codec_enc_config_default(global->codec, &stream->config.cfg,
744  global->usage);
745  if (res) fatal("Failed to get config: %s\n", aom_codec_err_to_string(res));
746 
747  /* Change the default timebase to a high enough value so that the
748  * encoder will always create strictly increasing timestamps.
749  */
750  stream->config.cfg.g_timebase.den = 1000;
751 
752  /* Never use the library's default resolution, require it be parsed
753  * from the file or set on the command line.
754  */
755  stream->config.cfg.g_w = 0;
756  stream->config.cfg.g_h = 0;
757 
758  /* Initialize remaining stream parameters */
759  stream->config.write_webm = 1;
760  stream->config.write_ivf = 0;
761 
762 #if CONFIG_WEBM_IO
763  stream->config.stereo_fmt = STEREO_FORMAT_MONO;
764  stream->webm_ctx.last_pts_ns = -1;
765  stream->webm_ctx.writer = NULL;
766  stream->webm_ctx.segment = NULL;
767 #endif
768 
769  /* Allows removal of the application version from the EBML tags */
770  stream->webm_ctx.debug = global->debug;
771  memcpy(&stream->config.cfg.encoder_cfg, &global->encoder_config,
772  sizeof(stream->config.cfg.encoder_cfg));
773  }
774 
775  /* Output files must be specified for each stream */
776  stream->config.out_fn = NULL;
777 
778  stream->next = NULL;
779  return stream;
780 }
781 
782 static void set_config_arg_ctrls(struct stream_config *config, int key,
783  const struct arg *arg) {
784  int j;
785  if (key == AV1E_SET_FILM_GRAIN_TABLE) {
786  config->film_grain_filename = arg->val;
787  return;
788  }
789 
790  // For target level, the settings should accumulate rather than overwrite,
791  // so we simply append it.
792  if (key == AV1E_SET_TARGET_SEQ_LEVEL_IDX) {
793  j = config->arg_ctrl_cnt;
794  assert(j < (int)ARG_CTRL_CNT_MAX);
795  config->arg_ctrls[j][0] = key;
796  config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
797  ++config->arg_ctrl_cnt;
798  return;
799  }
800 
801  /* Point either to the next free element or the first instance of this
802  * control.
803  */
804  for (j = 0; j < config->arg_ctrl_cnt; j++)
805  if (config->arg_ctrls[j][0] == key) break;
806 
807  /* Update/insert */
808  assert(j < (int)ARG_CTRL_CNT_MAX);
809  config->arg_ctrls[j][0] = key;
810  config->arg_ctrls[j][1] = arg_parse_enum_or_int(arg);
811 
812  if (key == AOME_SET_ENABLEAUTOALTREF && config->arg_ctrls[j][1] > 1) {
813  warn("auto-alt-ref > 1 is deprecated... setting auto-alt-ref=1\n");
814  config->arg_ctrls[j][1] = 1;
815  }
816  if (j == config->arg_ctrl_cnt) config->arg_ctrl_cnt++;
817 }
818 
819 static int parse_stream_params(struct AvxEncoderConfig *global,
820  struct stream_state *stream, char **argv) {
821  char **argi, **argj;
822  struct arg arg;
823  static const arg_def_t **ctrl_args = no_args;
824  static const int *ctrl_args_map = NULL;
825  struct stream_config *config = &stream->config;
826  int eos_mark_found = 0;
827  int webm_forced = 0;
828 
829  // Handle codec specific options
830  if (0) {
831 #if CONFIG_AV1_ENCODER
832  } else if (strcmp(get_short_name_by_aom_encoder(global->codec), "av1") == 0) {
833  // TODO(jingning): Reuse AV1 specific encoder configuration parameters.
834  // Consider to expand this set for AV1 encoder control.
835  ctrl_args = av1_args;
836  ctrl_args_map = av1_arg_ctrl_map;
837 #endif
838  }
839 
840  for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
841  arg.argv_step = 1;
842 
843  /* Once we've found an end-of-stream marker (--) we want to continue
844  * shifting arguments but not consuming them.
845  */
846  if (eos_mark_found) {
847  argj++;
848  continue;
849  } else if (!strcmp(*argj, "--")) {
850  eos_mark_found = 1;
851  continue;
852  }
853 
854  if (arg_match(&arg, &g_av1_codec_arg_defs.outputfile, argi)) {
855  config->out_fn = arg.val;
856  if (!webm_forced) {
857  const size_t out_fn_len = strlen(config->out_fn);
858  if (out_fn_len >= 4 &&
859  !strcmp(config->out_fn + out_fn_len - 4, ".ivf")) {
860  config->write_webm = 0;
861  config->write_ivf = 1;
862  } else if (out_fn_len >= 4 &&
863  !strcmp(config->out_fn + out_fn_len - 4, ".obu")) {
864  config->write_webm = 0;
865  config->write_ivf = 0;
866  }
867  }
868  } else if (arg_match(&arg, &g_av1_codec_arg_defs.fpf_name, argi)) {
869  config->stats_fn = arg.val;
870  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_webm, argi)) {
871 #if CONFIG_WEBM_IO
872  config->write_webm = 1;
873  webm_forced = 1;
874 #else
875  die("Error: --webm specified but webm is disabled.");
876 #endif
877  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_ivf, argi)) {
878  config->write_webm = 0;
879  config->write_ivf = 1;
880  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_obu, argi)) {
881  config->write_webm = 0;
882  config->write_ivf = 0;
883  } else if (arg_match(&arg, &g_av1_codec_arg_defs.threads, argi)) {
884  config->cfg.g_threads = arg_parse_uint(&arg);
885  } else if (arg_match(&arg, &g_av1_codec_arg_defs.profile, argi)) {
886  config->cfg.g_profile = arg_parse_uint(&arg);
887  } else if (arg_match(&arg, &g_av1_codec_arg_defs.width, argi)) {
888  config->cfg.g_w = arg_parse_uint(&arg);
889  } else if (arg_match(&arg, &g_av1_codec_arg_defs.height, argi)) {
890  config->cfg.g_h = arg_parse_uint(&arg);
891  } else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_width,
892  argi)) {
893  config->cfg.g_forced_max_frame_width = arg_parse_uint(&arg);
894  } else if (arg_match(&arg, &g_av1_codec_arg_defs.forced_max_frame_height,
895  argi)) {
896  config->cfg.g_forced_max_frame_height = arg_parse_uint(&arg);
897  } else if (arg_match(&arg, &g_av1_codec_arg_defs.bitdeptharg, argi)) {
898  config->cfg.g_bit_depth = arg_parse_enum_or_int(&arg);
899  } else if (arg_match(&arg, &g_av1_codec_arg_defs.inbitdeptharg, argi)) {
900  config->cfg.g_input_bit_depth = arg_parse_uint(&arg);
901  } else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_x,
902  argi)) {
903  stream->chroma_subsampling_x = arg_parse_uint(&arg);
904  } else if (arg_match(&arg, &g_av1_codec_arg_defs.input_chroma_subsampling_y,
905  argi)) {
906  stream->chroma_subsampling_y = arg_parse_uint(&arg);
907 #if CONFIG_WEBM_IO
908  } else if (arg_match(&arg, &g_av1_codec_arg_defs.stereo_mode, argi)) {
909  config->stereo_fmt = arg_parse_enum_or_int(&arg);
910 #endif
911  } else if (arg_match(&arg, &g_av1_codec_arg_defs.timebase, argi)) {
912  config->cfg.g_timebase = arg_parse_rational(&arg);
913  validate_positive_rational(arg.name, &config->cfg.g_timebase);
914  } else if (arg_match(&arg, &g_av1_codec_arg_defs.global_error_resilient,
915  argi)) {
916  config->cfg.g_error_resilient = arg_parse_uint(&arg);
917  } else if (arg_match(&arg, &g_av1_codec_arg_defs.lag_in_frames, argi)) {
918  config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
919  } else if (arg_match(&arg, &g_av1_codec_arg_defs.large_scale_tile, argi)) {
920  config->cfg.large_scale_tile = arg_parse_uint(&arg);
921  if (config->cfg.large_scale_tile) {
922  global->codec = get_aom_encoder_by_short_name("av1");
923  }
924  } else if (arg_match(&arg, &g_av1_codec_arg_defs.monochrome, argi)) {
925  config->cfg.monochrome = 1;
926  } else if (arg_match(&arg, &g_av1_codec_arg_defs.full_still_picture_hdr,
927  argi)) {
928  config->cfg.full_still_picture_hdr = 1;
929  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_16bit_internal,
930  argi)) {
931  config->use_16bit_internal = CONFIG_AV1_HIGHBITDEPTH;
932  if (!config->use_16bit_internal) {
933  warn("%s option ignored with CONFIG_AV1_HIGHBITDEPTH=0.\n", arg.name);
934  }
935  } else if (arg_match(&arg, &g_av1_codec_arg_defs.dropframe_thresh, argi)) {
936  config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg);
937  } else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_mode, argi)) {
938  config->cfg.rc_resize_mode = arg_parse_uint(&arg);
939  } else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_denominator,
940  argi)) {
941  config->cfg.rc_resize_denominator = arg_parse_uint(&arg);
942  } else if (arg_match(&arg, &g_av1_codec_arg_defs.resize_kf_denominator,
943  argi)) {
944  config->cfg.rc_resize_kf_denominator = arg_parse_uint(&arg);
945  } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_mode, argi)) {
946  config->cfg.rc_superres_mode = arg_parse_uint(&arg);
947  } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_denominator,
948  argi)) {
949  config->cfg.rc_superres_denominator = arg_parse_uint(&arg);
950  } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_denominator,
951  argi)) {
952  config->cfg.rc_superres_kf_denominator = arg_parse_uint(&arg);
953  } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_qthresh, argi)) {
954  config->cfg.rc_superres_qthresh = arg_parse_uint(&arg);
955  } else if (arg_match(&arg, &g_av1_codec_arg_defs.superres_kf_qthresh,
956  argi)) {
957  config->cfg.rc_superres_kf_qthresh = arg_parse_uint(&arg);
958  } else if (arg_match(&arg, &g_av1_codec_arg_defs.end_usage, argi)) {
959  config->cfg.rc_end_usage = arg_parse_enum_or_int(&arg);
960  } else if (arg_match(&arg, &g_av1_codec_arg_defs.target_bitrate, argi)) {
961  config->cfg.rc_target_bitrate = arg_parse_uint(&arg);
962  } else if (arg_match(&arg, &g_av1_codec_arg_defs.min_quantizer, argi)) {
963  config->cfg.rc_min_quantizer = arg_parse_uint(&arg);
964  } else if (arg_match(&arg, &g_av1_codec_arg_defs.max_quantizer, argi)) {
965  config->cfg.rc_max_quantizer = arg_parse_uint(&arg);
966  } else if (arg_match(&arg, &g_av1_codec_arg_defs.undershoot_pct, argi)) {
967  config->cfg.rc_undershoot_pct = arg_parse_uint(&arg);
968  } else if (arg_match(&arg, &g_av1_codec_arg_defs.overshoot_pct, argi)) {
969  config->cfg.rc_overshoot_pct = arg_parse_uint(&arg);
970  } else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_sz, argi)) {
971  config->cfg.rc_buf_sz = arg_parse_uint(&arg);
972  } else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_initial_sz, argi)) {
973  config->cfg.rc_buf_initial_sz = arg_parse_uint(&arg);
974  } else if (arg_match(&arg, &g_av1_codec_arg_defs.buf_optimal_sz, argi)) {
975  config->cfg.rc_buf_optimal_sz = arg_parse_uint(&arg);
976  } else if (arg_match(&arg, &g_av1_codec_arg_defs.bias_pct, argi)) {
977  config->cfg.rc_2pass_vbr_bias_pct = arg_parse_uint(&arg);
978  if (global->passes < 2)
979  warn("option %s ignored in one-pass mode.\n", arg.name);
980  } else if (arg_match(&arg, &g_av1_codec_arg_defs.minsection_pct, argi)) {
981  config->cfg.rc_2pass_vbr_minsection_pct = arg_parse_uint(&arg);
982 
983  if (global->passes < 2)
984  warn("option %s ignored in one-pass mode.\n", arg.name);
985  } else if (arg_match(&arg, &g_av1_codec_arg_defs.maxsection_pct, argi)) {
986  config->cfg.rc_2pass_vbr_maxsection_pct = arg_parse_uint(&arg);
987 
988  if (global->passes < 2)
989  warn("option %s ignored in one-pass mode.\n", arg.name);
990  } else if (arg_match(&arg, &g_av1_codec_arg_defs.fwd_kf_enabled, argi)) {
991  config->cfg.fwd_kf_enabled = arg_parse_uint(&arg);
992  } else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_min_dist, argi)) {
993  config->cfg.kf_min_dist = arg_parse_uint(&arg);
994  } else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_max_dist, argi)) {
995  config->cfg.kf_max_dist = arg_parse_uint(&arg);
996  } else if (arg_match(&arg, &g_av1_codec_arg_defs.kf_disabled, argi)) {
997  config->cfg.kf_mode = AOM_KF_DISABLED;
998  } else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_dist, argi)) {
999  config->cfg.sframe_dist = arg_parse_uint(&arg);
1000  } else if (arg_match(&arg, &g_av1_codec_arg_defs.sframe_mode, argi)) {
1001  config->cfg.sframe_mode = arg_parse_uint(&arg);
1002  } else if (arg_match(&arg, &g_av1_codec_arg_defs.save_as_annexb, argi)) {
1003  config->cfg.save_as_annexb = arg_parse_uint(&arg);
1004  } else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_width, argi)) {
1005  config->cfg.tile_width_count =
1006  arg_parse_list(&arg, config->cfg.tile_widths, MAX_TILE_WIDTHS);
1007  } else if (arg_match(&arg, &g_av1_codec_arg_defs.tile_height, argi)) {
1008  config->cfg.tile_height_count =
1009  arg_parse_list(&arg, config->cfg.tile_heights, MAX_TILE_HEIGHTS);
1010 #if CONFIG_TUNE_VMAF
1011  } else if (arg_match(&arg, &g_av1_codec_arg_defs.vmaf_model_path, argi)) {
1012  config->vmaf_model_path = arg.val;
1013 #endif
1014  } else if (arg_match(&arg, &g_av1_codec_arg_defs.use_fixed_qp_offsets,
1015  argi)) {
1016  config->cfg.use_fixed_qp_offsets = arg_parse_uint(&arg);
1017  } else if (arg_match(&arg, &g_av1_codec_arg_defs.fixed_qp_offsets, argi)) {
1018  const int fixed_qp_offset_count = arg_parse_list(
1019  &arg, config->cfg.fixed_qp_offsets, FIXED_QP_OFFSET_COUNT);
1020  if (fixed_qp_offset_count < FIXED_QP_OFFSET_COUNT) {
1021  die("Option --fixed_qp_offsets requires %d comma-separated values, but "
1022  "only %d values were provided.\n",
1023  FIXED_QP_OFFSET_COUNT, fixed_qp_offset_count);
1024  }
1025  config->cfg.use_fixed_qp_offsets = 1;
1026  } else if (global->usage == AOM_USAGE_REALTIME &&
1027  arg_match(&arg, &g_av1_codec_arg_defs.enable_restoration,
1028  argi)) {
1029  if (arg_parse_uint(&arg) == 1) {
1030  warn("non-zero %s option ignored in realtime mode.\n", arg.name);
1031  }
1032  } else {
1033  int i, match = 0;
1034  for (i = 0; ctrl_args[i]; i++) {
1035  if (arg_match(&arg, ctrl_args[i], argi)) {
1036  match = 1;
1037  if (ctrl_args_map) {
1038  set_config_arg_ctrls(config, ctrl_args_map[i], &arg);
1039  }
1040  break;
1041  }
1042  }
1043  if (!match) argj++;
1044  }
1045  }
1046  config->use_16bit_internal |= config->cfg.g_bit_depth > AOM_BITS_8;
1047 
1048  if (global->usage == AOM_USAGE_REALTIME && config->cfg.g_lag_in_frames != 0) {
1049  warn("non-zero lag-in-frames option ignored in realtime mode.\n");
1050  config->cfg.g_lag_in_frames = 0;
1051  }
1052  return eos_mark_found;
1053 }
1054 
1055 #define FOREACH_STREAM(iterator, list) \
1056  for (struct stream_state *iterator = list; iterator; \
1057  iterator = iterator->next)
1058 
1059 static void validate_stream_config(const struct stream_state *stream,
1060  const struct AvxEncoderConfig *global) {
1061  const struct stream_state *streami;
1062  (void)global;
1063 
1064  if (!stream->config.cfg.g_w || !stream->config.cfg.g_h)
1065  fatal(
1066  "Stream %d: Specify stream dimensions with --width (-w) "
1067  " and --height (-h)",
1068  stream->index);
1069 
1070  /* Even if bit depth is set on the command line flag to be lower,
1071  * it is upgraded to at least match the input bit depth.
1072  */
1073  assert(stream->config.cfg.g_input_bit_depth <=
1074  (unsigned int)stream->config.cfg.g_bit_depth);
1075 
1076  for (streami = stream; streami; streami = streami->next) {
1077  /* All streams require output files */
1078  if (!streami->config.out_fn)
1079  fatal("Stream %d: Output file is required (specify with -o)",
1080  streami->index);
1081 
1082  /* Check for two streams outputting to the same file */
1083  if (streami != stream) {
1084  const char *a = stream->config.out_fn;
1085  const char *b = streami->config.out_fn;
1086  if (!strcmp(a, b) && strcmp(a, "/dev/null") && strcmp(a, ":nul"))
1087  fatal("Stream %d: duplicate output file (from stream %d)",
1088  streami->index, stream->index);
1089  }
1090 
1091  /* Check for two streams sharing a stats file. */
1092  if (streami != stream) {
1093  const char *a = stream->config.stats_fn;
1094  const char *b = streami->config.stats_fn;
1095  if (a && b && !strcmp(a, b))
1096  fatal("Stream %d: duplicate stats file (from stream %d)",
1097  streami->index, stream->index);
1098  }
1099  }
1100 }
1101 
1102 static void set_stream_dimensions(struct stream_state *stream, unsigned int w,
1103  unsigned int h) {
1104  if (!stream->config.cfg.g_w) {
1105  if (!stream->config.cfg.g_h)
1106  stream->config.cfg.g_w = w;
1107  else
1108  stream->config.cfg.g_w = w * stream->config.cfg.g_h / h;
1109  }
1110  if (!stream->config.cfg.g_h) {
1111  stream->config.cfg.g_h = h * stream->config.cfg.g_w / w;
1112  }
1113 }
1114 
1115 static const char *file_type_to_string(enum VideoFileType t) {
1116  switch (t) {
1117  case FILE_TYPE_RAW: return "RAW";
1118  case FILE_TYPE_Y4M: return "Y4M";
1119  default: return "Other";
1120  }
1121 }
1122 
1123 static const char *image_format_to_string(aom_img_fmt_t f) {
1124  switch (f) {
1125  case AOM_IMG_FMT_I420: return "I420";
1126  case AOM_IMG_FMT_I422: return "I422";
1127  case AOM_IMG_FMT_I444: return "I444";
1128  case AOM_IMG_FMT_YV12: return "YV12";
1129  case AOM_IMG_FMT_YV1216: return "YV1216";
1130  case AOM_IMG_FMT_I42016: return "I42016";
1131  case AOM_IMG_FMT_I42216: return "I42216";
1132  case AOM_IMG_FMT_I44416: return "I44416";
1133  default: return "Other";
1134  }
1135 }
1136 
1137 static void show_stream_config(struct stream_state *stream,
1138  struct AvxEncoderConfig *global,
1139  struct AvxInputContext *input) {
1140 #define SHOW(field) \
1141  fprintf(stderr, " %-28s = %d\n", #field, stream->config.cfg.field)
1142 
1143  if (stream->index == 0) {
1144  fprintf(stderr, "Codec: %s\n", aom_codec_iface_name(global->codec));
1145  fprintf(stderr, "Source file: %s File Type: %s Format: %s\n",
1146  input->filename, file_type_to_string(input->file_type),
1147  image_format_to_string(input->fmt));
1148  }
1149  if (stream->next || stream->index)
1150  fprintf(stderr, "\nStream Index: %d\n", stream->index);
1151  fprintf(stderr, "Destination file: %s\n", stream->config.out_fn);
1152  fprintf(stderr, "Coding path: %s\n",
1153  stream->config.use_16bit_internal ? "HBD" : "LBD");
1154  fprintf(stderr, "Encoder parameters:\n");
1155 
1156  SHOW(g_usage);
1157  SHOW(g_threads);
1158  SHOW(g_profile);
1159  SHOW(g_w);
1160  SHOW(g_h);
1161  SHOW(g_bit_depth);
1162  SHOW(g_input_bit_depth);
1163  SHOW(g_timebase.num);
1164  SHOW(g_timebase.den);
1165  SHOW(g_error_resilient);
1166  SHOW(g_pass);
1167  SHOW(g_lag_in_frames);
1168  SHOW(large_scale_tile);
1169  SHOW(rc_dropframe_thresh);
1170  SHOW(rc_resize_mode);
1171  SHOW(rc_resize_denominator);
1172  SHOW(rc_resize_kf_denominator);
1173  SHOW(rc_superres_mode);
1174  SHOW(rc_superres_denominator);
1175  SHOW(rc_superres_kf_denominator);
1176  SHOW(rc_superres_qthresh);
1177  SHOW(rc_superres_kf_qthresh);
1178  SHOW(rc_end_usage);
1179  SHOW(rc_target_bitrate);
1180  SHOW(rc_min_quantizer);
1181  SHOW(rc_max_quantizer);
1182  SHOW(rc_undershoot_pct);
1183  SHOW(rc_overshoot_pct);
1184  SHOW(rc_buf_sz);
1185  SHOW(rc_buf_initial_sz);
1186  SHOW(rc_buf_optimal_sz);
1187  SHOW(rc_2pass_vbr_bias_pct);
1188  SHOW(rc_2pass_vbr_minsection_pct);
1189  SHOW(rc_2pass_vbr_maxsection_pct);
1190  SHOW(fwd_kf_enabled);
1191  SHOW(kf_mode);
1192  SHOW(kf_min_dist);
1193  SHOW(kf_max_dist);
1194 
1195 #define SHOW_PARAMS(field) \
1196  fprintf(stderr, " %-28s = %d\n", #field, \
1197  stream->config.cfg.encoder_cfg.field)
1198  if (global->encoder_config.init_by_cfg_file) {
1199  SHOW_PARAMS(super_block_size);
1200  SHOW_PARAMS(max_partition_size);
1201  SHOW_PARAMS(min_partition_size);
1202  SHOW_PARAMS(disable_ab_partition_type);
1203  SHOW_PARAMS(disable_rect_partition_type);
1204  SHOW_PARAMS(disable_1to4_partition_type);
1205  SHOW_PARAMS(disable_flip_idtx);
1206  SHOW_PARAMS(disable_cdef);
1207  SHOW_PARAMS(disable_lr);
1208  SHOW_PARAMS(disable_obmc);
1209  SHOW_PARAMS(disable_warp_motion);
1210  SHOW_PARAMS(disable_global_motion);
1211  SHOW_PARAMS(disable_dist_wtd_comp);
1212  SHOW_PARAMS(disable_diff_wtd_comp);
1213  SHOW_PARAMS(disable_inter_intra_comp);
1214  SHOW_PARAMS(disable_masked_comp);
1215  SHOW_PARAMS(disable_one_sided_comp);
1216  SHOW_PARAMS(disable_palette);
1217  SHOW_PARAMS(disable_intrabc);
1218  SHOW_PARAMS(disable_cfl);
1219  SHOW_PARAMS(disable_smooth_intra);
1220  SHOW_PARAMS(disable_filter_intra);
1221  SHOW_PARAMS(disable_dual_filter);
1222  SHOW_PARAMS(disable_intra_angle_delta);
1223  SHOW_PARAMS(disable_intra_edge_filter);
1224  SHOW_PARAMS(disable_tx_64x64);
1225  SHOW_PARAMS(disable_smooth_inter_intra);
1226  SHOW_PARAMS(disable_inter_inter_wedge);
1227  SHOW_PARAMS(disable_inter_intra_wedge);
1228  SHOW_PARAMS(disable_paeth_intra);
1229  SHOW_PARAMS(disable_trellis_quant);
1230  SHOW_PARAMS(disable_ref_frame_mv);
1231  SHOW_PARAMS(reduced_reference_set);
1232  SHOW_PARAMS(reduced_tx_type_set);
1233  }
1234 }
1235 
1236 static void open_output_file(struct stream_state *stream,
1237  struct AvxEncoderConfig *global,
1238  const struct AvxRational *pixel_aspect_ratio,
1239  const char *encoder_settings) {
1240  const char *fn = stream->config.out_fn;
1241  const struct aom_codec_enc_cfg *const cfg = &stream->config.cfg;
1242 
1243  if (cfg->g_pass == AOM_RC_FIRST_PASS) return;
1244 
1245  stream->file = strcmp(fn, "-") ? fopen(fn, "wb") : set_binary_mode(stdout);
1246 
1247  if (!stream->file) fatal("Failed to open output file");
1248 
1249  if (stream->config.write_webm && fseek(stream->file, 0, SEEK_CUR))
1250  fatal("WebM output to pipes not supported.");
1251 
1252 #if CONFIG_WEBM_IO
1253  if (stream->config.write_webm) {
1254  stream->webm_ctx.stream = stream->file;
1255  if (write_webm_file_header(&stream->webm_ctx, &stream->encoder, cfg,
1256  stream->config.stereo_fmt,
1257  get_fourcc_by_aom_encoder(global->codec),
1258  pixel_aspect_ratio, encoder_settings) != 0) {
1259  fatal("WebM writer initialization failed.");
1260  }
1261  }
1262 #else
1263  (void)pixel_aspect_ratio;
1264  (void)encoder_settings;
1265 #endif
1266 
1267  if (!stream->config.write_webm && stream->config.write_ivf) {
1268  ivf_write_file_header(stream->file, cfg,
1269  get_fourcc_by_aom_encoder(global->codec), 0);
1270  }
1271 }
1272 
1273 static void close_output_file(struct stream_state *stream,
1274  unsigned int fourcc) {
1275  const struct aom_codec_enc_cfg *const cfg = &stream->config.cfg;
1276 
1277  if (cfg->g_pass == AOM_RC_FIRST_PASS) return;
1278 
1279 #if CONFIG_WEBM_IO
1280  if (stream->config.write_webm) {
1281  if (write_webm_file_footer(&stream->webm_ctx) != 0) {
1282  fatal("WebM writer finalization failed.");
1283  }
1284  }
1285 #endif
1286 
1287  if (!stream->config.write_webm && stream->config.write_ivf) {
1288  if (!fseek(stream->file, 0, SEEK_SET))
1289  ivf_write_file_header(stream->file, &stream->config.cfg, fourcc,
1290  stream->frames_out);
1291  }
1292 
1293  fclose(stream->file);
1294 }
1295 
1296 static void setup_pass(struct stream_state *stream,
1297  struct AvxEncoderConfig *global, int pass) {
1298  if (stream->config.stats_fn) {
1299  if (!stats_open_file(&stream->stats, stream->config.stats_fn, pass))
1300  fatal("Failed to open statistics store");
1301  } else {
1302  if (!stats_open_mem(&stream->stats, pass))
1303  fatal("Failed to open statistics store");
1304  }
1305 
1306  stream->config.cfg.g_pass = global->passes == 2
1308  : AOM_RC_ONE_PASS;
1309  if (pass) {
1310  stream->config.cfg.rc_twopass_stats_in = stats_get(&stream->stats);
1311  }
1312 
1313  stream->cx_time = 0;
1314  stream->nbytes = 0;
1315  stream->frames_out = 0;
1316 }
1317 
1318 static void initialize_encoder(struct stream_state *stream,
1319  struct AvxEncoderConfig *global) {
1320  int i;
1321  int flags = 0;
1322 
1323  flags |= (global->show_psnr >= 1) ? AOM_CODEC_USE_PSNR : 0;
1324  flags |= stream->config.use_16bit_internal ? AOM_CODEC_USE_HIGHBITDEPTH : 0;
1325 
1326  /* Construct Encoder Context */
1327  aom_codec_enc_init(&stream->encoder, global->codec, &stream->config.cfg,
1328  flags);
1329  ctx_exit_on_error(&stream->encoder, "Failed to initialize encoder");
1330 
1331  for (i = 0; i < stream->config.arg_ctrl_cnt; i++) {
1332  int ctrl = stream->config.arg_ctrls[i][0];
1333  int value = stream->config.arg_ctrls[i][1];
1334  if (aom_codec_control(&stream->encoder, ctrl, value))
1335  fprintf(stderr, "Error: Tried to set control %d = %d\n", ctrl, value);
1336 
1337  ctx_exit_on_error(&stream->encoder, "Failed to control codec");
1338  }
1339 
1340 #if CONFIG_TUNE_VMAF
1341  if (stream->config.vmaf_model_path) {
1343  stream->config.vmaf_model_path);
1344  }
1345 #endif
1346 
1347  if (stream->config.film_grain_filename) {
1349  stream->config.film_grain_filename);
1350  }
1352  stream->config.color_range);
1353 
1354 #if CONFIG_AV1_DECODER
1355  if (global->test_decode != TEST_DECODE_OFF) {
1356  aom_codec_iface_t *decoder = get_aom_decoder_by_short_name(
1357  get_short_name_by_aom_encoder(global->codec));
1358  aom_codec_dec_cfg_t cfg = { 0, 0, 0, !stream->config.use_16bit_internal };
1359  aom_codec_dec_init(&stream->decoder, decoder, &cfg, 0);
1360 
1361  if (strcmp(get_short_name_by_aom_encoder(global->codec), "av1") == 0) {
1363  stream->config.cfg.large_scale_tile);
1364  ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_mode");
1365 
1367  stream->config.cfg.save_as_annexb);
1368  ctx_exit_on_error(&stream->decoder, "Failed to set is_annexb");
1369 
1371  -1);
1372  ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_row");
1373 
1374  AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_SET_DECODE_TILE_COL,
1375  -1);
1376  ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_col");
1377  }
1378  }
1379 #endif
1380 }
1381 
1382 static void encode_frame(struct stream_state *stream,
1383  struct AvxEncoderConfig *global, struct aom_image *img,
1384  unsigned int frames_in) {
1385  aom_codec_pts_t frame_start, next_frame_start;
1386  struct aom_codec_enc_cfg *cfg = &stream->config.cfg;
1387  struct aom_usec_timer timer;
1388 
1389  frame_start =
1390  (cfg->g_timebase.den * (int64_t)(frames_in - 1) * global->framerate.den) /
1391  cfg->g_timebase.num / global->framerate.num;
1392  next_frame_start =
1393  (cfg->g_timebase.den * (int64_t)(frames_in)*global->framerate.den) /
1394  cfg->g_timebase.num / global->framerate.num;
1395 
1396  /* Scale if necessary */
1397  if (img) {
1398  if ((img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) &&
1399  (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) {
1400  if (img->fmt != AOM_IMG_FMT_I42016) {
1401  fprintf(stderr, "%s can only scale 4:2:0 inputs\n", exec_name);
1402  exit(EXIT_FAILURE);
1403  }
1404 #if CONFIG_LIBYUV
1405  if (!stream->img) {
1406  stream->img =
1407  aom_img_alloc(NULL, AOM_IMG_FMT_I42016, cfg->g_w, cfg->g_h, 16);
1408  }
1409  I420Scale_16(
1410  (uint16_t *)img->planes[AOM_PLANE_Y], img->stride[AOM_PLANE_Y] / 2,
1411  (uint16_t *)img->planes[AOM_PLANE_U], img->stride[AOM_PLANE_U] / 2,
1412  (uint16_t *)img->planes[AOM_PLANE_V], img->stride[AOM_PLANE_V] / 2,
1413  img->d_w, img->d_h, (uint16_t *)stream->img->planes[AOM_PLANE_Y],
1414  stream->img->stride[AOM_PLANE_Y] / 2,
1415  (uint16_t *)stream->img->planes[AOM_PLANE_U],
1416  stream->img->stride[AOM_PLANE_U] / 2,
1417  (uint16_t *)stream->img->planes[AOM_PLANE_V],
1418  stream->img->stride[AOM_PLANE_V] / 2, stream->img->d_w,
1419  stream->img->d_h, kFilterBox);
1420  img = stream->img;
1421 #else
1422  stream->encoder.err = 1;
1423  ctx_exit_on_error(&stream->encoder,
1424  "Stream %d: Failed to encode frame.\n"
1425  "libyuv is required for scaling but is currently "
1426  "disabled.\n"
1427  "Be sure to specify -DCONFIG_LIBYUV=1 when running "
1428  "cmake.\n",
1429  stream->index);
1430 #endif
1431  }
1432  }
1433  if (img && (img->d_w != cfg->g_w || img->d_h != cfg->g_h)) {
1434  if (img->fmt != AOM_IMG_FMT_I420 && img->fmt != AOM_IMG_FMT_YV12) {
1435  fprintf(stderr, "%s can only scale 4:2:0 8bpp inputs\n", exec_name);
1436  exit(EXIT_FAILURE);
1437  }
1438 #if CONFIG_LIBYUV
1439  if (!stream->img)
1440  stream->img =
1441  aom_img_alloc(NULL, AOM_IMG_FMT_I420, cfg->g_w, cfg->g_h, 16);
1442  I420Scale(
1443  img->planes[AOM_PLANE_Y], img->stride[AOM_PLANE_Y],
1444  img->planes[AOM_PLANE_U], img->stride[AOM_PLANE_U],
1445  img->planes[AOM_PLANE_V], img->stride[AOM_PLANE_V], img->d_w, img->d_h,
1446  stream->img->planes[AOM_PLANE_Y], stream->img->stride[AOM_PLANE_Y],
1447  stream->img->planes[AOM_PLANE_U], stream->img->stride[AOM_PLANE_U],
1448  stream->img->planes[AOM_PLANE_V], stream->img->stride[AOM_PLANE_V],
1449  stream->img->d_w, stream->img->d_h, kFilterBox);
1450  img = stream->img;
1451 #else
1452  stream->encoder.err = 1;
1453  ctx_exit_on_error(&stream->encoder,
1454  "Stream %d: Failed to encode frame.\n"
1455  "Scaling disabled in this configuration. \n"
1456  "To enable, configure with --enable-libyuv\n",
1457  stream->index);
1458 #endif
1459  }
1460 
1461  aom_usec_timer_start(&timer);
1462  aom_codec_encode(&stream->encoder, img, frame_start,
1463  (uint32_t)(next_frame_start - frame_start), 0);
1464  aom_usec_timer_mark(&timer);
1465  stream->cx_time += aom_usec_timer_elapsed(&timer);
1466  ctx_exit_on_error(&stream->encoder, "Stream %d: Failed to encode frame",
1467  stream->index);
1468 }
1469 
1470 static void update_quantizer_histogram(struct stream_state *stream) {
1471  if (stream->config.cfg.g_pass != AOM_RC_FIRST_PASS) {
1472  int q;
1473 
1475  &q);
1476  ctx_exit_on_error(&stream->encoder, "Failed to read quantizer");
1477  stream->counts[q]++;
1478  }
1479 }
1480 
1481 static void get_cx_data(struct stream_state *stream,
1482  struct AvxEncoderConfig *global, int *got_data) {
1483  const aom_codec_cx_pkt_t *pkt;
1484  const struct aom_codec_enc_cfg *cfg = &stream->config.cfg;
1485  aom_codec_iter_t iter = NULL;
1486 
1487  *got_data = 0;
1488  while ((pkt = aom_codec_get_cx_data(&stream->encoder, &iter))) {
1489  static size_t fsize = 0;
1490  static FileOffset ivf_header_pos = 0;
1491 
1492  switch (pkt->kind) {
1494  ++stream->frames_out;
1495  if (!global->quiet)
1496  fprintf(stderr, " %6luF", (unsigned long)pkt->data.frame.sz);
1497 
1498  update_rate_histogram(stream->rate_hist, cfg, pkt);
1499 #if CONFIG_WEBM_IO
1500  if (stream->config.write_webm) {
1501  if (write_webm_block(&stream->webm_ctx, cfg, pkt) != 0) {
1502  fatal("WebM writer failed.");
1503  }
1504  }
1505 #endif
1506  if (!stream->config.write_webm) {
1507  if (stream->config.write_ivf) {
1508  if (pkt->data.frame.partition_id <= 0) {
1509  ivf_header_pos = ftello(stream->file);
1510  fsize = pkt->data.frame.sz;
1511 
1512  ivf_write_frame_header(stream->file, pkt->data.frame.pts, fsize);
1513  } else {
1514  fsize += pkt->data.frame.sz;
1515 
1516  const FileOffset currpos = ftello(stream->file);
1517  fseeko(stream->file, ivf_header_pos, SEEK_SET);
1518  ivf_write_frame_size(stream->file, fsize);
1519  fseeko(stream->file, currpos, SEEK_SET);
1520  }
1521  }
1522 
1523  (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz,
1524  stream->file);
1525  }
1526  stream->nbytes += pkt->data.raw.sz;
1527 
1528  *got_data = 1;
1529 #if CONFIG_AV1_DECODER
1530  if (global->test_decode != TEST_DECODE_OFF && !stream->mismatch_seen) {
1531  aom_codec_decode(&stream->decoder, pkt->data.frame.buf,
1532  pkt->data.frame.sz, NULL);
1533  if (stream->decoder.err) {
1534  warn_or_exit_on_error(&stream->decoder,
1535  global->test_decode == TEST_DECODE_FATAL,
1536  "Failed to decode frame %d in stream %d",
1537  stream->frames_out + 1, stream->index);
1538  stream->mismatch_seen = stream->frames_out + 1;
1539  }
1540  }
1541 #endif
1542  break;
1543  case AOM_CODEC_STATS_PKT:
1544  stream->frames_out++;
1545  stats_write(&stream->stats, pkt->data.twopass_stats.buf,
1546  pkt->data.twopass_stats.sz);
1547  stream->nbytes += pkt->data.raw.sz;
1548  break;
1549  case AOM_CODEC_PSNR_PKT:
1550 
1551  if (global->show_psnr >= 1) {
1552  int i;
1553 
1554  stream->psnr_sse_total[0] += pkt->data.psnr.sse[0];
1555  stream->psnr_samples_total[0] += pkt->data.psnr.samples[0];
1556  for (i = 0; i < 4; i++) {
1557  if (!global->quiet)
1558  fprintf(stderr, "%.3f ", pkt->data.psnr.psnr[i]);
1559  stream->psnr_totals[0][i] += pkt->data.psnr.psnr[i];
1560  }
1561  stream->psnr_count[0]++;
1562 
1563 #if CONFIG_AV1_HIGHBITDEPTH
1564  if (stream->config.cfg.g_input_bit_depth <
1565  (unsigned int)stream->config.cfg.g_bit_depth) {
1566  stream->psnr_sse_total[1] += pkt->data.psnr.sse_hbd[0];
1567  stream->psnr_samples_total[1] += pkt->data.psnr.samples_hbd[0];
1568  for (i = 0; i < 4; i++) {
1569  if (!global->quiet)
1570  fprintf(stderr, "%.3f ", pkt->data.psnr.psnr_hbd[i]);
1571  stream->psnr_totals[1][i] += pkt->data.psnr.psnr_hbd[i];
1572  }
1573  stream->psnr_count[1]++;
1574  }
1575 #endif
1576  }
1577 
1578  break;
1579  default: break;
1580  }
1581  }
1582 }
1583 
1584 static void show_psnr(struct stream_state *stream, double peak, int64_t bps) {
1585  int i;
1586  double ovpsnr;
1587 
1588  if (!stream->psnr_count[0]) return;
1589 
1590  fprintf(stderr, "Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1591  ovpsnr = sse_to_psnr((double)stream->psnr_samples_total[0], peak,
1592  (double)stream->psnr_sse_total[0]);
1593  fprintf(stderr, " %.3f", ovpsnr);
1594 
1595  for (i = 0; i < 4; i++) {
1596  fprintf(stderr, " %.3f", stream->psnr_totals[0][i] / stream->psnr_count[0]);
1597  }
1598  if (bps > 0) {
1599  fprintf(stderr, " %7" PRId64 " bps", bps);
1600  }
1601  fprintf(stderr, " %7" PRId64 " ms", stream->cx_time / 1000);
1602  fprintf(stderr, "\n");
1603 }
1604 
1605 #if CONFIG_AV1_HIGHBITDEPTH
1606 static void show_psnr_hbd(struct stream_state *stream, double peak,
1607  int64_t bps) {
1608  int i;
1609  double ovpsnr;
1610  // Compute PSNR based on stream bit depth
1611  if (!stream->psnr_count[1]) return;
1612 
1613  fprintf(stderr, "Stream %d PSNR (Overall/Avg/Y/U/V)", stream->index);
1614  ovpsnr = sse_to_psnr((double)stream->psnr_samples_total[1], peak,
1615  (double)stream->psnr_sse_total[1]);
1616  fprintf(stderr, " %.3f", ovpsnr);
1617 
1618  for (i = 0; i < 4; i++) {
1619  fprintf(stderr, " %.3f", stream->psnr_totals[1][i] / stream->psnr_count[1]);
1620  }
1621  if (bps > 0) {
1622  fprintf(stderr, " %7" PRId64 " bps", bps);
1623  }
1624  fprintf(stderr, " %7" PRId64 " ms", stream->cx_time / 1000);
1625  fprintf(stderr, "\n");
1626 }
1627 #endif
1628 
1629 static float usec_to_fps(uint64_t usec, unsigned int frames) {
1630  return (float)(usec > 0 ? frames * 1000000.0 / (float)usec : 0);
1631 }
1632 
1633 static void test_decode(struct stream_state *stream,
1634  enum TestDecodeFatality fatal) {
1635  aom_image_t enc_img, dec_img;
1636 
1637  if (stream->mismatch_seen) return;
1638 
1639  /* Get the internal reference frame */
1641  &enc_img);
1643  &dec_img);
1644 
1645  if ((enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) !=
1646  (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH)) {
1647  if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
1648  aom_image_t enc_hbd_img;
1649  aom_img_alloc(&enc_hbd_img, enc_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH,
1650  enc_img.d_w, enc_img.d_h, 16);
1651  aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1652  enc_img = enc_hbd_img;
1653  }
1654  if (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
1655  aom_image_t dec_hbd_img;
1656  aom_img_alloc(&dec_hbd_img, dec_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH,
1657  dec_img.d_w, dec_img.d_h, 16);
1658  aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1659  dec_img = dec_hbd_img;
1660  }
1661  }
1662 
1663  ctx_exit_on_error(&stream->encoder, "Failed to get encoder reference frame");
1664  ctx_exit_on_error(&stream->decoder, "Failed to get decoder reference frame");
1665 
1666  if (!aom_compare_img(&enc_img, &dec_img)) {
1667  int y[4], u[4], v[4];
1668  if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
1669  aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1670  } else {
1671  aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1672  }
1673  stream->decoder.err = 1;
1674  warn_or_exit_on_error(&stream->decoder, fatal == TEST_DECODE_FATAL,
1675  "Stream %d: Encode/decode mismatch on frame %d at"
1676  " Y[%d, %d] {%d/%d},"
1677  " U[%d, %d] {%d/%d},"
1678  " V[%d, %d] {%d/%d}",
1679  stream->index, stream->frames_out, y[0], y[1], y[2],
1680  y[3], u[0], u[1], u[2], u[3], v[0], v[1], v[2], v[3]);
1681  stream->mismatch_seen = stream->frames_out;
1682  }
1683 
1684  aom_img_free(&enc_img);
1685  aom_img_free(&dec_img);
1686 }
1687 
1688 static void print_time(const char *label, int64_t etl) {
1689  int64_t hours;
1690  int64_t mins;
1691  int64_t secs;
1692 
1693  if (etl >= 0) {
1694  hours = etl / 3600;
1695  etl -= hours * 3600;
1696  mins = etl / 60;
1697  etl -= mins * 60;
1698  secs = etl;
1699 
1700  fprintf(stderr, "[%3s %2" PRId64 ":%02" PRId64 ":%02" PRId64 "] ", label,
1701  hours, mins, secs);
1702  } else {
1703  fprintf(stderr, "[%3s unknown] ", label);
1704  }
1705 }
1706 
1707 int main(int argc, const char **argv_) {
1708  int pass;
1709  aom_image_t raw;
1710  aom_image_t raw_shift;
1711  int allocated_raw_shift = 0;
1712  int do_16bit_internal = 0;
1713  int input_shift = 0;
1714  int frame_avail, got_data;
1715 
1716  struct AvxInputContext input;
1717  struct AvxEncoderConfig global;
1718  struct stream_state *streams = NULL;
1719  char **argv, **argi;
1720  uint64_t cx_time = 0;
1721  int stream_cnt = 0;
1722  int res = 0;
1723  int profile_updated = 0;
1724 
1725  memset(&input, 0, sizeof(input));
1726  memset(&raw, 0, sizeof(raw));
1727  exec_name = argv_[0];
1728 
1729  /* Setup default input stream settings */
1730  input.framerate.numerator = 30;
1731  input.framerate.denominator = 1;
1732  input.only_i420 = 1;
1733  input.bit_depth = 0;
1734 
1735  /* First parse the global configuration values, because we want to apply
1736  * other parameters on top of the default configuration provided by the
1737  * codec.
1738  */
1739  argv = argv_dup(argc - 1, argv_ + 1);
1740  parse_global_config(&global, &argv);
1741 
1742  if (argc < 2) usage_exit();
1743 
1744  switch (global.color_type) {
1745  case I420: input.fmt = AOM_IMG_FMT_I420; break;
1746  case I422: input.fmt = AOM_IMG_FMT_I422; break;
1747  case I444: input.fmt = AOM_IMG_FMT_I444; break;
1748  case YV12: input.fmt = AOM_IMG_FMT_YV12; break;
1749  }
1750 
1751  {
1752  /* Now parse each stream's parameters. Using a local scope here
1753  * due to the use of 'stream' as loop variable in FOREACH_STREAM
1754  * loops
1755  */
1756  struct stream_state *stream = NULL;
1757 
1758  do {
1759  stream = new_stream(&global, stream);
1760  stream_cnt++;
1761  if (!streams) streams = stream;
1762  } while (parse_stream_params(&global, stream, argv));
1763  }
1764 
1765  /* Check for unrecognized options */
1766  for (argi = argv; *argi; argi++)
1767  if (argi[0][0] == '-' && argi[0][1])
1768  die("Error: Unrecognized option %s\n", *argi);
1769 
1770  FOREACH_STREAM(stream, streams) {
1771  check_encoder_config(global.disable_warning_prompt, &global,
1772  &stream->config.cfg);
1773 
1774  // If large_scale_tile = 1, only support to output to ivf format.
1775  if (stream->config.cfg.large_scale_tile && !stream->config.write_ivf)
1776  die("only support ivf output format while large-scale-tile=1\n");
1777  }
1778 
1779  /* Handle non-option arguments */
1780  input.filename = argv[0];
1781 
1782  if (!input.filename) {
1783  fprintf(stderr, "No input file specified!\n");
1784  usage_exit();
1785  }
1786 
1787  /* Decide if other chroma subsamplings than 4:2:0 are supported */
1788  if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC)
1789  input.only_i420 = 0;
1790 
1791  for (pass = global.pass ? global.pass - 1 : 0; pass < global.passes; pass++) {
1792  int frames_in = 0, seen_frames = 0;
1793  int64_t estimated_time_left = -1;
1794  int64_t average_rate = -1;
1795  int64_t lagged_count = 0;
1796 
1797  open_input_file(&input, global.csp);
1798 
1799  /* If the input file doesn't specify its w/h (raw files), try to get
1800  * the data from the first stream's configuration.
1801  */
1802  if (!input.width || !input.height) {
1803  FOREACH_STREAM(stream, streams) {
1804  if (stream->config.cfg.g_w && stream->config.cfg.g_h) {
1805  input.width = stream->config.cfg.g_w;
1806  input.height = stream->config.cfg.g_h;
1807  break;
1808  }
1809  };
1810  }
1811 
1812  /* Update stream configurations from the input file's parameters */
1813  if (!input.width || !input.height)
1814  fatal(
1815  "Specify stream dimensions with --width (-w) "
1816  " and --height (-h)");
1817 
1818  /* If input file does not specify bit-depth but input-bit-depth parameter
1819  * exists, assume that to be the input bit-depth. However, if the
1820  * input-bit-depth paramter does not exist, assume the input bit-depth
1821  * to be the same as the codec bit-depth.
1822  */
1823  if (!input.bit_depth) {
1824  FOREACH_STREAM(stream, streams) {
1825  if (stream->config.cfg.g_input_bit_depth)
1826  input.bit_depth = stream->config.cfg.g_input_bit_depth;
1827  else
1828  input.bit_depth = stream->config.cfg.g_input_bit_depth =
1829  (int)stream->config.cfg.g_bit_depth;
1830  }
1831  if (input.bit_depth > 8) input.fmt |= AOM_IMG_FMT_HIGHBITDEPTH;
1832  } else {
1833  FOREACH_STREAM(stream, streams) {
1834  stream->config.cfg.g_input_bit_depth = input.bit_depth;
1835  }
1836  }
1837 
1838  FOREACH_STREAM(stream, streams) {
1839  if (input.fmt != AOM_IMG_FMT_I420 && input.fmt != AOM_IMG_FMT_I42016) {
1840  /* Automatically upgrade if input is non-4:2:0 but a 4:2:0 profile
1841  was selected. */
1842  switch (stream->config.cfg.g_profile) {
1843  case 0:
1844  if (input.bit_depth < 12 && (input.fmt == AOM_IMG_FMT_I444 ||
1845  input.fmt == AOM_IMG_FMT_I44416)) {
1846  if (!stream->config.cfg.monochrome) {
1847  stream->config.cfg.g_profile = 1;
1848  profile_updated = 1;
1849  }
1850  } else if (input.bit_depth == 12 || input.fmt == AOM_IMG_FMT_I422 ||
1851  input.fmt == AOM_IMG_FMT_I42216) {
1852  stream->config.cfg.g_profile = 2;
1853  profile_updated = 1;
1854  }
1855  break;
1856  case 1:
1857  if (input.bit_depth == 12 || input.fmt == AOM_IMG_FMT_I422 ||
1858  input.fmt == AOM_IMG_FMT_I42216) {
1859  stream->config.cfg.g_profile = 2;
1860  profile_updated = 1;
1861  } else if (input.bit_depth < 12 &&
1862  (input.fmt == AOM_IMG_FMT_I420 ||
1863  input.fmt == AOM_IMG_FMT_I42016)) {
1864  stream->config.cfg.g_profile = 0;
1865  profile_updated = 1;
1866  }
1867  break;
1868  case 2:
1869  if (input.bit_depth < 12 && (input.fmt == AOM_IMG_FMT_I444 ||
1870  input.fmt == AOM_IMG_FMT_I44416)) {
1871  stream->config.cfg.g_profile = 1;
1872  profile_updated = 1;
1873  } else if (input.bit_depth < 12 &&
1874  (input.fmt == AOM_IMG_FMT_I420 ||
1875  input.fmt == AOM_IMG_FMT_I42016)) {
1876  stream->config.cfg.g_profile = 0;
1877  profile_updated = 1;
1878  } else if (input.bit_depth == 12 &&
1879  input.file_type == FILE_TYPE_Y4M) {
1880  // Note that here the input file values for chroma subsampling
1881  // are used instead of those from the command line.
1882  AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder,
1884  input.y4m.dst_c_dec_h >> 1);
1885  AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder,
1887  input.y4m.dst_c_dec_v >> 1);
1888  } else if (input.bit_depth == 12 &&
1889  input.file_type == FILE_TYPE_RAW) {
1890  AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder,
1892  stream->chroma_subsampling_x);
1893  AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder,
1895  stream->chroma_subsampling_y);
1896  }
1897  break;
1898  default: break;
1899  }
1900  }
1901  /* Automatically set the codec bit depth to match the input bit depth.
1902  * Upgrade the profile if required. */
1903  if (stream->config.cfg.g_input_bit_depth >
1904  (unsigned int)stream->config.cfg.g_bit_depth) {
1905  stream->config.cfg.g_bit_depth = stream->config.cfg.g_input_bit_depth;
1906  if (!global.quiet) {
1907  fprintf(stderr,
1908  "Warning: automatically updating bit depth to %d to "
1909  "match input format.\n",
1910  stream->config.cfg.g_input_bit_depth);
1911  }
1912  }
1913 #if !CONFIG_AV1_HIGHBITDEPTH
1914  if (stream->config.cfg.g_bit_depth > 8) {
1915  fatal("Unsupported bit-depth with CONFIG_AV1_HIGHBITDEPTH=0\n");
1916  }
1917 #endif // CONFIG_AV1_HIGHBITDEPTH
1918  if (stream->config.cfg.g_bit_depth > 10) {
1919  switch (stream->config.cfg.g_profile) {
1920  case 0:
1921  case 1:
1922  stream->config.cfg.g_profile = 2;
1923  profile_updated = 1;
1924  break;
1925  default: break;
1926  }
1927  }
1928  if (stream->config.cfg.g_bit_depth > 8) {
1929  stream->config.use_16bit_internal = 1;
1930  }
1931  if (profile_updated && !global.quiet) {
1932  fprintf(stderr,
1933  "Warning: automatically updating to profile %d to "
1934  "match input format.\n",
1935  stream->config.cfg.g_profile);
1936  }
1937  if ((global.show_psnr == 2) && (stream->config.cfg.g_input_bit_depth ==
1938  stream->config.cfg.g_bit_depth)) {
1939  fprintf(stderr,
1940  "Warning: --psnr==2 and --psnr==1 will provide same "
1941  "results when input bit-depth == stream bit-depth, "
1942  "falling back to default psnr value\n");
1943  global.show_psnr = 1;
1944  }
1945  if (global.show_psnr < 0 || global.show_psnr > 2) {
1946  fprintf(stderr,
1947  "Warning: --psnr can take only 0,1,2 as values,"
1948  "falling back to default psnr value\n");
1949  global.show_psnr = 1;
1950  }
1951  /* Set limit */
1952  stream->config.cfg.g_limit = global.limit;
1953  }
1954 
1955  FOREACH_STREAM(stream, streams) {
1956  set_stream_dimensions(stream, input.width, input.height);
1957  stream->config.color_range = input.color_range;
1958  }
1959  FOREACH_STREAM(stream, streams) { validate_stream_config(stream, &global); }
1960 
1961  /* Ensure that --passes and --pass are consistent. If --pass is set and
1962  * --passes=2, ensure --fpf was set.
1963  */
1964  if (global.pass && global.passes == 2) {
1965  FOREACH_STREAM(stream, streams) {
1966  if (!stream->config.stats_fn)
1967  die("Stream %d: Must specify --fpf when --pass=%d"
1968  " and --passes=2\n",
1969  stream->index, global.pass);
1970  }
1971  }
1972 
1973 #if !CONFIG_WEBM_IO
1974  FOREACH_STREAM(stream, streams) {
1975  if (stream->config.write_webm) {
1976  stream->config.write_webm = 0;
1977  stream->config.write_ivf = 0;
1978  warn("aomenc compiled w/o WebM support. Writing OBU stream.");
1979  }
1980  }
1981 #endif
1982 
1983  /* Use the frame rate from the file only if none was specified
1984  * on the command-line.
1985  */
1986  if (!global.have_framerate) {
1987  global.framerate.num = input.framerate.numerator;
1988  global.framerate.den = input.framerate.denominator;
1989  }
1990  FOREACH_STREAM(stream, streams) {
1991  stream->config.cfg.g_timebase.den = global.framerate.num;
1992  stream->config.cfg.g_timebase.num = global.framerate.den;
1993  }
1994  /* Show configuration */
1995  if (global.verbose && pass == 0) {
1996  FOREACH_STREAM(stream, streams) {
1997  show_stream_config(stream, &global, &input);
1998  }
1999  }
2000 
2001  if (pass == (global.pass ? global.pass - 1 : 0)) {
2002  // The Y4M reader does its own allocation.
2003  if (input.file_type != FILE_TYPE_Y4M) {
2004  aom_img_alloc(&raw, input.fmt, input.width, input.height, 32);
2005  }
2006  FOREACH_STREAM(stream, streams) {
2007  stream->rate_hist =
2008  init_rate_histogram(&stream->config.cfg, &global.framerate);
2009  }
2010  }
2011 
2012  FOREACH_STREAM(stream, streams) { setup_pass(stream, &global, pass); }
2013  FOREACH_STREAM(stream, streams) { initialize_encoder(stream, &global); }
2014  FOREACH_STREAM(stream, streams) {
2015  char *encoder_settings = NULL;
2016 #if CONFIG_WEBM_IO
2017  // Test frameworks may compare outputs from different versions, but only
2018  // wish to check for bitstream changes. The encoder-settings tag, however,
2019  // can vary if the version is updated, even if no encoder algorithm
2020  // changes were made. To work around this issue, do not output
2021  // the encoder-settings tag when --debug is enabled (which is the flag
2022  // that test frameworks should use, when they want deterministic output
2023  // from the container format).
2024  if (stream->config.write_webm && !stream->webm_ctx.debug) {
2025  encoder_settings = extract_encoder_settings(
2026  aom_codec_version_str(), argv_, argc, input.filename);
2027  if (encoder_settings == NULL) {
2028  fprintf(
2029  stderr,
2030  "Warning: unable to extract encoder settings. Continuing...\n");
2031  }
2032  }
2033 #endif
2034  open_output_file(stream, &global, &input.pixel_aspect_ratio,
2035  encoder_settings);
2036  free(encoder_settings);
2037  }
2038 
2039  if (strcmp(get_short_name_by_aom_encoder(global.codec), "av1") == 0) {
2040  // Check to see if at least one stream uses 16 bit internal.
2041  // Currently assume that the bit_depths for all streams using
2042  // highbitdepth are the same.
2043  FOREACH_STREAM(stream, streams) {
2044  if (stream->config.use_16bit_internal) {
2045  do_16bit_internal = 1;
2046  }
2047  input_shift = (int)stream->config.cfg.g_bit_depth -
2048  stream->config.cfg.g_input_bit_depth;
2049  };
2050  }
2051 
2052  frame_avail = 1;
2053  got_data = 0;
2054 
2055  while (frame_avail || got_data) {
2056  struct aom_usec_timer timer;
2057 
2058  if (!global.limit || frames_in < global.limit) {
2059  frame_avail = read_frame(&input, &raw);
2060 
2061  if (frame_avail) frames_in++;
2062  seen_frames =
2063  frames_in > global.skip_frames ? frames_in - global.skip_frames : 0;
2064 
2065  if (!global.quiet) {
2066  float fps = usec_to_fps(cx_time, seen_frames);
2067  fprintf(stderr, "\rPass %d/%d ", pass + 1, global.passes);
2068 
2069  if (stream_cnt == 1)
2070  fprintf(stderr, "frame %4d/%-4d %7" PRId64 "B ", frames_in,
2071  streams->frames_out, (int64_t)streams->nbytes);
2072  else
2073  fprintf(stderr, "frame %4d ", frames_in);
2074 
2075  fprintf(stderr, "%7" PRId64 " %s %.2f %s ",
2076  cx_time > 9999999 ? cx_time / 1000 : cx_time,
2077  cx_time > 9999999 ? "ms" : "us", fps >= 1.0 ? fps : fps * 60,
2078  fps >= 1.0 ? "fps" : "fpm");
2079  print_time("ETA", estimated_time_left);
2080  }
2081 
2082  } else {
2083  frame_avail = 0;
2084  }
2085 
2086  if (frames_in > global.skip_frames) {
2087  aom_image_t *frame_to_encode;
2088  if (input_shift || (do_16bit_internal && input.bit_depth == 8)) {
2089  assert(do_16bit_internal);
2090  // Input bit depth and stream bit depth do not match, so up
2091  // shift frame to stream bit depth
2092  if (!allocated_raw_shift) {
2093  aom_img_alloc(&raw_shift, raw.fmt | AOM_IMG_FMT_HIGHBITDEPTH,
2094  input.width, input.height, 32);
2095  allocated_raw_shift = 1;
2096  }
2097  aom_img_upshift(&raw_shift, &raw, input_shift);
2098  frame_to_encode = &raw_shift;
2099  } else {
2100  frame_to_encode = &raw;
2101  }
2102  aom_usec_timer_start(&timer);
2103  if (do_16bit_internal) {
2104  assert(frame_to_encode->fmt & AOM_IMG_FMT_HIGHBITDEPTH);
2105  FOREACH_STREAM(stream, streams) {
2106  if (stream->config.use_16bit_internal)
2107  encode_frame(stream, &global,
2108  frame_avail ? frame_to_encode : NULL, frames_in);
2109  else
2110  assert(0);
2111  };
2112  } else {
2113  assert((frame_to_encode->fmt & AOM_IMG_FMT_HIGHBITDEPTH) == 0);
2114  FOREACH_STREAM(stream, streams) {
2115  encode_frame(stream, &global, frame_avail ? frame_to_encode : NULL,
2116  frames_in);
2117  }
2118  }
2119  aom_usec_timer_mark(&timer);
2120  cx_time += aom_usec_timer_elapsed(&timer);
2121 
2122  FOREACH_STREAM(stream, streams) { update_quantizer_histogram(stream); }
2123 
2124  got_data = 0;
2125  FOREACH_STREAM(stream, streams) {
2126  get_cx_data(stream, &global, &got_data);
2127  }
2128 
2129  if (!got_data && input.length && streams != NULL &&
2130  !streams->frames_out) {
2131  lagged_count = global.limit ? seen_frames : ftello(input.file);
2132  } else if (input.length) {
2133  int64_t remaining;
2134  int64_t rate;
2135 
2136  if (global.limit) {
2137  const int64_t frame_in_lagged = (seen_frames - lagged_count) * 1000;
2138 
2139  rate = cx_time ? frame_in_lagged * (int64_t)1000000 / cx_time : 0;
2140  remaining = 1000 * (global.limit - global.skip_frames -
2141  seen_frames + lagged_count);
2142  } else {
2143  const int64_t input_pos = ftello(input.file);
2144  const int64_t input_pos_lagged = input_pos - lagged_count;
2145  const int64_t input_limit = input.length;
2146 
2147  rate = cx_time ? input_pos_lagged * (int64_t)1000000 / cx_time : 0;
2148  remaining = input_limit - input_pos + lagged_count;
2149  }
2150 
2151  average_rate =
2152  (average_rate <= 0) ? rate : (average_rate * 7 + rate) / 8;
2153  estimated_time_left = average_rate ? remaining / average_rate : -1;
2154  }
2155 
2156  if (got_data && global.test_decode != TEST_DECODE_OFF) {
2157  FOREACH_STREAM(stream, streams) {
2158  test_decode(stream, global.test_decode);
2159  }
2160  }
2161  }
2162 
2163  fflush(stdout);
2164  if (!global.quiet) fprintf(stderr, "\033[K");
2165  }
2166 
2167  if (stream_cnt > 1) fprintf(stderr, "\n");
2168 
2169  if (!global.quiet) {
2170  FOREACH_STREAM(stream, streams) {
2171  const int64_t bpf =
2172  seen_frames ? (int64_t)(stream->nbytes * 8 / seen_frames) : 0;
2173  const int64_t bps = bpf * global.framerate.num / global.framerate.den;
2174  fprintf(stderr,
2175  "\rPass %d/%d frame %4d/%-4d %7" PRId64 "B %7" PRId64
2176  "b/f %7" PRId64
2177  "b/s"
2178  " %7" PRId64 " %s (%.2f fps)\033[K\n",
2179  pass + 1, global.passes, frames_in, stream->frames_out,
2180  (int64_t)stream->nbytes, bpf, bps,
2181  stream->cx_time > 9999999 ? stream->cx_time / 1000
2182  : stream->cx_time,
2183  stream->cx_time > 9999999 ? "ms" : "us",
2184  usec_to_fps(stream->cx_time, seen_frames));
2185  }
2186  }
2187 
2188  if (global.show_psnr >= 1) {
2189  if (get_fourcc_by_aom_encoder(global.codec) == AV1_FOURCC) {
2190  FOREACH_STREAM(stream, streams) {
2191  int64_t bps = 0;
2192  if (global.show_psnr == 1) {
2193  if (stream->psnr_count[0] && seen_frames && global.framerate.den) {
2194  bps = (int64_t)stream->nbytes * 8 *
2195  (int64_t)global.framerate.num / global.framerate.den /
2196  seen_frames;
2197  }
2198  show_psnr(stream, (1 << stream->config.cfg.g_input_bit_depth) - 1,
2199  bps);
2200  }
2201  if (global.show_psnr == 2) {
2202 #if CONFIG_AV1_HIGHBITDEPTH
2203  if (stream->config.cfg.g_input_bit_depth <
2204  (unsigned int)stream->config.cfg.g_bit_depth)
2205  show_psnr_hbd(stream, (1 << stream->config.cfg.g_bit_depth) - 1,
2206  bps);
2207 #endif
2208  }
2209  }
2210  } else {
2211  FOREACH_STREAM(stream, streams) { show_psnr(stream, 255.0, 0); }
2212  }
2213  }
2214 
2215  FOREACH_STREAM(stream, streams) { aom_codec_destroy(&stream->encoder); }
2216 
2217  if (global.test_decode != TEST_DECODE_OFF) {
2218  FOREACH_STREAM(stream, streams) { aom_codec_destroy(&stream->decoder); }
2219  }
2220 
2221  close_input_file(&input);
2222 
2223  if (global.test_decode == TEST_DECODE_FATAL) {
2224  FOREACH_STREAM(stream, streams) { res |= stream->mismatch_seen; }
2225  }
2226  FOREACH_STREAM(stream, streams) {
2227  close_output_file(stream, get_fourcc_by_aom_encoder(global.codec));
2228  }
2229 
2230  FOREACH_STREAM(stream, streams) {
2231  stats_close(&stream->stats, global.passes - 1);
2232  }
2233 
2234  if (global.pass) break;
2235  }
2236 
2237  if (global.show_q_hist_buckets) {
2238  FOREACH_STREAM(stream, streams) {
2239  show_q_histogram(stream->counts, global.show_q_hist_buckets);
2240  }
2241  }
2242 
2243  if (global.show_rate_hist_buckets) {
2244  FOREACH_STREAM(stream, streams) {
2245  show_rate_histogram(stream->rate_hist, &stream->config.cfg,
2246  global.show_rate_hist_buckets);
2247  }
2248  }
2249  FOREACH_STREAM(stream, streams) { destroy_rate_histogram(stream->rate_hist); }
2250 
2251 #if CONFIG_INTERNAL_STATS
2252  /* TODO(jkoleszar): This doesn't belong in this executable. Do it for now,
2253  * to match some existing utilities.
2254  */
2255  if (!(global.pass == 1 && global.passes == 2)) {
2256  FOREACH_STREAM(stream, streams) {
2257  FILE *f = fopen("opsnr.stt", "a");
2258  if (stream->mismatch_seen) {
2259  fprintf(f, "First mismatch occurred in frame %d\n",
2260  stream->mismatch_seen);
2261  } else {
2262  fprintf(f, "No mismatch detected in recon buffers\n");
2263  }
2264  fclose(f);
2265  }
2266  }
2267 #endif
2268 
2269  if (allocated_raw_shift) aom_img_free(&raw_shift);
2270  aom_img_free(&raw);
2271  free(argv);
2272  free(streams);
2273  return res ? EXIT_FAILURE : EXIT_SUCCESS;
2274 }
Describes the decoder algorithm interface to applications.
Describes the encoder algorithm interface to applications.
#define MAX_TILE_WIDTHS
Maximum number of tile widths in tile widths array.
Definition: aom_encoder.h:836
#define MAX_TILE_HEIGHTS
Maximum number of tile heights in tile heights array.
Definition: aom_encoder.h:849
#define FIXED_QP_OFFSET_COUNT
Number of fixed QP offsets.
Definition: aom_encoder.h:876
#define AOM_PLANE_U
Definition: aom_image.h:200
@ AOM_CSP_UNKNOWN
Definition: aom_image.h:133
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
#define AOM_PLANE_Y
Definition: aom_image.h:199
#define AOM_PLANE_V
Definition: aom_image.h:201
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.
enum aom_color_range aom_color_range_t
List of supported color range.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition: aom_image.h:38
@ AOM_IMG_FMT_I42216
Definition: aom_image.h:53
@ AOM_IMG_FMT_I42016
Definition: aom_image.h:51
@ AOM_IMG_FMT_YV1216
Definition: aom_image.h:52
@ AOM_IMG_FMT_I444
Definition: aom_image.h:50
@ AOM_IMG_FMT_I422
Definition: aom_image.h:49
@ AOM_IMG_FMT_I44416
Definition: aom_image.h:54
@ AOM_IMG_FMT_I420
Definition: aom_image.h:45
@ AOM_IMG_FMT_YV12
Definition: aom_image.h:43
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
void aom_img_free(aom_image_t *img)
Close an image descriptor.
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
Provides definitions for using AOM or AV1 within the aom Decoder interface.
@ AV1_SET_TILE_MODE
Codec control function to set the tile coding mode, int parameter.
Definition: aomdx.h:309
@ AV1D_SET_IS_ANNEXB
Codec control function to indicate whether bitstream is in Annex-B format, unsigned int parameter.
Definition: aomdx.h:345
@ AV1_SET_DECODE_TILE_ROW
Codec control function to set the range of tile decoding, int parameter.
Definition: aomdx.h:301
@ AV1E_SET_MATRIX_COEFFICIENTS
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:560
@ AV1E_SET_ENABLE_INTERINTER_WEDGE
Codec control function to turn on / off interinter wedge compound, int parameter.
Definition: aomcx.h:992
@ AV1E_SET_MAX_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition: aomcx.h:581
@ AV1E_SET_ROW_MT
Codec control function to enable the row based multi-threading of the encoder, unsigned int parameter...
Definition: aomcx.h:348
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition: aomcx.h:1052
@ AOME_SET_SHARPNESS
Codec control function to set loop filter sharpness, unsigned int parameter.
Definition: aomcx.h:230
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition: aomcx.h:395
@ AOME_GET_LAST_QUANTIZER_64
Codec control function to get last quantizer chosen by the encoder, int* parameter.
Definition: aomcx.h:252
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition: aomcx.h:455
@ AV1E_SET_REDUCED_REFERENCE_SET
Control to use reduced set of single and compound references, int parameter.
Definition: aomcx.h:1204
@ AV1E_SET_GF_MIN_PYRAMID_HEIGHT
Control to select minimum height for the GF group pyramid structure, unsigned int parameter.
Definition: aomcx.h:1300
@ AV1E_SET_ENABLE_PAETH_INTRA
Codec control function to turn on / off Paeth intra mode usage, int parameter.
Definition: aomcx.h:1060
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type, aom_tune_content parameter.
Definition: aomcx.h:484
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition: aomcx.h:493
@ AV1E_SET_CHROMA_SUBSAMPLING_X
Sets the chroma subsampling x value, unsigned int parameter.
Definition: aomcx.h:1167
@ AV1E_SET_COLOR_RANGE
Codec control function to set color range bit, int parameter.
Definition: aomcx.h:593
@ AV1E_SET_ENABLE_RESTORATION
Codec control function to encode with Loop Restoration Filter, unsigned int parameter.
Definition: aomcx.h:662
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta, int parameter.
Definition: aomcx.h:1099
@ AV1E_SET_MIN_GF_INTERVAL
Codec control function to set minimum interval between GF/ARF frames, unsigned int parameter.
Definition: aomcx.h:574
@ AOME_SET_ARNR_MAXFRAMES
Codec control function to set the max no of frames to create arf, unsigned int parameter.
Definition: aomcx.h:257
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition: aomcx.h:1234
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes, int parameter.
Definition: aomcx.h:1183
@ AV1E_SET_TRANSFER_CHARACTERISTICS
Codec control function to set transfer function info, int parameter.
Definition: aomcx.h:539
@ AV1E_SET_MTU
Codec control function to set an MTU size for a tile group, unsigned int parameter.
Definition: aomcx.h:782
@ AV1E_SET_DISABLE_TRELLIS_QUANT
Codec control function to encode without trellis quantization, unsigned int parameter.
Definition: aomcx.h:689
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode, int parameter.
Definition: aomcx.h:1095
@ AV1E_SET_ENABLE_AB_PARTITIONS
Codec control function to enable/disable AB partitions, int parameter.
Definition: aomcx.h:800
@ AV1E_SET_ENABLE_INTERINTRA_COMP
Codec control function to turn on / off interintra compound for a sequence, int parameter.
Definition: aomcx.h:968
@ 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:1153
@ AV1E_SET_ENABLE_CHROMA_DELTAQ
Codec control function to turn on / off delta quantization in chroma planes for a sequence,...
Definition: aomcx.h:944
@ AV1E_SET_ENABLE_DUAL_FILTER
Codec control function to turn on / off dual interpolation filter for a sequence, int parameter.
Definition: aomcx.h:936
@ AV1E_SET_FRAME_PARALLEL_DECODING
Codec control function to enable frame parallel decoding feature, unsigned int parameter.
Definition: aomcx.h:418
@ AV1E_SET_MIN_PARTITION_SIZE
Codec control function to set min partition size, int parameter.
Definition: aomcx.h:819
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level, int parameter.
Definition: aomcx.h:1020
@ AV1E_SET_FORCE_VIDEO_MODE
Codec control function to force video mode, unsigned int parameter.
Definition: aomcx.h:669
@ AV1E_SET_CHROMA_SUBSAMPLING_Y
Sets the chroma subsampling y value, unsigned int parameter.
Definition: aomcx.h:1170
@ AV1E_SET_ENABLE_INTRA_EDGE_FILTER
Codec control function to turn on / off intra edge filter at sequence level, int parameter.
Definition: aomcx.h:838
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition: aomcx.h:1214
@ AV1E_SET_MAX_INTER_BITRATE_PCT
Codec control function to set max data rate for inter frames, unsigned int parameter.
Definition: aomcx.h:312
@ AV1E_SET_DENOISE_NOISE_LEVEL
Sets the noise level, int parameter.
Definition: aomcx.h:1161
@ AV1E_SET_INTRA_DCT_ONLY
Control to use dct only for intra modes, int parameter.
Definition: aomcx.h:1176
@ AV1E_SET_TILE_ROWS
Codec control function to set number of tile rows, unsigned int parameter.
Definition: aomcx.h:385
@ AV1E_SET_ENABLE_REF_FRAME_MVS
Codec control function to turn on / off ref frame mvs (mfmv) usage at sequence level,...
Definition: aomcx.h:917
@ AV1E_SET_ENABLE_MASKED_COMP
Codec control function to turn on / off masked compound usage (wedge and diff-wtd compound modes) for...
Definition: aomcx.h:952
@ AV1E_SET_VBR_CORPUS_COMPLEXITY_LAP
Control to set average complexity of the corpus in the case of single pass vbr based on LAP,...
Definition: aomcx.h:1305
@ AV1E_SET_GF_MAX_PYRAMID_HEIGHT
Control to select maximum height for the GF group pyramid structure, unsigned int parameter.
Definition: aomcx.h:1193
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition: aomcx.h:652
@ AV1E_SET_ENABLE_FLIP_IDTX
Codec control function to turn on / off flip and identity transforms, int parameter.
Definition: aomcx.h:882
@ AV1E_SET_FRAME_PERIODIC_BOOST
Codec control function to enable/disable periodic Q boost, unsigned int parameter.
Definition: aomcx.h:467
@ AV1E_SET_ENABLE_RECT_TX
Codec control function to turn on / off rectangular transforms, int parameter.
Definition: aomcx.h:894
@ AV1E_SET_ENABLE_DIST_WTD_COMP
Codec control function to turn on / off dist-wtd compound mode at sequence level, int parameter.
Definition: aomcx.h:906
@ AV1E_SET_TIMING_INFO_TYPE
Codec control function to signal picture timing info in the bitstream, aom_timing_info_type_t paramet...
Definition: aomcx.h:1146
@ AV1E_SET_SUPERBLOCK_SIZE
Codec control function to set intended superblock size, unsigned int parameter.
Definition: aomcx.h:634
@ 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:1242
@ AV1E_SET_ENABLE_INTERINTRA_WEDGE
Codec control function to turn on / off interintra wedge compound, int parameter.
Definition: aomcx.h:1000
@ AV1E_SET_NOISE_SENSITIVITY
Codec control function to set noise sensitivity, unsigned int parameter.
Definition: aomcx.h:475
@ AV1E_SET_ENABLE_DIFF_WTD_COMP
Codec control function to turn on / off difference weighted compound, int parameter.
Definition: aomcx.h:984
@ AV1E_SET_QUANT_B_ADAPT
Control to use adaptive quantize_b, int parameter.
Definition: aomcx.h:1186
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level, int parameter.
Definition: aomcx.h:1041
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode, int parameter.
Definition: aomcx.h:1091
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition: aomcx.h:1070
@ AV1E_SET_ENABLE_KEYFRAME_FILTERING
Codec control function to enable temporal filtering on key frame, unsigned int parameter.
Definition: aomcx.h:404
@ AV1E_SET_NUM_TG
Codec control function to set a maximum number of tile groups, unsigned int parameter.
Definition: aomcx.h:771
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition: aomcx.h:293
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition: aomcx.h:429
@ AV1E_SET_ENABLE_SMOOTH_INTERINTRA
Codec control function to turn on / off smooth inter-intra mode for a sequence, int parameter.
Definition: aomcx.h:976
@ AOME_SET_STATIC_THRESHOLD
Codec control function to set the threshold for MBs treated static, unsigned int parameter.
Definition: aomcx.h:235
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition: aomcx.h:679
@ AV1E_SET_MAX_PARTITION_SIZE
Codec control function to set max partition size, int parameter.
Definition: aomcx.h:830
@ AV1E_SET_ENABLE_1TO4_PARTITIONS
Codec control function to enable/disable 1:4 and 4:1 partitions, int parameter.
Definition: aomcx.h:808
@ AV1E_SET_DELTALF_MODE
Codec control function to turn on/off loopfilter modulation when delta q modulation is enabled,...
Definition: aomcx.h:1119
@ AV1E_SET_ENABLE_TX64
Codec control function to turn on / off 64-length transforms, int parameter.
Definition: aomcx.h:858
@ AOME_SET_TUNING
Codec control function to set visual tuning, aom_tune_metric (int) parameter.
Definition: aomcx.h:269
@ AV1E_SET_TARGET_SEQ_LEVEL_IDX
Control to set target sequence level index for a certain operating point(OP), int parameter Possible ...
Definition: aomcx.h:619
@ AV1E_SET_CHROMA_SAMPLE_POSITION
Codec control function to set chroma 4:2:0 sample position info, aom_chroma_sample_position_t paramet...
Definition: aomcx.h:567
@ AV1E_SET_REDUCED_TX_TYPE_SET
Control to use a reduced tx type set, int parameter.
Definition: aomcx.h:1173
@ AV1E_SET_INTER_DCT_ONLY
Control to use dct only for inter modes, int parameter.
Definition: aomcx.h:1179
@ AOME_SET_ENABLEAUTOALTREF
Codec control function to enable automatic set and use alf frames, unsigned int parameter.
Definition: aomcx.h:221
@ AV1E_SET_TILE_COLUMNS
Codec control function to set number of tile columns. unsigned int parameter.
Definition: aomcx.h:367
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition: aomcx.h:847
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition: aomcx.h:1111
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition: aomcx.h:1010
@ AV1E_SET_FILM_GRAIN_TABLE
Codec control function to set the path to the film grain parameters, const char* parameter.
Definition: aomcx.h:1158
@ AV1E_SET_QM_MAX
Codec control function to set the max quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:725
@ AV1E_SET_MAX_REFERENCE_FRAMES
Control to select maximum reference frames allowed per frame, int parameter.
Definition: aomcx.h:1200
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition: aomcx.h:213
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition: aomcx.h:326
@ AV1E_SET_ENABLE_ONESIDED_COMP
Codec control function to turn on / off one sided compound usage for a sequence, int parameter.
Definition: aomcx.h:960
@ AV1E_SET_DENOISE_BLOCK_SIZE
Sets the denoisers block size, unsigned int parameter.
Definition: aomcx.h:1164
@ AV1E_SET_VMAF_MODEL_PATH
Codec control function to set the path to the VMAF model used when tuning the encoder for VMAF,...
Definition: aomcx.h:1272
@ AV1E_SET_QM_MIN
Codec control function to set the min quant matrix flatness, unsigned int parameter.
Definition: aomcx.h:713
@ AV1E_SET_ENABLE_QM
Codec control function to encode with quantisation matrices, unsigned int parameter.
Definition: aomcx.h:700
@ AV1E_SET_ENABLE_OVERLAY
Codec control function to turn on / off overlay frames for filtered ALTREF frames,...
Definition: aomcx.h:1088
@ AV1E_SET_ENABLE_RECT_PARTITIONS
Codec control function to enable/disable rectangular partitions, int parameter.
Definition: aomcx.h:792
@ AV1E_SET_COLOR_PRIMARIES
Codec control function to set color space info, int parameter.
Definition: aomcx.h:514
@ AOME_SET_CQ_LEVEL
Codec control function to set constrained / constant quality level, unsigned int parameter.
Definition: aomcx.h:279
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition: aomcx.h:1224
@ AV1E_SET_MIN_CR
Control to set minimum compression ratio, unsigned int parameter Take integer values....
Definition: aomcx.h:1249
@ AV1E_SET_LOSSLESS
Codec control function to set lossless encoding mode, unsigned int parameter.
Definition: aomcx.h:340
@ AOME_SET_ARNR_STRENGTH
Codec control function to set the filter strength for the arf, unsigned int parameter.
Definition: aomcx.h:262
@ AV1_GET_NEW_FRAME_IMAGE
Codec control function to get a pointer to the new frame.
Definition: aom.h:70
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
const char * aom_codec_error_detail(aom_codec_ctx_t *ctx)
Retrieve detailed error information for codec context.
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition: aom_codec.h:254
const char * aom_codec_error(aom_codec_ctx_t *ctx)
Retrieve error synopsis for codec context.
const char * aom_codec_version_str(void)
Return the version information (as a string)
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
int64_t aom_codec_pts_t
Time Stamp Type.
Definition: aom_codec.h:235
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
aom_codec_err_t
Algorithm return codes.
Definition: aom_codec.h:155
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition: aom_codec.h:520
const void * aom_codec_iter_t
Iterator.
Definition: aom_codec.h:288
@ AOM_BITS_8
Definition: aom_codec.h:319
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.
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition: aom_decoder.h:129
#define AOM_USAGE_GOOD_QUALITY
usage parameter analogous to AV1 GOOD QUALITY mode.
Definition: aom_encoder.h:1002
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.
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition: aom_encoder.h:931
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg, unsigned int usage)
Get the default configuration for a usage.
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition: aom_encoder.h:1004
#define AOM_CODEC_USE_HIGHBITDEPTH
Make the encoder output one partition at a time.
Definition: aom_encoder.h:70
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition: aom_encoder.h:68
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_RC_ONE_PASS
Definition: aom_encoder.h:159
@ AOM_RC_LAST_PASS
Definition: aom_encoder.h:161
@ AOM_RC_FIRST_PASS
Definition: aom_encoder.h:160
@ AOM_KF_DISABLED
Definition: aom_encoder.h:183
@ AOM_CODEC_PSNR_PKT
Definition: aom_encoder.h:101
@ AOM_CODEC_CX_FRAME_PKT
Definition: aom_encoder.h:98
@ AOM_CODEC_STATS_PKT
Definition: aom_encoder.h:99
Codec context structure.
Definition: aom_codec.h:298
aom_codec_err_t err
Definition: aom_codec.h:301
Encoder output packet.
Definition: aom_encoder.h:110
enum aom_codec_cx_pkt_kind kind
Definition: aom_encoder.h:111
double psnr[4]
Definition: aom_encoder.h:133
aom_fixed_buf_t twopass_stats
Definition: aom_encoder.h:128
aom_fixed_buf_t raw
Definition: aom_encoder.h:144
union aom_codec_cx_pkt::@1 data
struct aom_codec_cx_pkt::@1::@2 frame
Initialization Configurations.
Definition: aom_decoder.h:91
Encoder configuration structure.
Definition: aom_encoder.h:367
struct aom_rational g_timebase
Stream timebase units.
Definition: aom_encoder.h:464
unsigned int g_h
Height of the frame.
Definition: aom_encoder.h:415
unsigned int g_w
Width of the frame.
Definition: aom_encoder.h:406
enum aom_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: aom_encoder.h:479
size_t sz
Definition: aom_encoder.h:78
void * buf
Definition: aom_encoder.h:77
Image Descriptor.
Definition: aom_image.h:171
aom_img_fmt_t fmt
Definition: aom_image.h:172
int stride[3]
Definition: aom_image.h:203
unsigned int d_w
Definition: aom_image.h:186
unsigned int d_h
Definition: aom_image.h:187
unsigned char * planes[3]
Definition: aom_image.h:202
Rational Number.
Definition: aom_encoder.h:152
int num
Definition: aom_encoder.h:153
int den
Definition: aom_encoder.h:154
Encoder Config Options.
Definition: aom_encoder.h:207
unsigned int min_partition_size
min partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:223
unsigned int max_partition_size
max partition size 8, 16, 32, 64, 128
Definition: aom_encoder.h:219
unsigned int disable_trellis_quant
disable trellis quantization
Definition: aom_encoder.h:335
unsigned int super_block_size
Superblock size 0, 64 or 128.
Definition: aom_encoder.h:215