29#define AOM_DISABLE_CTRL_TYPECHECKS 1
30#include <aom/aom_encoder.h>
78#define QPFILE_AOM_USAGE_REALTIME 1
79#define QPFILE_AOM_MIN_CPU_USED 7
81typedef struct AOMEncoderContext {
185#define OFFSET(x) offsetof(AOMContext, x)
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",
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",
247 [AV1_GET_NEW_FRAME_IMAGE] =
"AV1_GET_NEW_FRAME_IMAGE",
253 const char *
error = aom_codec_error(&
ctx->encoder);
254 const char *detail = aom_codec_error_detail(&
ctx->encoder);
262 const struct aom_codec_enc_cfg *
cfg,
269 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
271 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
273 width,
"g_threads:",
cfg->g_threads,
274 width,
"g_profile:",
cfg->g_profile,
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,
282 width,
"g_lag_in_frames:",
cfg->g_lag_in_frames);
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);
291 width,
"rc_min_quantizer:",
cfg->rc_min_quantizer,
292 width,
"rc_max_quantizer:",
cfg->rc_max_quantizer);
295 width,
"rc_undershoot_pct:",
cfg->rc_undershoot_pct,
296 width,
"rc_overshoot_pct:",
cfg->rc_overshoot_pct);
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);
308 " %*s%d\n %*s%u\n %*s%u\n",
310 width,
"kf_min_dist:",
cfg->kf_min_dist,
311 width,
"kf_max_dist:",
cfg->kf_max_dist);
314 width,
"tile_width_count:",
cfg->tile_width_count,
315 width,
"tile_height_count:",
cfg->tile_height_count);
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",
385 uint8_t *hdr_plus_buf;
387 const size_t hdr_plus_buf_size = payload_size + 6;
388 hdr_plus_buf =
av_malloc(hdr_plus_buf_size);
392 uint8_t *payload = hdr_plus_buf;
396 bytestream_put_be16(&payload, 0x0001);
397 bytestream_put_byte(&payload, 0x04);
406 res = aom_img_add_metadata(
img, OBU_METADATA_TYPE_ITUT_T35,
407 hdr_plus_buf, hdr_plus_buf_size, AOM_MIF_ANY_FRAME);
434 const size_t hdr_buf_size = payload_size + 5;
439 uint8_t *payload = hdr_buf;
442 bytestream_put_be16(&payload, 0x0001);
451 res = aom_img_add_metadata(
img, OBU_METADATA_TYPE_ITUT_T35,
452 hdr_buf, hdr_buf_size, AOM_MIF_ANY_FRAME);
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)
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",
490 struct aom_image *
img)
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",
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)
517 int num_operating_points;
519 int target_levels[32];
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,
526 for (
int i = 0;
i < num_operating_points;
i++) {
527 if (levels[
i] > target_levels[
i]) {
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) {
537 "Output level for operating point %d is %d.%d.\n",
538 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
545 aom_codec_destroy(&
ctx->encoder);
546 aom_img_remove_metadata(&
ctx->rawimg);
547 if (
ctx->qpfile_loaded) {
549 ctx->qpfile_loaded = 0;
552 ctx->roi_mi_rows = 0;
553 ctx->roi_mi_cols = 0;
554 ctx->roi_input_frame = 0;
567 struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *
flags,
568 aom_img_fmt_t *img_fmt)
571 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
574 enccfg->monochrome = 1;
578 *img_fmt = AOM_IMG_FMT_I420;
582 *img_fmt = AOM_IMG_FMT_I422;
587 *img_fmt = AOM_IMG_FMT_I444;
591 enccfg->monochrome = 1;
595 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
598 *img_fmt = AOM_IMG_FMT_I42016;
599 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
605 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
607 *img_fmt = AOM_IMG_FMT_I42216;
608 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
616 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
619 *img_fmt = AOM_IMG_FMT_I44416;
620 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
633 aom_color_range_t aom_cr;
649 int sb_dim = (
dim + sb_size - 1) / sb_size;
650 int tile_dim = (sb_dim + (1 << tiles_log2) - 1) >> tiles_log2;
652 return (sb_dim + tile_dim - 1) / tile_dim;
656 struct aom_codec_enc_cfg *enccfg)
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;
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;
669 if (
ctx->tile_cols == 0) {
672 if (
ctx->tile_cols > 1) {
674 "columns to fill width.\n",
ctx->tile_cols);
678 if (
ctx->tile_rows == 0) {
681 ctx->tile_cols - 1) /
ctx->tile_cols, 128);
685 if (
ctx->tile_rows > 1) {
687 "rows to fill area.\n",
ctx->tile_rows);
692 if ((avctx->
width + 63) / 64 <
ctx->tile_cols ||
693 (avctx->
height + 63) / 64 <
ctx->tile_rows) {
695 "large enough to fit specified tile arrangement.\n");
701 "not allow more than %dx%d tiles.\n",
707 "not allow tiles of width greater than %d.\n",
712 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
714 if (
ctx->tile_cols == 1 &&
ctx->tile_rows == 1) {
719 sb_128x128_possible =
720 (avctx->
width + 127) / 128 >=
ctx->tile_cols &&
721 (avctx->
height + 127) / 128 >=
ctx->tile_rows;
723 ctx->tile_cols_log2 =
ctx->tile_cols == 1 ? 0 :
725 ctx->tile_rows_log2 =
ctx->tile_rows == 1 ? 0 :
729 64,
ctx->tile_cols_log2);
731 64,
ctx->tile_rows_log2);
733 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
734 uniform_64x64_possible = uniform_cols ==
ctx->tile_cols &&
735 uniform_rows ==
ctx->tile_rows;
737 if (sb_128x128_possible) {
739 128,
ctx->tile_cols_log2);
741 128,
ctx->tile_rows_log2);
743 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
744 uniform_128x128_possible = uniform_cols ==
ctx->tile_cols &&
745 uniform_rows ==
ctx->tile_rows;
748 uniform_128x128_possible = 0;
751 ctx->uniform_tiles = 1;
752 if (uniform_64x64_possible && uniform_128x128_possible) {
754 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
755 ctx->tile_cols_log2,
ctx->tile_rows_log2);
758 if (uniform_64x64_possible && !sb_128x128_possible) {
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;
765 if (uniform_128x128_possible) {
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;
772 ctx->uniform_tiles = 0;
774 if (sb_128x128_possible) {
776 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
779 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
782 "superblocks (tile_cols = %d, tile_rows = %d).\n",
783 sb_size, sb_size,
ctx->tile_cols,
ctx->tile_rows);
785 enccfg->tile_width_count =
ctx->tile_cols;
786 enccfg->tile_height_count =
ctx->tile_rows;
788 sb_width = (avctx->
width + sb_size - 1) / sb_size;
789 sb_height = (avctx->
height + sb_size - 1) / sb_size;
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 +
796 i >
ctx->tile_cols - 1 - (rounding + 1) / 2);
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 +
804 i >
ctx->tile_rows - 1 - (rounding + 1) / 2);
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) },
858 return ctx->cpu_used;
859 v = strtol(en->
value, &end, 10);
863#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
875 ctx->qpfile_loaded = 1;
882 const struct aom_codec_iface *iface)
886 aom_codec_caps_t codec_caps = aom_codec_get_caps(iface);
890 if ((res = aom_codec_enc_config_default(iface, &
ctx->enccfg,
ctx->usage)) != AOM_CODEC_OK) {
892 aom_codec_err_to_string(res));
909 ctx->enccfg.g_threads =
912 if (
ctx->lag_in_frames >= 0)
913 ctx->enccfg.g_lag_in_frames =
ctx->lag_in_frames;
917 ctx->enccfg.rc_end_usage = AOM_CBR;
918 }
else if (
ctx->crf >= 0) {
919 ctx->enccfg.rc_end_usage = AOM_CQ;
921 ctx->enccfg.rc_end_usage = AOM_Q;
927 }
else if (
ctx->enccfg.rc_end_usage != AOM_Q) {
928 ctx->enccfg.rc_end_usage = AOM_Q;
931 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
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;
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) {
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);
952 ctx->enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
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;
959 ctx->enccfg.rc_2pass_vbr_minsection_pct =
961 if (
ctx->maxsection_pct >= 0)
962 ctx->enccfg.rc_2pass_vbr_maxsection_pct =
ctx->maxsection_pct;
964 ctx->enccfg.rc_2pass_vbr_maxsection_pct =
968 ctx->enccfg.rc_buf_sz =
971 ctx->enccfg.rc_buf_initial_sz =
973 ctx->enccfg.rc_buf_optimal_sz =
ctx->enccfg.rc_buf_sz * 5 / 6;
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;
992 ctx->enccfg.g_error_resilient =
ctx->error_resilient;
998 if (
ctx->still_picture) {
1002 ctx->enccfg.g_limit = 1;
1004 ctx->enccfg.g_lag_in_frames = 0;
1006 ctx->enccfg.kf_max_dist = 0;
1007 ctx->enccfg.kf_mode = AOM_KF_DISABLED;
1017 aom_codec_caps_t codec_caps = aom_codec_get_caps(
ctx->encoder.iface);
1043 if (
ctx->aq_mode >= 0)
1045 if (
ctx->frame_parallel >= 0)
1046 codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
1050 if (
ctx->uniform_tiles) {
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) {
1064 if (
ctx->row_mt >= 0)
1066 if (
ctx->enable_intrabc >= 0)
1069#if AOM_ENCODER_ABI_VERSION >= 23
1074 int ret = aom_codec_set_option(&
ctx->encoder, en->
key, en->
value);
1075 if (
ret != AOM_CODEC_OK) {
1087 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
1088 ctx->rawimg.bit_depth =
ctx->enccfg.g_bit_depth;
1094 const struct aom_codec_iface *iface)
1107 ctx->enccfg.g_pass = AOM_RC_FIRST_PASS;
1109 ctx->enccfg.g_pass = AOM_RC_LAST_PASS;
1111 ctx->enccfg.g_pass = AOM_RC_ONE_PASS;
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;
1123 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
1127 "Stat buffer alloc (%zu bytes) failed\n",
1128 ctx->twopass_stats.sz);
1129 ctx->twopass_stats.sz = 0;
1133 ctx->twopass_stats.sz);
1134 if (decode_size < 0) {
1139 ctx->twopass_stats.sz = decode_size;
1140 ctx->enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
1144 res = aom_codec_enc_init(&
ctx->encoder, iface, &
ctx->enccfg,
ctx->flags);
1145 if (res != AOM_CODEC_OK) {
1156 if (
ctx->qpfile_path && *
ctx->qpfile_path) {
1157#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1160 "qpfile needs one-pass encoding: libaom applies "
1161 "ROI maps only without recode.\n");
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");
1172 if (
ctx->enccfg.g_lag_in_frames) {
1174 "qpfile with libaom-av1 needs -lag-in-frames 0; "
1175 "libaom ignores ROI maps with lookahead.\n");
1186 ctx->roi_mi_cols = ((unsigned)((avctx->
width + 7) & ~7)) >> 2;
1187 ctx->roi_mi_rows = ((unsigned)((avctx->
height + 7) & ~7)) >> 2;
1190 sizeof(*
ctx->roi_seg_map));
1191 if (!
ctx->roi_seg_map)
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);
1201 "qpfile needs libaom 3.13.0 or newer.\n");
1206 ctx->dovi.logctx = avctx;
1216 "not found. This is a bug, please report it.\n");
1236 if (
ctx->enccfg.rc_end_usage == AOM_CBR ||
1237 ctx->enccfg.g_pass != AOM_RC_ONE_PASS) {
1249 const struct aom_codec_cx_pkt *
src)
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) {
1261 memcpy(
dst->sse,
ctx->sse,
sizeof(
dst->sse));
1281 "Error getting output packet of size %zu.\n", cx_frame->
sz);
1284 memcpy(
pkt->data, cx_frame->
buf,
pkt->size);
1288 if (!!(cx_frame->
flags & AOM_FRAME_IS_KEY)) {
1291 }
else if (cx_frame->
flags & AOM_FRAME_IS_INTRAONLY) {
1298 cx_frame->
have_sse ? 3 : 0, pict_type);
1302 for (
i = 0;
i < 3; ++
i) {
1312 "failed to send input packet\n");
1319 "failed to receive output packet\n");
1337 const struct aom_codec_cx_pkt *
pkt;
1338 const void *iter =
NULL;
1341 if (
ctx->coded_frame_list) {
1347 ctx->coded_frame_list = cx_frame->
next;
1353 while ((
pkt = aom_codec_get_cx_data(&
ctx->encoder, &iter))) {
1354 switch (
pkt->kind) {
1355 case AOM_CODEC_CX_FRAME_PKT:
1372 "Frame queue element alloc failed\n");
1378 if (!cx_frame->
buf) {
1380 "Data buffer alloc (%zu bytes) failed\n",
1385 memcpy(cx_frame->
buf,
pkt->data.frame.buf,
pkt->data.frame.sz);
1389 case AOM_CODEC_STATS_PKT:
1391 struct aom_fixed_buf *
stats = &
ctx->twopass_stats;
1393 &
ctx->twopass_stats_size,
1395 pkt->data.twopass_stats.sz);
1404 pkt->data.twopass_stats.buf,
pkt->data.twopass_stats.sz);
1405 stats->sz +=
pkt->data.twopass_stats.sz;
1408 case AOM_CODEC_PSNR_PKT:
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];
1418 case AOM_CODEC_CUSTOM_PKT:
1430 case AOM_IMG_FMT_I420:
1431 case AOM_IMG_FMT_I42016:
1432 if (
img->bit_depth == 8)
1434 else if (
img->bit_depth == 10)
1438 case AOM_IMG_FMT_I422:
1439 case AOM_IMG_FMT_I42216:
1440 if (
img->bit_depth == 8)
1442 else if (
img->bit_depth == 10)
1446 case AOM_IMG_FMT_I444:
1447 case AOM_IMG_FMT_I44416:
1448 if (
img->bit_depth == 8)
1450 else if (
img->bit_depth == 10)
1458#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1471#define QPFILE_AOM_MAX_SEGMENTS AOM_MAX_SEGMENTS
1472#define QPFILE_AOM_MI_PER_MB 4
1475static void qpfile_aom_paint_seg_map(
const FFQpFrame *qf,
1477 unsigned mi_rows,
unsigned mi_cols,
1478 const int *seg_q,
unsigned n_seg)
1481 unsigned mi_y, mi_x;
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;
1494 mb_x =
FFMIN(mb_x, mb_cols - 1u);
1502static int qpfile_aom_send_roi(
AVCodecContext *avctx, aom_roi_map_t *roi,
1503 unsigned frame_index)
1506 int res = aom_codec_control(&
ctx->encoder, AOME_SET_ROI_MAP, roi);
1508 if (res != AOM_CODEC_OK) {
1510 "AOME_SET_ROI_MAP failed for frame %u (res=%d).\n",
1518static void qpfile_aom_init_roi(aom_roi_map_t *roi,
unsigned rows,
unsigned cols)
1520 memset(roi, 0,
sizeof(*roi));
1523 for (
unsigned i = 0;
i < QPFILE_AOM_MAX_SEGMENTS;
i++)
1524 roi->ref_frame[
i] = -1;
1533 QPFILE_AOM_MAX_SEGMENTS);
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);
1539 ctx->roi_cached = 1;
1543static int qpfile_aom_apply_roi(
AVCodecContext *avctx,
unsigned frame_index)
1549 if (!
ctx->qpfile_loaded || !
ctx->roi_seg_map ||
1550 !
ctx->roi_mi_rows || !
ctx->roi_mi_cols)
1554 if (!
ctx->roi_cached || qf !=
ctx->roi_qf)
1555 qpfile_aom_update_map(
ctx, qf);
1557 qpfile_aom_init_roi(&roi,
ctx->roi_mi_rows,
ctx->roi_mi_cols);
1558 if (
ctx->roi_n_seg) {
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];
1566 return qpfile_aom_send_roi(avctx, &roi, frame_index);
1574 struct aom_image *rawimg =
NULL;
1577 int res, coded_size;
1578 aom_enc_frame_flags_t
flags = 0;
1580#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1581 unsigned roi_frame = 0;
1585#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1588 if (
ctx->qpfile_loaded)
1589 roi_frame =
ctx->roi_input_frame++;
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;
1601 if (
frame->duration > ULONG_MAX) {
1603 "Frame duration too large: %"PRId64
"\n",
frame->duration);
1604 }
else if (
frame->duration)
1612 switch (
frame->color_range) {
1614 rawimg->range = AOM_CR_STUDIO_RANGE;
1617 rawimg->range = AOM_CR_FULL_RANGE;
1622 if (
ctx->dovi.cfg.dv_profile && sd) {
1629 res = aom_img_add_metadata(rawimg, OBU_METADATA_TYPE_ITUT_T35,
1630 t35,
size, AOM_MIF_ANY_FRAME);
1632 if (res != AOM_CODEC_OK)
1634 }
else if (
ctx->dovi.cfg.dv_profile) {
1636 "without AV_FRAME_DATA_DOVI_METADATA\n");
1641 flags |= AOM_EFLAG_FORCE_KF;
1652#if HAVE_STRUCT_AOM_ROI_MAP_REF_FRAME
1654 int qret = qpfile_aom_apply_roi(avctx, roi_frame);
1661 if (res != AOM_CODEC_OK) {
1679 ctx->twopass_stats.sz);
1682 *got_packet = !!coded_size;
1686 struct aom_image
img;
1697 "Unhandled reconstructed frame colorspace: %d\n",
1709 if ((
img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) &&
img.bit_depth == 8)
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] };
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) {
1793 if (supports_monochrome) {
1809 return aom_init(avctx, aom_codec_av1_cx());
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");
1833 res = aom_codec_enc_config_set(&
ctx->encoder, &
ctx->enccfg);
1835 av_log(avctx, loglevel,
"Reconfigure options:\n");
1837 if (res != AOM_CODEC_OK) {
1849#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1850#define VER VE | AV_OPT_FLAG_RUNTIME_PARAM
1853 {
"auto-alt-ref",
"Enable use of alternate reference "
1855 {
"lag-in-frames",
"Number of frames to look ahead at for "
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"},
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"},
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},
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},
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"},
1886 {
"realtime",
"Realtime encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0,
VE, .unit =
"usage"},
1887 {
"allintra",
"All Intra encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 2 }, 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"},
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 },
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},
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},
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 },
1939 {
"keyint_min",
"-1" },
1944 .class_name =
"libaom-av1 encoder",
1951 .p.name =
"libaom-av1",
1962 .p.wrapper_name =
"libaom",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_libaom_av1_encoder
static const FFCodecDefault defaults[]
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.
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)
Libavcodec external API header.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#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)
#define AV_PROFILE_AV1_HIGH
#define AV_PROFILE_UNKNOWN
#define AV_PROFILE_AV1_MAIN
#define AV_PROFILE_AV1_PROFESSIONAL
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
#define FF_DOVI_AUTOMATIC
Enable tri-state.
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
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)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
av_cold int ff_encode_reconf_parse_dict(AVCodecContext *avctx, AVDictionary **dict)
static CheckasmStats stats
static CheckasmConfig cfg
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ 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...
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
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.
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
#define AV_CODEC_FLAG_PSNR
error[?
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
#define AV_CODEC_FLAG_RECON_FRAME
Request the encoder to output reconstructed frames, i.e. frames that would be produced by decoding th...
@ AV_CODEC_CONFIG_PIX_FORMAT
AVPixelFormat, terminated by AV_PIX_FMT_NONE.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
@ AV_FRAME_DATA_DYNAMIC_HDR_PLUS
HDR dynamic metadata associated with a video frame.
@ AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
HDR dynamic metadata associated with a video frame.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
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.
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.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
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.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
#define LIBAVUTIL_VERSION_INT
#define ITU_T_T35_PROVIDER_CODE_SMPTE
#define ITU_T_T35_COUNTRY_CODE_US
#define ITU_T_T35_PROVIDER_CODE_SAMSUNG
void ff_aom_image_copy_16_to_8(AVFrame *pic, struct aom_image *img)
static av_cold int av1_init(AVCodecContext *avctx)
static av_cold int aom_free(AVCodecContext *avctx)
static int add_hdr_smpte2094_app5(AVCodecContext *avctx, struct aom_image *img, const AVFrame *frame)
static const char *const ctlidstr[]
static av_cold int av1_reconf(AVCodecContext *avctx, AVDictionary **dict)
static enum AVPixelFormat av1_pix_fmts_highbd_with_gray[]
static enum AVPixelFormat aomfmt_to_pixfmt(struct aom_image *img)
#define QPFILE_AOM_MIN_CPU_USED
static enum AVPixelFormat av1_pix_fmts_highbd[]
static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
Queue multiple output frames from the encoder, returning the front-most.
static void cx_pktcpy(AOMContext *ctx, struct FrameListData *dst, const struct aom_codec_cx_pkt *src)
static int add_hdr_plus(AVCodecContext *avctx, struct aom_image *img, const AVFrame *frame)
static enum AVPixelFormat av1_pix_fmts_with_gray[]
static av_cold int codecctl_imgp(AVCodecContext *avctx, int id, struct aom_image *img)
static void set_color_range(AVCodecContext *avctx)
#define QPFILE_AOM_USAGE_REALTIME
static av_cold int av1_init(AVCodecContext *avctx)
static int av1_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out, int *out_num)
static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
static int count_uniform_tiling(int dim, int sb_size, int tiles_log2)
static av_cold void free_coded_frame(struct FrameListData *cx_frame)
static av_cold int codecctl_int(AVCodecContext *avctx, int id, int val)
static av_cold int aom_free(AVCodecContext *avctx)
static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static av_cold int aom_init(AVCodecContext *avctx, const struct aom_codec_iface *iface)
static int qpfile_aom_cpu_used(const AOMContext *ctx)
static av_cold int aom_config(AVCodecContext *avctx, const struct aom_codec_iface *iface)
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().
static enum AVPixelFormat av1_pix_fmts[]
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)
static void coded_frame_add(void *list, struct FrameListData *cx_frame)
static av_cold int aom_codecctl(AVCodecContext *avctx)
static av_cold void free_frame_list(struct FrameListData *list)
static const AVClass class_aom
static av_cold void dump_enc_cfg(AVCodecContext *avctx, const struct aom_codec_enc_cfg *cfg, int level)
static int choose_tiling(AVCodecContext *avctx, struct aom_codec_enc_cfg *enccfg)
common internal api header.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int load_qpfile(AVCodecContext *avctx)
static const struct @257111027162314367033347246032313251342043035002 planes[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV420P10
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AV_PIX_FMT_GRAY10
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
#define AV_PIX_FMT_YUV444P10
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
const AVProfile ff_av1_profiles[]
#define FF_AV1_PROFILE_OPTS
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 FF_ARRAY_ELEMS(a)
int use_intra_default_tx_only
AVDictionary * aom_params
int enable_interintra_wedge
int enable_smooth_interintra
struct aom_fixed_buf twopass_stats
int enable_reduced_reference_set
int enable_1to4_partitions
int enable_rect_partitions
aom_superblock_size_t superblock_size
int roi_seg_q[AOM_MAX_SEGMENTS]
int have_sse
true if we have pending sse[]
struct FrameListData * coded_frame_list
int enable_interintra_comp
unsigned int roi_input_frame
struct aom_codec_enc_cfg enccfg
unsigned twopass_stats_size
int enable_interinter_wedge
int enable_intra_edge_filter
struct aom_codec_ctx encoder
The bitstream filter state.
uint8_t * data
The data buffer.
This structure describes the bitrate properties of an encoded bitstream.
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
char * stats_out
pass1 encoding statistics output buffer
int rc_buffer_size
decoder bitstream buffer size
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int qmin
minimum quantizer
int keyint_min
minimum GOP size
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
int64_t bit_rate
the average bitrate
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
enum AVColorSpace colorspace
YUV colorspace type.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int refs
number of reference frames
int64_t rc_max_rate
maximum bitrate
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int qmax
maximum quantizer
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
int64_t rc_min_rate
minimum bitrate
uint64_t error[AV_NUM_DATA_POINTERS]
error
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
struct AVCodecInternal * internal
Private context used for internal data.
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
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.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
int64_t pts
time stamp to show frame (in timebase units)
struct FrameListData * next
size_t sz
length of compressed data
void * buf
compressed data buffer
unsigned long duration
duration to show frame (in timebase units)
int have_sse
true if we have pending sse[]
uint32_t flags
flags for this frame
static void error(const char *err)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)