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