28 #define AOM_DISABLE_CTRL_TYPECHECKS 1
29 #include <aom/aom_encoder.h>
30 #include <aom/aomcx.h>
142 [AOME_SET_CPUUSED] =
"AOME_SET_CPUUSED",
143 [AOME_SET_CQ_LEVEL] =
"AOME_SET_CQ_LEVEL",
144 [AOME_SET_ENABLEAUTOALTREF] =
"AOME_SET_ENABLEAUTOALTREF",
145 [AOME_SET_ARNR_MAXFRAMES] =
"AOME_SET_ARNR_MAXFRAMES",
146 [AOME_SET_ARNR_STRENGTH] =
"AOME_SET_ARNR_STRENGTH",
147 [AOME_SET_STATIC_THRESHOLD] =
"AOME_SET_STATIC_THRESHOLD",
148 [AV1E_SET_COLOR_RANGE] =
"AV1E_SET_COLOR_RANGE",
149 [AV1E_SET_COLOR_PRIMARIES] =
"AV1E_SET_COLOR_PRIMARIES",
150 [AV1E_SET_MATRIX_COEFFICIENTS] =
"AV1E_SET_MATRIX_COEFFICIENTS",
151 [AV1E_SET_TRANSFER_CHARACTERISTICS] =
"AV1E_SET_TRANSFER_CHARACTERISTICS",
152 [AV1E_SET_AQ_MODE] =
"AV1E_SET_AQ_MODE",
153 [AV1E_SET_FRAME_PARALLEL_DECODING] =
"AV1E_SET_FRAME_PARALLEL_DECODING",
154 [AV1E_SET_SUPERBLOCK_SIZE] =
"AV1E_SET_SUPERBLOCK_SIZE",
155 [AV1E_SET_TILE_COLUMNS] =
"AV1E_SET_TILE_COLUMNS",
156 [AV1E_SET_TILE_ROWS] =
"AV1E_SET_TILE_ROWS",
157 [AV1E_SET_ENABLE_RESTORATION] =
"AV1E_SET_ENABLE_RESTORATION",
158 [AV1E_SET_ROW_MT] =
"AV1E_SET_ROW_MT",
159 [AV1E_SET_DENOISE_NOISE_LEVEL] =
"AV1E_SET_DENOISE_NOISE_LEVEL",
160 [AV1E_SET_DENOISE_BLOCK_SIZE] =
"AV1E_SET_DENOISE_BLOCK_SIZE",
161 [AV1E_SET_MAX_REFERENCE_FRAMES] =
"AV1E_SET_MAX_REFERENCE_FRAMES",
162 [AV1E_SET_ENABLE_GLOBAL_MOTION] =
"AV1E_SET_ENABLE_GLOBAL_MOTION",
163 [AV1E_SET_ENABLE_INTRABC] =
"AV1E_SET_ENABLE_INTRABC",
164 [AV1E_SET_ENABLE_CDEF] =
"AV1E_SET_ENABLE_CDEF",
165 [AOME_SET_TUNING] =
"AOME_SET_TUNING",
166 [AV1E_SET_ENABLE_1TO4_PARTITIONS] =
"AV1E_SET_ENABLE_1TO4_PARTITIONS",
167 [AV1E_SET_ENABLE_AB_PARTITIONS] =
"AV1E_SET_ENABLE_AB_PARTITIONS",
168 [AV1E_SET_ENABLE_RECT_PARTITIONS] =
"AV1E_SET_ENABLE_RECT_PARTITIONS",
169 [AV1E_SET_ENABLE_ANGLE_DELTA] =
"AV1E_SET_ENABLE_ANGLE_DELTA",
170 [AV1E_SET_ENABLE_CFL_INTRA] =
"AV1E_SET_ENABLE_CFL_INTRA",
171 [AV1E_SET_ENABLE_FILTER_INTRA] =
"AV1E_SET_ENABLE_FILTER_INTRA",
172 [AV1E_SET_ENABLE_INTRA_EDGE_FILTER] =
"AV1E_SET_ENABLE_INTRA_EDGE_FILTER",
173 [AV1E_SET_ENABLE_PAETH_INTRA] =
"AV1E_SET_ENABLE_PAETH_INTRA",
174 [AV1E_SET_ENABLE_SMOOTH_INTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTRA",
175 [AV1E_SET_ENABLE_PALETTE] =
"AV1E_SET_ENABLE_PALETTE",
176 [AV1E_SET_ENABLE_FLIP_IDTX] =
"AV1E_SET_ENABLE_FLIP_IDTX",
177 [AV1E_SET_ENABLE_TX64] =
"AV1E_SET_ENABLE_TX64",
178 [AV1E_SET_INTRA_DCT_ONLY] =
"AV1E_SET_INTRA_DCT_ONLY",
179 [AV1E_SET_INTER_DCT_ONLY] =
"AV1E_SET_INTER_DCT_ONLY",
180 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] =
"AV1E_SET_INTRA_DEFAULT_TX_ONLY",
181 [AV1E_SET_REDUCED_TX_TYPE_SET] =
"AV1E_SET_REDUCED_TX_TYPE_SET",
182 [AV1E_SET_ENABLE_DIFF_WTD_COMP] =
"AV1E_SET_ENABLE_DIFF_WTD_COMP",
183 [AV1E_SET_ENABLE_DIST_WTD_COMP] =
"AV1E_SET_ENABLE_DIST_WTD_COMP",
184 [AV1E_SET_ENABLE_DUAL_FILTER] =
"AV1E_SET_ENABLE_DUAL_FILTER",
185 [AV1E_SET_ENABLE_INTERINTER_WEDGE] =
"AV1E_SET_ENABLE_INTERINTER_WEDGE",
186 [AV1E_SET_ENABLE_INTERINTRA_WEDGE] =
"AV1E_SET_ENABLE_INTERINTRA_WEDGE",
187 [AV1E_SET_ENABLE_MASKED_COMP] =
"AV1E_SET_ENABLE_MASKED_COMP",
188 [AV1E_SET_ENABLE_INTERINTRA_COMP] =
"AV1E_SET_ENABLE_INTERINTRA_COMP",
189 [AV1E_SET_ENABLE_OBMC] =
"AV1E_SET_ENABLE_OBMC",
190 [AV1E_SET_ENABLE_ONESIDED_COMP] =
"AV1E_SET_ENABLE_ONESIDED_COMP",
191 [AV1E_SET_REDUCED_REFERENCE_SET] =
"AV1E_SET_REDUCED_REFERENCE_SET",
192 [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
193 [AV1E_SET_ENABLE_REF_FRAME_MVS] =
"AV1E_SET_ENABLE_REF_FRAME_MVS",
194 #ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS
195 [AV1E_GET_NUM_OPERATING_POINTS] =
"AV1E_GET_NUM_OPERATING_POINTS",
197 [AV1E_GET_SEQ_LEVEL_IDX] =
"AV1E_GET_SEQ_LEVEL_IDX",
198 #ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
199 [AV1E_GET_TARGET_SEQ_LEVEL_IDX] =
"AV1E_GET_TARGET_SEQ_LEVEL_IDX",
201 [AV1_GET_NEW_FRAME_IMAGE] =
"AV1_GET_NEW_FRAME_IMAGE",
207 const char *
error = aom_codec_error(&
ctx->encoder);
208 const char *detail = aom_codec_error_detail(&
ctx->encoder);
216 const struct aom_codec_enc_cfg *cfg,
223 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
225 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
226 width,
"g_usage:", cfg->g_usage,
227 width,
"g_threads:", cfg->g_threads,
228 width,
"g_profile:", cfg->g_profile,
229 width,
"g_w:", cfg->g_w,
230 width,
"g_h:", cfg->g_h,
231 width,
"g_bit_depth:", cfg->g_bit_depth,
232 width,
"g_input_bit_depth:", cfg->g_input_bit_depth,
233 width,
"g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
234 width,
"g_error_resilient:", cfg->g_error_resilient,
235 width,
"g_pass:", cfg->g_pass,
236 width,
"g_lag_in_frames:", cfg->g_lag_in_frames);
239 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
240 width,
"rc_end_usage:", cfg->rc_end_usage,
241 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
242 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
245 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
246 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
249 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
250 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
252 " %*s%u\n %*s%u\n %*s%u\n",
253 width,
"rc_buf_sz:", cfg->rc_buf_sz,
254 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
255 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
256 av_log(avctx,
level,
"2 pass rate control settings\n"
257 " %*s%u\n %*s%u\n %*s%u\n",
258 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
259 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
260 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
262 " %*s%d\n %*s%u\n %*s%u\n",
263 width,
"kf_mode:", cfg->kf_mode,
264 width,
"kf_min_dist:", cfg->kf_min_dist,
265 width,
"kf_max_dist:", cfg->kf_max_dist);
268 width,
"tile_width_count:", cfg->tile_width_count,
269 width,
"tile_height_count:", cfg->tile_height_count);
302 aome_enc_control_id
id,
304 enum aome_enc_control_id
id,
316 res = aom_codec_control(&
ctx->encoder,
id,
val);
317 if (res != AOM_CODEC_OK) {
327 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
328 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
329 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
332 aome_enc_control_id
id,
334 enum aome_enc_control_id
id,
346 res = aom_codec_control(&
ctx->encoder,
id, ptr);
347 if (res != AOM_CODEC_OK) {
360 aome_enc_control_id
id,
362 enum aome_enc_control_id
id,
364 struct aom_image *
img)
372 res = aom_codec_control(&
ctx->encoder,
id,
img);
373 if (res != AOM_CODEC_OK) {
387 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
388 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
389 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
391 int num_operating_points;
393 int target_levels[32];
395 if (!codecctl_intp(avctx, AV1E_GET_NUM_OPERATING_POINTS,
396 &num_operating_points) &&
397 !codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) &&
398 !codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX,
400 for (
int i = 0;
i < num_operating_points;
i++) {
401 if (levels[
i] > target_levels[
i]) {
404 "Could not encode to target level %d.%d for "
405 "operating point %d. The output level is %d.%d.\n",
406 2 + (target_levels[
i] >> 2), target_levels[
i] & 3,
407 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
408 }
else if (target_levels[
i] < 31) {
411 "Output level for operating point %d is %d.%d.\n",
412 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
419 aom_codec_destroy(&
ctx->encoder);
428 struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *
flags,
429 aom_img_fmt_t *img_fmt)
433 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
436 enccfg->monochrome = 1;
440 *img_fmt = AOM_IMG_FMT_I420;
444 *img_fmt = AOM_IMG_FMT_I422;
449 *img_fmt = AOM_IMG_FMT_I444;
453 enccfg->monochrome = 1;
457 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
460 *img_fmt = AOM_IMG_FMT_I42016;
461 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
467 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
469 *img_fmt = AOM_IMG_FMT_I42216;
470 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
478 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
481 *img_fmt = AOM_IMG_FMT_I44416;
482 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
495 aom_color_range_t aom_cr;
511 int sb_dim = (
dim + sb_size - 1) / sb_size;
512 int tile_dim = (sb_dim + (1 << tiles_log2) - 1) >> tiles_log2;
514 return (sb_dim + tile_dim - 1) / tile_dim;
518 struct aom_codec_enc_cfg *enccfg)
521 int sb_128x128_possible, sb_size, sb_width, sb_height;
522 int uniform_rows, uniform_cols;
523 int uniform_64x64_possible, uniform_128x128_possible;
524 int tile_size, rounding,
i;
526 if (
ctx->tile_cols_log2 >= 0)
527 ctx->tile_cols = 1 <<
ctx->tile_cols_log2;
528 if (
ctx->tile_rows_log2 >= 0)
529 ctx->tile_rows = 1 <<
ctx->tile_rows_log2;
531 if (
ctx->tile_cols == 0) {
534 if (
ctx->tile_cols > 1) {
536 "columns to fill width.\n",
ctx->tile_cols);
540 if (
ctx->tile_rows == 0) {
543 ctx->tile_cols - 1) /
ctx->tile_cols, 128);
547 if (
ctx->tile_rows > 1) {
549 "rows to fill area.\n",
ctx->tile_rows);
554 if ((avctx->
width + 63) / 64 <
ctx->tile_cols ||
555 (avctx->
height + 63) / 64 <
ctx->tile_rows) {
557 "large enough to fit specified tile arrangement.\n");
563 "not allow more than %dx%d tiles.\n",
569 "not allow tiles of width greater than %d.\n",
574 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
576 if (
ctx->tile_cols == 1 &&
ctx->tile_rows == 1) {
581 sb_128x128_possible =
582 (avctx->
width + 127) / 128 >=
ctx->tile_cols &&
583 (avctx->
height + 127) / 128 >=
ctx->tile_rows;
585 ctx->tile_cols_log2 =
ctx->tile_cols == 1 ? 0 :
587 ctx->tile_rows_log2 =
ctx->tile_rows == 1 ? 0 :
591 64,
ctx->tile_cols_log2);
593 64,
ctx->tile_rows_log2);
595 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
596 uniform_64x64_possible = uniform_cols ==
ctx->tile_cols &&
597 uniform_rows ==
ctx->tile_rows;
599 if (sb_128x128_possible) {
601 128,
ctx->tile_cols_log2);
603 128,
ctx->tile_rows_log2);
605 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
606 uniform_128x128_possible = uniform_cols ==
ctx->tile_cols &&
607 uniform_rows ==
ctx->tile_rows;
610 uniform_128x128_possible = 0;
613 ctx->uniform_tiles = 1;
614 if (uniform_64x64_possible && uniform_128x128_possible) {
616 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
617 ctx->tile_cols_log2,
ctx->tile_rows_log2);
620 if (uniform_64x64_possible && !sb_128x128_possible) {
622 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
623 ctx->tile_cols_log2,
ctx->tile_rows_log2);
624 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
627 if (uniform_128x128_possible) {
629 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
630 ctx->tile_cols_log2,
ctx->tile_rows_log2);
631 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
634 ctx->uniform_tiles = 0;
636 if (sb_128x128_possible) {
638 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
641 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
644 "superblocks (tile_cols = %d, tile_rows = %d).\n",
645 sb_size, sb_size,
ctx->tile_cols,
ctx->tile_rows);
647 enccfg->tile_width_count =
ctx->tile_cols;
648 enccfg->tile_height_count =
ctx->tile_rows;
650 sb_width = (avctx->
width + sb_size - 1) / sb_size;
651 sb_height = (avctx->
height + sb_size - 1) / sb_size;
653 tile_size = sb_width /
ctx->tile_cols;
654 rounding = sb_width %
ctx->tile_cols;
655 for (
i = 0;
i <
ctx->tile_cols;
i++) {
656 enccfg->tile_widths[
i] = tile_size +
658 i >
ctx->tile_cols - 1 - (rounding + 1) / 2);
661 tile_size = sb_height /
ctx->tile_rows;
662 rounding = sb_height %
ctx->tile_rows;
663 for (
i = 0;
i <
ctx->tile_rows;
i++) {
664 enccfg->tile_heights[
i] = tile_size +
666 i >
ctx->tile_rows - 1 - (rounding + 1) / 2);
673 const struct aom_codec_iface *iface)
677 struct aom_codec_enc_cfg enccfg = { 0 };
678 aom_codec_flags_t
flags =
682 aom_img_fmt_t img_fmt;
683 aom_codec_caps_t codec_caps = aom_codec_get_caps(iface);
688 if ((res = aom_codec_enc_config_default(iface, &enccfg,
ctx->usage)) != AOM_CODEC_OK) {
690 aom_codec_err_to_string(res));
705 enccfg.g_w = avctx->
width;
706 enccfg.g_h = avctx->
height;
712 if (
ctx->lag_in_frames >= 0)
713 enccfg.g_lag_in_frames =
ctx->lag_in_frames;
716 enccfg.g_pass = AOM_RC_FIRST_PASS;
718 enccfg.g_pass = AOM_RC_LAST_PASS;
720 enccfg.g_pass = AOM_RC_ONE_PASS;
724 enccfg.rc_end_usage = AOM_CBR;
725 }
else if (
ctx->crf >= 0) {
726 enccfg.rc_end_usage = AOM_CQ;
728 enccfg.rc_end_usage = AOM_Q;
734 }
else if (enccfg.rc_end_usage != AOM_Q) {
735 enccfg.rc_end_usage = AOM_Q;
738 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
742 if (avctx->
qmin >= 0)
743 enccfg.rc_min_quantizer = avctx->
qmin;
744 if (avctx->
qmax >= 0) {
745 enccfg.rc_max_quantizer = avctx->
qmax;
746 }
else if (!
ctx->crf) {
747 enccfg.rc_max_quantizer = 0;
750 if (enccfg.rc_end_usage == AOM_CQ || enccfg.rc_end_usage == AOM_Q) {
751 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
753 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
754 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
759 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
763 if (
ctx->minsection_pct >= 0)
764 enccfg.rc_2pass_vbr_minsection_pct =
ctx->minsection_pct;
766 enccfg.rc_2pass_vbr_minsection_pct =
768 if (
ctx->maxsection_pct >= 0)
769 enccfg.rc_2pass_vbr_maxsection_pct =
ctx->maxsection_pct;
771 enccfg.rc_2pass_vbr_maxsection_pct =
778 enccfg.rc_buf_initial_sz =
780 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
782 if (
ctx->rc_undershoot_pct >= 0)
783 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
784 if (
ctx->rc_overshoot_pct >= 0)
785 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
791 enccfg.kf_max_dist = avctx->
gop_size;
793 if (enccfg.g_pass == AOM_RC_FIRST_PASS)
794 enccfg.g_lag_in_frames = 0;
795 else if (enccfg.g_pass == AOM_RC_LAST_PASS) {
796 int decode_size,
ret;
803 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
808 ctx->twopass_stats.sz);
809 ctx->twopass_stats.sz = 0;
813 ctx->twopass_stats.sz);
814 if (decode_size < 0) {
819 ctx->twopass_stats.sz = decode_size;
820 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
827 enccfg.g_profile = avctx->
profile;
829 enccfg.g_error_resilient =
ctx->error_resilient;
835 if (
ctx->still_picture) {
841 enccfg.g_lag_in_frames = 0;
843 enccfg.kf_max_dist = 0;
844 enccfg.kf_mode = AOM_KF_DISABLED;
848 res = aom_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
849 if (res != AOM_CODEC_OK) {
859 if (
ctx->auto_alt_ref >= 0)
861 if (
ctx->arnr_max_frames >= 0)
863 if (
ctx->arnr_strength >= 0)
865 if (
ctx->enable_cdef >= 0)
867 if (
ctx->enable_restoration >= 0)
868 codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION,
ctx->enable_restoration);
869 if (
ctx->enable_rect_partitions >= 0)
870 codecctl_int(avctx, AV1E_SET_ENABLE_RECT_PARTITIONS,
ctx->enable_rect_partitions);
871 if (
ctx->enable_1to4_partitions >= 0)
872 codecctl_int(avctx, AV1E_SET_ENABLE_1TO4_PARTITIONS,
ctx->enable_1to4_partitions);
873 if (
ctx->enable_ab_partitions >= 0)
874 codecctl_int(avctx, AV1E_SET_ENABLE_AB_PARTITIONS,
ctx->enable_ab_partitions);
875 if (
ctx->enable_angle_delta >= 0)
876 codecctl_int(avctx, AV1E_SET_ENABLE_ANGLE_DELTA,
ctx->enable_angle_delta);
877 if (
ctx->enable_cfl_intra >= 0)
879 if (
ctx->enable_filter_intra >= 0)
880 codecctl_int(avctx, AV1E_SET_ENABLE_FILTER_INTRA,
ctx->enable_filter_intra);
881 if (
ctx->enable_intra_edge_filter >= 0)
882 codecctl_int(avctx, AV1E_SET_ENABLE_INTRA_EDGE_FILTER,
ctx->enable_intra_edge_filter);
883 if (
ctx->enable_paeth_intra >= 0)
884 codecctl_int(avctx, AV1E_SET_ENABLE_PAETH_INTRA,
ctx->enable_paeth_intra);
885 if (
ctx->enable_smooth_intra >= 0)
886 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA,
ctx->enable_smooth_intra);
887 if (
ctx->enable_palette >= 0)
889 if (
ctx->enable_tx64 >= 0)
891 if (
ctx->enable_flip_idtx >= 0)
893 if (
ctx->use_intra_dct_only >= 0)
895 if (
ctx->use_inter_dct_only >= 0)
897 if (
ctx->use_intra_default_tx_only >= 0)
898 codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY,
ctx->use_intra_default_tx_only);
899 if (
ctx->reduced_tx_type_set >= 0)
900 codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET,
ctx->reduced_tx_type_set);
901 if (
ctx->enable_ref_frame_mvs >= 0)
902 codecctl_int(avctx, AV1E_SET_ENABLE_REF_FRAME_MVS,
ctx->enable_ref_frame_mvs);
903 if (
ctx->enable_reduced_reference_set >= 0)
904 codecctl_int(avctx, AV1E_SET_REDUCED_REFERENCE_SET,
ctx->enable_reduced_reference_set);
905 if (
ctx->enable_diff_wtd_comp >= 0)
906 codecctl_int(avctx, AV1E_SET_ENABLE_DIFF_WTD_COMP,
ctx->enable_diff_wtd_comp);
907 if (
ctx->enable_dist_wtd_comp >= 0)
908 codecctl_int(avctx, AV1E_SET_ENABLE_DIST_WTD_COMP,
ctx->enable_dist_wtd_comp);
909 if (
ctx->enable_dual_filter >= 0)
910 codecctl_int(avctx, AV1E_SET_ENABLE_DUAL_FILTER,
ctx->enable_dual_filter);
911 if (
ctx->enable_interinter_wedge >= 0)
912 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTER_WEDGE,
ctx->enable_interinter_wedge);
913 if (
ctx->enable_masked_comp >= 0)
914 codecctl_int(avctx, AV1E_SET_ENABLE_MASKED_COMP,
ctx->enable_masked_comp);
915 if (
ctx->enable_interintra_comp >= 0)
916 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_COMP,
ctx->enable_interintra_comp);
917 if (
ctx->enable_interintra_wedge >= 0)
918 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_WEDGE,
ctx->enable_interintra_wedge);
919 if (
ctx->enable_obmc >= 0)
921 if (
ctx->enable_onesided_comp >= 0)
922 codecctl_int(avctx, AV1E_SET_ENABLE_ONESIDED_COMP,
ctx->enable_onesided_comp);
923 if (
ctx->enable_smooth_interintra >= 0)
924 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTERINTRA,
ctx->enable_smooth_interintra);
941 if (
ctx->aq_mode >= 0)
943 if (
ctx->frame_parallel >= 0)
944 codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
948 if (
ctx->uniform_tiles) {
953 if (
ctx->denoise_noise_level >= 0)
954 codecctl_int(avctx, AV1E_SET_DENOISE_NOISE_LEVEL,
ctx->denoise_noise_level);
955 if (
ctx->denoise_block_size >= 0)
956 codecctl_int(avctx, AV1E_SET_DENOISE_BLOCK_SIZE,
ctx->denoise_block_size);
957 if (
ctx->enable_global_motion >= 0)
958 codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION,
ctx->enable_global_motion);
959 if (avctx->
refs >= 3) {
962 if (
ctx->row_mt >= 0)
964 if (
ctx->enable_intrabc >= 0)
967 #if AOM_ENCODER_ABI_VERSION >= 23
972 int ret = aom_codec_set_option(&
ctx->encoder, en->
key, en->
value);
973 if (
ret != AOM_CODEC_OK) {
982 aom_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
985 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
986 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
998 "not found. This is a bug, please report it.\n");
1014 if (enccfg.rc_end_usage == AOM_CBR ||
1015 enccfg.g_pass != AOM_RC_ONE_PASS) {
1027 const struct aom_codec_cx_pkt *
src)
1029 dst->
pts =
src->data.frame.pts;
1031 dst->
flags =
src->data.frame.flags;
1032 dst->
sz =
src->data.frame.sz;
1033 dst->
buf =
src->data.frame.buf;
1036 if (
ctx->have_sse) {
1039 memcpy(dst->
sse,
ctx->sse,
sizeof(dst->
sse));
1066 if (!!(cx_frame->
flags & AOM_FRAME_IS_KEY)) {
1069 }
else if (cx_frame->
flags & AOM_FRAME_IS_INTRAONLY) {
1076 cx_frame->
have_sse ? 3 : 0, pict_type);
1080 for (
i = 0;
i < 3; ++
i) {
1090 "failed to send input packet\n");
1097 "failed to receive output packet\n");
1115 const struct aom_codec_cx_pkt *
pkt;
1116 const void *iter =
NULL;
1119 if (
ctx->coded_frame_list) {
1125 ctx->coded_frame_list = cx_frame->
next;
1131 while ((
pkt = aom_codec_get_cx_data(&
ctx->encoder, &iter))) {
1132 switch (
pkt->kind) {
1133 case AOM_CODEC_CX_FRAME_PKT:
1150 "Frame queue element alloc failed\n");
1156 if (!cx_frame->
buf) {
1167 case AOM_CODEC_STATS_PKT:
1169 struct aom_fixed_buf *
stats = &
ctx->twopass_stats;
1171 &
ctx->twopass_stats_size,
1186 case AOM_CODEC_PSNR_PKT:
1196 case AOM_CODEC_CUSTOM_PKT:
1208 case AOM_IMG_FMT_I420:
1209 case AOM_IMG_FMT_I42016:
1210 if (
img->bit_depth == 8)
1212 else if (
img->bit_depth == 10)
1216 case AOM_IMG_FMT_I422:
1217 case AOM_IMG_FMT_I42216:
1218 if (
img->bit_depth == 8)
1220 else if (
img->bit_depth == 10)
1224 case AOM_IMG_FMT_I444:
1225 case AOM_IMG_FMT_I44416:
1226 if (
img->bit_depth == 8)
1228 else if (
img->bit_depth == 10)
1240 struct aom_image *rawimg =
NULL;
1241 int64_t timestamp = 0;
1243 int res, coded_size;
1244 aom_enc_frame_flags_t
flags = 0;
1247 rawimg = &
ctx->rawimg;
1248 rawimg->planes[AOM_PLANE_Y] =
frame->data[0];
1249 rawimg->planes[AOM_PLANE_U] =
frame->data[1];
1250 rawimg->planes[AOM_PLANE_V] =
frame->data[2];
1251 rawimg->stride[AOM_PLANE_Y] =
frame->linesize[0];
1252 rawimg->stride[AOM_PLANE_U] =
frame->linesize[1];
1253 rawimg->stride[AOM_PLANE_V] =
frame->linesize[2];
1254 timestamp =
frame->pts;
1256 if (
frame->duration > ULONG_MAX) {
1258 "Frame duration too large: %"PRId64
"\n",
frame->duration);
1259 }
else if (
frame->duration)
1266 #if FF_API_TICKS_PER_FRAME
1273 switch (
frame->color_range) {
1275 rawimg->range = AOM_CR_STUDIO_RANGE;
1278 rawimg->range = AOM_CR_FULL_RANGE;
1283 flags |= AOM_EFLAG_FORCE_KF;
1287 if (res != AOM_CODEC_OK) {
1305 ctx->twopass_stats.sz);
1308 *got_packet = !!coded_size;
1312 struct aom_image
img;
1323 "Unhandled reconstructed frame colorspace: %d\n",
1335 if ((
img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) &&
img.bit_depth == 8)
1338 const uint8_t *
planes[4] = {
img.planes[0],
img.planes[1],
img.planes[2] };
1339 const int stride[4] = {
img.stride[0],
img.stride[1],
img.stride[2] };
1403 int supports_monochrome = aom_codec_version() >= 20001;
1404 aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
1405 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
1415 return aom_init(avctx, aom_codec_av1_cx());
1418 #define OFFSET(x) offsetof(AOMContext, x)
1419 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1422 {
"auto-alt-ref",
"Enable use of alternate reference "
1424 {
"lag-in-frames",
"Number of frames to look ahead at for "
1426 {
"arnr-max-frames",
"altref noise reduction max frame count",
OFFSET(arnr_max_frames),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1427 {
"arnr-strength",
"altref noise reduction filter strength",
OFFSET(arnr_strength),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1428 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE, .unit =
"aq_mode"},
1430 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"aq_mode"},
1431 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"aq_mode"},
1432 {
"cyclic",
"Cyclic Refresh Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0,
VE, .unit =
"aq_mode"},
1433 {
"error-resilience",
"Error resilience configuration",
OFFSET(error_resilient),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
VE, .unit =
"er"},
1434 {
"default",
"Improve resiliency against losses of whole frames", 0,
AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0,
VE, .unit =
"er"},
1435 {
"crf",
"Select the quality for constant quality mode", offsetof(AOMContext, crf),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63,
VE },
1436 {
"static-thresh",
"A change threshold on blocks below which they will be skipped by the encoder",
OFFSET(static_thresh),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
VE },
1437 {
"drop-threshold",
"Frame drop threshold", offsetof(AOMContext, drop_threshold),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
VE },
1438 {
"denoise-noise-level",
"Amount of noise to be removed",
OFFSET(denoise_noise_level),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1439 {
"denoise-block-size",
"Denoise block size ",
OFFSET(denoise_block_size),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1440 {
"undershoot-pct",
"Datarate undershoot (min) target (%)",
OFFSET(rc_undershoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1441 {
"overshoot-pct",
"Datarate overshoot (max) target (%)",
OFFSET(rc_overshoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1000,
VE},
1442 {
"minsection-pct",
"GOP min bitrate (% of target)",
OFFSET(minsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1443 {
"maxsection-pct",
"GOP max bitrate (% of target)",
OFFSET(maxsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 5000,
VE},
1444 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1446 {
"tile-columns",
"Log2 of number of tile columns to use",
OFFSET(tile_cols_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1447 {
"tile-rows",
"Log2 of number of tile rows to use",
OFFSET(tile_rows_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1450 {
"enable-global-motion",
"Enable global motion",
OFFSET(enable_global_motion),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1451 {
"enable-intrabc",
"Enable intra block copy prediction mode",
OFFSET(enable_intrabc),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1452 {
"enable-restoration",
"Enable Loop Restoration filtering",
OFFSET(enable_restoration),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1453 {
"usage",
"Quality and compression efficiency vs speed trade-off",
OFFSET(
usage),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
VE, .unit =
"usage"},
1455 {
"realtime",
"Realtime encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0,
VE, .unit =
"usage"},
1456 {
"allintra",
"All Intra encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0,
VE, .unit =
"usage"},
1457 {
"tune",
"The metric that the encoder tunes for. Automatically chosen by the encoder by default",
OFFSET(tune),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, AOM_TUNE_SSIM,
VE, .unit =
"tune"},
1461 {
"still-picture",
"Encode in single frame mode (typically used for still AVIF images).",
OFFSET(still_picture),
AV_OPT_TYPE_BOOL, {.i64 = 0}, -1, 1,
VE },
1462 {
"enable-rect-partitions",
"Enable rectangular partitions",
OFFSET(enable_rect_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1463 {
"enable-1to4-partitions",
"Enable 1:4/4:1 partitions",
OFFSET(enable_1to4_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1464 {
"enable-ab-partitions",
"Enable ab shape partitions",
OFFSET(enable_ab_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1465 {
"enable-angle-delta",
"Enable angle delta intra prediction",
OFFSET(enable_angle_delta),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1466 {
"enable-cfl-intra",
"Enable chroma predicted from luma intra prediction",
OFFSET(enable_cfl_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1467 {
"enable-filter-intra",
"Enable filter intra predictor",
OFFSET(enable_filter_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1468 {
"enable-intra-edge-filter",
"Enable intra edge filter",
OFFSET(enable_intra_edge_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1469 {
"enable-smooth-intra",
"Enable smooth intra prediction mode",
OFFSET(enable_smooth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1470 {
"enable-paeth-intra",
"Enable paeth predictor in intra prediction",
OFFSET(enable_paeth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1471 {
"enable-palette",
"Enable palette prediction mode",
OFFSET(enable_palette),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1472 {
"enable-flip-idtx",
"Enable extended transform type",
OFFSET(enable_flip_idtx),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1474 {
"reduced-tx-type-set",
"Use reduced set of transform types",
OFFSET(reduced_tx_type_set),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1475 {
"use-intra-dct-only",
"Use DCT only for INTRA modes",
OFFSET(use_intra_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1476 {
"use-inter-dct-only",
"Use DCT only for INTER modes",
OFFSET(use_inter_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1477 {
"use-intra-default-tx-only",
"Use default-transform only for INTRA modes",
OFFSET(use_intra_default_tx_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1478 {
"enable-ref-frame-mvs",
"Enable temporal mv prediction",
OFFSET(enable_ref_frame_mvs),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1479 {
"enable-reduced-reference-set",
"Use reduced set of single and compound references",
OFFSET(enable_reduced_reference_set),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1481 {
"enable-dual-filter",
"Enable dual filter",
OFFSET(enable_dual_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1482 {
"enable-diff-wtd-comp",
"Enable difference-weighted compound",
OFFSET(enable_diff_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1483 {
"enable-dist-wtd-comp",
"Enable distance-weighted compound",
OFFSET(enable_dist_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1484 {
"enable-onesided-comp",
"Enable one sided compound",
OFFSET(enable_onesided_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1485 {
"enable-interinter-wedge",
"Enable interinter wedge compound",
OFFSET(enable_interinter_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1486 {
"enable-interintra-wedge",
"Enable interintra wedge compound",
OFFSET(enable_interintra_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1487 {
"enable-masked-comp",
"Enable masked compound",
OFFSET(enable_masked_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1488 {
"enable-interintra-comp",
"Enable interintra compound",
OFFSET(enable_interintra_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1489 {
"enable-smooth-interintra",
"Enable smooth interintra mode",
OFFSET(enable_smooth_interintra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1490 #if AOM_ENCODER_ABI_VERSION >= 23
1491 {
"aom-params",
"Set libaom options using a :-separated list of key=value pairs",
OFFSET(aom_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
1501 {
"keyint_min",
"-1" },
1513 .
p.
name =
"libaom-av1",
1522 .p.wrapper_name =
"libaom",
1523 .priv_data_size =
sizeof(AOMContext),