FFmpeg
Loading...
Searching...
No Matches
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#include <stdlib.h>
28
29#define AOM_DISABLE_CTRL_TYPECHECKS 1
30#include <aom/aom_encoder.h>
31#include <aom/aomcx.h>
32
33#include "libavutil/avassert.h"
34#include "libavutil/base64.h"
35#include "libavutil/cpu.h"
36#include "libavutil/dict.h"
38#include "libavutil/imgutils.h"
40#include "libavutil/mem.h"
41#include "libavutil/opt.h"
42#include "libavutil/pixdesc.h"
43
44#include "av1.h"
45#include "avcodec.h"
46#include "bsf.h"
47#include "bytestream.h"
48#include "codec_internal.h"
49#include "dovi_rpu.h"
50#include "encode.h"
51#include "internal.h"
52#include "itut35.h"
53#include "libaom.h"
54#include "profiles.h"
55#include "qpfile_parser.h"
56
57/*
58 * Portion of struct aom_codec_cx_pkt from aom_encoder.h.
59 * One encoded frame returned from the library.
60 */
62 void *buf; /**< compressed data buffer */
63 size_t sz; /**< length of compressed data */
64 int64_t pts; /**< time stamp to show frame
65 (in timebase units) */
66 unsigned long duration; /**< duration to show frame
67 (in timebase units) */
68 uint32_t flags; /**< flags for this frame */
69 uint64_t sse[4];
70 int have_sse; /**< true if we have pending sse[] */
71 uint64_t frame_number;
73};
74
75/* libaom 3.15.3 applies ROI maps only in realtime usage at cpu-used >= 7
76 * without lookahead (measured: lower speeds, good usage and a nonzero
77 * lag-in-frames ignore the map content). */
78#define QPFILE_AOM_USAGE_REALTIME 1 /* AOM_USAGE_REALTIME */
79#define QPFILE_AOM_MIN_CPU_USED 7
80
81typedef struct AOMEncoderContext {
82 AVClass *class;
85 struct aom_codec_ctx encoder;
86 struct aom_codec_enc_cfg enccfg;
87 struct aom_image rawimg;
88 aom_codec_flags_t flags;
89 aom_img_fmt_t img_fmt;
90 struct aom_fixed_buf twopass_stats;
100 int crf;
105 uint64_t sse[4];
106 int have_sse; /**< true if we have pending sse[] */
107 uint64_t frame_number;
115 aom_superblock_size_t superblock_size;
123
124 /* qpfile -> libaom AOME_SET_ROI_MAP ROI map.
125 * Populated by ff_qpfile_load() in aom_init() when qpfile_path is set,
126 * consumed per-frame in aom_encode(), released in aom_free().
127 *
128 * libaom requires the segment-id map to match its mode-info grid
129 * exactly: rows == mi_rows, cols == mi_cols (4x4-luma cells; see
130 * av1/encoder/encoder.c::av1_set_roi_map). The qpfile rows are at
131 * 16x16-MB granularity, so each MB cell expands into a 4x4 block of
132 * mi cells. delta_q[8] holds up to AOM_MAX_SEGMENTS distinct QP
133 * deltas; per-frame qp_offsets are quantised into <=8 segment ids
134 * (uniform binning when more distinct values than segments exist).
135 *
136 * roi_seg_map is allocated once at the encoder grid size; libaom
137 * deep-copies it on every aom_codec_control() call, so the buffer
138 * can be reused across frames.
139 */
142 uint8_t *roi_seg_map;
143 unsigned int roi_mi_rows;
144 unsigned int roi_mi_cols;
145 unsigned int roi_input_frame; /* input frames seen: the qpfile's frame index */
146 const FFQpFrame *roi_qf; /* record the cached map was built from */
147 int roi_cached; /* roi_qf, roi_seg_q and roi_n_seg are valid */
148 int roi_seg_q[AOM_MAX_SEGMENTS];
149 unsigned int roi_n_seg;
150
151 int usage;
152 int tune;
183} AOMContext;
184
185#define OFFSET(x) offsetof(AOMContext, x)
186
187static const char *const ctlidstr[] = {
188 [AOME_SET_CPUUSED] = "AOME_SET_CPUUSED",
189 [AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL",
190 [AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF",
191 [AOME_SET_ARNR_MAXFRAMES] = "AOME_SET_ARNR_MAXFRAMES",
192 [AOME_SET_ARNR_STRENGTH] = "AOME_SET_ARNR_STRENGTH",
193 [AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD",
194 [AV1E_SET_COLOR_RANGE] = "AV1E_SET_COLOR_RANGE",
195 [AV1E_SET_COLOR_PRIMARIES] = "AV1E_SET_COLOR_PRIMARIES",
196 [AV1E_SET_MATRIX_COEFFICIENTS] = "AV1E_SET_MATRIX_COEFFICIENTS",
197 [AV1E_SET_TRANSFER_CHARACTERISTICS] = "AV1E_SET_TRANSFER_CHARACTERISTICS",
198 [AV1E_SET_AQ_MODE] = "AV1E_SET_AQ_MODE",
199 [AV1E_SET_FRAME_PARALLEL_DECODING] = "AV1E_SET_FRAME_PARALLEL_DECODING",
200 [AV1E_SET_SUPERBLOCK_SIZE] = "AV1E_SET_SUPERBLOCK_SIZE",
201 [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
202 [AV1E_SET_TILE_ROWS] = "AV1E_SET_TILE_ROWS",
203 [AV1E_SET_ENABLE_RESTORATION] = "AV1E_SET_ENABLE_RESTORATION",
204 [AV1E_SET_ROW_MT] = "AV1E_SET_ROW_MT",
205 [AV1E_SET_DENOISE_NOISE_LEVEL] = "AV1E_SET_DENOISE_NOISE_LEVEL",
206 [AV1E_SET_DENOISE_BLOCK_SIZE] = "AV1E_SET_DENOISE_BLOCK_SIZE",
207 [AV1E_SET_MAX_REFERENCE_FRAMES] = "AV1E_SET_MAX_REFERENCE_FRAMES",
208 [AV1E_SET_ENABLE_GLOBAL_MOTION] = "AV1E_SET_ENABLE_GLOBAL_MOTION",
209 [AV1E_SET_ENABLE_INTRABC] = "AV1E_SET_ENABLE_INTRABC",
210 [AV1E_SET_ENABLE_CDEF] = "AV1E_SET_ENABLE_CDEF",
211 [AOME_SET_TUNING] = "AOME_SET_TUNING",
212 [AV1E_SET_ENABLE_1TO4_PARTITIONS] = "AV1E_SET_ENABLE_1TO4_PARTITIONS",
213 [AV1E_SET_ENABLE_AB_PARTITIONS] = "AV1E_SET_ENABLE_AB_PARTITIONS",
214 [AV1E_SET_ENABLE_RECT_PARTITIONS] = "AV1E_SET_ENABLE_RECT_PARTITIONS",
215 [AV1E_SET_ENABLE_ANGLE_DELTA] = "AV1E_SET_ENABLE_ANGLE_DELTA",
216 [AV1E_SET_ENABLE_CFL_INTRA] = "AV1E_SET_ENABLE_CFL_INTRA",
217 [AV1E_SET_ENABLE_FILTER_INTRA] = "AV1E_SET_ENABLE_FILTER_INTRA",
218 [AV1E_SET_ENABLE_INTRA_EDGE_FILTER] = "AV1E_SET_ENABLE_INTRA_EDGE_FILTER",
219 [AV1E_SET_ENABLE_PAETH_INTRA] = "AV1E_SET_ENABLE_PAETH_INTRA",
220 [AV1E_SET_ENABLE_SMOOTH_INTRA] = "AV1E_SET_ENABLE_SMOOTH_INTRA",
221 [AV1E_SET_ENABLE_PALETTE] = "AV1E_SET_ENABLE_PALETTE",
222 [AV1E_SET_ENABLE_FLIP_IDTX] = "AV1E_SET_ENABLE_FLIP_IDTX",
223 [AV1E_SET_ENABLE_TX64] = "AV1E_SET_ENABLE_TX64",
224 [AV1E_SET_INTRA_DCT_ONLY] = "AV1E_SET_INTRA_DCT_ONLY",
225 [AV1E_SET_INTER_DCT_ONLY] = "AV1E_SET_INTER_DCT_ONLY",
226 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] = "AV1E_SET_INTRA_DEFAULT_TX_ONLY",
227 [AV1E_SET_REDUCED_TX_TYPE_SET] = "AV1E_SET_REDUCED_TX_TYPE_SET",
228 [AV1E_SET_ENABLE_DIFF_WTD_COMP] = "AV1E_SET_ENABLE_DIFF_WTD_COMP",
229 [AV1E_SET_ENABLE_DIST_WTD_COMP] = "AV1E_SET_ENABLE_DIST_WTD_COMP",
230 [AV1E_SET_ENABLE_DUAL_FILTER] = "AV1E_SET_ENABLE_DUAL_FILTER",
231 [AV1E_SET_ENABLE_INTERINTER_WEDGE] = "AV1E_SET_ENABLE_INTERINTER_WEDGE",
232 [AV1E_SET_ENABLE_INTERINTRA_WEDGE] = "AV1E_SET_ENABLE_INTERINTRA_WEDGE",
233 [AV1E_SET_ENABLE_MASKED_COMP] = "AV1E_SET_ENABLE_MASKED_COMP",
234 [AV1E_SET_ENABLE_INTERINTRA_COMP] = "AV1E_SET_ENABLE_INTERINTRA_COMP",
235 [AV1E_SET_ENABLE_OBMC] = "AV1E_SET_ENABLE_OBMC",
236 [AV1E_SET_ENABLE_ONESIDED_COMP] = "AV1E_SET_ENABLE_ONESIDED_COMP",
237 [AV1E_SET_REDUCED_REFERENCE_SET] = "AV1E_SET_REDUCED_REFERENCE_SET",
238 [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] = "AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
239 [AV1E_SET_ENABLE_REF_FRAME_MVS] = "AV1E_SET_ENABLE_REF_FRAME_MVS",
240#ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS
241 [AV1E_GET_NUM_OPERATING_POINTS] = "AV1E_GET_NUM_OPERATING_POINTS",
242#endif
243 [AV1E_GET_SEQ_LEVEL_IDX] = "AV1E_GET_SEQ_LEVEL_IDX",
244#ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
245 [AV1E_GET_TARGET_SEQ_LEVEL_IDX] = "AV1E_GET_TARGET_SEQ_LEVEL_IDX",
246#endif
247 [AV1_GET_NEW_FRAME_IMAGE] = "AV1_GET_NEW_FRAME_IMAGE",
248};
249
250static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
251{
252 AOMContext *ctx = avctx->priv_data;
253 const char *error = aom_codec_error(&ctx->encoder);
254 const char *detail = aom_codec_error_detail(&ctx->encoder);
255
256 av_log(avctx, AV_LOG_ERROR, "%s: %s\n", desc, error);
257 if (detail)
258 av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n", detail);
259}
260
262 const struct aom_codec_enc_cfg *cfg,
263 int level)
264{
265 int width = -30;
266
267 av_log(avctx, level, "aom_codec_enc_cfg\n");
268 av_log(avctx, level, "generic settings\n"
269 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
270 " %*s%u\n %*s%u\n"
271 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
272 width, "g_usage:", cfg->g_usage,
273 width, "g_threads:", cfg->g_threads,
274 width, "g_profile:", cfg->g_profile,
275 width, "g_w:", cfg->g_w,
276 width, "g_h:", cfg->g_h,
277 width, "g_bit_depth:", cfg->g_bit_depth,
278 width, "g_input_bit_depth:", cfg->g_input_bit_depth,
279 width, "g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
280 width, "g_error_resilient:", cfg->g_error_resilient,
281 width, "g_pass:", cfg->g_pass,
282 width, "g_lag_in_frames:", cfg->g_lag_in_frames);
283 av_log(avctx, level, "rate control settings\n"
284 " %*s%u\n %*s%d\n %*s%p(%zu)\n %*s%u\n",
285 width, "rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
286 width, "rc_end_usage:", cfg->rc_end_usage,
287 width, "rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
288 width, "rc_target_bitrate:", cfg->rc_target_bitrate);
289 av_log(avctx, level, "quantizer settings\n"
290 " %*s%u\n %*s%u\n",
291 width, "rc_min_quantizer:", cfg->rc_min_quantizer,
292 width, "rc_max_quantizer:", cfg->rc_max_quantizer);
293 av_log(avctx, level, "bitrate tolerance\n"
294 " %*s%u\n %*s%u\n",
295 width, "rc_undershoot_pct:", cfg->rc_undershoot_pct,
296 width, "rc_overshoot_pct:", cfg->rc_overshoot_pct);
297 av_log(avctx, level, "decoder buffer model\n"
298 " %*s%u\n %*s%u\n %*s%u\n",
299 width, "rc_buf_sz:", cfg->rc_buf_sz,
300 width, "rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
301 width, "rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
302 av_log(avctx, level, "2 pass rate control settings\n"
303 " %*s%u\n %*s%u\n %*s%u\n",
304 width, "rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
305 width, "rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
306 width, "rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
307 av_log(avctx, level, "keyframing settings\n"
308 " %*s%d\n %*s%u\n %*s%u\n",
309 width, "kf_mode:", cfg->kf_mode,
310 width, "kf_min_dist:", cfg->kf_min_dist,
311 width, "kf_max_dist:", cfg->kf_max_dist);
312 av_log(avctx, level, "tile settings\n"
313 " %*s%d\n %*s%d\n",
314 width, "tile_width_count:", cfg->tile_width_count,
315 width, "tile_height_count:", cfg->tile_height_count);
316 av_log(avctx, level, "\n");
317}
318
319static void coded_frame_add(void *list, struct FrameListData *cx_frame)
320{
321 struct FrameListData **p = list;
322
323 while (*p)
324 p = &(*p)->next;
325 *p = cx_frame;
326 cx_frame->next = NULL;
327}
328
329static av_cold void free_coded_frame(struct FrameListData *cx_frame)
330{
331 av_freep(&cx_frame->buf);
332 av_freep(&cx_frame);
333}
334
336{
337 struct FrameListData *p = list;
338
339 while (p) {
340 list = list->next;
342 p = list;
343 }
344}
345
347 int id,
348 int val)
349{
350 AOMContext *ctx = avctx->priv_data;
351 char buf[80];
352 int width = -30;
353 int res;
354
355 snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
356 av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, val);
357
358 res = aom_codec_control(&ctx->encoder, id, val);
359 if (res != AOM_CODEC_OK) {
360 snprintf(buf, sizeof(buf), "Failed to set %s codec control",
361 ctlidstr[id]);
362 log_encoder_error(avctx, buf);
363 return AVERROR(EINVAL);
364 }
365
366 return 0;
367}
368
369static int add_hdr_plus(AVCodecContext *avctx, struct aom_image *img, const AVFrame *frame)
370{
371 // Check for HDR10+
372 AVFrameSideData *side_data =
374 if (!side_data)
375 return 0;
376
377 size_t payload_size;
378 AVDynamicHDRPlus *hdr_plus = (AVDynamicHDRPlus *)side_data->buf->data;
379 int res = av_dynamic_hdr_plus_to_t35(hdr_plus, NULL, &payload_size);
380 if (res < 0) {
381 log_encoder_error(avctx, "Error finding the size of HDR10+");
382 return res;
383 }
384
385 uint8_t *hdr_plus_buf;
386 // Extra bytes for the country code, provider code, provider oriented code and app id.
387 const size_t hdr_plus_buf_size = payload_size + 6;
388 hdr_plus_buf = av_malloc(hdr_plus_buf_size);
389 if (!hdr_plus_buf)
390 return AVERROR(ENOMEM);
391
392 uint8_t *payload = hdr_plus_buf;
393 // See "HDR10+ AV1 Metadata Handling Specification" v1.0.1, Section 2.1.
394 bytestream_put_byte(&payload, ITU_T_T35_COUNTRY_CODE_US);
395 bytestream_put_be16(&payload, ITU_T_T35_PROVIDER_CODE_SAMSUNG);
396 bytestream_put_be16(&payload, 0x0001); // provider_oriented_code
397 bytestream_put_byte(&payload, 0x04); // application_identifier
398
399 res = av_dynamic_hdr_plus_to_t35(hdr_plus, &payload, &payload_size);
400 if (res < 0) {
401 av_free(hdr_plus_buf);
402 log_encoder_error(avctx, "Error encoding HDR10+ from side data");
403 return res;
404 }
405
406 res = aom_img_add_metadata(img, OBU_METADATA_TYPE_ITUT_T35,
407 hdr_plus_buf, hdr_plus_buf_size, AOM_MIF_ANY_FRAME);
408 av_free(hdr_plus_buf);
409 if (res < 0) {
410 log_encoder_error(avctx, "Error adding HDR10+ to aom_img");
411 return res;
412 }
413 return 0;
414}
415
416static int add_hdr_smpte2094_app5(AVCodecContext *avctx, struct aom_image *img,
417 const AVFrame *frame)
418{
419 AVFrameSideData *side_data =
421 if (!side_data)
422 return 0;
423
424 size_t payload_size;
426 int res = av_dynamic_hdr_smpte2094_app5_to_t35(hdr, NULL, &payload_size);
427 if (res < 0) {
428 log_encoder_error(avctx, "Error finding the size of HDR SMPTE-2094-50");
429 return res;
430 }
431
432 uint8_t *hdr_buf;
433 // Extra bytes for the country code, provider code, provider oriented code.
434 const size_t hdr_buf_size = payload_size + 5;
435 hdr_buf = av_malloc(hdr_buf_size);
436 if (!hdr_buf)
437 return AVERROR(ENOMEM);
438
439 uint8_t *payload = hdr_buf;
440 bytestream_put_byte(&payload, ITU_T_T35_COUNTRY_CODE_US);
441 bytestream_put_be16(&payload, ITU_T_T35_PROVIDER_CODE_SMPTE);
442 bytestream_put_be16(&payload, 0x0001); // provider_oriented_code
443
444 res = av_dynamic_hdr_smpte2094_app5_to_t35(hdr, &payload, &payload_size);
445 if (res < 0) {
446 av_free(hdr_buf);
447 log_encoder_error(avctx, "Error encoding HDR SMPTE-2094-50 from side data");
448 return res;
449 }
450
451 res = aom_img_add_metadata(img, OBU_METADATA_TYPE_ITUT_T35,
452 hdr_buf, hdr_buf_size, AOM_MIF_ANY_FRAME);
453 av_free(hdr_buf);
454 if (res < 0) {
455 log_encoder_error(avctx, "Error adding HDR SMPTE-2094-50 to aom_img");
456 return res;
457 }
458 return 0;
459}
460
461#if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
462 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
463 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
464static av_cold int codecctl_intp(AVCodecContext *avctx,
465 int id,
466 int* ptr)
467{
468 AOMContext *ctx = avctx->priv_data;
469 char buf[80];
470 int width = -30;
471 int res;
472
473 res = aom_codec_control(&ctx->encoder, id, ptr);
474 if (res != AOM_CODEC_OK) {
475 snprintf(buf, sizeof(buf), "Failed to get %s codec control",
476 ctlidstr[id]);
477 log_encoder_error(avctx, buf);
478 return AVERROR(EINVAL);
479 }
480
481 snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
482 av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, *ptr);
483
484 return 0;
485}
486#endif
487
489 int id,
490 struct aom_image *img)
491{
492 AOMContext *ctx = avctx->priv_data;
493 char buf[80];
494 int res;
495
496 snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
497
498 res = aom_codec_control(&ctx->encoder, id, img);
499 if (res != AOM_CODEC_OK) {
500 snprintf(buf, sizeof(buf), "Failed to get %s codec control",
501 ctlidstr[id]);
502 log_encoder_error(avctx, buf);
503 return AVERROR(EINVAL);
504 }
505
506 return 0;
507}
508
510{
511 AOMContext *ctx = avctx->priv_data;
512
513#if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
514 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
515 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
516 if (ctx->encoder.iface && !(avctx->flags & AV_CODEC_FLAG_PASS1)) {
517 int num_operating_points;
518 int levels[32];
519 int target_levels[32];
520
521 if (!codecctl_intp(avctx, AV1E_GET_NUM_OPERATING_POINTS,
522 &num_operating_points) &&
523 !codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) &&
524 !codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX,
525 target_levels)) {
526 for (int i = 0; i < num_operating_points; i++) {
527 if (levels[i] > target_levels[i]) {
528 // Warn when the target level was not met
529 av_log(avctx, AV_LOG_WARNING,
530 "Could not encode to target level %d.%d for "
531 "operating point %d. The output level is %d.%d.\n",
532 2 + (target_levels[i] >> 2), target_levels[i] & 3,
533 i, 2 + (levels[i] >> 2), levels[i] & 3);
534 } else if (target_levels[i] < 31) {
535 // Log the encoded level if a target level was given
536 av_log(avctx, AV_LOG_INFO,
537 "Output level for operating point %d is %d.%d.\n",
538 i, 2 + (levels[i] >> 2), levels[i] & 3);
539 }
540 }
541 }
542 }
543#endif
544
545 aom_codec_destroy(&ctx->encoder);
546 aom_img_remove_metadata(&ctx->rawimg);
547 if (ctx->qpfile_loaded) {
548 ff_qpfile_free(&ctx->qpfile);
549 ctx->qpfile_loaded = 0;
550 }
551 av_freep(&ctx->roi_seg_map);
552 ctx->roi_mi_rows = 0;
553 ctx->roi_mi_cols = 0;
554 ctx->roi_input_frame = 0;
555 ctx->roi_qf = NULL;
556 ctx->roi_cached = 0;
557 ctx->roi_n_seg = 0;
558 av_freep(&ctx->twopass_stats.buf);
559 av_freep(&avctx->stats_out);
560 free_frame_list(ctx->coded_frame_list);
561 av_bsf_free(&ctx->bsf);
562 ff_dovi_ctx_unref(&ctx->dovi);
563 return 0;
564}
565
566static int set_pix_fmt(AVCodecContext *avctx, aom_codec_caps_t codec_caps,
567 struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *flags,
568 aom_img_fmt_t *img_fmt)
569{
571 enccfg->g_bit_depth = enccfg->g_input_bit_depth = desc->comp[0].depth;
572 switch (avctx->pix_fmt) {
573 case AV_PIX_FMT_GRAY8:
574 enccfg->monochrome = 1;
577 enccfg->g_profile = AV_PROFILE_AV1_MAIN;
578 *img_fmt = AOM_IMG_FMT_I420;
579 return 0;
581 enccfg->g_profile = AV_PROFILE_AV1_PROFESSIONAL;
582 *img_fmt = AOM_IMG_FMT_I422;
583 return 0;
585 case AV_PIX_FMT_GBRP:
586 enccfg->g_profile = AV_PROFILE_AV1_HIGH;
587 *img_fmt = AOM_IMG_FMT_I444;
588 return 0;
591 enccfg->monochrome = 1;
595 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
596 enccfg->g_profile =
597 enccfg->g_bit_depth == 10 ? AV_PROFILE_AV1_MAIN : AV_PROFILE_AV1_PROFESSIONAL;
598 *img_fmt = AOM_IMG_FMT_I42016;
599 *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
600 return 0;
601 }
602 break;
605 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
606 enccfg->g_profile = AV_PROFILE_AV1_PROFESSIONAL;
607 *img_fmt = AOM_IMG_FMT_I42216;
608 *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
609 return 0;
610 }
611 break;
616 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
617 enccfg->g_profile =
618 enccfg->g_bit_depth == 10 ? AV_PROFILE_AV1_HIGH : AV_PROFILE_AV1_PROFESSIONAL;
619 *img_fmt = AOM_IMG_FMT_I44416;
620 *flags |= AOM_CODEC_USE_HIGHBITDEPTH;
621 return 0;
622 }
623 break;
624 default:
625 break;
626 }
627 av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
628 return AVERROR_INVALIDDATA;
629}
630
632{
633 aom_color_range_t aom_cr;
634 switch (avctx->color_range) {
636 case AVCOL_RANGE_MPEG: aom_cr = AOM_CR_STUDIO_RANGE; break;
637 case AVCOL_RANGE_JPEG: aom_cr = AOM_CR_FULL_RANGE; break;
638 default:
639 av_log(avctx, AV_LOG_WARNING, "Unsupported color range (%d)\n",
640 avctx->color_range);
641 return;
642 }
643
644 codecctl_int(avctx, AV1E_SET_COLOR_RANGE, aom_cr);
645}
646
647static int count_uniform_tiling(int dim, int sb_size, int tiles_log2)
648{
649 int sb_dim = (dim + sb_size - 1) / sb_size;
650 int tile_dim = (sb_dim + (1 << tiles_log2) - 1) >> tiles_log2;
651 av_assert0(tile_dim > 0);
652 return (sb_dim + tile_dim - 1) / tile_dim;
653}
654
656 struct aom_codec_enc_cfg *enccfg)
657{
658 AOMContext *ctx = avctx->priv_data;
659 int sb_128x128_possible, sb_size, sb_width, sb_height;
660 int uniform_rows, uniform_cols;
661 int uniform_64x64_possible, uniform_128x128_possible;
662 int tile_size, rounding, i;
663
664 if (ctx->tile_cols_log2 >= 0)
665 ctx->tile_cols = 1 << ctx->tile_cols_log2;
666 if (ctx->tile_rows_log2 >= 0)
667 ctx->tile_rows = 1 << ctx->tile_rows_log2;
668
669 if (ctx->tile_cols == 0) {
670 ctx->tile_cols = (avctx->width + AV1_MAX_TILE_WIDTH - 1) /
672 if (ctx->tile_cols > 1) {
673 av_log(avctx, AV_LOG_DEBUG, "Automatically using %d tile "
674 "columns to fill width.\n", ctx->tile_cols);
675 }
676 }
677 av_assert0(ctx->tile_cols > 0);
678 if (ctx->tile_rows == 0) {
679 int max_tile_width =
680 FFALIGN((FFALIGN(avctx->width, 128) +
681 ctx->tile_cols - 1) / ctx->tile_cols, 128);
682 ctx->tile_rows =
683 (max_tile_width * FFALIGN(avctx->height, 128) +
685 if (ctx->tile_rows > 1) {
686 av_log(avctx, AV_LOG_DEBUG, "Automatically using %d tile "
687 "rows to fill area.\n", ctx->tile_rows);
688 }
689 }
690 av_assert0(ctx->tile_rows > 0);
691
692 if ((avctx->width + 63) / 64 < ctx->tile_cols ||
693 (avctx->height + 63) / 64 < ctx->tile_rows) {
694 av_log(avctx, AV_LOG_ERROR, "Invalid tile sizing: frame not "
695 "large enough to fit specified tile arrangement.\n");
696 return AVERROR(EINVAL);
697 }
698 if (ctx->tile_cols > AV1_MAX_TILE_COLS ||
699 ctx->tile_rows > AV1_MAX_TILE_ROWS) {
700 av_log(avctx, AV_LOG_ERROR, "Invalid tile sizing: AV1 does "
701 "not allow more than %dx%d tiles.\n",
703 return AVERROR(EINVAL);
704 }
705 if (avctx->width / ctx->tile_cols > AV1_MAX_TILE_WIDTH) {
706 av_log(avctx, AV_LOG_ERROR, "Invalid tile sizing: AV1 does "
707 "not allow tiles of width greater than %d.\n",
709 return AVERROR(EINVAL);
710 }
711
712 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
713
714 if (ctx->tile_cols == 1 && ctx->tile_rows == 1) {
715 av_log(avctx, AV_LOG_DEBUG, "Using a single tile.\n");
716 return 0;
717 }
718
719 sb_128x128_possible =
720 (avctx->width + 127) / 128 >= ctx->tile_cols &&
721 (avctx->height + 127) / 128 >= ctx->tile_rows;
722
723 ctx->tile_cols_log2 = ctx->tile_cols == 1 ? 0 :
724 av_log2(ctx->tile_cols - 1) + 1;
725 ctx->tile_rows_log2 = ctx->tile_rows == 1 ? 0 :
726 av_log2(ctx->tile_rows - 1) + 1;
727
728 uniform_cols = count_uniform_tiling(avctx->width,
729 64, ctx->tile_cols_log2);
730 uniform_rows = count_uniform_tiling(avctx->height,
731 64, ctx->tile_rows_log2);
732 av_log(avctx, AV_LOG_DEBUG, "Uniform with 64x64 superblocks "
733 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
734 uniform_64x64_possible = uniform_cols == ctx->tile_cols &&
735 uniform_rows == ctx->tile_rows;
736
737 if (sb_128x128_possible) {
738 uniform_cols = count_uniform_tiling(avctx->width,
739 128, ctx->tile_cols_log2);
740 uniform_rows = count_uniform_tiling(avctx->height,
741 128, ctx->tile_rows_log2);
742 av_log(avctx, AV_LOG_DEBUG, "Uniform with 128x128 superblocks "
743 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
744 uniform_128x128_possible = uniform_cols == ctx->tile_cols &&
745 uniform_rows == ctx->tile_rows;
746 } else {
747 av_log(avctx, AV_LOG_DEBUG, "128x128 superblocks not possible.\n");
748 uniform_128x128_possible = 0;
749 }
750
751 ctx->uniform_tiles = 1;
752 if (uniform_64x64_possible && uniform_128x128_possible) {
753 av_log(avctx, AV_LOG_DEBUG, "Using uniform tiling with dynamic "
754 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
755 ctx->tile_cols_log2, ctx->tile_rows_log2);
756 return 0;
757 }
758 if (uniform_64x64_possible && !sb_128x128_possible) {
759 av_log(avctx, AV_LOG_DEBUG, "Using uniform tiling with 64x64 "
760 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
761 ctx->tile_cols_log2, ctx->tile_rows_log2);
762 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
763 return 0;
764 }
765 if (uniform_128x128_possible) {
766 av_log(avctx, AV_LOG_DEBUG, "Using uniform tiling with 128x128 "
767 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
768 ctx->tile_cols_log2, ctx->tile_rows_log2);
769 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
770 return 0;
771 }
772 ctx->uniform_tiles = 0;
773
774 if (sb_128x128_possible) {
775 sb_size = 128;
776 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
777 } else {
778 sb_size = 64;
779 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
780 }
781 av_log(avctx, AV_LOG_DEBUG, "Using fixed tiling with %dx%d "
782 "superblocks (tile_cols = %d, tile_rows = %d).\n",
783 sb_size, sb_size, ctx->tile_cols, ctx->tile_rows);
784
785 enccfg->tile_width_count = ctx->tile_cols;
786 enccfg->tile_height_count = ctx->tile_rows;
787
788 sb_width = (avctx->width + sb_size - 1) / sb_size;
789 sb_height = (avctx->height + sb_size - 1) / sb_size;
790
791 tile_size = sb_width / ctx->tile_cols;
792 rounding = sb_width % ctx->tile_cols;
793 for (i = 0; i < ctx->tile_cols; i++) {
794 enccfg->tile_widths[i] = tile_size +
795 (i < rounding / 2 ||
796 i > ctx->tile_cols - 1 - (rounding + 1) / 2);
797 }
798
799 tile_size = sb_height / ctx->tile_rows;
800 rounding = sb_height % ctx->tile_rows;
801 for (i = 0; i < ctx->tile_rows; i++) {
802 enccfg->tile_heights[i] = tile_size +
803 (i < rounding / 2 ||
804 i > ctx->tile_rows - 1 - (rounding + 1) / 2);
805 }
806
807 return 0;
808}
809
810static const struct {
812 unsigned offset;
813} option_map[] = {
814 { AOME_SET_ENABLEAUTOALTREF, OFFSET(auto_alt_ref) },
815 { AOME_SET_ARNR_MAXFRAMES, OFFSET(arnr_max_frames) },
816 { AOME_SET_ARNR_STRENGTH, OFFSET(arnr_strength) },
817 { AV1E_SET_ENABLE_CDEF, OFFSET(enable_cdef) },
818 { AV1E_SET_ENABLE_RESTORATION, OFFSET(enable_restoration) },
819 { AV1E_SET_ENABLE_RECT_PARTITIONS, OFFSET(enable_rect_partitions) },
820 { AV1E_SET_ENABLE_1TO4_PARTITIONS, OFFSET(enable_1to4_partitions) },
821 { AV1E_SET_ENABLE_AB_PARTITIONS, OFFSET(enable_ab_partitions) },
822 { AV1E_SET_ENABLE_ANGLE_DELTA, OFFSET(enable_angle_delta) },
823 { AV1E_SET_ENABLE_CFL_INTRA, OFFSET(enable_cfl_intra) },
824 { AV1E_SET_ENABLE_FILTER_INTRA, OFFSET(enable_filter_intra) },
825 { AV1E_SET_ENABLE_INTRA_EDGE_FILTER, OFFSET(enable_intra_edge_filter) },
826 { AV1E_SET_ENABLE_PAETH_INTRA, OFFSET(enable_paeth_intra) },
827 { AV1E_SET_ENABLE_SMOOTH_INTRA, OFFSET(enable_smooth_intra) },
828 { AV1E_SET_ENABLE_PALETTE, OFFSET(enable_palette) },
829 { AV1E_SET_ENABLE_TX64, OFFSET(enable_tx64) },
830 { AV1E_SET_ENABLE_FLIP_IDTX, OFFSET(enable_flip_idtx) },
831 { AV1E_SET_INTRA_DCT_ONLY, OFFSET(use_intra_dct_only) },
832 { AV1E_SET_INTER_DCT_ONLY, OFFSET(use_inter_dct_only) },
833 { AV1E_SET_INTRA_DEFAULT_TX_ONLY, OFFSET(use_intra_default_tx_only) },
834 { AV1E_SET_REDUCED_TX_TYPE_SET, OFFSET(reduced_tx_type_set) },
835 { AV1E_SET_ENABLE_REF_FRAME_MVS, OFFSET(enable_ref_frame_mvs) },
836 { AV1E_SET_REDUCED_REFERENCE_SET, OFFSET(enable_reduced_reference_set) },
837 { AV1E_SET_ENABLE_DIFF_WTD_COMP, OFFSET(enable_diff_wtd_comp) },
838 { AV1E_SET_ENABLE_DIST_WTD_COMP, OFFSET(enable_dist_wtd_comp) },
839 { AV1E_SET_ENABLE_DUAL_FILTER, OFFSET(enable_dual_filter) },
840 { AV1E_SET_ENABLE_INTERINTER_WEDGE, OFFSET(enable_interinter_wedge) },
841 { AV1E_SET_ENABLE_MASKED_COMP, OFFSET(enable_masked_comp) },
842 { AV1E_SET_ENABLE_INTERINTRA_COMP, OFFSET(enable_interintra_comp) },
843 { AV1E_SET_ENABLE_INTERINTRA_WEDGE, OFFSET(enable_interintra_wedge) },
844 { AV1E_SET_ENABLE_OBMC, OFFSET(enable_obmc) },
845 { AV1E_SET_ENABLE_ONESIDED_COMP, OFFSET(enable_onesided_comp) },
846 { AV1E_SET_ENABLE_SMOOTH_INTERINTRA, OFFSET(enable_smooth_interintra) },
848
849/* Return the cpu-used value libaom runs with: an aom-params entry wins over -cpu-used. */
851{
852 const AVDictionaryEntry *en = av_dict_get(ctx->aom_params, "cpu-used",
854 char *end;
855 long v;
856
857 if (!en)
858 return ctx->cpu_used;
859 v = strtol(en->value, &end, 10);
860 return end == en->value ? ctx->cpu_used : (int)av_clip64(v, INT_MIN, INT_MAX);
861}
862
863#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
864/* Load the QP file and check its grid, returning 0 or a negative error code. */
865static av_cold int load_qpfile(AVCodecContext *avctx)
866{
867 AOMContext *ctx = avctx->priv_data;
868 int ret = ff_qpfile_load(avctx, ctx->qpfile_path, &ctx->qpfile);
869
870 if (ret < 0) {
871 av_log(avctx, AV_LOG_ERROR, "cannot read qpfile %s: %s\n",
872 ctx->qpfile_path, av_err2str(ret));
873 return ret;
874 }
875 ctx->qpfile_loaded = 1;
876 return ff_qpfile_check_grid(avctx, "libaom", &ctx->qpfile,
877 avctx->width, avctx->height);
878}
879#endif
880
882 const struct aom_codec_iface *iface)
883{
884 AOMContext *ctx = avctx->priv_data;
885 int res;
886 aom_codec_caps_t codec_caps = aom_codec_get_caps(iface);
887
888 ctx->flags = (avctx->flags & AV_CODEC_FLAG_PSNR) ? AOM_CODEC_USE_PSNR : 0;
889
890 if ((res = aom_codec_enc_config_default(iface, &ctx->enccfg, ctx->usage)) != AOM_CODEC_OK) {
891 av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n",
892 aom_codec_err_to_string(res));
893 return AVERROR(EINVAL);
894 }
895
896 if (set_pix_fmt(avctx, codec_caps, &ctx->enccfg, &ctx->flags, &ctx->img_fmt))
897 return AVERROR(EINVAL);
898
899 if(!avctx->bit_rate)
900 if(avctx->rc_max_rate || avctx->rc_buffer_size || avctx->rc_initial_buffer_occupancy) {
901 av_log( avctx, AV_LOG_ERROR, "Rate control parameters set without a bitrate\n");
902 return AVERROR(EINVAL);
903 }
904
905 ctx->enccfg.g_w = avctx->width;
906 ctx->enccfg.g_h = avctx->height;
907 ctx->enccfg.g_timebase.num = avctx->time_base.num;
908 ctx->enccfg.g_timebase.den = avctx->time_base.den;
909 ctx->enccfg.g_threads =
910 FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 64);
911
912 if (ctx->lag_in_frames >= 0)
913 ctx->enccfg.g_lag_in_frames = ctx->lag_in_frames;
914
915 if (avctx->rc_min_rate == avctx->rc_max_rate &&
916 avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) {
917 ctx->enccfg.rc_end_usage = AOM_CBR;
918 } else if (ctx->crf >= 0) {
919 ctx->enccfg.rc_end_usage = AOM_CQ;
920 if (!avctx->bit_rate)
921 ctx->enccfg.rc_end_usage = AOM_Q;
922 }
923
924 if (avctx->bit_rate) {
925 ctx->enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
927 } else if (ctx->enccfg.rc_end_usage != AOM_Q) {
928 ctx->enccfg.rc_end_usage = AOM_Q;
929 ctx->crf = 32;
930 av_log(avctx, AV_LOG_WARNING,
931 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
932 ctx->crf);
933 }
934
935 if (avctx->qmin >= 0)
936 ctx->enccfg.rc_min_quantizer = avctx->qmin;
937 if (avctx->qmax >= 0) {
938 ctx->enccfg.rc_max_quantizer = avctx->qmax;
939 } else if (!ctx->crf) {
940 ctx->enccfg.rc_max_quantizer = 0;
941 }
942
943 if (ctx->enccfg.rc_end_usage == AOM_CQ || ctx->enccfg.rc_end_usage == AOM_Q) {
944 if (ctx->crf < ctx->enccfg.rc_min_quantizer || ctx->crf > ctx->enccfg.rc_max_quantizer) {
945 av_log(avctx, AV_LOG_ERROR,
946 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
947 ctx->crf, ctx->enccfg.rc_min_quantizer, ctx->enccfg.rc_max_quantizer);
948 return AVERROR(EINVAL);
949 }
950 }
951
952 ctx->enccfg.rc_dropframe_thresh = ctx->drop_threshold;
953
954 // 0-100 (0 => CBR, 100 => VBR)
955 ctx->enccfg.rc_2pass_vbr_bias_pct = round(avctx->qcompress * 100);
956 if (ctx->minsection_pct >= 0)
957 ctx->enccfg.rc_2pass_vbr_minsection_pct = ctx->minsection_pct;
958 else if (avctx->bit_rate)
959 ctx->enccfg.rc_2pass_vbr_minsection_pct =
960 avctx->rc_min_rate * 100LL / avctx->bit_rate;
961 if (ctx->maxsection_pct >= 0)
962 ctx->enccfg.rc_2pass_vbr_maxsection_pct = ctx->maxsection_pct;
963 else if (avctx->rc_max_rate)
964 ctx->enccfg.rc_2pass_vbr_maxsection_pct =
965 avctx->rc_max_rate * 100LL / avctx->bit_rate;
966
967 if (avctx->rc_buffer_size)
968 ctx->enccfg.rc_buf_sz =
969 avctx->rc_buffer_size * 1000LL / avctx->bit_rate;
971 ctx->enccfg.rc_buf_initial_sz =
972 avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
973 ctx->enccfg.rc_buf_optimal_sz = ctx->enccfg.rc_buf_sz * 5 / 6;
974
975 if (ctx->rc_undershoot_pct >= 0)
976 ctx->enccfg.rc_undershoot_pct = ctx->rc_undershoot_pct;
977 if (ctx->rc_overshoot_pct >= 0)
978 ctx->enccfg.rc_overshoot_pct = ctx->rc_overshoot_pct;
979
980 // _enc_init() will balk if kf_min_dist differs from max w/AOM_KF_AUTO
981 if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
982 ctx->enccfg.kf_min_dist = avctx->keyint_min;
983 if (avctx->gop_size >= 0)
984 ctx->enccfg.kf_max_dist = avctx->gop_size;
985
986 /* 0-3: For non-zero values the encoder increasingly optimizes for reduced
987 * complexity playback on low powered devices at the expense of encode
988 * quality. */
989 if (avctx->profile != AV_PROFILE_UNKNOWN)
990 ctx->enccfg.g_profile = avctx->profile;
991
992 ctx->enccfg.g_error_resilient = ctx->error_resilient;
993
994 res = choose_tiling(avctx, &ctx->enccfg);
995 if (res < 0)
996 return res;
997
998 if (ctx->still_picture) {
999 // Set the maximum number of frames to 1. This will let libaom set
1000 // still_picture and reduced_still_picture_header to 1 in the Sequence
1001 // Header as required by AVIF still images.
1002 ctx->enccfg.g_limit = 1;
1003 // Reduce memory usage for still images.
1004 ctx->enccfg.g_lag_in_frames = 0;
1005 // All frames will be key frames.
1006 ctx->enccfg.kf_max_dist = 0;
1007 ctx->enccfg.kf_mode = AOM_KF_DISABLED;
1008 }
1009
1010 return 0;
1011}
1012
1014{
1015 AOMContext *ctx = avctx->priv_data;
1017 aom_codec_caps_t codec_caps = aom_codec_get_caps(ctx->encoder.iface);
1018
1019 // codec control failures are currently treated only as warnings
1020 av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
1021 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
1022
1023 for (size_t i = 0; i < FF_ARRAY_ELEMS(option_map); ++i) {
1024 int val = *(int*)((char*)ctx + option_map[i].offset);
1025 if (val >= 0)
1027 }
1028 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
1029 if (ctx->crf >= 0)
1030 codecctl_int(avctx, AOME_SET_CQ_LEVEL, ctx->crf);
1031 if (ctx->tune >= 0)
1032 codecctl_int(avctx, AOME_SET_TUNING, ctx->tune);
1033
1034 if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
1035 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, AVCOL_PRI_BT709);
1036 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, AVCOL_SPC_RGB);
1037 codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, AVCOL_TRC_IEC61966_2_1);
1038 } else {
1039 codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries);
1040 codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace);
1041 codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, avctx->color_trc);
1042 }
1043 if (ctx->aq_mode >= 0)
1044 codecctl_int(avctx, AV1E_SET_AQ_MODE, ctx->aq_mode);
1045 if (ctx->frame_parallel >= 0)
1046 codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel);
1047 set_color_range(avctx);
1048
1049 codecctl_int(avctx, AV1E_SET_SUPERBLOCK_SIZE, ctx->superblock_size);
1050 if (ctx->uniform_tiles) {
1051 codecctl_int(avctx, AV1E_SET_TILE_COLUMNS, ctx->tile_cols_log2);
1052 codecctl_int(avctx, AV1E_SET_TILE_ROWS, ctx->tile_rows_log2);
1053 }
1054
1055 if (ctx->denoise_noise_level >= 0)
1056 codecctl_int(avctx, AV1E_SET_DENOISE_NOISE_LEVEL, ctx->denoise_noise_level);
1057 if (ctx->denoise_block_size >= 0)
1058 codecctl_int(avctx, AV1E_SET_DENOISE_BLOCK_SIZE, ctx->denoise_block_size);
1059 if (ctx->enable_global_motion >= 0)
1060 codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION, ctx->enable_global_motion);
1061 if (avctx->refs >= 3) {
1062 codecctl_int(avctx, AV1E_SET_MAX_REFERENCE_FRAMES, avctx->refs);
1063 }
1064 if (ctx->row_mt >= 0)
1065 codecctl_int(avctx, AV1E_SET_ROW_MT, ctx->row_mt);
1066 if (ctx->enable_intrabc >= 0)
1067 codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC, ctx->enable_intrabc);
1068
1069#if AOM_ENCODER_ABI_VERSION >= 23
1070 {
1071 const AVDictionaryEntry *en = NULL;
1072
1073 while ((en = av_dict_iterate(ctx->aom_params, en))) {
1074 int ret = aom_codec_set_option(&ctx->encoder, en->key, en->value);
1075 if (ret != AOM_CODEC_OK) {
1076 log_encoder_error(avctx, en->key);
1077 return AVERROR_EXTERNAL;
1078 }
1079 }
1080 }
1081#endif
1082
1083 // provide dummy value to initialize wrapper, values will be updated each _encode()
1084 aom_img_wrap(&ctx->rawimg, ctx->img_fmt, avctx->width, avctx->height, 1,
1085 (unsigned char*)1);
1086
1087 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
1088 ctx->rawimg.bit_depth = ctx->enccfg.g_bit_depth;
1089
1090 return 0;
1091}
1092
1094 const struct aom_codec_iface *iface)
1095{
1096 AOMContext *ctx = avctx->priv_data;
1097 int res;
1098
1099 av_log(avctx, AV_LOG_INFO, "%s\n", aom_codec_version_str());
1100 av_log(avctx, AV_LOG_VERBOSE, "%s\n", aom_codec_build_config());
1101
1102 res = aom_config(avctx, iface);
1103 if (res < 0)
1104 return res;
1105
1106 if (avctx->flags & AV_CODEC_FLAG_PASS1)
1107 ctx->enccfg.g_pass = AOM_RC_FIRST_PASS;
1108 else if (avctx->flags & AV_CODEC_FLAG_PASS2)
1109 ctx->enccfg.g_pass = AOM_RC_LAST_PASS;
1110 else
1111 ctx->enccfg.g_pass = AOM_RC_ONE_PASS;
1112
1113 if (ctx->enccfg.g_pass == AOM_RC_FIRST_PASS)
1114 ctx->enccfg.g_lag_in_frames = 0;
1115 else if (ctx->enccfg.g_pass == AOM_RC_LAST_PASS) {
1116 int decode_size, ret;
1117
1118 if (!avctx->stats_in) {
1119 av_log(avctx, AV_LOG_ERROR, "No stats file for second pass\n");
1120 return AVERROR_INVALIDDATA;
1121 }
1122
1123 ctx->twopass_stats.sz = strlen(avctx->stats_in) * 3 / 4;
1124 ret = av_reallocp(&ctx->twopass_stats.buf, ctx->twopass_stats.sz);
1125 if (ret < 0) {
1126 av_log(avctx, AV_LOG_ERROR,
1127 "Stat buffer alloc (%zu bytes) failed\n",
1128 ctx->twopass_stats.sz);
1129 ctx->twopass_stats.sz = 0;
1130 return ret;
1131 }
1132 decode_size = av_base64_decode(ctx->twopass_stats.buf, avctx->stats_in,
1133 ctx->twopass_stats.sz);
1134 if (decode_size < 0) {
1135 av_log(avctx, AV_LOG_ERROR, "Stat buffer decode failed\n");
1136 return AVERROR_INVALIDDATA;
1137 }
1138
1139 ctx->twopass_stats.sz = decode_size;
1140 ctx->enccfg.rc_twopass_stats_in = ctx->twopass_stats;
1141 }
1142
1143 /* Construct Encoder Context */
1144 res = aom_codec_enc_init(&ctx->encoder, iface, &ctx->enccfg, ctx->flags);
1145 if (res != AOM_CODEC_OK) {
1146 dump_enc_cfg(avctx, &ctx->enccfg, AV_LOG_WARNING);
1147 log_encoder_error(avctx, "Failed to initialize encoder");
1148 return AVERROR(EINVAL);
1149 }
1150 dump_enc_cfg(avctx, &ctx->enccfg, AV_LOG_DEBUG);
1151
1152 res = aom_codecctl(avctx);
1153 if (res < 0)
1154 return res;
1155
1156 if (ctx->qpfile_path && *ctx->qpfile_path) {
1157#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1159 av_log(avctx, AV_LOG_ERROR,
1160 "qpfile needs one-pass encoding: libaom applies "
1161 "ROI maps only without recode.\n");
1162 return AVERROR(EINVAL);
1163 }
1164 if (ctx->usage != QPFILE_AOM_USAGE_REALTIME ||
1166 av_log(avctx, AV_LOG_ERROR,
1167 "qpfile with libaom-av1 requires -usage realtime and cpu-used >= 7, "
1168 "also when set through aom-params; libaom applies ROI maps only in "
1169 "realtime usage at speed 7 or more.\n");
1170 return AVERROR(EINVAL);
1171 }
1172 if (ctx->enccfg.g_lag_in_frames) {
1173 av_log(avctx, AV_LOG_ERROR,
1174 "qpfile with libaom-av1 needs -lag-in-frames 0; "
1175 "libaom ignores ROI maps with lookahead.\n");
1176 return AVERROR(EINVAL);
1177 }
1178 res = load_qpfile(avctx);
1179 if (res < 0)
1180 return res;
1181 /* libaom's segmentation map is sized at the mode-info grid:
1182 * size_in_mi(x) == ALIGN_POWER_OF_TWO(x, 3) >> MI_SIZE_LOG2,
1183 * i.e. each dim aligned up to a multiple of 8 px and divided
1184 * by 4. Mirror that here so av1_set_roi_map's (rows, cols)
1185 * equality check passes. */
1186 ctx->roi_mi_cols = ((unsigned)((avctx->width + 7) & ~7)) >> 2;
1187 ctx->roi_mi_rows = ((unsigned)((avctx->height + 7) & ~7)) >> 2;
1188 ctx->roi_seg_map = av_calloc((size_t)ctx->roi_mi_rows *
1189 ctx->roi_mi_cols,
1190 sizeof(*ctx->roi_seg_map));
1191 if (!ctx->roi_seg_map)
1192 return AVERROR(ENOMEM);
1193 av_log(avctx, AV_LOG_VERBOSE,
1194 "qpfile=%s loaded (frames=%u, %ux%u qpfile blocks "
1195 "-> %ux%u mi grid).\n",
1196 ctx->qpfile_path, ctx->qpfile.frame_count,
1197 ctx->qpfile.block_cols, ctx->qpfile.block_rows,
1198 ctx->roi_mi_cols, ctx->roi_mi_rows);
1199#else
1200 av_log(avctx, AV_LOG_ERROR,
1201 "qpfile needs libaom 3.13.0 or newer.\n");
1202 return AVERROR(ENOSYS);
1203#endif
1204 }
1205
1206 ctx->dovi.logctx = avctx;
1207 if ((res = ff_dovi_configure(&ctx->dovi, avctx)) < 0)
1208 return res;
1209
1210 if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
1211 const AVBitStreamFilter *filter = av_bsf_get_by_name("extract_extradata");
1212 int ret;
1213
1214 if (!filter) {
1215 av_log(avctx, AV_LOG_ERROR, "extract_extradata bitstream filter "
1216 "not found. This is a bug, please report it.\n");
1217 return AVERROR_BUG;
1218 }
1219 ret = av_bsf_alloc(filter, &ctx->bsf);
1220 if (ret < 0)
1221 return ret;
1222
1223 ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx);
1224 if (ret < 0)
1225 return ret;
1226
1227 ret = av_bsf_init(ctx->bsf);
1228 if (ret < 0)
1229 return ret;
1230 }
1231
1232 AVCPBProperties *cpb_props = ff_encode_add_cpb_side_data(avctx);
1233 if (!cpb_props)
1234 return AVERROR(ENOMEM);
1235
1236 if (ctx->enccfg.rc_end_usage == AOM_CBR ||
1237 ctx->enccfg.g_pass != AOM_RC_ONE_PASS) {
1238 cpb_props->max_bitrate = avctx->rc_max_rate;
1239 cpb_props->min_bitrate = avctx->rc_min_rate;
1240 cpb_props->avg_bitrate = avctx->bit_rate;
1241 }
1242 cpb_props->buffer_size = avctx->rc_buffer_size;
1243
1244 return 0;
1245}
1246
1247static inline void cx_pktcpy(AOMContext *ctx,
1248 struct FrameListData *dst,
1249 const struct aom_codec_cx_pkt *src)
1250{
1251 dst->pts = src->data.frame.pts;
1252 dst->duration = src->data.frame.duration;
1253 dst->flags = src->data.frame.flags;
1254 dst->sz = src->data.frame.sz;
1255 dst->buf = src->data.frame.buf;
1256 dst->frame_number = ++ctx->frame_number;
1257 dst->have_sse = ctx->have_sse;
1258 if (ctx->have_sse) {
1259 /* associate last-seen SSE to the frame. */
1260 /* Transfers ownership from ctx to dst. */
1261 memcpy(dst->sse, ctx->sse, sizeof(dst->sse));
1262 ctx->have_sse = 0;
1263 }
1264}
1265
1266/**
1267 * Store coded frame information in format suitable for return from encode2().
1268 *
1269 * Write information from @a cx_frame to @a pkt
1270 * @return packet data size on success
1271 * @return a negative AVERROR on error
1272 */
1273static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
1274 AVPacket *pkt)
1275{
1276 AOMContext *ctx = avctx->priv_data;
1277 enum AVPictureType pict_type;
1278 int ret = ff_get_encode_buffer(avctx, pkt, cx_frame->sz, 0);
1279 if (ret < 0) {
1280 av_log(avctx, AV_LOG_ERROR,
1281 "Error getting output packet of size %zu.\n", cx_frame->sz);
1282 return ret;
1283 }
1284 memcpy(pkt->data, cx_frame->buf, pkt->size);
1285 pkt->pts = pkt->dts = cx_frame->pts;
1286 pkt->duration = cx_frame->duration;
1287
1288 if (!!(cx_frame->flags & AOM_FRAME_IS_KEY)) {
1289 pkt->flags |= AV_PKT_FLAG_KEY;
1290 pict_type = AV_PICTURE_TYPE_I;
1291 } else if (cx_frame->flags & AOM_FRAME_IS_INTRAONLY) {
1292 pict_type = AV_PICTURE_TYPE_I;
1293 } else {
1294 pict_type = AV_PICTURE_TYPE_P;
1295 }
1296
1297 ff_encode_add_stats_side_data(pkt, 0, cx_frame->sse + 1,
1298 cx_frame->have_sse ? 3 : 0, pict_type);
1299
1300 if (cx_frame->have_sse) {
1301 int i;
1302 for (i = 0; i < 3; ++i) {
1303 avctx->error[i] += cx_frame->sse[i + 1];
1304 }
1305 cx_frame->have_sse = 0;
1306 }
1307
1308 if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
1309 ret = av_bsf_send_packet(ctx->bsf, pkt);
1310 if (ret < 0) {
1311 av_log(avctx, AV_LOG_ERROR, "extract_extradata filter "
1312 "failed to send input packet\n");
1313 return ret;
1314 }
1316
1317 if (ret < 0) {
1318 av_log(avctx, AV_LOG_ERROR, "extract_extradata filter "
1319 "failed to receive output packet\n");
1320 return ret;
1321 }
1322 }
1323 return pkt->size;
1324}
1325
1326/**
1327 * Queue multiple output frames from the encoder, returning the front-most.
1328 * In cases where aom_codec_get_cx_data() returns more than 1 frame append
1329 * the frame queue. Return the head frame if available.
1330 * @return Stored frame size
1331 * @return AVERROR(EINVAL) on output size error
1332 * @return AVERROR(ENOMEM) on coded frame queue data allocation error
1333 */
1334static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
1335{
1336 AOMContext *ctx = avctx->priv_data;
1337 const struct aom_codec_cx_pkt *pkt;
1338 const void *iter = NULL;
1339 int size = 0;
1340
1341 if (ctx->coded_frame_list) {
1342 struct FrameListData *cx_frame = ctx->coded_frame_list;
1343 /* return the leading frame if we've already begun queueing */
1344 size = storeframe(avctx, cx_frame, pkt_out);
1345 if (size < 0)
1346 return size;
1347 ctx->coded_frame_list = cx_frame->next;
1348 free_coded_frame(cx_frame);
1349 }
1350
1351 /* consume all available output from the encoder before returning. buffers
1352 * are only good through the next aom_codec call */
1353 while ((pkt = aom_codec_get_cx_data(&ctx->encoder, &iter))) {
1354 switch (pkt->kind) {
1355 case AOM_CODEC_CX_FRAME_PKT:
1356 if (!size) {
1357 struct FrameListData cx_frame;
1358
1359 /* avoid storing the frame when the list is empty and we haven't yet
1360 * provided a frame for output */
1361 av_assert0(!ctx->coded_frame_list);
1362 cx_pktcpy(ctx, &cx_frame, pkt);
1363 size = storeframe(avctx, &cx_frame, pkt_out);
1364 if (size < 0)
1365 return size;
1366 } else {
1367 struct FrameListData *cx_frame =
1368 av_malloc(sizeof(struct FrameListData));
1369
1370 if (!cx_frame) {
1371 av_log(avctx, AV_LOG_ERROR,
1372 "Frame queue element alloc failed\n");
1373 return AVERROR(ENOMEM);
1374 }
1375 cx_pktcpy(ctx, cx_frame, pkt);
1376 cx_frame->buf = av_malloc(cx_frame->sz);
1377
1378 if (!cx_frame->buf) {
1379 av_log(avctx, AV_LOG_ERROR,
1380 "Data buffer alloc (%zu bytes) failed\n",
1381 cx_frame->sz);
1382 av_freep(&cx_frame);
1383 return AVERROR(ENOMEM);
1384 }
1385 memcpy(cx_frame->buf, pkt->data.frame.buf, pkt->data.frame.sz);
1386 coded_frame_add(&ctx->coded_frame_list, cx_frame);
1387 }
1388 break;
1389 case AOM_CODEC_STATS_PKT:
1390 {
1391 struct aom_fixed_buf *stats = &ctx->twopass_stats;
1392 uint8_t *tmp = av_fast_realloc(stats->buf,
1393 &ctx->twopass_stats_size,
1394 stats->sz +
1395 pkt->data.twopass_stats.sz);
1396 if (!tmp) {
1397 av_freep(&stats->buf);
1398 stats->sz = 0;
1399 av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
1400 return AVERROR(ENOMEM);
1401 }
1402 stats->buf = tmp;
1403 memcpy((uint8_t *)stats->buf + stats->sz,
1404 pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
1405 stats->sz += pkt->data.twopass_stats.sz;
1406 break;
1407 }
1408 case AOM_CODEC_PSNR_PKT:
1409 {
1410 av_assert0(!ctx->have_sse);
1411 ctx->sse[0] = pkt->data.psnr.sse[0];
1412 ctx->sse[1] = pkt->data.psnr.sse[1];
1413 ctx->sse[2] = pkt->data.psnr.sse[2];
1414 ctx->sse[3] = pkt->data.psnr.sse[3];
1415 ctx->have_sse = 1;
1416 break;
1417 }
1418 case AOM_CODEC_CUSTOM_PKT:
1419 // ignore unsupported/unrecognized packet types
1420 break;
1421 }
1422 }
1423
1424 return size;
1425}
1426
1427static enum AVPixelFormat aomfmt_to_pixfmt(struct aom_image *img)
1428{
1429 switch (img->fmt) {
1430 case AOM_IMG_FMT_I420:
1431 case AOM_IMG_FMT_I42016:
1432 if (img->bit_depth == 8)
1433 return img->monochrome ? AV_PIX_FMT_GRAY8 : AV_PIX_FMT_YUV420P;
1434 else if (img->bit_depth == 10)
1435 return img->monochrome ? AV_PIX_FMT_GRAY10 : AV_PIX_FMT_YUV420P10;
1436 else
1437 return img->monochrome ? AV_PIX_FMT_GRAY12 : AV_PIX_FMT_YUV420P12;
1438 case AOM_IMG_FMT_I422:
1439 case AOM_IMG_FMT_I42216:
1440 if (img->bit_depth == 8)
1441 return AV_PIX_FMT_YUV422P;
1442 else if (img->bit_depth == 10)
1443 return AV_PIX_FMT_YUV422P10;
1444 else
1445 return AV_PIX_FMT_YUV422P12;
1446 case AOM_IMG_FMT_I444:
1447 case AOM_IMG_FMT_I44416:
1448 if (img->bit_depth == 8)
1449 return AV_PIX_FMT_YUV444P;
1450 else if (img->bit_depth == 10)
1451 return AV_PIX_FMT_YUV444P10;
1452 else
1453 return AV_PIX_FMT_YUV444P12;
1454 };
1455 return AV_PIX_FMT_NONE;
1456}
1457
1458#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1459/* libaom-av1 ROI map helpers. Convert one FFQpFrame into a
1460 * libaom aom_roi_map_t whose (rows, cols, roi_map, delta_q) match the
1461 * encoder's mode-info grid (4x4-luma cells).
1462 *
1463 * Quantisation: per-MB qp_offsets are clipped to [-12, +12] by the
1464 * shared parser. Per frame, we discover the actual value range and
1465 * emit one segment per distinct value when there are at most
1466 * AOM_MAX_SEGMENTS of them, or do uniform linear binning across the span
1467 * (lossy: each MB rounds to its nearest segment QP). Each frame's map is
1468 * built through a 25-entry offset lookup table and reused while the same
1469 * record applies. */
1470
1471#define QPFILE_AOM_MAX_SEGMENTS AOM_MAX_SEGMENTS /* 8, see aomcx.h */
1472#define QPFILE_AOM_MI_PER_MB 4 /* 16 px MB / 4 px mi */
1473
1474/* Give each mode-info cell the segment nearest its macroblock's QP offset. */
1475static void qpfile_aom_paint_seg_map(const FFQpFrame *qf,
1476 uint8_t *seg_map,
1477 unsigned mi_rows, unsigned mi_cols,
1478 const int *seg_q, unsigned n_seg)
1479{
1480 uint8_t lut[QPFILE_LUT_SIZE];
1481 unsigned mi_y, mi_x;
1482 unsigned mb_rows = qf->block_rows;
1483 unsigned mb_cols = qf->block_cols;
1484
1485 ff_qpfile_segment_lut(lut, seg_q, n_seg);
1486 /* For each mi cell, pick the qpfile MB it overlaps, then snap that
1487 * MB's QP-offset to the nearest segment id. mi index / 4 = mb idx. */
1488 for (mi_y = 0; mi_y < mi_rows; mi_y++) {
1489 unsigned mb_y = mi_y / QPFILE_AOM_MI_PER_MB;
1490 mb_y = FFMIN(mb_y, mb_rows - 1u);
1491 for (mi_x = 0; mi_x < mi_cols; mi_x++) {
1492 unsigned mb_x = mi_x / QPFILE_AOM_MI_PER_MB;
1493 int v;
1494 mb_x = FFMIN(mb_x, mb_cols - 1u);
1495 v = qf->block_offsets[mb_y * mb_cols + mb_x];
1496 seg_map[mi_y * mi_cols + mi_x] = lut[v - QPFILE_DELTA_MIN];
1497 }
1498 }
1499}
1500
1501/* Send an ROI map to libaom via AOME_SET_ROI_MAP, returning 0 or an error. */
1502static int qpfile_aom_send_roi(AVCodecContext *avctx, aom_roi_map_t *roi,
1503 unsigned frame_index)
1504{
1505 AOMContext *ctx = avctx->priv_data;
1506 int res = aom_codec_control(&ctx->encoder, AOME_SET_ROI_MAP, roi);
1507
1508 if (res != AOM_CODEC_OK) {
1509 av_log(avctx, AV_LOG_ERROR,
1510 "AOME_SET_ROI_MAP failed for frame %u (res=%d).\n",
1511 frame_index, res);
1512 return AVERROR_EXTERNAL;
1513 }
1514 return 0;
1515}
1516
1517/* Clear an ROI map to rows x cols mode-info cells with no reference frame. */
1518static void qpfile_aom_init_roi(aom_roi_map_t *roi, unsigned rows, unsigned cols)
1519{
1520 memset(roi, 0, sizeof(*roi));
1521 roi->rows = rows;
1522 roi->cols = cols;
1523 for (unsigned i = 0; i < QPFILE_AOM_MAX_SEGMENTS; i++)
1524 roi->ref_frame[i] = -1;
1525}
1526
1527/* Refresh the cached ROI segment map and QP deltas when the active record changes. */
1528static void qpfile_aom_update_map(AOMContext *ctx, const FFQpFrame *qf)
1529{
1530 ctx->roi_n_seg = 0;
1531 if (qf)
1532 ctx->roi_n_seg = ff_qpfile_segment_values(qf, ctx->roi_seg_q,
1533 QPFILE_AOM_MAX_SEGMENTS);
1534 if (ctx->roi_n_seg)
1535 qpfile_aom_paint_seg_map(qf, ctx->roi_seg_map,
1536 ctx->roi_mi_rows, ctx->roi_mi_cols,
1537 ctx->roi_seg_q, ctx->roi_n_seg);
1538 ctx->roi_qf = qf;
1539 ctx->roi_cached = 1;
1540}
1541
1542/* Build and apply the ROI map for a frame, returning 0 or a negative error. */
1543static int qpfile_aom_apply_roi(AVCodecContext *avctx, unsigned frame_index)
1544{
1545 AOMContext *ctx = avctx->priv_data;
1546 aom_roi_map_t roi;
1547 const FFQpFrame *qf;
1548
1549 if (!ctx->qpfile_loaded || !ctx->roi_seg_map ||
1550 !ctx->roi_mi_rows || !ctx->roi_mi_cols)
1551 return 0;
1552
1553 qf = ff_qpfile_frame_for_index(&ctx->qpfile, frame_index);
1554 if (!ctx->roi_cached || qf != ctx->roi_qf)
1555 qpfile_aom_update_map(ctx, qf);
1556
1557 qpfile_aom_init_roi(&roi, ctx->roi_mi_rows, ctx->roi_mi_cols);
1558 if (ctx->roi_n_seg) {
1559 roi.enabled = 1;
1560 roi.roi_map = ctx->roi_seg_map;
1561 roi.delta_qp_enabled = 1;
1562 for (unsigned i = 0; i < ctx->roi_n_seg; i++)
1563 roi.delta_q[i] = ctx->roi_seg_q[i];
1564 }
1565
1566 return qpfile_aom_send_roi(avctx, &roi, frame_index);
1567}
1568#endif
1569
1571 const AVFrame *frame, int *got_packet)
1572{
1573 AOMContext *ctx = avctx->priv_data;
1574 struct aom_image *rawimg = NULL;
1575 int64_t timestamp = 0;
1576 unsigned long duration = 0;
1577 int res, coded_size;
1578 aom_enc_frame_flags_t flags = 0;
1579 AVFrameSideData *sd;
1580#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1581 unsigned roi_frame = 0;
1582#endif
1583
1584 if (frame) {
1585#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1586 /* Count every input frame before any step that can fail, so that
1587 * the frames after a dropped one keep their own qpfile records. */
1588 if (ctx->qpfile_loaded)
1589 roi_frame = ctx->roi_input_frame++;
1590#endif
1591 rawimg = &ctx->rawimg;
1592 aom_img_remove_metadata(rawimg);
1593 rawimg->planes[AOM_PLANE_Y] = frame->data[0];
1594 rawimg->planes[AOM_PLANE_U] = frame->data[1];
1595 rawimg->planes[AOM_PLANE_V] = frame->data[2];
1596 rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
1597 rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
1598 rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
1599 timestamp = frame->pts;
1600
1601 if (frame->duration > ULONG_MAX) {
1602 av_log(avctx, AV_LOG_WARNING,
1603 "Frame duration too large: %"PRId64"\n", frame->duration);
1604 } else if (frame->duration)
1605 duration = frame->duration;
1606 else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
1607 duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
1608 else {
1609 duration = 1;
1610 }
1611
1612 switch (frame->color_range) {
1613 case AVCOL_RANGE_MPEG:
1614 rawimg->range = AOM_CR_STUDIO_RANGE;
1615 break;
1616 case AVCOL_RANGE_JPEG:
1617 rawimg->range = AOM_CR_FULL_RANGE;
1618 break;
1619 }
1620
1622 if (ctx->dovi.cfg.dv_profile && sd) {
1623 const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
1624 uint8_t *t35;
1625 int size;
1627 &t35, &size)) < 0)
1628 return res;
1629 res = aom_img_add_metadata(rawimg, OBU_METADATA_TYPE_ITUT_T35,
1630 t35, size, AOM_MIF_ANY_FRAME);
1631 av_free(t35);
1632 if (res != AOM_CODEC_OK)
1633 return AVERROR(ENOMEM);
1634 } else if (ctx->dovi.cfg.dv_profile) {
1635 av_log(avctx, AV_LOG_ERROR, "Dolby Vision enabled, but received frame "
1636 "without AV_FRAME_DATA_DOVI_METADATA\n");
1637 return AVERROR_INVALIDDATA;
1638 }
1639
1640 if (frame->pict_type == AV_PICTURE_TYPE_I)
1641 flags |= AOM_EFLAG_FORCE_KF;
1642
1643 res = add_hdr_plus(avctx, rawimg, frame);
1644 if (res < 0)
1645 return res;
1646
1647 res = add_hdr_smpte2094_app5(avctx, rawimg, frame);
1648 if (res < 0)
1649 return res;
1650 }
1651
1652#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1653 if (ctx->qpfile_loaded && frame) {
1654 int qret = qpfile_aom_apply_roi(avctx, roi_frame);
1655 if (qret < 0)
1656 return qret;
1657 }
1658#endif
1659
1660 res = aom_codec_encode(&ctx->encoder, rawimg, timestamp, duration, flags);
1661 if (res != AOM_CODEC_OK) {
1662 log_encoder_error(avctx, "Error encoding frame");
1663 return AVERROR_INVALIDDATA;
1664 }
1665 coded_size = queue_frames(avctx, pkt);
1666 if (coded_size < 0)
1667 return coded_size;
1668
1669 if (!frame && avctx->flags & AV_CODEC_FLAG_PASS1) {
1670 size_t b64_size = AV_BASE64_SIZE(ctx->twopass_stats.sz);
1671
1672 avctx->stats_out = av_malloc(b64_size);
1673 if (!avctx->stats_out) {
1674 av_log(avctx, AV_LOG_ERROR, "Stat buffer alloc (%zu bytes) failed\n",
1675 b64_size);
1676 return AVERROR(ENOMEM);
1677 }
1678 av_base64_encode(avctx->stats_out, b64_size, ctx->twopass_stats.buf,
1679 ctx->twopass_stats.sz);
1680 }
1681
1682 *got_packet = !!coded_size;
1683
1684 if (*got_packet && avctx->flags & AV_CODEC_FLAG_RECON_FRAME) {
1685 AVCodecInternal *avci = avctx->internal;
1686 struct aom_image img;
1687
1689
1690 res = codecctl_imgp(avctx, AV1_GET_NEW_FRAME_IMAGE, &img);
1691 if (res < 0)
1692 return res;
1693
1695 if (avci->recon_frame->format == AV_PIX_FMT_NONE) {
1697 "Unhandled reconstructed frame colorspace: %d\n",
1698 img.fmt);
1699 return AVERROR(ENOSYS);
1700 }
1701
1702 avci->recon_frame->width = img.d_w;
1703 avci->recon_frame->height = img.d_h;
1704
1705 res = av_frame_get_buffer(avci->recon_frame, 0);
1706 if (res < 0)
1707 return res;
1708
1709 if ((img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) && img.bit_depth == 8)
1711 else {
1712 const uint8_t *planes[4] = { img.planes[0], img.planes[1], img.planes[2] };
1713 const int stride[4] = { img.stride[0], img.stride[1], img.stride[2] };
1714
1716 stride, avci->recon_frame->format, img.d_w, img.d_h);
1717 }
1718 }
1719
1720 return 0;
1721}
1722
1730
1739
1755
1774
1776 const AVCodec *codec,
1777 enum AVCodecConfig config,
1778 unsigned flags, const void **out,
1779 int *out_num)
1780{
1781 if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
1782 int supports_monochrome = aom_codec_version() >= 20001;
1783 aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
1784 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
1785 if (supports_monochrome) {
1788 } else {
1790 *out_num = FF_ARRAY_ELEMS(av1_pix_fmts_highbd) - 1;
1791 }
1792 } else {
1793 if (supports_monochrome) {
1795 *out_num = FF_ARRAY_ELEMS(av1_pix_fmts_with_gray) - 1;
1796 } else {
1797 *out = av1_pix_fmts;
1798 *out_num = FF_ARRAY_ELEMS(av1_pix_fmts) - 1;
1799 }
1800 }
1801 return 0;
1802 }
1803
1804 return ff_default_get_supported_config(avctx, codec, config, flags, out, out_num);
1805}
1806
1808{
1809 return aom_init(avctx, aom_codec_av1_cx());
1810}
1811
1813{
1814 AOMContext *ctx = avctx->priv_data;
1815 int loglevel;
1816 int res;
1817
1818 res = ff_encode_reconf_parse_dict(avctx, dict);
1819 if (res < 0)
1820 return res;
1821
1822 if (ctx->qpfile_loaded && qpfile_aom_cpu_used(ctx) < QPFILE_AOM_MIN_CPU_USED) {
1823 av_log(avctx, AV_LOG_ERROR,
1824 "qpfile with libaom-av1 requires cpu-used >= 7, also when set through "
1825 "aom-params; libaom applies ROI maps only at speed 7 or more.\n");
1826 return AVERROR(EINVAL);
1827 }
1828
1829 res = aom_config(avctx, ctx->encoder.iface);
1830 if (res < 0)
1831 return res;
1832
1833 res = aom_codec_enc_config_set(&ctx->encoder, &ctx->enccfg);
1834 loglevel = res != AOM_CODEC_OK ? AV_LOG_WARNING : AV_LOG_DEBUG;
1835 av_log(avctx, loglevel, "Reconfigure options:\n");
1836 dump_enc_cfg(avctx, &ctx->enccfg, loglevel);
1837 if (res != AOM_CODEC_OK) {
1838 log_encoder_error(avctx, "Failed to reconfigure encoder");
1839 return AVERROR(EINVAL);
1840 }
1841
1842 res = aom_codecctl(avctx);
1843 if (res < 0)
1844 return res;
1845
1846 return 0;
1847}
1848
1849#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1850#define VER VE | AV_OPT_FLAG_RUNTIME_PARAM
1851static const AVOption options[] = {
1852 { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 8, VER},
1853 { "auto-alt-ref", "Enable use of alternate reference "
1854 "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE},
1855 { "lag-in-frames", "Number of frames to look ahead at for "
1856 "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
1857 { "arnr-max-frames", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
1858 { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
1859 { "aq-mode", "adaptive quantization mode", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4, VE, .unit = "aq_mode"},
1860 { "none", "Aq not used", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, .unit = "aq_mode"},
1861 { "variance", "Variance based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, .unit = "aq_mode"},
1862 { "complexity", "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, .unit = "aq_mode"},
1863 { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, .unit = "aq_mode"},
1864 { "error-resilience", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, .unit = "er"},
1865 { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, .unit = "er"},
1866 { "crf", "Select the quality for constant quality mode", offsetof(AOMContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VER },
1867 { "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 },
1868 { "drop-threshold", "Frame drop threshold", offsetof(AOMContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE },
1869 { "denoise-noise-level", "Amount of noise to be removed", OFFSET(denoise_noise_level), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
1870 { "denoise-block-size", "Denoise block size ", OFFSET(denoise_block_size), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
1871 { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100, VE},
1872 { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1000, VE},
1873 { "minsection-pct", "GOP min bitrate (% of target)", OFFSET(minsection_pct), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100, VE},
1874 { "maxsection-pct", "GOP max bitrate (% of target)", OFFSET(maxsection_pct), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 5000, VE},
1875 { "frame-parallel", "Enable frame parallel decodability features", OFFSET(frame_parallel), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1876 { "tiles", "Tile columns x rows", OFFSET(tile_cols), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, VE },
1877 { "tile-columns", "Log2 of number of tile columns to use", OFFSET(tile_cols_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
1878 { "tile-rows", "Log2 of number of tile rows to use", OFFSET(tile_rows_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
1879 { "row-mt", "Enable row based multi-threading", OFFSET(row_mt), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1880 { "enable-cdef", "Enable CDEF filtering", OFFSET(enable_cdef), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1881 { "enable-global-motion", "Enable global motion", OFFSET(enable_global_motion), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1882 { "enable-intrabc", "Enable intra block copy prediction mode", OFFSET(enable_intrabc), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1883 { "enable-restoration", "Enable Loop Restoration filtering", OFFSET(enable_restoration), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1884 { "usage", "Quality and compression efficiency vs speed trade-off", OFFSET(usage), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "usage"},
1885 { "good", "Good quality", 0, AV_OPT_TYPE_CONST, {.i64 = 0 /* AOM_USAGE_GOOD_QUALITY */}, 0, 0, VE, .unit = "usage"},
1886 { "realtime", "Realtime encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 1 /* AOM_USAGE_REALTIME */}, 0, 0, VE, .unit = "usage"},
1887 { "allintra", "All Intra encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 2 /* AOM_USAGE_ALL_INTRA */}, 0, 0, VE, .unit = "usage"},
1888 { "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"},
1889 { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_PSNR}, 0, 0, VE, .unit = "tune"},
1890 { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_SSIM}, 0, 0, VE, .unit = "tune"},
1891 { "qpfile", "Read per-frame QP offsets from a file as a region-of-interest map (needs libaom 3.13.0 or newer)", OFFSET(qpfile_path), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE },
1893 { "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 },
1894 { "dolbyvision", "Enable Dolby Vision RPU coding", OFFSET(dovi.enable), AV_OPT_TYPE_BOOL, {.i64 = FF_DOVI_AUTOMATIC }, -1, 1, VE, .unit = "dovi" },
1895 { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DOVI_AUTOMATIC}, .flags = VE, .unit = "dovi" },
1896 { "enable-rect-partitions", "Enable rectangular partitions", OFFSET(enable_rect_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1897 { "enable-1to4-partitions", "Enable 1:4/4:1 partitions", OFFSET(enable_1to4_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1898 { "enable-ab-partitions", "Enable ab shape partitions", OFFSET(enable_ab_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1899 { "enable-angle-delta", "Enable angle delta intra prediction", OFFSET(enable_angle_delta), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1900 { "enable-cfl-intra", "Enable chroma predicted from luma intra prediction", OFFSET(enable_cfl_intra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1901 { "enable-filter-intra", "Enable filter intra predictor", OFFSET(enable_filter_intra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1902 { "enable-intra-edge-filter", "Enable intra edge filter", OFFSET(enable_intra_edge_filter), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1903 { "enable-smooth-intra", "Enable smooth intra prediction mode", OFFSET(enable_smooth_intra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1904 { "enable-paeth-intra", "Enable paeth predictor in intra prediction", OFFSET(enable_paeth_intra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1905 { "enable-palette", "Enable palette prediction mode", OFFSET(enable_palette), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1906 { "enable-flip-idtx", "Enable extended transform type", OFFSET(enable_flip_idtx), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1907 { "enable-tx64", "Enable 64-pt transform", OFFSET(enable_tx64), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1908 { "reduced-tx-type-set", "Use reduced set of transform types", OFFSET(reduced_tx_type_set), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1909 { "use-intra-dct-only", "Use DCT only for INTRA modes", OFFSET(use_intra_dct_only), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1910 { "use-inter-dct-only", "Use DCT only for INTER modes", OFFSET(use_inter_dct_only), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1911 { "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},
1912 { "enable-ref-frame-mvs", "Enable temporal mv prediction", OFFSET(enable_ref_frame_mvs), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1913 { "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},
1914 { "enable-obmc", "Enable obmc", OFFSET(enable_obmc), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1915 { "enable-dual-filter", "Enable dual filter", OFFSET(enable_dual_filter), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1916 { "enable-diff-wtd-comp", "Enable difference-weighted compound", OFFSET(enable_diff_wtd_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1917 { "enable-dist-wtd-comp", "Enable distance-weighted compound", OFFSET(enable_dist_wtd_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1918 { "enable-onesided-comp", "Enable one sided compound", OFFSET(enable_onesided_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1919 { "enable-interinter-wedge", "Enable interinter wedge compound", OFFSET(enable_interinter_wedge), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1920 { "enable-interintra-wedge", "Enable interintra wedge compound", OFFSET(enable_interintra_wedge), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1921 { "enable-masked-comp", "Enable masked compound", OFFSET(enable_masked_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1922 { "enable-interintra-comp", "Enable interintra compound", OFFSET(enable_interintra_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1923 { "enable-smooth-interintra", "Enable smooth interintra mode", OFFSET(enable_smooth_interintra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
1924#if AOM_ENCODER_ABI_VERSION >= 23
1925 { "aom-params", "Set libaom options using a :-separated list of key=value pairs", OFFSET(aom_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
1926#endif
1927 { NULL },
1928};
1929
1930static const FFCodecDefault defaults[] = {
1931 { "b", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1932 { "bufsize", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1933 { "maxrate", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1934 { "minrate", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1935 { "qmin", "-1", AV_OPT_FLAG_RUNTIME_PARAM },
1936 { "qmax", "-1", AV_OPT_FLAG_RUNTIME_PARAM },
1937 { "sar", "0", AV_OPT_FLAG_RUNTIME_PARAM },
1938 { "g", "-1" },
1939 { "keyint_min", "-1" },
1940 { NULL },
1941};
1942
1943static const AVClass class_aom = {
1944 .class_name = "libaom-av1 encoder",
1945 .item_name = av_default_item_name,
1946 .option = options,
1947 .version = LIBAVUTIL_VERSION_INT,
1948};
1949
1951 .p.name = "libaom-av1",
1952 CODEC_LONG_NAME("libaom AV1"),
1953 .p.type = AVMEDIA_TYPE_VIDEO,
1954 .p.id = AV_CODEC_ID_AV1,
1955 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
1959 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
1961 .p.priv_class = &class_aom,
1962 .p.wrapper_name = "libaom",
1963 .priv_data_size = sizeof(AOMContext),
1964 .init = av1_init,
1965 .reconf = av1_reconf,
1967 .close = aom_free,
1968 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1971 .defaults = defaults,
1972 .get_supported_config = av1_get_supported_config,
1973};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static double val(void *priv, double ch)
Definition aeval.c:77
const FFCodec ff_libaom_av1_encoder
Definition libaomenc.c:1950
#define VE
Definition amfenc_av1.c:30
static const FFCodecDefault defaults[]
Definition amfenc_av1.c:725
static FILE * out
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
int ff_default_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out_configs, int *out_num_configs)
Definition avcodec.c:763
Libavcodec external API header.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Definition codec_par.c:138
#define av_clip64
Definition common.h:103
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define AV_PROFILE_AV1_HIGH
Definition defs.h:184
#define AV_PROFILE_UNKNOWN
Definition defs.h:65
#define AV_PROFILE_AV1_MAIN
Definition defs.h:183
#define AV_PROFILE_AV1_PROFESSIONAL
Definition defs.h:185
static AVPacket * pkt
static AVFrame * frame
Public dictionary API.
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
Definition dovi_rpu.c:30
#define FF_DOVI_AUTOMATIC
Enable tri-state.
Definition dovi_rpu.h:49
int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, int flags, uint8_t **out_rpu, int *out_size)
Synthesize a Dolby Vision RPU reflecting the current state.
@ FF_DOVI_WRAP_T35
wrap inside T.35+EMDF
Definition dovi_rpu.h:160
int ff_dovi_configure(DOVIContext *s, AVCodecContext *avctx)
Variant of ff_dovi_configure_from_codedpar which infers the codec parameters from an AVCodecContext.
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:107
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition encode.c:1061
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
Definition encode.c:1092
av_cold int ff_encode_reconf_parse_dict(AVCodecContext *avctx, AVDictionary **dict)
Definition encode.c:621
static CheckasmStats stats
Definition checkasm.c:75
static CheckasmConfig cfg
Definition checkasm.c:74
static int64_t duration
Definition ffplay.c:359
int ret
Definition ffplay.c:391
static ListView * list
Definition ffplay.c:377
const char * usage
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
Definition opt.h:376
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition opt.h:302
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition opt.h:254
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
Definition opt.h:289
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
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:47
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition bsf.c:147
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
Definition bsf.c:99
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition bsf.c:228
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition bsf.c:200
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
#define AV_CODEC_CAP_ENCODER_RECONF
Encoder can be reconfigured by passing new initialization parameters.
Definition codec.h:54
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition avcodec.h:294
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition codec.h:112
#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:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition avcodec.h:290
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition avcodec.h:318
#define AV_CODEC_FLAG_PSNR
error[?
Definition avcodec.h:306
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
Definition codec.h:162
#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:244
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
AVCodecConfig
Definition avcodec.h:2592
@ AV_CODEC_CONFIG_PIX_FORMAT
AVPixelFormat, terminated by AV_PIX_FMT_NONE.
Definition avcodec.h:2593
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:657
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:152
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
Definition base64.h:66
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
Definition base64.c:86
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:61
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:43
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition dict.h:74
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:500
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:663
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition frame.c:210
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
Definition frame.h:208
@ AV_FRAME_DATA_DYNAMIC_HDR_PLUS
HDR dynamic metadata associated with a video frame.
Definition frame.h:159
@ AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
HDR dynamic metadata associated with a video frame.
Definition frame.h:270
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
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
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
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:601
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:289
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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
AVPictureType
Definition avutil.h:276
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int av_dynamic_hdr_smpte2094_app5_to_t35(const AVDynamicHDRSmpte2094App5 *s, uint8_t **data, size_t *size)
Serialize dynamic SMPTE-2094-50 metadata to a ITU-T T.35 message.
int av_dynamic_hdr_plus_to_t35(const AVDynamicHDRPlus *s, uint8_t **data, size_t *size)
Serialize dynamic HDR10+ metadata to a user data registered ITU-T T.35 buffer, excluding the first 48...
misc image utilities
#define av_log2
Definition intmath.h:84
#define ITU_T_T35_PROVIDER_CODE_SMPTE
Definition itut35.h:48
#define ITU_T_T35_COUNTRY_CODE_US
Definition itut35.h:32
#define ITU_T_T35_PROVIDER_CODE_SAMSUNG
Definition itut35.h:47
void ff_aom_image_copy_16_to_8(AVFrame *pic, struct aom_image *img)
Definition libaom.c:27
AOM common functions.
static av_cold int av1_init(AVCodecContext *avctx)
Definition libaomdec.c:284
static av_cold int aom_free(AVCodecContext *avctx)
Definition libaomdec.c:277
static int add_hdr_smpte2094_app5(AVCodecContext *avctx, struct aom_image *img, const AVFrame *frame)
Definition libaomenc.c:416
static const char *const ctlidstr[]
Definition libaomenc.c:187
static av_cold int av1_reconf(AVCodecContext *avctx, AVDictionary **dict)
Definition libaomenc.c:1812
unsigned offset
Definition libaomenc.c:812
static enum AVPixelFormat av1_pix_fmts_highbd_with_gray[]
Definition libaomenc.c:1756
static enum AVPixelFormat aomfmt_to_pixfmt(struct aom_image *img)
Definition libaomenc.c:1427
#define QPFILE_AOM_MIN_CPU_USED
Definition libaomenc.c:79
static enum AVPixelFormat av1_pix_fmts_highbd[]
Definition libaomenc.c:1740
static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
Queue multiple output frames from the encoder, returning the front-most.
Definition libaomenc.c:1334
static void cx_pktcpy(AOMContext *ctx, struct FrameListData *dst, const struct aom_codec_cx_pkt *src)
Definition libaomenc.c:1247
static int add_hdr_plus(AVCodecContext *avctx, struct aom_image *img, const AVFrame *frame)
Definition libaomenc.c:369
static enum AVPixelFormat av1_pix_fmts_with_gray[]
Definition libaomenc.c:1731
static av_cold int codecctl_imgp(AVCodecContext *avctx, int id, struct aom_image *img)
Definition libaomenc.c:488
static void set_color_range(AVCodecContext *avctx)
Definition libaomenc.c:631
#define QPFILE_AOM_USAGE_REALTIME
Definition libaomenc.c:78
static av_cold int av1_init(AVCodecContext *avctx)
Definition libaomenc.c:1807
static int av1_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out, int *out_num)
Definition libaomenc.c:1775
static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
Definition libaomenc.c:250
static int count_uniform_tiling(int dim, int sb_size, int tiles_log2)
Definition libaomenc.c:647
static av_cold void free_coded_frame(struct FrameListData *cx_frame)
Definition libaomenc.c:329
int aom_enum
Definition libaomenc.c:811
static av_cold int codecctl_int(AVCodecContext *avctx, int id, int val)
Definition libaomenc.c:346
static av_cold int aom_free(AVCodecContext *avctx)
Definition libaomenc.c:509
static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition libaomenc.c:1570
static av_cold int aom_init(AVCodecContext *avctx, const struct aom_codec_iface *iface)
Definition libaomenc.c:1093
#define VER
Definition libaomenc.c:1850
static int qpfile_aom_cpu_used(const AOMContext *ctx)
Definition libaomenc.c:850
static av_cold int aom_config(AVCodecContext *avctx, const struct aom_codec_iface *iface)
Definition libaomenc.c:881
static const struct @177033264217101044054267161301277114055300120044 option_map[]
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:1273
static enum AVPixelFormat av1_pix_fmts[]
Definition libaomenc.c:1723
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:566
#define OFFSET(x)
Definition libaomenc.c:185
static void coded_frame_add(void *list, struct FrameListData *cx_frame)
Definition libaomenc.c:319
static av_cold int aom_codecctl(AVCodecContext *avctx)
Definition libaomenc.c:1013
static av_cold void free_frame_list(struct FrameListData *list)
Definition libaomenc.c:335
static const AVClass class_aom
Definition libaomenc.c:1943
static av_cold void dump_enc_cfg(AVCodecContext *avctx, const struct aom_codec_enc_cfg *cfg, int level)
Definition libaomenc.c:261
static int choose_tiling(AVCodecContext *avctx, struct aom_codec_enc_cfg *enccfg)
Definition libaomenc.c:655
AV1 common definitions.
@ AV1_MAX_TILE_WIDTH
Definition av1.h:79
@ AV1_MAX_TILE_COLS
Definition av1.h:82
@ AV1_MAX_TILE_ROWS
Definition av1.h:81
@ AV1_MAX_TILE_AREA
Definition av1.h:80
common internal api header.
#define av_fallthrough
Definition attributes.h:67
#define av_cold
Definition attributes.h:117
int av_cpu_count(void)
Definition cpu.c:230
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:98
static av_cold int load_qpfile(AVCodecContext *avctx)
Definition libsvtav1.c:716
const char * desc
Definition libsvtav1.c:110
static const struct @257111027162314367033347246032313251342043035002 planes[]
#define FFMIN(a, b)
Definition macros.h:49
#define FFALIGN(x, a)
Definition macros.h:78
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition pixdesc.h:136
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:555
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:548
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:775
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:758
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:792
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:553
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:567
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:549
#define AV_PIX_FMT_GRAY12
Definition pixfmt.h:529
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:568
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
#define AV_PIX_FMT_GRAY10
Definition pixfmt.h:528
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition pixfmt.h:649
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition pixfmt.h:691
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:551
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:712
const AVProfile ff_av1_profiles[]
Definition profiles.c:177
#define FF_AV1_PROFILE_OPTS
Definition profiles.h:56
int ff_qpfile_load(void *log_ctx, const char *path, FFQpFile *out)
Load a per-frame QP-offset file into out, logging errors to log_ctx.
const FFQpFrame * ff_qpfile_frame_for_index(const FFQpFile *qf, unsigned frame_index)
Look up the QP frame record matching or preceding the given frame index.
unsigned ff_qpfile_segment_values(const FFQpFrame *qf, int *seg_values, unsigned max_segments)
Fill seg_values with the palette (see ff_qpfile_palette) of the frame's block offsets,...
void ff_qpfile_segment_lut(uint8_t *lut, const int *seg_values, unsigned n_seg)
Fill lut[QPFILE_LUT_SIZE] with the nearest segment index of each offset from QPFILE_DELTA_MIN to QPFI...
int ff_qpfile_check_grid(void *log_ctx, const char *encoder, const FFQpFile *qf, int width, int height)
Verify that the QP file grid matches the video macroblock dimensions.
void ff_qpfile_free(FFQpFile *qpf)
Free all memory allocated inside an FFQpFile structure.
Shared parser for the per-frame QP-offset file format.
#define QPFILE_DELTA_MIN
#define QPFILE_LUT_SIZE
#define FF_ARRAY_ELEMS(a)
int qpfile_loaded
Definition libaomenc.c:141
aom_img_fmt_t img_fmt
Definition libaomenc.c:89
struct aom_image rawimg
Definition libaomenc.c:87
unsigned int roi_mi_rows
Definition libaomenc.c:143
int use_intra_default_tx_only
Definition libaomenc.c:169
int auto_alt_ref
Definition libaomenc.c:94
AVDictionary * aom_params
Definition libaomenc.c:182
int error_resilient
Definition libaomenc.c:99
int tile_rows
Definition libaomenc.c:113
int enable_onesided_comp
Definition libaomenc.c:176
int reduced_tx_type_set
Definition libaomenc.c:166
aom_codec_flags_t flags
Definition libaomenc.c:88
int enable_interintra_wedge
Definition libaomenc.c:172
int enable_global_motion
Definition libaomenc.c:119
int use_intra_dct_only
Definition libaomenc.c:167
int enable_restoration
Definition libaomenc.c:121
int enable_masked_comp
Definition libaomenc.c:174
int enable_smooth_interintra
Definition libaomenc.c:178
int minsection_pct
Definition libaomenc.c:110
int use_inter_dct_only
Definition libaomenc.c:168
int tile_cols
Definition libaomenc.c:113
int enable_diff_wtd_comp
Definition libaomenc.c:179
struct aom_fixed_buf twopass_stats
Definition libaomenc.c:90
int uniform_tiles
Definition libaomenc.c:116
int rc_overshoot_pct
Definition libaomenc.c:109
uint8_t * roi_seg_map
Definition libaomenc.c:142
int enable_reduced_reference_set
Definition libaomenc.c:177
uint64_t frame_number
Definition libaomenc.c:107
int enable_1to4_partitions
Definition libaomenc.c:155
int enable_paeth_intra
Definition libaomenc.c:159
int enable_rect_partitions
Definition libaomenc.c:154
aom_superblock_size_t superblock_size
Definition libaomenc.c:115
int roi_seg_q[AOM_MAX_SEGMENTS]
Definition libaomenc.c:148
int tile_cols_log2
Definition libaomenc.c:114
int enable_tx64
Definition libaomenc.c:165
int have_sse
true if we have pending sse[]
Definition libaomenc.c:106
unsigned int roi_mi_cols
Definition libaomenc.c:144
int arnr_strength
Definition libaomenc.c:96
int still_picture
Definition libaomenc.c:153
int enable_dual_filter
Definition libaomenc.c:181
struct FrameListData * coded_frame_list
Definition libaomenc.c:92
int lag_in_frames
Definition libaomenc.c:98
int static_thresh
Definition libaomenc.c:101
int enable_obmc
Definition libaomenc.c:175
int roi_cached
Definition libaomenc.c:147
int enable_interintra_comp
Definition libaomenc.c:173
int enable_flip_idtx
Definition libaomenc.c:164
int enable_palette
Definition libaomenc.c:162
char * qpfile_path
Definition libaomenc.c:122
int enable_intrabc
Definition libaomenc.c:120
int maxsection_pct
Definition libaomenc.c:111
unsigned int roi_input_frame
Definition libaomenc.c:145
int denoise_noise_level
Definition libaomenc.c:103
int tile_rows_log2
Definition libaomenc.c:114
struct aom_codec_enc_cfg enccfg
Definition libaomenc.c:86
int denoise_block_size
Definition libaomenc.c:104
int enable_filter_intra
Definition libaomenc.c:163
int rc_undershoot_pct
Definition libaomenc.c:108
unsigned twopass_stats_size
Definition libaomenc.c:91
int enable_interinter_wedge
Definition libaomenc.c:171
int enable_ab_partitions
Definition libaomenc.c:156
int enable_dist_wtd_comp
Definition libaomenc.c:180
unsigned int roi_n_seg
Definition libaomenc.c:149
int frame_parallel
Definition libaomenc.c:112
int enable_smooth_intra
Definition libaomenc.c:160
const FFQpFrame * roi_qf
Definition libaomenc.c:146
int enable_intra_edge_filter
Definition libaomenc.c:161
int enable_cdef
Definition libaomenc.c:118
int arnr_max_frames
Definition libaomenc.c:95
int aq_mode
Definition libaomenc.c:97
int enable_cfl_intra
Definition libaomenc.c:158
int enable_angle_delta
Definition libaomenc.c:157
struct aom_codec_ctx encoder
Definition libaomenc.c:85
AVBSFContext * bsf
Definition libaomenc.c:83
FFQpFile qpfile
Definition libaomenc.c:140
int drop_threshold
Definition libaomenc.c:102
int enable_ref_frame_mvs
Definition libaomenc.c:170
DOVIContext dovi
Definition libaomenc.c:84
int cpu_used
Definition libaomenc.c:93
uint64_t sse[4]
Definition libaomenc.c:105
The bitstream filter state.
Definition bsf.h:68
uint8_t * data
The data buffer.
Definition buffer.h:90
This structure describes the bitrate properties of an encoded bitstream.
Definition defs.h:298
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
Definition defs.h:313
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition defs.h:303
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition defs.h:319
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
Definition defs.h:308
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:644
int width
picture width / height.
Definition avcodec.h:605
char * stats_out
pass1 encoding statistics output buffer
Definition avcodec.h:1335
int rc_buffer_size
decoder bitstream buffer size
Definition avcodec.h:1278
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:685
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:658
int qmin
minimum quantizer
Definition avcodec.h:1257
int keyint_min
minimum GOP size
Definition avcodec.h:1018
AVRational framerate
Definition avcodec.h:563
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition avcodec.h:1343
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition avcodec.h:1321
int profile
profile
Definition avcodec.h:1646
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:672
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition avcodec.h:1025
int refs
number of reference frames
Definition avcodec.h:705
int64_t rc_max_rate
maximum bitrate
Definition avcodec.h:1293
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition avcodec.h:1589
int qmax
maximum quantizer
Definition avcodec.h:1264
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:665
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avcodec.h:547
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
int64_t rc_min_rate
minimum bitrate
Definition avcodec.h:1300
uint64_t error[AV_NUM_DATA_POINTERS]
error
Definition avcodec.h:1529
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
Definition avcodec.h:1249
struct AVCodecInternal * internal
Private context used for internal data.
Definition avcodec.h:478
void * priv_data
Definition avcodec.h:470
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
Definition internal.h:114
AVCodec.
Definition codec.h:175
Combined struct representing a combination of header, mapping and color metadata, for attaching to fr...
Definition dovi_meta.h:345
char * key
Definition dict.h:91
char * value
Definition dict.h:92
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
This struct represents dynamic metadata for color volume transform as specified in the SMPTE 2094-50 ...
Structure to hold side data for an AVFrame.
Definition frame.h:334
uint8_t * data
Definition frame.h:336
AVBufferRef * buf
Definition frame.h:339
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
int width
Definition frame.h:551
int height
Definition frame.h:551
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:524
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:566
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
unsigned int block_cols
int8_t * block_offsets
unsigned int block_rows
Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
Definition libaomenc.c:61
int64_t pts
time stamp to show frame (in timebase units)
Definition libaomenc.c:64
uint64_t sse[4]
Definition libaomenc.c:69
struct FrameListData * next
Definition libaomenc.c:72
size_t sz
length of compressed data
Definition libaomenc.c:63
void * buf
compressed data buffer
Definition libaomenc.c:62
unsigned long duration
duration to show frame (in timebase units)
Definition libaomenc.c:66
int have_sse
true if we have pending sse[]
Definition libaomenc.c:70
uint64_t frame_number
Definition libaomenc.c:71
uint32_t flags
flags for this frame
Definition libaomenc.c:68
uint8_t level
Definition svq3.c:208
#define stride
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
static void error(const char *err)
static uint8_t tmp[40]
Definition aes_ctr.c:52
int tile_cols
Definition av1_levels.c:73
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
#define src
Definition vp8dsp.c:248
#define width
Definition dsp.h:99
int size
#define img
int dim