FFmpeg
libaomenc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Google, Inc.
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * AV1 encoder support via libaom
24  */
25 
26 #define AOM_DISABLE_CTRL_TYPECHECKS 1
27 #include <aom/aom_encoder.h>
28 #include <aom/aomcx.h>
29 
30 #include "libavutil/avassert.h"
31 #include "libavutil/base64.h"
32 #include "libavutil/common.h"
33 #include "libavutil/cpu.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/pixdesc.h"
37 
38 #include "av1.h"
39 #include "avcodec.h"
40 #include "bsf.h"
41 #include "codec_internal.h"
42 #include "encode.h"
43 #include "internal.h"
44 #include "packet_internal.h"
45 #include "profiles.h"
46 
47 /*
48  * Portion of struct aom_codec_cx_pkt from aom_encoder.h.
49  * One encoded frame returned from the library.
50  */
51 struct FrameListData {
52  void *buf; /**< compressed data buffer */
53  size_t sz; /**< length of compressed data */
54  int64_t pts; /**< time stamp to show frame
55  (in timebase units) */
56  unsigned long duration; /**< duration to show frame
57  (in timebase units) */
58  uint32_t flags; /**< flags for this frame */
59  uint64_t sse[4];
60  int have_sse; /**< true if we have pending sse[] */
61  uint64_t frame_number;
63 };
64 
65 typedef struct AOMEncoderContext {
66  AVClass *class;
68  struct aom_codec_ctx encoder;
69  struct aom_image rawimg;
70  struct aom_fixed_buf twopass_stats;
72  int cpu_used;
76  int aq_mode;
79  int crf;
84  uint64_t sse[4];
85  int have_sse; /**< true if we have pending sse[] */
86  uint64_t frame_number;
94  aom_superblock_size_t superblock_size;
96  int row_mt;
101  int usage;
102  int tune;
133 } AOMContext;
134 
135 static const char *const ctlidstr[] = {
136  [AOME_SET_CPUUSED] = "AOME_SET_CPUUSED",
137  [AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL",
138  [AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF",
139  [AOME_SET_ARNR_MAXFRAMES] = "AOME_SET_ARNR_MAXFRAMES",
140  [AOME_SET_ARNR_STRENGTH] = "AOME_SET_ARNR_STRENGTH",
141  [AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD",
142  [AV1E_SET_COLOR_RANGE] = "AV1E_SET_COLOR_RANGE",
143  [AV1E_SET_COLOR_PRIMARIES] = "AV1E_SET_COLOR_PRIMARIES",
144  [AV1E_SET_MATRIX_COEFFICIENTS] = "AV1E_SET_MATRIX_COEFFICIENTS",
145  [AV1E_SET_TRANSFER_CHARACTERISTICS] = "AV1E_SET_TRANSFER_CHARACTERISTICS",
146  [AV1E_SET_AQ_MODE] = "AV1E_SET_AQ_MODE",
147  [AV1E_SET_FRAME_PARALLEL_DECODING] = "AV1E_SET_FRAME_PARALLEL_DECODING",
148  [AV1E_SET_SUPERBLOCK_SIZE] = "AV1E_SET_SUPERBLOCK_SIZE",
149  [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
150  [AV1E_SET_TILE_ROWS] = "AV1E_SET_TILE_ROWS",
151  [AV1E_SET_ENABLE_RESTORATION] = "AV1E_SET_ENABLE_RESTORATION",
152 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
153  [AV1E_SET_ROW_MT] = "AV1E_SET_ROW_MT",
154 #endif
155 #ifdef AOM_CTRL_AV1E_SET_DENOISE_NOISE_LEVEL
156  [AV1E_SET_DENOISE_NOISE_LEVEL] = "AV1E_SET_DENOISE_NOISE_LEVEL",
157 #endif
158 #ifdef AOM_CTRL_AV1E_SET_DENOISE_BLOCK_SIZE
159  [AV1E_SET_DENOISE_BLOCK_SIZE] = "AV1E_SET_DENOISE_BLOCK_SIZE",
160 #endif
161 #ifdef AOM_CTRL_AV1E_SET_MAX_REFERENCE_FRAMES
162  [AV1E_SET_MAX_REFERENCE_FRAMES] = "AV1E_SET_MAX_REFERENCE_FRAMES",
163 #endif
164 #ifdef AOM_CTRL_AV1E_SET_ENABLE_GLOBAL_MOTION
165  [AV1E_SET_ENABLE_GLOBAL_MOTION] = "AV1E_SET_ENABLE_GLOBAL_MOTION",
166 #endif
167 #ifdef AOM_CTRL_AV1E_SET_ENABLE_INTRABC
168  [AV1E_SET_ENABLE_INTRABC] = "AV1E_SET_ENABLE_INTRABC",
169 #endif
170  [AV1E_SET_ENABLE_CDEF] = "AV1E_SET_ENABLE_CDEF",
171  [AOME_SET_TUNING] = "AOME_SET_TUNING",
172 #if AOM_ENCODER_ABI_VERSION >= 22
173  [AV1E_SET_ENABLE_1TO4_PARTITIONS] = "AV1E_SET_ENABLE_1TO4_PARTITIONS",
174  [AV1E_SET_ENABLE_AB_PARTITIONS] = "AV1E_SET_ENABLE_AB_PARTITIONS",
175  [AV1E_SET_ENABLE_RECT_PARTITIONS] = "AV1E_SET_ENABLE_RECT_PARTITIONS",
176  [AV1E_SET_ENABLE_ANGLE_DELTA] = "AV1E_SET_ENABLE_ANGLE_DELTA",
177  [AV1E_SET_ENABLE_CFL_INTRA] = "AV1E_SET_ENABLE_CFL_INTRA",
178  [AV1E_SET_ENABLE_FILTER_INTRA] = "AV1E_SET_ENABLE_FILTER_INTRA",
179  [AV1E_SET_ENABLE_INTRA_EDGE_FILTER] = "AV1E_SET_ENABLE_INTRA_EDGE_FILTER",
180  [AV1E_SET_ENABLE_PAETH_INTRA] = "AV1E_SET_ENABLE_PAETH_INTRA",
181  [AV1E_SET_ENABLE_SMOOTH_INTRA] = "AV1E_SET_ENABLE_SMOOTH_INTRA",
182  [AV1E_SET_ENABLE_PALETTE] = "AV1E_SET_ENABLE_PALETTE",
183  [AV1E_SET_ENABLE_FLIP_IDTX] = "AV1E_SET_ENABLE_FLIP_IDTX",
184  [AV1E_SET_ENABLE_TX64] = "AV1E_SET_ENABLE_TX64",
185  [AV1E_SET_INTRA_DCT_ONLY] = "AV1E_SET_INTRA_DCT_ONLY",
186  [AV1E_SET_INTER_DCT_ONLY] = "AV1E_SET_INTER_DCT_ONLY",
187  [AV1E_SET_INTRA_DEFAULT_TX_ONLY] = "AV1E_SET_INTRA_DEFAULT_TX_ONLY",
188  [AV1E_SET_REDUCED_TX_TYPE_SET] = "AV1E_SET_REDUCED_TX_TYPE_SET",
189  [AV1E_SET_ENABLE_DIFF_WTD_COMP] = "AV1E_SET_ENABLE_DIFF_WTD_COMP",
190  [AV1E_SET_ENABLE_DIST_WTD_COMP] = "AV1E_SET_ENABLE_DIST_WTD_COMP",
191  [AV1E_SET_ENABLE_DUAL_FILTER] = "AV1E_SET_ENABLE_DUAL_FILTER",
192  [AV1E_SET_ENABLE_INTERINTER_WEDGE] = "AV1E_SET_ENABLE_INTERINTER_WEDGE",
193  [AV1E_SET_ENABLE_INTERINTRA_WEDGE] = "AV1E_SET_ENABLE_INTERINTRA_WEDGE",
194  [AV1E_SET_ENABLE_MASKED_COMP] = "AV1E_SET_ENABLE_MASKED_COMP",
195  [AV1E_SET_ENABLE_INTERINTRA_COMP] = "AV1E_SET_ENABLE_INTERINTRA_COMP",
196  [AV1E_SET_ENABLE_OBMC] = "AV1E_SET_ENABLE_OBMC",
197  [AV1E_SET_ENABLE_ONESIDED_COMP] = "AV1E_SET_ENABLE_ONESIDED_COMP",
198  [AV1E_SET_REDUCED_REFERENCE_SET] = "AV1E_SET_REDUCED_REFERENCE_SET",
199  [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] = "AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
200  [AV1E_SET_ENABLE_REF_FRAME_MVS] = "AV1E_SET_ENABLE_REF_FRAME_MVS",
201 #endif
202 #ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS
203  [AV1E_GET_NUM_OPERATING_POINTS] = "AV1E_GET_NUM_OPERATING_POINTS",
204 #endif
205 #ifdef AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX
206  [AV1E_GET_SEQ_LEVEL_IDX] = "AV1E_GET_SEQ_LEVEL_IDX",
207 #endif
208 #ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
209  [AV1E_GET_TARGET_SEQ_LEVEL_IDX] = "AV1E_GET_TARGET_SEQ_LEVEL_IDX",
210 #endif
211 };
212 
213 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
214 {
215  AOMContext *ctx = avctx->priv_data;
216  const char *error = aom_codec_error(&ctx->encoder);
217  const char *detail = aom_codec_error_detail(&ctx->encoder);
218 
219  av_log(avctx, AV_LOG_ERROR, "%s: %s\n", desc, error);
220  if (detail)
221  av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n", detail);
222 }
223 
225  const struct aom_codec_enc_cfg *cfg,
226  int level)
227 {
228  int width = -30;
229 
230  av_log(avctx, level, "aom_codec_enc_cfg\n");
231  av_log(avctx, level, "generic settings\n"
232  " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
233  " %*s%u\n %*s%u\n"
234  " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
235  width, "g_usage:", cfg->g_usage,
236  width, "g_threads:", cfg->g_threads,
237  width, "g_profile:", cfg->g_profile,
238  width, "g_w:", cfg->g_w,
239  width, "g_h:", cfg->g_h,
240  width, "g_bit_depth:", cfg->g_bit_depth,
241  width, "g_input_bit_depth:", cfg->g_input_bit_depth,
242  width, "g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
243  width, "g_error_resilient:", cfg->g_error_resilient,
244  width, "g_pass:", cfg->g_pass,
245  width, "g_lag_in_frames:", cfg->g_lag_in_frames);
246  av_log(avctx, level, "rate control settings\n"
247  " %*s%u\n %*s%d\n %*s%p(%"SIZE_SPECIFIER")\n %*s%u\n",
248  width, "rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
249  width, "rc_end_usage:", cfg->rc_end_usage,
250  width, "rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
251  width, "rc_target_bitrate:", cfg->rc_target_bitrate);
252  av_log(avctx, level, "quantizer settings\n"
253  " %*s%u\n %*s%u\n",
254  width, "rc_min_quantizer:", cfg->rc_min_quantizer,
255  width, "rc_max_quantizer:", cfg->rc_max_quantizer);
256  av_log(avctx, level, "bitrate tolerance\n"
257  " %*s%u\n %*s%u\n",
258  width, "rc_undershoot_pct:", cfg->rc_undershoot_pct,
259  width, "rc_overshoot_pct:", cfg->rc_overshoot_pct);
260  av_log(avctx, level, "decoder buffer model\n"
261  " %*s%u\n %*s%u\n %*s%u\n",
262  width, "rc_buf_sz:", cfg->rc_buf_sz,
263  width, "rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
264  width, "rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
265  av_log(avctx, level, "2 pass rate control settings\n"
266  " %*s%u\n %*s%u\n %*s%u\n",
267  width, "rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
268  width, "rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
269  width, "rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
270  av_log(avctx, level, "keyframing settings\n"
271  " %*s%d\n %*s%u\n %*s%u\n",
272  width, "kf_mode:", cfg->kf_mode,
273  width, "kf_min_dist:", cfg->kf_min_dist,
274  width, "kf_max_dist:", cfg->kf_max_dist);
275  av_log(avctx, level, "tile settings\n"
276  " %*s%d\n %*s%d\n",
277  width, "tile_width_count:", cfg->tile_width_count,
278  width, "tile_height_count:", cfg->tile_height_count);
279  av_log(avctx, level, "\n");
280 }
281 
282 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
283 {
284  struct FrameListData **p = list;
285 
286  while (*p)
287  p = &(*p)->next;
288  *p = cx_frame;
289  cx_frame->next = NULL;
290 }
291 
292 static av_cold void free_coded_frame(struct FrameListData *cx_frame)
293 {
294  av_freep(&cx_frame->buf);
295  av_freep(&cx_frame);
296 }
297 
299 {
300  struct FrameListData *p = list;
301 
302  while (p) {
303  list = list->next;
304  free_coded_frame(p);
305  p = list;
306  }
307 }
308 
310 #ifdef UENUM1BYTE
311  aome_enc_control_id id,
312 #else
313  enum aome_enc_control_id id,
314 #endif
315  int val)
316 {
317  AOMContext *ctx = avctx->priv_data;
318  char buf[80];
319  int width = -30;
320  int res;
321 
322  snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
323  av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, val);
324 
325  res = aom_codec_control(&ctx->encoder, id, val);
326  if (res != AOM_CODEC_OK) {
327  snprintf(buf, sizeof(buf), "Failed to set %s codec control",
328  ctlidstr[id]);
329  log_encoder_error(avctx, buf);
330  return AVERROR(EINVAL);
331  }
332 
333  return 0;
334 }
335 
336 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
337  defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
338  defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
339 static av_cold int codecctl_intp(AVCodecContext *avctx,
340 #ifdef UENUM1BYTE
341  aome_enc_control_id id,
342 #else
343  enum aome_enc_control_id id,
344 #endif
345  int* ptr)
346 {
347  AOMContext *ctx = avctx->priv_data;
348  char buf[80];
349  int width = -30;
350  int res;
351 
352  snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
353  av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, *ptr);
354 
355  res = aom_codec_control(&ctx->encoder, id, ptr);
356  if (res != AOM_CODEC_OK) {
357  snprintf(buf, sizeof(buf), "Failed to set %s codec control",
358  ctlidstr[id]);
359  log_encoder_error(avctx, buf);
360  return AVERROR(EINVAL);
361  }
362 
363  return 0;
364 }
365 #endif
366 
367 static av_cold int aom_free(AVCodecContext *avctx)
368 {
369  AOMContext *ctx = avctx->priv_data;
370 
371 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
372  defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
373  defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
374  if (!(avctx->flags & AV_CODEC_FLAG_PASS1)) {
375  int num_operating_points;
376  int levels[32];
377  int target_levels[32];
378 
379  if (!codecctl_intp(avctx, AV1E_GET_NUM_OPERATING_POINTS,
380  &num_operating_points) &&
381  !codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) &&
382  !codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX,
383  target_levels)) {
384  for (int i = 0; i < num_operating_points; i++) {
385  if (levels[i] > target_levels[i]) {
386  // Warn when the target level was not met
387  av_log(avctx, AV_LOG_WARNING,
388  "Could not encode to target level %d.%d for "
389  "operating point %d. The output level is %d.%d.\n",
390  2 + (target_levels[i] >> 2), target_levels[i] & 3,
391  i, 2 + (levels[i] >> 2), levels[i] & 3);
392  } else if (target_levels[i] < 31) {
393  // Log the encoded level if a target level was given
394  av_log(avctx, AV_LOG_INFO,
395  "Output level for operating point %d is %d.%d.\n",
396  i, 2 + (levels[i] >> 2), levels[i] & 3);
397  }
398  }
399  }
400  }
401 #endif
402 
403  aom_codec_destroy(&ctx->encoder);
404  av_freep(&ctx->twopass_stats.buf);
405  av_freep(&avctx->stats_out);
406  free_frame_list(ctx->coded_frame_list);
407  av_bsf_free(&ctx->bsf);
408  return 0;
409 }
410 
411 static int set_pix_fmt(AVCodecContext *avctx, aom_codec_caps_t codec_caps,
412  struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *flags,
413  aom_img_fmt_t *img_fmt)
414 {
415  AOMContext av_unused *ctx = avctx->priv_data;
417  enccfg->g_bit_depth = enccfg->g_input_bit_depth = desc->comp[0].depth;
418  switch (avctx->pix_fmt) {
419  case AV_PIX_FMT_GRAY8:
420  enccfg->monochrome = 1;
421  /* Fall-through */
422  case AV_PIX_FMT_YUV420P:
423  enccfg->g_profile = FF_PROFILE_AV1_MAIN;
424  *img_fmt = AOM_IMG_FMT_I420;
425  return 0;
426  case AV_PIX_FMT_YUV422P:
427  enccfg->g_profile = FF_PROFILE_AV1_PROFESSIONAL;
428  *img_fmt = AOM_IMG_FMT_I422;
429  return 0;
430  case AV_PIX_FMT_YUV444P:
431  case AV_PIX_FMT_GBRP:
432  enccfg->g_profile = FF_PROFILE_AV1_HIGH;
433  *img_fmt = AOM_IMG_FMT_I444;
434  return 0;
435  case AV_PIX_FMT_GRAY10:
436  case AV_PIX_FMT_GRAY12:
437  enccfg->monochrome = 1;
438  /* Fall-through */
441  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
442  enccfg->g_profile =
443  enccfg->g_bit_depth == 10 ? FF_PROFILE_AV1_MAIN : FF_PROFILE_AV1_PROFESSIONAL;
444  *img_fmt = AOM_IMG_FMT_I42016;
445  *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
446  return 0;
447  }
448  break;
451  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
452  enccfg->g_profile = FF_PROFILE_AV1_PROFESSIONAL;
453  *img_fmt = AOM_IMG_FMT_I42216;
454  *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
455  return 0;
456  }
457  break;
460  case AV_PIX_FMT_GBRP10:
461  case AV_PIX_FMT_GBRP12:
462  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
463  enccfg->g_profile =
464  enccfg->g_bit_depth == 10 ? FF_PROFILE_AV1_HIGH : FF_PROFILE_AV1_PROFESSIONAL;
465  *img_fmt = AOM_IMG_FMT_I44416;
466  *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
467  return 0;
468  }
469  break;
470  default:
471  break;
472  }
473  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
474  return AVERROR_INVALIDDATA;
475 }
476 
477 static void set_color_range(AVCodecContext *avctx)
478 {
479  aom_color_range_t aom_cr;
480  switch (avctx->color_range) {
482  case AVCOL_RANGE_MPEG: aom_cr = AOM_CR_STUDIO_RANGE; break;
483  case AVCOL_RANGE_JPEG: aom_cr = AOM_CR_FULL_RANGE; break;
484  default:
485  av_log(avctx, AV_LOG_WARNING, "Unsupported color range (%d)\n",
486  avctx->color_range);
487  return;
488  }
489 
490  codecctl_int(avctx, AV1E_SET_COLOR_RANGE, aom_cr);
491 }
492 
493 static int count_uniform_tiling(int dim, int sb_size, int tiles_log2)
494 {
495  int sb_dim = (dim + sb_size - 1) / sb_size;
496  int tile_dim = (sb_dim + (1 << tiles_log2) - 1) >> tiles_log2;
497  av_assert0(tile_dim > 0);
498  return (sb_dim + tile_dim - 1) / tile_dim;
499 }
500 
501 static int choose_tiling(AVCodecContext *avctx,
502  struct aom_codec_enc_cfg *enccfg)
503 {
504  AOMContext *ctx = avctx->priv_data;
505  int sb_128x128_possible, sb_size, sb_width, sb_height;
506  int uniform_rows, uniform_cols;
507  int uniform_64x64_possible, uniform_128x128_possible;
508  int tile_size, rounding, i;
509 
510  if (ctx->tile_cols_log2 >= 0)
511  ctx->tile_cols = 1 << ctx->tile_cols_log2;
512  if (ctx->tile_rows_log2 >= 0)
513  ctx->tile_rows = 1 << ctx->tile_rows_log2;
514 
515  if (ctx->tile_cols == 0) {
516  ctx->tile_cols = (avctx->width + AV1_MAX_TILE_WIDTH - 1) /
518  if (ctx->tile_cols > 1) {
519  av_log(avctx, AV_LOG_DEBUG, "Automatically using %d tile "
520  "columns to fill width.\n", ctx->tile_cols);
521  }
522  }
523  av_assert0(ctx->tile_cols > 0);
524  if (ctx->tile_rows == 0) {
525  int max_tile_width =
526  FFALIGN((FFALIGN(avctx->width, 128) +
527  ctx->tile_cols - 1) / ctx->tile_cols, 128);
528  ctx->tile_rows =
529  (max_tile_width * FFALIGN(avctx->height, 128) +
531  if (ctx->tile_rows > 1) {
532  av_log(avctx, AV_LOG_DEBUG, "Automatically using %d tile "
533  "rows to fill area.\n", ctx->tile_rows);
534  }
535  }
536  av_assert0(ctx->tile_rows > 0);
537 
538  if ((avctx->width + 63) / 64 < ctx->tile_cols ||
539  (avctx->height + 63) / 64 < ctx->tile_rows) {
540  av_log(avctx, AV_LOG_ERROR, "Invalid tile sizing: frame not "
541  "large enough to fit specified tile arrangement.\n");
542  return AVERROR(EINVAL);
543  }
544  if (ctx->tile_cols > AV1_MAX_TILE_COLS ||
545  ctx->tile_rows > AV1_MAX_TILE_ROWS) {
546  av_log(avctx, AV_LOG_ERROR, "Invalid tile sizing: AV1 does "
547  "not allow more than %dx%d tiles.\n",
549  return AVERROR(EINVAL);
550  }
551  if (avctx->width / ctx->tile_cols > AV1_MAX_TILE_WIDTH) {
552  av_log(avctx, AV_LOG_ERROR, "Invalid tile sizing: AV1 does "
553  "not allow tiles of width greater than %d.\n",
555  return AVERROR(EINVAL);
556  }
557 
558  ctx->superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
559 
560  if (ctx->tile_cols == 1 && ctx->tile_rows == 1) {
561  av_log(avctx, AV_LOG_DEBUG, "Using a single tile.\n");
562  return 0;
563  }
564 
565  sb_128x128_possible =
566  (avctx->width + 127) / 128 >= ctx->tile_cols &&
567  (avctx->height + 127) / 128 >= ctx->tile_rows;
568 
569  ctx->tile_cols_log2 = ctx->tile_cols == 1 ? 0 :
570  av_log2(ctx->tile_cols - 1) + 1;
571  ctx->tile_rows_log2 = ctx->tile_rows == 1 ? 0 :
572  av_log2(ctx->tile_rows - 1) + 1;
573 
574  uniform_cols = count_uniform_tiling(avctx->width,
575  64, ctx->tile_cols_log2);
576  uniform_rows = count_uniform_tiling(avctx->height,
577  64, ctx->tile_rows_log2);
578  av_log(avctx, AV_LOG_DEBUG, "Uniform with 64x64 superblocks "
579  "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
580  uniform_64x64_possible = uniform_cols == ctx->tile_cols &&
581  uniform_rows == ctx->tile_rows;
582 
583  if (sb_128x128_possible) {
584  uniform_cols = count_uniform_tiling(avctx->width,
585  128, ctx->tile_cols_log2);
586  uniform_rows = count_uniform_tiling(avctx->height,
587  128, ctx->tile_rows_log2);
588  av_log(avctx, AV_LOG_DEBUG, "Uniform with 128x128 superblocks "
589  "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
590  uniform_128x128_possible = uniform_cols == ctx->tile_cols &&
591  uniform_rows == ctx->tile_rows;
592  } else {
593  av_log(avctx, AV_LOG_DEBUG, "128x128 superblocks not possible.\n");
594  uniform_128x128_possible = 0;
595  }
596 
597  ctx->uniform_tiles = 1;
598  if (uniform_64x64_possible && uniform_128x128_possible) {
599  av_log(avctx, AV_LOG_DEBUG, "Using uniform tiling with dynamic "
600  "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
601  ctx->tile_cols_log2, ctx->tile_rows_log2);
602  return 0;
603  }
604  if (uniform_64x64_possible && !sb_128x128_possible) {
605  av_log(avctx, AV_LOG_DEBUG, "Using uniform tiling with 64x64 "
606  "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
607  ctx->tile_cols_log2, ctx->tile_rows_log2);
608  ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
609  return 0;
610  }
611  if (uniform_128x128_possible) {
612  av_log(avctx, AV_LOG_DEBUG, "Using uniform tiling with 128x128 "
613  "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
614  ctx->tile_cols_log2, ctx->tile_rows_log2);
615  ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
616  return 0;
617  }
618  ctx->uniform_tiles = 0;
619 
620  if (sb_128x128_possible) {
621  sb_size = 128;
622  ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
623  } else {
624  sb_size = 64;
625  ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
626  }
627  av_log(avctx, AV_LOG_DEBUG, "Using fixed tiling with %dx%d "
628  "superblocks (tile_cols = %d, tile_rows = %d).\n",
629  sb_size, sb_size, ctx->tile_cols, ctx->tile_rows);
630 
631  enccfg->tile_width_count = ctx->tile_cols;
632  enccfg->tile_height_count = ctx->tile_rows;
633 
634  sb_width = (avctx->width + sb_size - 1) / sb_size;
635  sb_height = (avctx->height + sb_size - 1) / sb_size;
636 
637  tile_size = sb_width / ctx->tile_cols;
638  rounding = sb_width % ctx->tile_cols;
639  for (i = 0; i < ctx->tile_cols; i++) {
640  enccfg->tile_widths[i] = tile_size +
641  (i < rounding / 2 ||
642  i > ctx->tile_cols - 1 - (rounding + 1) / 2);
643  }
644 
645  tile_size = sb_height / ctx->tile_rows;
646  rounding = sb_height % ctx->tile_rows;
647  for (i = 0; i < ctx->tile_rows; i++) {
648  enccfg->tile_heights[i] = tile_size +
649  (i < rounding / 2 ||
650  i > ctx->tile_rows - 1 - (rounding + 1) / 2);
651  }
652 
653  return 0;
654 }
655 
656 static av_cold int aom_init(AVCodecContext *avctx,
657  const struct aom_codec_iface *iface)
658 {
659  AOMContext *ctx = avctx->priv_data;
661  struct aom_codec_enc_cfg enccfg = { 0 };
662 #ifdef AOM_FRAME_IS_INTRAONLY
663  aom_codec_flags_t flags =
664  (avctx->flags & AV_CODEC_FLAG_PSNR) ? AOM_CODEC_USE_PSNR : 0;
665 #else
666  aom_codec_flags_t flags = 0;
667 #endif
668  AVCPBProperties *cpb_props;
669  int res;
670  aom_img_fmt_t img_fmt;
671  aom_codec_caps_t codec_caps = aom_codec_get_caps(iface);
672 
673  av_log(avctx, AV_LOG_INFO, "%s\n", aom_codec_version_str());
674  av_log(avctx, AV_LOG_VERBOSE, "%s\n", aom_codec_build_config());
675 
676  if ((res = aom_codec_enc_config_default(iface, &enccfg, ctx->usage)) != AOM_CODEC_OK) {
677  av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n",
678  aom_codec_err_to_string(res));
679  return AVERROR(EINVAL);
680  }
681 
682  if (set_pix_fmt(avctx, codec_caps, &enccfg, &flags, &img_fmt))
683  return AVERROR(EINVAL);
684 
685  if(!avctx->bit_rate)
686  if(avctx->rc_max_rate || avctx->rc_buffer_size || avctx->rc_initial_buffer_occupancy) {
687  av_log( avctx, AV_LOG_ERROR, "Rate control parameters set without a bitrate\n");
688  return AVERROR(EINVAL);
689  }
690 
691  dump_enc_cfg(avctx, &enccfg, AV_LOG_DEBUG);
692 
693  enccfg.g_w = avctx->width;
694  enccfg.g_h = avctx->height;
695  enccfg.g_timebase.num = avctx->time_base.num;
696  enccfg.g_timebase.den = avctx->time_base.den;
697  enccfg.g_threads =
698  FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 64);
699 
700  if (ctx->lag_in_frames >= 0)
701  enccfg.g_lag_in_frames = ctx->lag_in_frames;
702 
703  if (avctx->flags & AV_CODEC_FLAG_PASS1)
704  enccfg.g_pass = AOM_RC_FIRST_PASS;
705  else if (avctx->flags & AV_CODEC_FLAG_PASS2)
706  enccfg.g_pass = AOM_RC_LAST_PASS;
707  else
708  enccfg.g_pass = AOM_RC_ONE_PASS;
709 
710  if (avctx->rc_min_rate == avctx->rc_max_rate &&
711  avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) {
712  enccfg.rc_end_usage = AOM_CBR;
713  } else if (ctx->crf >= 0) {
714  enccfg.rc_end_usage = AOM_CQ;
715  if (!avctx->bit_rate)
716  enccfg.rc_end_usage = AOM_Q;
717  }
718 
719  if (avctx->bit_rate) {
720  enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
722  } else if (enccfg.rc_end_usage != AOM_Q) {
723  enccfg.rc_end_usage = AOM_Q;
724  ctx->crf = 32;
725  av_log(avctx, AV_LOG_WARNING,
726  "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
727  ctx->crf);
728  }
729 
730  if (avctx->qmin >= 0)
731  enccfg.rc_min_quantizer = avctx->qmin;
732  if (avctx->qmax >= 0) {
733  enccfg.rc_max_quantizer = avctx->qmax;
734  } else if (!ctx->crf) {
735  enccfg.rc_max_quantizer = 0;
736  }
737 
738  if (enccfg.rc_end_usage == AOM_CQ || enccfg.rc_end_usage == AOM_Q) {
739  if (ctx->crf < enccfg.rc_min_quantizer || ctx->crf > enccfg.rc_max_quantizer) {
740  av_log(avctx, AV_LOG_ERROR,
741  "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
742  ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
743  return AVERROR(EINVAL);
744  }
745  }
746 
747  enccfg.rc_dropframe_thresh = ctx->drop_threshold;
748 
749  // 0-100 (0 => CBR, 100 => VBR)
750  enccfg.rc_2pass_vbr_bias_pct = round(avctx->qcompress * 100);
751  if (ctx->minsection_pct >= 0)
752  enccfg.rc_2pass_vbr_minsection_pct = ctx->minsection_pct;
753  else if (avctx->bit_rate)
754  enccfg.rc_2pass_vbr_minsection_pct =
755  avctx->rc_min_rate * 100LL / avctx->bit_rate;
756  if (ctx->maxsection_pct >= 0)
757  enccfg.rc_2pass_vbr_maxsection_pct = ctx->maxsection_pct;
758  else if (avctx->rc_max_rate)
759  enccfg.rc_2pass_vbr_maxsection_pct =
760  avctx->rc_max_rate * 100LL / avctx->bit_rate;
761 
762  if (avctx->rc_buffer_size)
763  enccfg.rc_buf_sz =
764  avctx->rc_buffer_size * 1000LL / avctx->bit_rate;
765  if (avctx->rc_initial_buffer_occupancy)
766  enccfg.rc_buf_initial_sz =
767  avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
768  enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
769 
770  if (ctx->rc_undershoot_pct >= 0)
771  enccfg.rc_undershoot_pct = ctx->rc_undershoot_pct;
772  if (ctx->rc_overshoot_pct >= 0)
773  enccfg.rc_overshoot_pct = ctx->rc_overshoot_pct;
774 
775  // _enc_init() will balk if kf_min_dist differs from max w/AOM_KF_AUTO
776  if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
777  enccfg.kf_min_dist = avctx->keyint_min;
778  if (avctx->gop_size >= 0)
779  enccfg.kf_max_dist = avctx->gop_size;
780 
781  if (enccfg.g_pass == AOM_RC_FIRST_PASS)
782  enccfg.g_lag_in_frames = 0;
783  else if (enccfg.g_pass == AOM_RC_LAST_PASS) {
784  int decode_size, ret;
785 
786  if (!avctx->stats_in) {
787  av_log(avctx, AV_LOG_ERROR, "No stats file for second pass\n");
788  return AVERROR_INVALIDDATA;
789  }
790 
791  ctx->twopass_stats.sz = strlen(avctx->stats_in) * 3 / 4;
792  ret = av_reallocp(&ctx->twopass_stats.buf, ctx->twopass_stats.sz);
793  if (ret < 0) {
794  av_log(avctx, AV_LOG_ERROR,
795  "Stat buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
796  ctx->twopass_stats.sz);
797  ctx->twopass_stats.sz = 0;
798  return ret;
799  }
800  decode_size = av_base64_decode(ctx->twopass_stats.buf, avctx->stats_in,
801  ctx->twopass_stats.sz);
802  if (decode_size < 0) {
803  av_log(avctx, AV_LOG_ERROR, "Stat buffer decode failed\n");
804  return AVERROR_INVALIDDATA;
805  }
806 
807  ctx->twopass_stats.sz = decode_size;
808  enccfg.rc_twopass_stats_in = ctx->twopass_stats;
809  }
810 
811  /* 0-3: For non-zero values the encoder increasingly optimizes for reduced
812  * complexity playback on low powered devices at the expense of encode
813  * quality. */
814  if (avctx->profile != FF_PROFILE_UNKNOWN)
815  enccfg.g_profile = avctx->profile;
816 
817  enccfg.g_error_resilient = ctx->error_resilient;
818 
819  res = choose_tiling(avctx, &enccfg);
820  if (res < 0)
821  return res;
822 
823  if (ctx->still_picture) {
824  // Set the maximum number of frames to 1. This will let libaom set
825  // still_picture and reduced_still_picture_header to 1 in the Sequence
826  // Header as required by AVIF still images.
827  enccfg.g_limit = 1;
828  // Reduce memory usage for still images.
829  enccfg.g_lag_in_frames = 0;
830  // All frames will be key frames.
831  enccfg.kf_max_dist = 0;
832  enccfg.kf_mode = AOM_KF_DISABLED;
833  }
834 
835  /* Construct Encoder Context */
836  res = aom_codec_enc_init(&ctx->encoder, iface, &enccfg, flags);
837  if (res != AOM_CODEC_OK) {
838  dump_enc_cfg(avctx, &enccfg, AV_LOG_WARNING);
839  log_encoder_error(avctx, "Failed to initialize encoder");
840  return AVERROR(EINVAL);
841  }
842  dump_enc_cfg(avctx, &enccfg, AV_LOG_DEBUG);
843 
844  // codec control failures are currently treated only as warnings
845  av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
846  codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
847  if (ctx->auto_alt_ref >= 0)
848  codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
849  if (ctx->arnr_max_frames >= 0)
850  codecctl_int(avctx, AOME_SET_ARNR_MAXFRAMES, ctx->arnr_max_frames);
851  if (ctx->arnr_strength >= 0)
852  codecctl_int(avctx, AOME_SET_ARNR_STRENGTH, ctx->arnr_strength);
853  if (ctx->enable_cdef >= 0)
854  codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, ctx->enable_cdef);
855  if (ctx->enable_restoration >= 0)
856  codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION, ctx->enable_restoration);
857 #if AOM_ENCODER_ABI_VERSION >= 22
858  if (ctx->enable_rect_partitions >= 0)
859  codecctl_int(avctx, AV1E_SET_ENABLE_RECT_PARTITIONS, ctx->enable_rect_partitions);
860  if (ctx->enable_1to4_partitions >= 0)
861  codecctl_int(avctx, AV1E_SET_ENABLE_1TO4_PARTITIONS, ctx->enable_1to4_partitions);
862  if (ctx->enable_ab_partitions >= 0)
863  codecctl_int(avctx, AV1E_SET_ENABLE_AB_PARTITIONS, ctx->enable_ab_partitions);
864  if (ctx->enable_angle_delta >= 0)
865  codecctl_int(avctx, AV1E_SET_ENABLE_ANGLE_DELTA, ctx->enable_angle_delta);
866  if (ctx->enable_cfl_intra >= 0)
867  codecctl_int(avctx, AV1E_SET_ENABLE_CFL_INTRA, ctx->enable_cfl_intra);
868  if (ctx->enable_filter_intra >= 0)
869  codecctl_int(avctx, AV1E_SET_ENABLE_FILTER_INTRA, ctx->enable_filter_intra);
870  if (ctx->enable_intra_edge_filter >= 0)
871  codecctl_int(avctx, AV1E_SET_ENABLE_INTRA_EDGE_FILTER, ctx->enable_intra_edge_filter);
872  if (ctx->enable_paeth_intra >= 0)
873  codecctl_int(avctx, AV1E_SET_ENABLE_PAETH_INTRA, ctx->enable_paeth_intra);
874  if (ctx->enable_smooth_intra >= 0)
875  codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA, ctx->enable_smooth_intra);
876  if (ctx->enable_palette >= 0)
877  codecctl_int(avctx, AV1E_SET_ENABLE_PALETTE, ctx->enable_palette);
878  if (ctx->enable_tx64 >= 0)
879  codecctl_int(avctx, AV1E_SET_ENABLE_TX64, ctx->enable_tx64);
880  if (ctx->enable_flip_idtx >= 0)
881  codecctl_int(avctx, AV1E_SET_ENABLE_FLIP_IDTX, ctx->enable_flip_idtx);
882  if (ctx->use_intra_dct_only >= 0)
883  codecctl_int(avctx, AV1E_SET_INTRA_DCT_ONLY, ctx->use_intra_dct_only);
884  if (ctx->use_inter_dct_only >= 0)
885  codecctl_int(avctx, AV1E_SET_INTER_DCT_ONLY, ctx->use_inter_dct_only);
886  if (ctx->use_intra_default_tx_only >= 0)
887  codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY, ctx->use_intra_default_tx_only);
888  if (ctx->reduced_tx_type_set >= 0)
889  codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET, ctx->reduced_tx_type_set);
890  if (ctx->enable_ref_frame_mvs >= 0)
891  codecctl_int(avctx, AV1E_SET_ENABLE_REF_FRAME_MVS, ctx->enable_ref_frame_mvs);
892  if (ctx->enable_reduced_reference_set >= 0)
893  codecctl_int(avctx, AV1E_SET_REDUCED_REFERENCE_SET, ctx->enable_reduced_reference_set);
894  if (ctx->enable_diff_wtd_comp >= 0)
895  codecctl_int(avctx, AV1E_SET_ENABLE_DIFF_WTD_COMP, ctx->enable_diff_wtd_comp);
896  if (ctx->enable_dist_wtd_comp >= 0)
897  codecctl_int(avctx, AV1E_SET_ENABLE_DIST_WTD_COMP, ctx->enable_dist_wtd_comp);
898  if (ctx->enable_dual_filter >= 0)
899  codecctl_int(avctx, AV1E_SET_ENABLE_DUAL_FILTER, ctx->enable_dual_filter);
900  if (ctx->enable_interinter_wedge >= 0)
901  codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTER_WEDGE, ctx->enable_interinter_wedge);
902  if (ctx->enable_masked_comp >= 0)
903  codecctl_int(avctx, AV1E_SET_ENABLE_MASKED_COMP, ctx->enable_masked_comp);
904  if (ctx->enable_interintra_comp >= 0)
905  codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_COMP, ctx->enable_interintra_comp);
906  if (ctx->enable_interintra_wedge >= 0)
907  codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_WEDGE, ctx->enable_interintra_wedge);
908  if (ctx->enable_obmc >= 0)
909  codecctl_int(avctx, AV1E_SET_ENABLE_OBMC, ctx->enable_obmc);
910  if (ctx->enable_onesided_comp >= 0)
911  codecctl_int(avctx, AV1E_SET_ENABLE_ONESIDED_COMP, ctx->enable_onesided_comp);
912  if (ctx->enable_smooth_interintra >= 0)
913  codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTERINTRA, ctx->enable_smooth_interintra);
914 #endif
915 
916  codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
917  if (ctx->crf >= 0)
918  codecctl_int(avctx, AOME_SET_CQ_LEVEL, ctx->crf);
919  if (ctx->tune >= 0)
920  codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
921 
922  if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
923  codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, AVCOL_PRI_BT709);
924  codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, AVCOL_SPC_RGB);
925  codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, AVCOL_TRC_IEC61966_2_1);
926  } else {
927  codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
928  codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
929  codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, avctx->color_trc);
930  }
931  if (ctx->aq_mode >= 0)
932  codecctl_int(avctx, AV1E_SET_AQ_MODE, ctx->aq_mode);
933  if (ctx->frame_parallel >= 0)
934  codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel);
935  set_color_range(avctx);
936 
937  codecctl_int(avctx, AV1E_SET_SUPERBLOCK_SIZE, ctx->superblock_size);
938  if (ctx->uniform_tiles) {
939  codecctl_int(avctx, AV1E_SET_TILE_COLUMNS, ctx->tile_cols_log2);
940  codecctl_int(avctx, AV1E_SET_TILE_ROWS, ctx->tile_rows_log2);
941  }
942 
943 #ifdef AOM_CTRL_AV1E_SET_DENOISE_NOISE_LEVEL
944  if (ctx->denoise_noise_level >= 0)
945  codecctl_int(avctx, AV1E_SET_DENOISE_NOISE_LEVEL, ctx->denoise_noise_level);
946 #endif
947 #ifdef AOM_CTRL_AV1E_SET_DENOISE_BLOCK_SIZE
948  if (ctx->denoise_block_size >= 0)
949  codecctl_int(avctx, AV1E_SET_DENOISE_BLOCK_SIZE, ctx->denoise_block_size);
950 #endif
951 #ifdef AOM_CTRL_AV1E_SET_ENABLE_GLOBAL_MOTION
952  if (ctx->enable_global_motion >= 0)
953  codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION, ctx->enable_global_motion);
954 #endif
955 #ifdef AOM_CTRL_AV1E_SET_MAX_REFERENCE_FRAMES
956  if (avctx->refs >= 3) {
957  codecctl_int(avctx, AV1E_SET_MAX_REFERENCE_FRAMES, avctx->refs);
958  }
959 #endif
960 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
961  if (ctx->row_mt >= 0)
962  codecctl_int(avctx, AV1E_SET_ROW_MT, ctx->row_mt);
963 #endif
964 #ifdef AOM_CTRL_AV1E_SET_ENABLE_INTRABC
965  if (ctx->enable_intrabc >= 0)
966  codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC, ctx->enable_intrabc);
967 #endif
968 
969 #if AOM_ENCODER_ABI_VERSION >= 23
970  {
971  AVDictionaryEntry *en = NULL;
972 
973  while ((en = av_dict_get(ctx->aom_params, "", en, AV_DICT_IGNORE_SUFFIX))) {
974  int ret = aom_codec_set_option(&ctx->encoder, en->key, en->value);
975  if (ret != AOM_CODEC_OK) {
976  log_encoder_error(avctx, en->key);
977  return AVERROR_EXTERNAL;
978  }
979  }
980  }
981 #endif
982 
983  // provide dummy value to initialize wrapper, values will be updated each _encode()
984  aom_img_wrap(&ctx->rawimg, img_fmt, avctx->width, avctx->height, 1,
985  (unsigned char*)1);
986 
987  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
988  ctx->rawimg.bit_depth = enccfg.g_bit_depth;
989 
990  cpb_props = ff_add_cpb_side_data(avctx);
991  if (!cpb_props)
992  return AVERROR(ENOMEM);
993 
994  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
995  const AVBitStreamFilter *filter = av_bsf_get_by_name("extract_extradata");
996  int ret;
997 
998  if (!filter) {
999  av_log(avctx, AV_LOG_ERROR, "extract_extradata bitstream filter "
1000  "not found. This is a bug, please report it.\n");
1001  return AVERROR_BUG;
1002  }
1003  ret = av_bsf_alloc(filter, &ctx->bsf);
1004  if (ret < 0)
1005  return ret;
1006 
1007  ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx);
1008  if (ret < 0)
1009  return ret;
1010 
1011  ret = av_bsf_init(ctx->bsf);
1012  if (ret < 0)
1013  return ret;
1014  }
1015 
1016  if (enccfg.rc_end_usage == AOM_CBR ||
1017  enccfg.g_pass != AOM_RC_ONE_PASS) {
1018  cpb_props->max_bitrate = avctx->rc_max_rate;
1019  cpb_props->min_bitrate = avctx->rc_min_rate;
1020  cpb_props->avg_bitrate = avctx->bit_rate;
1021  }
1022  cpb_props->buffer_size = avctx->rc_buffer_size;
1023 
1024  return 0;
1025 }
1026 
1027 static inline void cx_pktcpy(AOMContext *ctx,
1028  struct FrameListData *dst,
1029  const struct aom_codec_cx_pkt *src)
1030 {
1031  dst->pts = src->data.frame.pts;
1032  dst->duration = src->data.frame.duration;
1033  dst->flags = src->data.frame.flags;
1034  dst->sz = src->data.frame.sz;
1035  dst->buf = src->data.frame.buf;
1036 #ifdef AOM_FRAME_IS_INTRAONLY
1037  dst->frame_number = ++ctx->frame_number;
1038  dst->have_sse = ctx->have_sse;
1039  if (ctx->have_sse) {
1040  /* associate last-seen SSE to the frame. */
1041  /* Transfers ownership from ctx to dst. */
1042  memcpy(dst->sse, ctx->sse, sizeof(dst->sse));
1043  ctx->have_sse = 0;
1044  }
1045 #endif
1046 }
1047 
1048 /**
1049  * Store coded frame information in format suitable for return from encode2().
1050  *
1051  * Write information from @a cx_frame to @a pkt
1052  * @return packet data size on success
1053  * @return a negative AVERROR on error
1054  */
1055 static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
1056  AVPacket *pkt)
1057 {
1058  AOMContext *ctx = avctx->priv_data;
1059  int av_unused pict_type;
1060  int ret = ff_get_encode_buffer(avctx, pkt, cx_frame->sz, 0);
1061  if (ret < 0) {
1062  av_log(avctx, AV_LOG_ERROR,
1063  "Error getting output packet of size %"SIZE_SPECIFIER".\n", cx_frame->sz);
1064  return ret;
1065  }
1066  memcpy(pkt->data, cx_frame->buf, pkt->size);
1067  pkt->pts = pkt->dts = cx_frame->pts;
1068 
1069  if (!!(cx_frame->flags & AOM_FRAME_IS_KEY)) {
1071 #ifdef AOM_FRAME_IS_INTRAONLY
1072  pict_type = AV_PICTURE_TYPE_I;
1073  } else if (cx_frame->flags & AOM_FRAME_IS_INTRAONLY) {
1074  pict_type = AV_PICTURE_TYPE_I;
1075  } else {
1076  pict_type = AV_PICTURE_TYPE_P;
1077  }
1078 
1079  ff_side_data_set_encoder_stats(pkt, 0, cx_frame->sse + 1,
1080  cx_frame->have_sse ? 3 : 0, pict_type);
1081 
1082  if (cx_frame->have_sse) {
1083  int i;
1084  for (i = 0; i < 3; ++i) {
1085  avctx->error[i] += cx_frame->sse[i + 1];
1086  }
1087  cx_frame->have_sse = 0;
1088 #endif
1089  }
1090 
1091  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
1092  ret = av_bsf_send_packet(ctx->bsf, pkt);
1093  if (ret < 0) {
1094  av_log(avctx, AV_LOG_ERROR, "extract_extradata filter "
1095  "failed to send input packet\n");
1096  return ret;
1097  }
1098  ret = av_bsf_receive_packet(ctx->bsf, pkt);
1099 
1100  if (ret < 0) {
1101  av_log(avctx, AV_LOG_ERROR, "extract_extradata filter "
1102  "failed to receive output packet\n");
1103  return ret;
1104  }
1105  }
1106  return pkt->size;
1107 }
1108 
1109 /**
1110  * Queue multiple output frames from the encoder, returning the front-most.
1111  * In cases where aom_codec_get_cx_data() returns more than 1 frame append
1112  * the frame queue. Return the head frame if available.
1113  * @return Stored frame size
1114  * @return AVERROR(EINVAL) on output size error
1115  * @return AVERROR(ENOMEM) on coded frame queue data allocation error
1116  */
1117 static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
1118 {
1119  AOMContext *ctx = avctx->priv_data;
1120  const struct aom_codec_cx_pkt *pkt;
1121  const void *iter = NULL;
1122  int size = 0;
1123 
1124  if (ctx->coded_frame_list) {
1125  struct FrameListData *cx_frame = ctx->coded_frame_list;
1126  /* return the leading frame if we've already begun queueing */
1127  size = storeframe(avctx, cx_frame, pkt_out);
1128  if (size < 0)
1129  return size;
1130  ctx->coded_frame_list = cx_frame->next;
1131  free_coded_frame(cx_frame);
1132  }
1133 
1134  /* consume all available output from the encoder before returning. buffers
1135  * are only good through the next aom_codec call */
1136  while ((pkt = aom_codec_get_cx_data(&ctx->encoder, &iter))) {
1137  switch (pkt->kind) {
1138  case AOM_CODEC_CX_FRAME_PKT:
1139  if (!size) {
1140  struct FrameListData cx_frame;
1141 
1142  /* avoid storing the frame when the list is empty and we haven't yet
1143  * provided a frame for output */
1144  av_assert0(!ctx->coded_frame_list);
1145  cx_pktcpy(ctx, &cx_frame, pkt);
1146  size = storeframe(avctx, &cx_frame, pkt_out);
1147  if (size < 0)
1148  return size;
1149  } else {
1150  struct FrameListData *cx_frame =
1151  av_malloc(sizeof(struct FrameListData));
1152 
1153  if (!cx_frame) {
1154  av_log(avctx, AV_LOG_ERROR,
1155  "Frame queue element alloc failed\n");
1156  return AVERROR(ENOMEM);
1157  }
1158  cx_pktcpy(ctx, cx_frame, pkt);
1159  cx_frame->buf = av_malloc(cx_frame->sz);
1160 
1161  if (!cx_frame->buf) {
1162  av_log(avctx, AV_LOG_ERROR,
1163  "Data buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
1164  cx_frame->sz);
1165  av_freep(&cx_frame);
1166  return AVERROR(ENOMEM);
1167  }
1168  memcpy(cx_frame->buf, pkt->data.frame.buf, pkt->data.frame.sz);
1169  coded_frame_add(&ctx->coded_frame_list, cx_frame);
1170  }
1171  break;
1172  case AOM_CODEC_STATS_PKT:
1173  {
1174  struct aom_fixed_buf *stats = &ctx->twopass_stats;
1175  int err;
1176  if ((err = av_reallocp(&stats->buf,
1177  stats->sz +
1178  pkt->data.twopass_stats.sz)) < 0) {
1179  stats->sz = 0;
1180  av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
1181  return err;
1182  }
1183  memcpy((uint8_t *)stats->buf + stats->sz,
1184  pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
1185  stats->sz += pkt->data.twopass_stats.sz;
1186  break;
1187  }
1188 #ifdef AOM_FRAME_IS_INTRAONLY
1189  case AOM_CODEC_PSNR_PKT:
1190  {
1191  av_assert0(!ctx->have_sse);
1192  ctx->sse[0] = pkt->data.psnr.sse[0];
1193  ctx->sse[1] = pkt->data.psnr.sse[1];
1194  ctx->sse[2] = pkt->data.psnr.sse[2];
1195  ctx->sse[3] = pkt->data.psnr.sse[3];
1196  ctx->have_sse = 1;
1197  break;
1198  }
1199 #endif
1200  case AOM_CODEC_CUSTOM_PKT:
1201  // ignore unsupported/unrecognized packet types
1202  break;
1203  }
1204  }
1205 
1206  return size;
1207 }
1208 
1210  const AVFrame *frame, int *got_packet)
1211 {
1212  AOMContext *ctx = avctx->priv_data;
1213  struct aom_image *rawimg = NULL;
1214  int64_t timestamp = 0;
1215  int res, coded_size;
1216  aom_enc_frame_flags_t flags = 0;
1217 
1218  if (frame) {
1219  rawimg = &ctx->rawimg;
1220  rawimg->planes[AOM_PLANE_Y] = frame->data[0];
1221  rawimg->planes[AOM_PLANE_U] = frame->data[1];
1222  rawimg->planes[AOM_PLANE_V] = frame->data[2];
1223  rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
1224  rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
1225  rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
1226  timestamp = frame->pts;
1227  switch (frame->color_range) {
1228  case AVCOL_RANGE_MPEG:
1229  rawimg->range = AOM_CR_STUDIO_RANGE;
1230  break;
1231  case AVCOL_RANGE_JPEG:
1232  rawimg->range = AOM_CR_FULL_RANGE;
1233  break;
1234  }
1235 
1236  if (frame->pict_type == AV_PICTURE_TYPE_I)
1237  flags |= AOM_EFLAG_FORCE_KF;
1238  }
1239 
1240  res = aom_codec_encode(&ctx->encoder, rawimg, timestamp,
1241  avctx->ticks_per_frame, flags);
1242  if (res != AOM_CODEC_OK) {
1243  log_encoder_error(avctx, "Error encoding frame");
1244  return AVERROR_INVALIDDATA;
1245  }
1246  coded_size = queue_frames(avctx, pkt);
1247 
1248  if (!frame && avctx->flags & AV_CODEC_FLAG_PASS1) {
1249  size_t b64_size = AV_BASE64_SIZE(ctx->twopass_stats.sz);
1250 
1251  avctx->stats_out = av_malloc(b64_size);
1252  if (!avctx->stats_out) {
1253  av_log(avctx, AV_LOG_ERROR, "Stat buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
1254  b64_size);
1255  return AVERROR(ENOMEM);
1256  }
1257  av_base64_encode(avctx->stats_out, b64_size, ctx->twopass_stats.buf,
1258  ctx->twopass_stats.sz);
1259  }
1260 
1261  *got_packet = !!coded_size;
1262  return 0;
1263 }
1264 
1265 static const enum AVPixelFormat av1_pix_fmts[] = {
1271 };
1272 
1273 static const enum AVPixelFormat av1_pix_fmts_with_gray[] = {
1280 };
1281 
1282 static const enum AVPixelFormat av1_pix_fmts_highbd[] = {
1296 };
1297 
1315 };
1316 
1317 static av_cold void av1_init_static(FFCodec *codec)
1318 {
1319  int supports_monochrome = aom_codec_version() >= 20001;
1320  aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
1321  if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
1322  codec->p.pix_fmts = supports_monochrome ? av1_pix_fmts_highbd_with_gray :
1324  else
1325  codec->p.pix_fmts = supports_monochrome ? av1_pix_fmts_with_gray :
1326  av1_pix_fmts;
1327 
1328  if (aom_codec_version_major() < 2)
1330 }
1331 
1332 static av_cold int av1_init(AVCodecContext *avctx)
1333 {
1334  return aom_init(avctx, aom_codec_av1_cx());
1335 }
1336 
1337 #define OFFSET(x) offsetof(AOMContext, x)
1338 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1339 static const AVOption options[] = {
1340  { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 8, VE},
1341  { "auto-alt-ref", "Enable use of alternate reference "
1342  "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE},
1343  { "lag-in-frames", "Number of frames to look ahead at for "
1344  "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
1345  { "arnr-max-frames", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
1346  { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
1347  { "aq-mode", "adaptive quantization mode", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4, VE, "aq_mode"},
1348  { "none", "Aq not used", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "aq_mode"},
1349  { "variance", "Variance based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "aq_mode"},
1350  { "complexity", "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "aq_mode"},
1351  { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "aq_mode"},
1352  { "error-resilience", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"},
1353  { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"},
1354  { "crf", "Select the quality for constant quality mode", offsetof(AOMContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE },
1355  { "static-thresh", "A change threshold on blocks below which they will be skipped by the encoder", OFFSET(static_thresh), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
1356  { "drop-threshold", "Frame drop threshold", offsetof(AOMContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE },
1357  { "denoise-noise-level", "Amount of noise to be removed", OFFSET(denoise_noise_level), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
1358  { "denoise-block-size", "Denoise block size ", OFFSET(denoise_block_size), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
1359  { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100, VE},
1360  { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1000, VE},
1361  { "minsection-pct", "GOP min bitrate (% of target)", OFFSET(minsection_pct), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100, VE},
1362  { "maxsection-pct", "GOP max bitrate (% of target)", OFFSET(maxsection_pct), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 5000, VE},
1363  { "frame-parallel", "Enable frame parallel decodability features", OFFSET(frame_parallel), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1364  { "tiles", "Tile columns x rows", OFFSET(tile_cols), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, VE },
1365  { "tile-columns", "Log2 of number of tile columns to use", OFFSET(tile_cols_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
1366  { "tile-rows", "Log2 of number of tile rows to use", OFFSET(tile_rows_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
1367  { "row-mt", "Enable row based multi-threading", OFFSET(row_mt), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1368  { "enable-cdef", "Enable CDEF filtering", OFFSET(enable_cdef), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1369  { "enable-global-motion", "Enable global motion", OFFSET(enable_global_motion), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1370  { "enable-intrabc", "Enable intra block copy prediction mode", OFFSET(enable_intrabc), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1371  { "enable-restoration", "Enable Loop Restoration filtering", OFFSET(enable_restoration), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1372  { "usage", "Quality and compression efficiency vs speed trade-off", OFFSET(usage), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "usage"},
1373  { "good", "Good quality", 0, AV_OPT_TYPE_CONST, {.i64 = 0 /* AOM_USAGE_GOOD_QUALITY */}, 0, 0, VE, "usage"},
1374  { "realtime", "Realtime encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 1 /* AOM_USAGE_REALTIME */}, 0, 0, VE, "usage"},
1375  { "allintra", "All Intra encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 2 /* AOM_USAGE_ALL_INTRA */}, 0, 0, VE, "usage"},
1376  { "tune", "The metric that the encoder tunes for. Automatically chosen by the encoder by default", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, AOM_TUNE_SSIM, VE, "tune"},
1377  { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
1378  { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
1380  { "still-picture", "Encode in single frame mode (typically used for still AVIF images).", OFFSET(still_picture), AV_OPT_TYPE_BOOL, {.i64 = 0}, -1, 1, VE },
1381  { "enable-rect-partitions", "Enable rectangular partitions", OFFSET(enable_rect_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1382  { "enable-1to4-partitions", "Enable 1:4/4:1 partitions", OFFSET(enable_1to4_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1383  { "enable-ab-partitions", "Enable ab shape partitions", OFFSET(enable_ab_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1384  { "enable-angle-delta", "Enable angle delta intra prediction", OFFSET(enable_angle_delta), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1385  { "enable-cfl-intra", "Enable chroma predicted from luma intra prediction", OFFSET(enable_cfl_intra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1386  { "enable-filter-intra", "Enable filter intra predictor", OFFSET(enable_filter_intra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1387  { "enable-intra-edge-filter", "Enable intra edge filter", OFFSET(enable_intra_edge_filter), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1388  { "enable-smooth-intra", "Enable smooth intra prediction mode", OFFSET(enable_smooth_intra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1389  { "enable-paeth-intra", "Enable paeth predictor in intra prediction", OFFSET(enable_paeth_intra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1390  { "enable-palette", "Enable palette prediction mode", OFFSET(enable_palette), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1391  { "enable-flip-idtx", "Enable extended transform type", OFFSET(enable_flip_idtx), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1392  { "enable-tx64", "Enable 64-pt transform", OFFSET(enable_tx64), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1393  { "reduced-tx-type-set", "Use reduced set of transform types", OFFSET(reduced_tx_type_set), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1394  { "use-intra-dct-only", "Use DCT only for INTRA modes", OFFSET(use_intra_dct_only), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1395  { "use-inter-dct-only", "Use DCT only for INTER modes", OFFSET(use_inter_dct_only), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1396  { "use-intra-default-tx-only", "Use default-transform only for INTRA modes", OFFSET(use_intra_default_tx_only), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1397  { "enable-ref-frame-mvs", "Enable temporal mv prediction", OFFSET(enable_ref_frame_mvs), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1398  { "enable-reduced-reference-set", "Use reduced set of single and compound references", OFFSET(enable_reduced_reference_set), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1399  { "enable-obmc", "Enable obmc", OFFSET(enable_obmc), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1400  { "enable-dual-filter", "Enable dual filter", OFFSET(enable_dual_filter), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1401  { "enable-diff-wtd-comp", "Enable difference-weighted compound", OFFSET(enable_diff_wtd_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1402  { "enable-dist-wtd-comp", "Enable distance-weighted compound", OFFSET(enable_dist_wtd_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1403  { "enable-onesided-comp", "Enable one sided compound", OFFSET(enable_onesided_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1404  { "enable-interinter-wedge", "Enable interinter wedge compound", OFFSET(enable_interinter_wedge), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1405  { "enable-interintra-wedge", "Enable interintra wedge compound", OFFSET(enable_interintra_wedge), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1406  { "enable-masked-comp", "Enable masked compound", OFFSET(enable_masked_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1407  { "enable-interintra-comp", "Enable interintra compound", OFFSET(enable_interintra_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1408  { "enable-smooth-interintra", "Enable smooth interintra mode", OFFSET(enable_smooth_interintra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1409 #if AOM_ENCODER_ABI_VERSION >= 23
1410  { "aom-params", "Set libaom options using a :-separated list of key=value pairs", OFFSET(aom_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
1411 #endif
1412  { NULL },
1413 };
1414 
1415 static const FFCodecDefault defaults[] = {
1416  { "b", "0" },
1417  { "qmin", "-1" },
1418  { "qmax", "-1" },
1419  { "g", "-1" },
1420  { "keyint_min", "-1" },
1421  { NULL },
1422 };
1423 
1424 static const AVClass class_aom = {
1425  .class_name = "libaom-av1 encoder",
1426  .item_name = av_default_item_name,
1427  .option = options,
1428  .version = LIBAVUTIL_VERSION_INT,
1429 };
1430 
1432  .p.name = "libaom-av1",
1433  .p.long_name = NULL_IF_CONFIG_SMALL("libaom AV1"),
1434  .p.type = AVMEDIA_TYPE_VIDEO,
1435  .p.id = AV_CODEC_ID_AV1,
1436  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1438  .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
1439  .p.priv_class = &class_aom,
1440  .p.wrapper_name = "libaom",
1441  .priv_data_size = sizeof(AOMContext),
1442  .init = av1_init,
1444  .close = aom_free,
1445  .caps_internal = FF_CODEC_CAP_AUTO_THREADS,
1446  .defaults = defaults,
1447  .init_static_data = av1_init_static,
1448 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
AOMEncoderContext::error_resilient
int error_resilient
Definition: libaomenc.c:78
AOMEncoderContext::usage
int usage
Definition: libaomenc.c:101
dump_enc_cfg
static av_cold void dump_enc_cfg(AVCodecContext *avctx, const struct aom_codec_enc_cfg *cfg, int level)
Definition: libaomenc.c:224
AOMEncoderContext::enable_filter_intra
int enable_filter_intra
Definition: libaomenc.c:113
AOMEncoderContext::enable_paeth_intra
int enable_paeth_intra
Definition: libaomenc.c:109
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AOMEncoderContext::tile_rows_log2
int tile_rows_log2
Definition: libaomenc.c:93
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AOMEncoderContext::enable_interintra_comp
int enable_interintra_comp
Definition: libaomenc.c:123
level
uint8_t level
Definition: svq3.c:206
FrameListData::pts
int64_t pts
time stamp to show frame (in timebase units)
Definition: libaomenc.c:54
AVCodecContext::keyint_min
int keyint_min
minimum GOP size
Definition: avcodec.h:931
AOMEncoderContext::sse
uint64_t sse[4]
Definition: libaomenc.c:84
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
set_color_range
static void set_color_range(AVCodecContext *avctx)
Definition: libaomenc.c:477
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:966
AVCodecContext::rc_min_rate
int64_t rc_min_rate
minimum bitrate
Definition: avcodec.h:1221
defaults
static const FFCodecDefault defaults[]
Definition: libaomenc.c:1415
aom_init
static av_cold int aom_init(AVCodecContext *avctx, const struct aom_codec_iface *iface)
Definition: libaomenc.c:656
stats
static void stats(AVPacket *const *in, int n_in, unsigned *_max, unsigned *_sum)
Definition: vp9_superframe_bsf.c:34
AOMEncoderContext::enable_restoration
int enable_restoration
Definition: libaomenc.c:100
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2662
ff_side_data_set_encoder_stats
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
Definition: avpacket.c:602
avcodec_parameters_from_context
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:99
AOMEncoderContext::enable_smooth_intra
int enable_smooth_intra
Definition: libaomenc.c:110
AOMEncoderContext::enable_1to4_partitions
int enable_1to4_partitions
Definition: libaomenc.c:105
FF_AV1_PROFILE_OPTS
#define FF_AV1_PROFILE_OPTS
Definition: profiles.h:54
AOMEncoderContext::denoise_noise_level
int denoise_noise_level
Definition: libaomenc.c:82
av_unused
#define av_unused
Definition: attributes.h:131
AVCodec::pix_fmts
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:218
AOMEncoderContext::still_picture
int still_picture
Definition: libaomenc.c:103
AOMEncoderContext::lag_in_frames
int lag_in_frames
Definition: libaomenc.c:77
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:959
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:215
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:599
coded_frame_add
static void coded_frame_add(void *list, struct FrameListData *cx_frame)
Definition: libaomenc.c:282
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:374
AV1_MAX_TILE_ROWS
@ AV1_MAX_TILE_ROWS
Definition: av1.h:80
AOMEncoderContext::frame_number
uint64_t frame_number
Definition: libaomenc.c:86
AVOption
AVOption.
Definition: opt.h:251
encode.h
AOMEncoderContext::use_intra_default_tx_only
int use_intra_default_tx_only
Definition: libaomenc.c:119
cx_pktcpy
static void cx_pktcpy(AOMContext *ctx, struct FrameListData *dst, const struct aom_codec_cx_pkt *src)
Definition: libaomenc.c:1027
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:406
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:68
FFCodec
Definition: codec_internal.h:112
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:526
mathematics.h
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
AVDictionary
Definition: dict.c:30
AV_CODEC_FLAG_PSNR
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
Definition: avcodec.h:253
AOMEncoderContext::aom_params
AVDictionary * aom_params
Definition: libaomenc.c:132
ff_add_cpb_side_data
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:1032
AVCodecContext::qmax
int qmax
maximum quantizer
Definition: avcodec.h:1185
options
static const AVOption options[]
Definition: libaomenc.c:1339
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:53
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AV_CODEC_FLAG_GLOBAL_HEADER
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:274
init
static int init
Definition: av_tx.c:47
storeframe
static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, AVPacket *pkt)
Store coded frame information in format suitable for return from encode2().
Definition: libaomenc.c:1055
FrameListData::flags
uint32_t flags
flags for this frame
Definition: libaomenc.c:58
AOMEncoderContext::cpu_used
int cpu_used
Definition: libaomenc.c:72
FFCodecDefault
Definition: codec_internal.h:82
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:116
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:510
bsf.h
AOMEncoderContext::enable_ab_partitions
int enable_ab_partitions
Definition: libaomenc.c:106
AOMEncoderContext::coded_frame_list
struct FrameListData * coded_frame_list
Definition: libaomenc.c:71
AOMEncoderContext::static_thresh
int static_thresh
Definition: libaomenc.c:80
AV1_MAX_TILE_AREA
@ AV1_MAX_TILE_AREA
Definition: av1.h:79
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1463
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:422
AOMEncoderContext::minsection_pct
int minsection_pct
Definition: libaomenc.c:89
AOMEncoderContext::uniform_tiles
int uniform_tiles
Definition: libaomenc.c:95
AOMEncoderContext::enable_ref_frame_mvs
int enable_ref_frame_mvs
Definition: libaomenc.c:120
AOMEncoderContext::row_mt
int row_mt
Definition: libaomenc.c:96
AVCodecContext::refs
int refs
number of reference frames
Definition: avcodec.h:938
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:469
AOMEncoderContext::denoise_block_size
int denoise_block_size
Definition: libaomenc.c:83
val
static double val(void *priv, double ch)
Definition: aeval.c:77
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:263
AVRational::num
int num
Numerator.
Definition: rational.h:59
AOMEncoderContext::use_inter_dct_only
int use_inter_dct_only
Definition: libaomenc.c:118
ff_libaom_av1_encoder
FFCodec ff_libaom_av1_encoder
Definition: libaomenc.c:1431
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:409
free_coded_frame
static av_cold void free_coded_frame(struct FrameListData *cx_frame)
Definition: libaomenc.c:292
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:952
count_uniform_tiling
static int count_uniform_tiling(int dim, int sb_size, int tiles_log2)
Definition: libaomenc.c:493
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV_CODEC_CAP_EXPERIMENTAL
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: codec.h:105
av_cold
#define av_cold
Definition: attributes.h:90
AOMEncoderContext::enable_angle_delta
int enable_angle_delta
Definition: libaomenc.c:107
AVCodecContext::rc_initial_buffer_occupancy
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:1242
AOMEncoderContext::enable_cdef
int enable_cdef
Definition: libaomenc.c:97
AOMEncoderContext::enable_smooth_interintra
int enable_smooth_interintra
Definition: libaomenc.c:128
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
AOMEncoderContext::twopass_stats
struct aom_fixed_buf twopass_stats
Definition: libaomenc.c:70
width
#define width
queue_frames
static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
Queue multiple output frames from the encoder, returning the front-most.
Definition: libaomenc.c:1117
AVCodecContext::stats_in
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:1264
codecctl_int
static av_cold int codecctl_int(AVCodecContext *avctx, enum aome_enc_control_id id, int val)
Definition: libaomenc.c:309
AVDictionaryEntry::key
char * key
Definition: dict.h:80
AVCodecContext::ticks_per_frame
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:521
AV_CODEC_CAP_OTHER_THREADS
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:127
FrameListData::sse
uint64_t sse[4]
Definition: libaomenc.c:59
AOMEncoderContext::enable_interintra_wedge
int enable_interintra_wedge
Definition: libaomenc.c:122
FF_PROFILE_UNKNOWN
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:1548
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AOMEncoderContext::have_sse
int have_sse
true if we have pending sse[]
Definition: libaomenc.c:85
AOMEncoderContext::enable_obmc
int enable_obmc
Definition: libaomenc.c:125
FrameListData::frame_number
uint64_t frame_number
Definition: libaomenc.c:61
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
set_pix_fmt
static int set_pix_fmt(AVCodecContext *avctx, aom_codec_caps_t codec_caps, struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *flags, aom_img_fmt_t *img_fmt)
Definition: libaomenc.c:411
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ff_av1_profiles
const AVProfile ff_av1_profiles[]
Definition: profiles.c:147
tile_cols
int tile_cols
Definition: h265_levels.c:218
av_bsf_alloc
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
Definition: bsf.c:105
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AVCodecContext::rc_max_rate
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1214
AOMEncoderContext::superblock_size
aom_superblock_size_t superblock_size
Definition: libaomenc.c:94
AVCodecContext::error
uint64_t error[AV_NUM_DATA_POINTERS]
error
Definition: avcodec.h:1397
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: defs.h:104
AOMEncoderContext::enable_dist_wtd_comp
int enable_dist_wtd_comp
Definition: libaomenc.c:130
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:387
AVCodecContext::rc_buffer_size
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:1199
AOMEncoderContext::drop_threshold
int drop_threshold
Definition: libaomenc.c:81
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_bsf_init
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:150
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
AOMEncoderContext::tile_rows
int tile_rows
Definition: libaomenc.c:92
NULL
#define NULL
Definition: coverity.c:32
AOMEncoderContext
Definition: libaomenc.c:65
AOMEncoderContext::rc_overshoot_pct
int rc_overshoot_pct
Definition: libaomenc.c:88
AOMEncoderContext::enable_diff_wtd_comp
int enable_diff_wtd_comp
Definition: libaomenc.c:129
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:973
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:279
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:231
AOMEncoderContext::enable_palette
int enable_palette
Definition: libaomenc.c:112
AOMEncoderContext::arnr_max_frames
int arnr_max_frames
Definition: libaomenc.c:74
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:439
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Definition: opt.h:232
AOMEncoderContext::enable_tx64
int enable_tx64
Definition: libaomenc.c:115
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:473
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
profiles.h
list
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
Definition: filter_design.txt:25
FrameListData::buf
void * buf
compressed data buffer
Definition: libaomenc.c:52
AV_ROUND_NEAR_INF
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
Definition: mathematics.h:84
AOMEncoderContext::rc_undershoot_pct
int rc_undershoot_pct
Definition: libaomenc.c:87
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:407
AV1_MAX_TILE_COLS
@ AV1_MAX_TILE_COLS
Definition: av1.h:81
av_base64_decode
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
Definition: base64.c:81
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
base64.h
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:565
AOMEncoderContext::enable_global_motion
int enable_global_motion
Definition: libaomenc.c:98
AOMEncoderContext::encoder
struct aom_codec_ctx encoder
Definition: libaomenc.c:68
av1_init
static av_cold int av1_init(AVCodecContext *avctx)
Definition: libaomenc.c:1332
AOMEncoderContext::enable_onesided_comp
int enable_onesided_comp
Definition: libaomenc.c:126
av_cpu_count
int av_cpu_count(void)
Definition: cpu.c:195
usage
const char * usage
Definition: floatimg_cmp.c:60
AVCodecContext::qcompress
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
Definition: avcodec.h:1170
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:512
av_rescale_rnd
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
Definition: mathematics.c:58
FrameListData::next
struct FrameListData * next
Definition: libaomenc.c:62
AVCodecContext::stats_out
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:1256
ctlidstr
static const char *const ctlidstr[]
Definition: libaomenc.c:135
FF_PROFILE_AV1_MAIN
#define FF_PROFILE_AV1_MAIN
Definition: avcodec.h:1643
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:375
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:584
codec_internal.h
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
AOMEncoderContext::enable_flip_idtx
int enable_flip_idtx
Definition: libaomenc.c:114
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:203
cpu.h
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:411
size
int size
Definition: twinvq_data.h:10344
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:186
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:413
aom_encode
static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: libaomenc.c:1209
AVCPBProperties::min_bitrate
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
Definition: defs.h:114
av1.h
FrameListData
Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
Definition: libaomenc.c:51
AOMEncoderContext::tile_cols_log2
int tile_cols_log2
Definition: libaomenc.c:93
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
AV_CODEC_FLAG_PASS2
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:241
AOMEncoderContext::tile_cols
int tile_cols
Definition: libaomenc.c:92
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
AOMEncoderContext::rawimg
struct aom_image rawimg
Definition: libaomenc.c:69
AVCPBProperties::avg_bitrate
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
Definition: defs.h:119
AOMEncoderContext::enable_dual_filter
int enable_dual_filter
Definition: libaomenc.c:131
AOMEncoderContext::aq_mode
int aq_mode
Definition: libaomenc.c:76
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
AOMEncoderContext::enable_cfl_intra
int enable_cfl_intra
Definition: libaomenc.c:108
AV_BASE64_SIZE
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
Definition: base64.h:66
AOMEncoderContext::arnr_strength
int arnr_strength
Definition: libaomenc.c:75
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:423
AOMEncoderContext::enable_interinter_wedge
int enable_interinter_wedge
Definition: libaomenc.c:121
common.h
AVCPBProperties::max_bitrate
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition: defs.h:109
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:203
AVCodecContext::height
int height
Definition: avcodec.h:562
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:599
FrameListData::duration
unsigned long duration
duration to show frame (in timebase units)
Definition: libaomenc.c:56
AOMEncoderContext::auto_alt_ref
int auto_alt_ref
Definition: libaomenc.c:73
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:582
FF_PROFILE_AV1_PROFESSIONAL
#define FF_PROFILE_AV1_PROFESSIONAL
Definition: avcodec.h:1645
avcodec.h
dim
int dim
Definition: vorbis_enc_data.h:425
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
av1_pix_fmts_with_gray
static enum AVPixelFormat av1_pix_fmts_with_gray[]
Definition: libaomenc.c:1273
AVCPBProperties::buffer_size
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition: defs.h:125
AOMEncoderContext::bsf
AVBSFContext * bsf
Definition: libaomenc.c:67
log_encoder_error
static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
Definition: libaomenc.c:213
AV1_MAX_TILE_WIDTH
@ AV1_MAX_TILE_WIDTH
Definition: av1.h:78
VE
#define VE
Definition: libaomenc.c:1338
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:410
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:195
free_frame_list
static av_cold void free_frame_list(struct FrameListData *list)
Definition: libaomenc.c:298
AVCodecContext
main external API structure.
Definition: avcodec.h:389
AOMEncoderContext::enable_rect_partitions
int enable_rect_partitions
Definition: libaomenc.c:104
AVBitStreamFilter
Definition: bsf.h:111
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:79
AVCodecContext::qmin
int qmin
minimum quantizer
Definition: avcodec.h:1178
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1547
choose_tiling
static int choose_tiling(AVCodecContext *avctx, struct aom_codec_enc_cfg *enccfg)
Definition: libaomenc.c:501
AOMEncoderContext::maxsection_pct
int maxsection_pct
Definition: libaomenc.c:90
av_base64_encode
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
Definition: base64.c:145
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:82
AOMEncoderContext::enable_intra_edge_filter
int enable_intra_edge_filter
Definition: libaomenc.c:111
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
class_aom
static const AVClass class_aom
Definition: libaomenc.c:1424
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
desc
const char * desc
Definition: libsvtav1.c:83
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
av1_init_static
static av_cold void av1_init_static(FFCodec *codec)
Definition: libaomenc.c:1317
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
packet_internal.h
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:70
av1_pix_fmts
static enum AVPixelFormat av1_pix_fmts[]
Definition: libaomenc.c:1265
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AOMEncoderContext::enable_reduced_reference_set
int enable_reduced_reference_set
Definition: libaomenc.c:127
AVDictionaryEntry
Definition: dict.h:79
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AOMEncoderContext::frame_parallel
int frame_parallel
Definition: libaomenc.c:91
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:416
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
av1_pix_fmts_highbd
static enum AVPixelFormat av1_pix_fmts_highbd[]
Definition: libaomenc.c:1282
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:562
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:224
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AOMEncoderContext::enable_masked_comp
int enable_masked_comp
Definition: libaomenc.c:124
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FrameListData::sz
size_t sz
length of compressed data
Definition: libaomenc.c:53
AOMEncoderContext::reduced_tx_type_set
int reduced_tx_type_set
Definition: libaomenc.c:116
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
FF_PROFILE_AV1_HIGH
#define FF_PROFILE_AV1_HIGH
Definition: avcodec.h:1644
AVDictionaryEntry::value
char * value
Definition: dict.h:81
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:388
AOMEncoderContext::enable_intrabc
int enable_intrabc
Definition: libaomenc.c:99
aom_free
static av_cold int aom_free(AVCodecContext *avctx)
Definition: libaomenc.c:367
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
snprintf
#define snprintf
Definition: snprintf.h:34
AOMEncoderContext::tune
int tune
Definition: libaomenc.c:102
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
AOMEncoderContext::crf
int crf
Definition: libaomenc.c:79
OFFSET
#define OFFSET(x)
Definition: libaomenc.c:1337
AOMEncoderContext::use_intra_dct_only
int use_intra_dct_only
Definition: libaomenc.c:117
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:237
av_bsf_get_by_name
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Definition: bitstream_filters.c:81
FrameListData::have_sse
int have_sse
true if we have pending sse[]
Definition: libaomenc.c:60
av1_pix_fmts_highbd_with_gray
static enum AVPixelFormat av1_pix_fmts_highbd_with_gray[]
Definition: libaomenc.c:1298