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