28 #define AOM_DISABLE_CTRL_TYPECHECKS 1
29 #include <aom/aom_encoder.h>
30 #include <aom/aomcx.h>
141 [AOME_SET_CPUUSED] =
"AOME_SET_CPUUSED",
142 [AOME_SET_CQ_LEVEL] =
"AOME_SET_CQ_LEVEL",
143 [AOME_SET_ENABLEAUTOALTREF] =
"AOME_SET_ENABLEAUTOALTREF",
144 [AOME_SET_ARNR_MAXFRAMES] =
"AOME_SET_ARNR_MAXFRAMES",
145 [AOME_SET_ARNR_STRENGTH] =
"AOME_SET_ARNR_STRENGTH",
146 [AOME_SET_STATIC_THRESHOLD] =
"AOME_SET_STATIC_THRESHOLD",
147 [AV1E_SET_COLOR_RANGE] =
"AV1E_SET_COLOR_RANGE",
148 [AV1E_SET_COLOR_PRIMARIES] =
"AV1E_SET_COLOR_PRIMARIES",
149 [AV1E_SET_MATRIX_COEFFICIENTS] =
"AV1E_SET_MATRIX_COEFFICIENTS",
150 [AV1E_SET_TRANSFER_CHARACTERISTICS] =
"AV1E_SET_TRANSFER_CHARACTERISTICS",
151 [AV1E_SET_AQ_MODE] =
"AV1E_SET_AQ_MODE",
152 [AV1E_SET_FRAME_PARALLEL_DECODING] =
"AV1E_SET_FRAME_PARALLEL_DECODING",
153 [AV1E_SET_SUPERBLOCK_SIZE] =
"AV1E_SET_SUPERBLOCK_SIZE",
154 [AV1E_SET_TILE_COLUMNS] =
"AV1E_SET_TILE_COLUMNS",
155 [AV1E_SET_TILE_ROWS] =
"AV1E_SET_TILE_ROWS",
156 [AV1E_SET_ENABLE_RESTORATION] =
"AV1E_SET_ENABLE_RESTORATION",
157 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
158 [AV1E_SET_ROW_MT] =
"AV1E_SET_ROW_MT",
160 #ifdef AOM_CTRL_AV1E_SET_DENOISE_NOISE_LEVEL
161 [AV1E_SET_DENOISE_NOISE_LEVEL] =
"AV1E_SET_DENOISE_NOISE_LEVEL",
163 #ifdef AOM_CTRL_AV1E_SET_DENOISE_BLOCK_SIZE
164 [AV1E_SET_DENOISE_BLOCK_SIZE] =
"AV1E_SET_DENOISE_BLOCK_SIZE",
166 #ifdef AOM_CTRL_AV1E_SET_MAX_REFERENCE_FRAMES
167 [AV1E_SET_MAX_REFERENCE_FRAMES] =
"AV1E_SET_MAX_REFERENCE_FRAMES",
169 #ifdef AOM_CTRL_AV1E_SET_ENABLE_GLOBAL_MOTION
170 [AV1E_SET_ENABLE_GLOBAL_MOTION] =
"AV1E_SET_ENABLE_GLOBAL_MOTION",
172 #ifdef AOM_CTRL_AV1E_SET_ENABLE_INTRABC
173 [AV1E_SET_ENABLE_INTRABC] =
"AV1E_SET_ENABLE_INTRABC",
175 [AV1E_SET_ENABLE_CDEF] =
"AV1E_SET_ENABLE_CDEF",
176 [AOME_SET_TUNING] =
"AOME_SET_TUNING",
177 #if AOM_ENCODER_ABI_VERSION >= 22
178 [AV1E_SET_ENABLE_1TO4_PARTITIONS] =
"AV1E_SET_ENABLE_1TO4_PARTITIONS",
179 [AV1E_SET_ENABLE_AB_PARTITIONS] =
"AV1E_SET_ENABLE_AB_PARTITIONS",
180 [AV1E_SET_ENABLE_RECT_PARTITIONS] =
"AV1E_SET_ENABLE_RECT_PARTITIONS",
181 [AV1E_SET_ENABLE_ANGLE_DELTA] =
"AV1E_SET_ENABLE_ANGLE_DELTA",
182 [AV1E_SET_ENABLE_CFL_INTRA] =
"AV1E_SET_ENABLE_CFL_INTRA",
183 [AV1E_SET_ENABLE_FILTER_INTRA] =
"AV1E_SET_ENABLE_FILTER_INTRA",
184 [AV1E_SET_ENABLE_INTRA_EDGE_FILTER] =
"AV1E_SET_ENABLE_INTRA_EDGE_FILTER",
185 [AV1E_SET_ENABLE_PAETH_INTRA] =
"AV1E_SET_ENABLE_PAETH_INTRA",
186 [AV1E_SET_ENABLE_SMOOTH_INTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTRA",
187 [AV1E_SET_ENABLE_PALETTE] =
"AV1E_SET_ENABLE_PALETTE",
188 [AV1E_SET_ENABLE_FLIP_IDTX] =
"AV1E_SET_ENABLE_FLIP_IDTX",
189 [AV1E_SET_ENABLE_TX64] =
"AV1E_SET_ENABLE_TX64",
190 [AV1E_SET_INTRA_DCT_ONLY] =
"AV1E_SET_INTRA_DCT_ONLY",
191 [AV1E_SET_INTER_DCT_ONLY] =
"AV1E_SET_INTER_DCT_ONLY",
192 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] =
"AV1E_SET_INTRA_DEFAULT_TX_ONLY",
193 [AV1E_SET_REDUCED_TX_TYPE_SET] =
"AV1E_SET_REDUCED_TX_TYPE_SET",
194 [AV1E_SET_ENABLE_DIFF_WTD_COMP] =
"AV1E_SET_ENABLE_DIFF_WTD_COMP",
195 [AV1E_SET_ENABLE_DIST_WTD_COMP] =
"AV1E_SET_ENABLE_DIST_WTD_COMP",
196 [AV1E_SET_ENABLE_DUAL_FILTER] =
"AV1E_SET_ENABLE_DUAL_FILTER",
197 [AV1E_SET_ENABLE_INTERINTER_WEDGE] =
"AV1E_SET_ENABLE_INTERINTER_WEDGE",
198 [AV1E_SET_ENABLE_INTERINTRA_WEDGE] =
"AV1E_SET_ENABLE_INTERINTRA_WEDGE",
199 [AV1E_SET_ENABLE_MASKED_COMP] =
"AV1E_SET_ENABLE_MASKED_COMP",
200 [AV1E_SET_ENABLE_INTERINTRA_COMP] =
"AV1E_SET_ENABLE_INTERINTRA_COMP",
201 [AV1E_SET_ENABLE_OBMC] =
"AV1E_SET_ENABLE_OBMC",
202 [AV1E_SET_ENABLE_ONESIDED_COMP] =
"AV1E_SET_ENABLE_ONESIDED_COMP",
203 [AV1E_SET_REDUCED_REFERENCE_SET] =
"AV1E_SET_REDUCED_REFERENCE_SET",
204 [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
205 [AV1E_SET_ENABLE_REF_FRAME_MVS] =
"AV1E_SET_ENABLE_REF_FRAME_MVS",
207 #ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS
208 [AV1E_GET_NUM_OPERATING_POINTS] =
"AV1E_GET_NUM_OPERATING_POINTS",
210 #ifdef AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX
211 [AV1E_GET_SEQ_LEVEL_IDX] =
"AV1E_GET_SEQ_LEVEL_IDX",
213 #ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
214 [AV1E_GET_TARGET_SEQ_LEVEL_IDX] =
"AV1E_GET_TARGET_SEQ_LEVEL_IDX",
216 [AV1_GET_NEW_FRAME_IMAGE] =
"AV1_GET_NEW_FRAME_IMAGE",
222 const char *
error = aom_codec_error(&
ctx->encoder);
223 const char *detail = aom_codec_error_detail(&
ctx->encoder);
231 const struct aom_codec_enc_cfg *cfg,
238 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
240 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
241 width,
"g_usage:", cfg->g_usage,
242 width,
"g_threads:", cfg->g_threads,
243 width,
"g_profile:", cfg->g_profile,
244 width,
"g_w:", cfg->g_w,
245 width,
"g_h:", cfg->g_h,
246 width,
"g_bit_depth:", cfg->g_bit_depth,
247 width,
"g_input_bit_depth:", cfg->g_input_bit_depth,
248 width,
"g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
249 width,
"g_error_resilient:", cfg->g_error_resilient,
250 width,
"g_pass:", cfg->g_pass,
251 width,
"g_lag_in_frames:", cfg->g_lag_in_frames);
254 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
255 width,
"rc_end_usage:", cfg->rc_end_usage,
256 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
257 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
260 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
261 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
264 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
265 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
267 " %*s%u\n %*s%u\n %*s%u\n",
268 width,
"rc_buf_sz:", cfg->rc_buf_sz,
269 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
270 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
271 av_log(avctx,
level,
"2 pass rate control settings\n"
272 " %*s%u\n %*s%u\n %*s%u\n",
273 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
274 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
275 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
277 " %*s%d\n %*s%u\n %*s%u\n",
278 width,
"kf_mode:", cfg->kf_mode,
279 width,
"kf_min_dist:", cfg->kf_min_dist,
280 width,
"kf_max_dist:", cfg->kf_max_dist);
283 width,
"tile_width_count:", cfg->tile_width_count,
284 width,
"tile_height_count:", cfg->tile_height_count);
317 aome_enc_control_id
id,
319 enum aome_enc_control_id
id,
331 res = aom_codec_control(&
ctx->encoder,
id,
val);
332 if (res != AOM_CODEC_OK) {
342 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
343 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
344 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
347 aome_enc_control_id
id,
349 enum aome_enc_control_id
id,
361 res = aom_codec_control(&
ctx->encoder,
id, ptr);
362 if (res != AOM_CODEC_OK) {
375 aome_enc_control_id
id,
377 enum aome_enc_control_id
id,
379 struct aom_image *
img)
387 res = aom_codec_control(&
ctx->encoder,
id,
img);
388 if (res != AOM_CODEC_OK) {
402 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
403 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
404 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
406 int num_operating_points;
408 int target_levels[32];
410 if (!codecctl_intp(avctx, AV1E_GET_NUM_OPERATING_POINTS,
411 &num_operating_points) &&
412 !codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) &&
413 !codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX,
415 for (
int i = 0;
i < num_operating_points;
i++) {
416 if (levels[
i] > target_levels[
i]) {
419 "Could not encode to target level %d.%d for "
420 "operating point %d. The output level is %d.%d.\n",
421 2 + (target_levels[
i] >> 2), target_levels[
i] & 3,
422 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
423 }
else if (target_levels[
i] < 31) {
426 "Output level for operating point %d is %d.%d.\n",
427 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
434 aom_codec_destroy(&
ctx->encoder);
443 struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *
flags,
444 aom_img_fmt_t *img_fmt)
448 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
451 enccfg->monochrome = 1;
455 *img_fmt = AOM_IMG_FMT_I420;
459 *img_fmt = AOM_IMG_FMT_I422;
464 *img_fmt = AOM_IMG_FMT_I444;
468 enccfg->monochrome = 1;
472 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
475 *img_fmt = AOM_IMG_FMT_I42016;
476 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
482 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
484 *img_fmt = AOM_IMG_FMT_I42216;
485 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
493 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
496 *img_fmt = AOM_IMG_FMT_I44416;
497 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
510 aom_color_range_t aom_cr;
526 int sb_dim = (
dim + sb_size - 1) / sb_size;
527 int tile_dim = (sb_dim + (1 << tiles_log2) - 1) >> tiles_log2;
529 return (sb_dim + tile_dim - 1) / tile_dim;
533 struct aom_codec_enc_cfg *enccfg)
536 int sb_128x128_possible, sb_size, sb_width, sb_height;
537 int uniform_rows, uniform_cols;
538 int uniform_64x64_possible, uniform_128x128_possible;
539 int tile_size, rounding,
i;
541 if (
ctx->tile_cols_log2 >= 0)
542 ctx->tile_cols = 1 <<
ctx->tile_cols_log2;
543 if (
ctx->tile_rows_log2 >= 0)
544 ctx->tile_rows = 1 <<
ctx->tile_rows_log2;
546 if (
ctx->tile_cols == 0) {
549 if (
ctx->tile_cols > 1) {
551 "columns to fill width.\n",
ctx->tile_cols);
555 if (
ctx->tile_rows == 0) {
558 ctx->tile_cols - 1) /
ctx->tile_cols, 128);
562 if (
ctx->tile_rows > 1) {
564 "rows to fill area.\n",
ctx->tile_rows);
569 if ((avctx->
width + 63) / 64 <
ctx->tile_cols ||
570 (avctx->
height + 63) / 64 <
ctx->tile_rows) {
572 "large enough to fit specified tile arrangement.\n");
578 "not allow more than %dx%d tiles.\n",
584 "not allow tiles of width greater than %d.\n",
589 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
591 if (
ctx->tile_cols == 1 &&
ctx->tile_rows == 1) {
596 sb_128x128_possible =
597 (avctx->
width + 127) / 128 >=
ctx->tile_cols &&
598 (avctx->
height + 127) / 128 >=
ctx->tile_rows;
600 ctx->tile_cols_log2 =
ctx->tile_cols == 1 ? 0 :
602 ctx->tile_rows_log2 =
ctx->tile_rows == 1 ? 0 :
606 64,
ctx->tile_cols_log2);
608 64,
ctx->tile_rows_log2);
610 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
611 uniform_64x64_possible = uniform_cols ==
ctx->tile_cols &&
612 uniform_rows ==
ctx->tile_rows;
614 if (sb_128x128_possible) {
616 128,
ctx->tile_cols_log2);
618 128,
ctx->tile_rows_log2);
620 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
621 uniform_128x128_possible = uniform_cols ==
ctx->tile_cols &&
622 uniform_rows ==
ctx->tile_rows;
625 uniform_128x128_possible = 0;
628 ctx->uniform_tiles = 1;
629 if (uniform_64x64_possible && uniform_128x128_possible) {
631 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
632 ctx->tile_cols_log2,
ctx->tile_rows_log2);
635 if (uniform_64x64_possible && !sb_128x128_possible) {
637 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
638 ctx->tile_cols_log2,
ctx->tile_rows_log2);
639 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
642 if (uniform_128x128_possible) {
644 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
645 ctx->tile_cols_log2,
ctx->tile_rows_log2);
646 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
649 ctx->uniform_tiles = 0;
651 if (sb_128x128_possible) {
653 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
656 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
659 "superblocks (tile_cols = %d, tile_rows = %d).\n",
660 sb_size, sb_size,
ctx->tile_cols,
ctx->tile_rows);
662 enccfg->tile_width_count =
ctx->tile_cols;
663 enccfg->tile_height_count =
ctx->tile_rows;
665 sb_width = (avctx->
width + sb_size - 1) / sb_size;
666 sb_height = (avctx->
height + sb_size - 1) / sb_size;
668 tile_size = sb_width /
ctx->tile_cols;
669 rounding = sb_width %
ctx->tile_cols;
670 for (
i = 0;
i <
ctx->tile_cols;
i++) {
671 enccfg->tile_widths[
i] = tile_size +
673 i >
ctx->tile_cols - 1 - (rounding + 1) / 2);
676 tile_size = sb_height /
ctx->tile_rows;
677 rounding = sb_height %
ctx->tile_rows;
678 for (
i = 0;
i <
ctx->tile_rows;
i++) {
679 enccfg->tile_heights[
i] = tile_size +
681 i >
ctx->tile_rows - 1 - (rounding + 1) / 2);
688 const struct aom_codec_iface *iface)
692 struct aom_codec_enc_cfg enccfg = { 0 };
693 #ifdef AOM_FRAME_IS_INTRAONLY
694 aom_codec_flags_t
flags =
697 aom_codec_flags_t
flags = 0;
701 aom_img_fmt_t img_fmt;
702 aom_codec_caps_t codec_caps = aom_codec_get_caps(iface);
707 if ((res = aom_codec_enc_config_default(iface, &enccfg,
ctx->usage)) != AOM_CODEC_OK) {
709 aom_codec_err_to_string(res));
724 enccfg.g_w = avctx->
width;
725 enccfg.g_h = avctx->
height;
731 if (
ctx->lag_in_frames >= 0)
732 enccfg.g_lag_in_frames =
ctx->lag_in_frames;
735 enccfg.g_pass = AOM_RC_FIRST_PASS;
737 enccfg.g_pass = AOM_RC_LAST_PASS;
739 enccfg.g_pass = AOM_RC_ONE_PASS;
743 enccfg.rc_end_usage = AOM_CBR;
744 }
else if (
ctx->crf >= 0) {
745 enccfg.rc_end_usage = AOM_CQ;
747 enccfg.rc_end_usage = AOM_Q;
753 }
else if (enccfg.rc_end_usage != AOM_Q) {
754 enccfg.rc_end_usage = AOM_Q;
757 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
761 if (avctx->
qmin >= 0)
762 enccfg.rc_min_quantizer = avctx->
qmin;
763 if (avctx->
qmax >= 0) {
764 enccfg.rc_max_quantizer = avctx->
qmax;
765 }
else if (!
ctx->crf) {
766 enccfg.rc_max_quantizer = 0;
769 if (enccfg.rc_end_usage == AOM_CQ || enccfg.rc_end_usage == AOM_Q) {
770 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
772 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
773 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
778 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
782 if (
ctx->minsection_pct >= 0)
783 enccfg.rc_2pass_vbr_minsection_pct =
ctx->minsection_pct;
785 enccfg.rc_2pass_vbr_minsection_pct =
787 if (
ctx->maxsection_pct >= 0)
788 enccfg.rc_2pass_vbr_maxsection_pct =
ctx->maxsection_pct;
790 enccfg.rc_2pass_vbr_maxsection_pct =
797 enccfg.rc_buf_initial_sz =
799 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
801 if (
ctx->rc_undershoot_pct >= 0)
802 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
803 if (
ctx->rc_overshoot_pct >= 0)
804 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
810 enccfg.kf_max_dist = avctx->
gop_size;
812 if (enccfg.g_pass == AOM_RC_FIRST_PASS)
813 enccfg.g_lag_in_frames = 0;
814 else if (enccfg.g_pass == AOM_RC_LAST_PASS) {
815 int decode_size,
ret;
822 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
827 ctx->twopass_stats.sz);
828 ctx->twopass_stats.sz = 0;
832 ctx->twopass_stats.sz);
833 if (decode_size < 0) {
838 ctx->twopass_stats.sz = decode_size;
839 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
846 enccfg.g_profile = avctx->
profile;
848 enccfg.g_error_resilient =
ctx->error_resilient;
854 if (
ctx->still_picture) {
860 enccfg.g_lag_in_frames = 0;
862 enccfg.kf_max_dist = 0;
863 enccfg.kf_mode = AOM_KF_DISABLED;
867 res = aom_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
868 if (res != AOM_CODEC_OK) {
878 if (
ctx->auto_alt_ref >= 0)
880 if (
ctx->arnr_max_frames >= 0)
882 if (
ctx->arnr_strength >= 0)
884 if (
ctx->enable_cdef >= 0)
886 if (
ctx->enable_restoration >= 0)
887 codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION,
ctx->enable_restoration);
888 #if AOM_ENCODER_ABI_VERSION >= 22
889 if (
ctx->enable_rect_partitions >= 0)
890 codecctl_int(avctx, AV1E_SET_ENABLE_RECT_PARTITIONS,
ctx->enable_rect_partitions);
891 if (
ctx->enable_1to4_partitions >= 0)
892 codecctl_int(avctx, AV1E_SET_ENABLE_1TO4_PARTITIONS,
ctx->enable_1to4_partitions);
893 if (
ctx->enable_ab_partitions >= 0)
894 codecctl_int(avctx, AV1E_SET_ENABLE_AB_PARTITIONS,
ctx->enable_ab_partitions);
895 if (
ctx->enable_angle_delta >= 0)
896 codecctl_int(avctx, AV1E_SET_ENABLE_ANGLE_DELTA,
ctx->enable_angle_delta);
897 if (
ctx->enable_cfl_intra >= 0)
899 if (
ctx->enable_filter_intra >= 0)
900 codecctl_int(avctx, AV1E_SET_ENABLE_FILTER_INTRA,
ctx->enable_filter_intra);
901 if (
ctx->enable_intra_edge_filter >= 0)
902 codecctl_int(avctx, AV1E_SET_ENABLE_INTRA_EDGE_FILTER,
ctx->enable_intra_edge_filter);
903 if (
ctx->enable_paeth_intra >= 0)
904 codecctl_int(avctx, AV1E_SET_ENABLE_PAETH_INTRA,
ctx->enable_paeth_intra);
905 if (
ctx->enable_smooth_intra >= 0)
906 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA,
ctx->enable_smooth_intra);
907 if (
ctx->enable_palette >= 0)
909 if (
ctx->enable_tx64 >= 0)
911 if (
ctx->enable_flip_idtx >= 0)
913 if (
ctx->use_intra_dct_only >= 0)
915 if (
ctx->use_inter_dct_only >= 0)
917 if (
ctx->use_intra_default_tx_only >= 0)
918 codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY,
ctx->use_intra_default_tx_only);
919 if (
ctx->reduced_tx_type_set >= 0)
920 codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET,
ctx->reduced_tx_type_set);
921 if (
ctx->enable_ref_frame_mvs >= 0)
922 codecctl_int(avctx, AV1E_SET_ENABLE_REF_FRAME_MVS,
ctx->enable_ref_frame_mvs);
923 if (
ctx->enable_reduced_reference_set >= 0)
924 codecctl_int(avctx, AV1E_SET_REDUCED_REFERENCE_SET,
ctx->enable_reduced_reference_set);
925 if (
ctx->enable_diff_wtd_comp >= 0)
926 codecctl_int(avctx, AV1E_SET_ENABLE_DIFF_WTD_COMP,
ctx->enable_diff_wtd_comp);
927 if (
ctx->enable_dist_wtd_comp >= 0)
928 codecctl_int(avctx, AV1E_SET_ENABLE_DIST_WTD_COMP,
ctx->enable_dist_wtd_comp);
929 if (
ctx->enable_dual_filter >= 0)
930 codecctl_int(avctx, AV1E_SET_ENABLE_DUAL_FILTER,
ctx->enable_dual_filter);
931 if (
ctx->enable_interinter_wedge >= 0)
932 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTER_WEDGE,
ctx->enable_interinter_wedge);
933 if (
ctx->enable_masked_comp >= 0)
934 codecctl_int(avctx, AV1E_SET_ENABLE_MASKED_COMP,
ctx->enable_masked_comp);
935 if (
ctx->enable_interintra_comp >= 0)
936 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_COMP,
ctx->enable_interintra_comp);
937 if (
ctx->enable_interintra_wedge >= 0)
938 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_WEDGE,
ctx->enable_interintra_wedge);
939 if (
ctx->enable_obmc >= 0)
941 if (
ctx->enable_onesided_comp >= 0)
942 codecctl_int(avctx, AV1E_SET_ENABLE_ONESIDED_COMP,
ctx->enable_onesided_comp);
943 if (
ctx->enable_smooth_interintra >= 0)
944 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTERINTRA,
ctx->enable_smooth_interintra);
962 if (
ctx->aq_mode >= 0)
964 if (
ctx->frame_parallel >= 0)
965 codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
969 if (
ctx->uniform_tiles) {
974 #ifdef AOM_CTRL_AV1E_SET_DENOISE_NOISE_LEVEL
975 if (
ctx->denoise_noise_level >= 0)
976 codecctl_int(avctx, AV1E_SET_DENOISE_NOISE_LEVEL,
ctx->denoise_noise_level);
978 #ifdef AOM_CTRL_AV1E_SET_DENOISE_BLOCK_SIZE
979 if (
ctx->denoise_block_size >= 0)
980 codecctl_int(avctx, AV1E_SET_DENOISE_BLOCK_SIZE,
ctx->denoise_block_size);
982 #ifdef AOM_CTRL_AV1E_SET_ENABLE_GLOBAL_MOTION
983 if (
ctx->enable_global_motion >= 0)
984 codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION,
ctx->enable_global_motion);
986 #ifdef AOM_CTRL_AV1E_SET_MAX_REFERENCE_FRAMES
987 if (avctx->
refs >= 3) {
991 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
992 if (
ctx->row_mt >= 0)
995 #ifdef AOM_CTRL_AV1E_SET_ENABLE_INTRABC
996 if (
ctx->enable_intrabc >= 0)
1000 #if AOM_ENCODER_ABI_VERSION >= 23
1005 int ret = aom_codec_set_option(&
ctx->encoder, en->
key, en->
value);
1006 if (
ret != AOM_CODEC_OK) {
1015 aom_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
1018 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
1019 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
1031 "not found. This is a bug, please report it.\n");
1047 if (enccfg.rc_end_usage == AOM_CBR ||
1048 enccfg.g_pass != AOM_RC_ONE_PASS) {
1060 const struct aom_codec_cx_pkt *
src)
1062 dst->
pts =
src->data.frame.pts;
1064 dst->
flags =
src->data.frame.flags;
1065 dst->
sz =
src->data.frame.sz;
1066 dst->
buf =
src->data.frame.buf;
1067 #ifdef AOM_FRAME_IS_INTRAONLY
1070 if (
ctx->have_sse) {
1073 memcpy(dst->
sse,
ctx->sse,
sizeof(dst->
sse));
1101 if (!!(cx_frame->
flags & AOM_FRAME_IS_KEY)) {
1103 #ifdef AOM_FRAME_IS_INTRAONLY
1105 }
else if (cx_frame->
flags & AOM_FRAME_IS_INTRAONLY) {
1112 cx_frame->
have_sse ? 3 : 0, pict_type);
1116 for (
i = 0;
i < 3; ++
i) {
1127 "failed to send input packet\n");
1134 "failed to receive output packet\n");
1152 const struct aom_codec_cx_pkt *
pkt;
1153 const void *iter =
NULL;
1156 if (
ctx->coded_frame_list) {
1162 ctx->coded_frame_list = cx_frame->
next;
1168 while ((
pkt = aom_codec_get_cx_data(&
ctx->encoder, &iter))) {
1169 switch (
pkt->kind) {
1170 case AOM_CODEC_CX_FRAME_PKT:
1187 "Frame queue element alloc failed\n");
1193 if (!cx_frame->
buf) {
1204 case AOM_CODEC_STATS_PKT:
1206 struct aom_fixed_buf *
stats = &
ctx->twopass_stats;
1208 &
ctx->twopass_stats_size,
1223 #ifdef AOM_FRAME_IS_INTRAONLY
1224 case AOM_CODEC_PSNR_PKT:
1235 case AOM_CODEC_CUSTOM_PKT:
1247 case AOM_IMG_FMT_I420:
1248 case AOM_IMG_FMT_I42016:
1249 if (
img->bit_depth == 8)
1251 else if (
img->bit_depth == 10)
1255 case AOM_IMG_FMT_I422:
1256 case AOM_IMG_FMT_I42216:
1257 if (
img->bit_depth == 8)
1259 else if (
img->bit_depth == 10)
1263 case AOM_IMG_FMT_I444:
1264 case AOM_IMG_FMT_I44416:
1265 if (
img->bit_depth == 8)
1267 else if (
img->bit_depth == 10)
1279 struct aom_image *rawimg =
NULL;
1280 int64_t timestamp = 0;
1282 int res, coded_size;
1283 aom_enc_frame_flags_t
flags = 0;
1286 rawimg = &
ctx->rawimg;
1287 rawimg->planes[AOM_PLANE_Y] =
frame->
data[0];
1288 rawimg->planes[AOM_PLANE_U] =
frame->
data[1];
1289 rawimg->planes[AOM_PLANE_V] =
frame->
data[2];
1305 #if FF_API_TICKS_PER_FRAME
1314 rawimg->range = AOM_CR_STUDIO_RANGE;
1317 rawimg->range = AOM_CR_FULL_RANGE;
1322 flags |= AOM_EFLAG_FORCE_KF;
1326 if (res != AOM_CODEC_OK) {
1344 ctx->twopass_stats.sz);
1347 *got_packet = !!coded_size;
1351 struct aom_image
img;
1362 "Unhandled reconstructed frame colorspace: %d\n",
1374 if ((
img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) &&
img.bit_depth == 8)
1377 const uint8_t *
planes[4] = {
img.planes[0],
img.planes[1],
img.planes[2] };
1378 const int stride[4] = {
img.stride[0],
img.stride[1],
img.stride[2] };
1442 int supports_monochrome = aom_codec_version() >= 20001;
1443 aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
1444 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
1451 if (aom_codec_version_major() < 2)
1457 return aom_init(avctx, aom_codec_av1_cx());
1460 #define OFFSET(x) offsetof(AOMContext, x)
1461 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1464 {
"auto-alt-ref",
"Enable use of alternate reference "
1466 {
"lag-in-frames",
"Number of frames to look ahead at for "
1468 {
"arnr-max-frames",
"altref noise reduction max frame count",
OFFSET(arnr_max_frames),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1469 {
"arnr-strength",
"altref noise reduction filter strength",
OFFSET(arnr_strength),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1470 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE,
"aq_mode"},
1472 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE,
"aq_mode"},
1473 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE,
"aq_mode"},
1475 {
"error-resilience",
"Error resilience configuration",
OFFSET(error_resilient),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
VE,
"er"},
1476 {
"default",
"Improve resiliency against losses of whole frames", 0,
AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0,
VE,
"er"},
1477 {
"crf",
"Select the quality for constant quality mode", offsetof(AOMContext, crf),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63,
VE },
1478 {
"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 },
1479 {
"drop-threshold",
"Frame drop threshold", offsetof(AOMContext, drop_threshold),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
VE },
1480 {
"denoise-noise-level",
"Amount of noise to be removed",
OFFSET(denoise_noise_level),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1481 {
"denoise-block-size",
"Denoise block size ",
OFFSET(denoise_block_size),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1482 {
"undershoot-pct",
"Datarate undershoot (min) target (%)",
OFFSET(rc_undershoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1483 {
"overshoot-pct",
"Datarate overshoot (max) target (%)",
OFFSET(rc_overshoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1000,
VE},
1484 {
"minsection-pct",
"GOP min bitrate (% of target)",
OFFSET(minsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1485 {
"maxsection-pct",
"GOP max bitrate (% of target)",
OFFSET(maxsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 5000,
VE},
1486 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1488 {
"tile-columns",
"Log2 of number of tile columns to use",
OFFSET(tile_cols_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1489 {
"tile-rows",
"Log2 of number of tile rows to use",
OFFSET(tile_rows_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1492 {
"enable-global-motion",
"Enable global motion",
OFFSET(enable_global_motion),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1493 {
"enable-intrabc",
"Enable intra block copy prediction mode",
OFFSET(enable_intrabc),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1494 {
"enable-restoration",
"Enable Loop Restoration filtering",
OFFSET(enable_restoration),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1495 {
"usage",
"Quality and compression efficiency vs speed trade-off",
OFFSET(
usage),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
VE,
"usage"},
1498 {
"allintra",
"All Intra encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0,
VE,
"usage"},
1499 {
"tune",
"The metric that the encoder tunes for. Automatically chosen by the encoder by default",
OFFSET(tune),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, AOM_TUNE_SSIM,
VE,
"tune"},
1503 {
"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 },
1504 {
"enable-rect-partitions",
"Enable rectangular partitions",
OFFSET(enable_rect_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1505 {
"enable-1to4-partitions",
"Enable 1:4/4:1 partitions",
OFFSET(enable_1to4_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1506 {
"enable-ab-partitions",
"Enable ab shape partitions",
OFFSET(enable_ab_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1507 {
"enable-angle-delta",
"Enable angle delta intra prediction",
OFFSET(enable_angle_delta),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1508 {
"enable-cfl-intra",
"Enable chroma predicted from luma intra prediction",
OFFSET(enable_cfl_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1509 {
"enable-filter-intra",
"Enable filter intra predictor",
OFFSET(enable_filter_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1510 {
"enable-intra-edge-filter",
"Enable intra edge filter",
OFFSET(enable_intra_edge_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1511 {
"enable-smooth-intra",
"Enable smooth intra prediction mode",
OFFSET(enable_smooth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1512 {
"enable-paeth-intra",
"Enable paeth predictor in intra prediction",
OFFSET(enable_paeth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1513 {
"enable-palette",
"Enable palette prediction mode",
OFFSET(enable_palette),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1514 {
"enable-flip-idtx",
"Enable extended transform type",
OFFSET(enable_flip_idtx),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1516 {
"reduced-tx-type-set",
"Use reduced set of transform types",
OFFSET(reduced_tx_type_set),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1517 {
"use-intra-dct-only",
"Use DCT only for INTRA modes",
OFFSET(use_intra_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1518 {
"use-inter-dct-only",
"Use DCT only for INTER modes",
OFFSET(use_inter_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1519 {
"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},
1520 {
"enable-ref-frame-mvs",
"Enable temporal mv prediction",
OFFSET(enable_ref_frame_mvs),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1521 {
"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},
1523 {
"enable-dual-filter",
"Enable dual filter",
OFFSET(enable_dual_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1524 {
"enable-diff-wtd-comp",
"Enable difference-weighted compound",
OFFSET(enable_diff_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1525 {
"enable-dist-wtd-comp",
"Enable distance-weighted compound",
OFFSET(enable_dist_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1526 {
"enable-onesided-comp",
"Enable one sided compound",
OFFSET(enable_onesided_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1527 {
"enable-interinter-wedge",
"Enable interinter wedge compound",
OFFSET(enable_interinter_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1528 {
"enable-interintra-wedge",
"Enable interintra wedge compound",
OFFSET(enable_interintra_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1529 {
"enable-masked-comp",
"Enable masked compound",
OFFSET(enable_masked_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1530 {
"enable-interintra-comp",
"Enable interintra compound",
OFFSET(enable_interintra_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1531 {
"enable-smooth-interintra",
"Enable smooth interintra mode",
OFFSET(enable_smooth_interintra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1532 #if AOM_ENCODER_ABI_VERSION >= 23
1533 {
"aom-params",
"Set libaom options using a :-separated list of key=value pairs",
OFFSET(aom_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
1543 {
"keyint_min",
"-1" },
1555 .
p.
name =
"libaom-av1",
1564 .p.wrapper_name =
"libaom",
1565 .priv_data_size =
sizeof(AOMContext),