28 #define AOM_DISABLE_CTRL_TYPECHECKS 1
29 #include <aom/aom_encoder.h>
30 #include <aom/aomcx.h>
144 [AOME_SET_CPUUSED] =
"AOME_SET_CPUUSED",
145 [AOME_SET_CQ_LEVEL] =
"AOME_SET_CQ_LEVEL",
146 [AOME_SET_ENABLEAUTOALTREF] =
"AOME_SET_ENABLEAUTOALTREF",
147 [AOME_SET_ARNR_MAXFRAMES] =
"AOME_SET_ARNR_MAXFRAMES",
148 [AOME_SET_ARNR_STRENGTH] =
"AOME_SET_ARNR_STRENGTH",
149 [AOME_SET_STATIC_THRESHOLD] =
"AOME_SET_STATIC_THRESHOLD",
150 [AV1E_SET_COLOR_RANGE] =
"AV1E_SET_COLOR_RANGE",
151 [AV1E_SET_COLOR_PRIMARIES] =
"AV1E_SET_COLOR_PRIMARIES",
152 [AV1E_SET_MATRIX_COEFFICIENTS] =
"AV1E_SET_MATRIX_COEFFICIENTS",
153 [AV1E_SET_TRANSFER_CHARACTERISTICS] =
"AV1E_SET_TRANSFER_CHARACTERISTICS",
154 [AV1E_SET_AQ_MODE] =
"AV1E_SET_AQ_MODE",
155 [AV1E_SET_FRAME_PARALLEL_DECODING] =
"AV1E_SET_FRAME_PARALLEL_DECODING",
156 [AV1E_SET_SUPERBLOCK_SIZE] =
"AV1E_SET_SUPERBLOCK_SIZE",
157 [AV1E_SET_TILE_COLUMNS] =
"AV1E_SET_TILE_COLUMNS",
158 [AV1E_SET_TILE_ROWS] =
"AV1E_SET_TILE_ROWS",
159 [AV1E_SET_ENABLE_RESTORATION] =
"AV1E_SET_ENABLE_RESTORATION",
160 [AV1E_SET_ROW_MT] =
"AV1E_SET_ROW_MT",
161 [AV1E_SET_DENOISE_NOISE_LEVEL] =
"AV1E_SET_DENOISE_NOISE_LEVEL",
162 [AV1E_SET_DENOISE_BLOCK_SIZE] =
"AV1E_SET_DENOISE_BLOCK_SIZE",
163 [AV1E_SET_MAX_REFERENCE_FRAMES] =
"AV1E_SET_MAX_REFERENCE_FRAMES",
164 [AV1E_SET_ENABLE_GLOBAL_MOTION] =
"AV1E_SET_ENABLE_GLOBAL_MOTION",
165 [AV1E_SET_ENABLE_INTRABC] =
"AV1E_SET_ENABLE_INTRABC",
166 [AV1E_SET_ENABLE_CDEF] =
"AV1E_SET_ENABLE_CDEF",
167 [AOME_SET_TUNING] =
"AOME_SET_TUNING",
168 [AV1E_SET_ENABLE_1TO4_PARTITIONS] =
"AV1E_SET_ENABLE_1TO4_PARTITIONS",
169 [AV1E_SET_ENABLE_AB_PARTITIONS] =
"AV1E_SET_ENABLE_AB_PARTITIONS",
170 [AV1E_SET_ENABLE_RECT_PARTITIONS] =
"AV1E_SET_ENABLE_RECT_PARTITIONS",
171 [AV1E_SET_ENABLE_ANGLE_DELTA] =
"AV1E_SET_ENABLE_ANGLE_DELTA",
172 [AV1E_SET_ENABLE_CFL_INTRA] =
"AV1E_SET_ENABLE_CFL_INTRA",
173 [AV1E_SET_ENABLE_FILTER_INTRA] =
"AV1E_SET_ENABLE_FILTER_INTRA",
174 [AV1E_SET_ENABLE_INTRA_EDGE_FILTER] =
"AV1E_SET_ENABLE_INTRA_EDGE_FILTER",
175 [AV1E_SET_ENABLE_PAETH_INTRA] =
"AV1E_SET_ENABLE_PAETH_INTRA",
176 [AV1E_SET_ENABLE_SMOOTH_INTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTRA",
177 [AV1E_SET_ENABLE_PALETTE] =
"AV1E_SET_ENABLE_PALETTE",
178 [AV1E_SET_ENABLE_FLIP_IDTX] =
"AV1E_SET_ENABLE_FLIP_IDTX",
179 [AV1E_SET_ENABLE_TX64] =
"AV1E_SET_ENABLE_TX64",
180 [AV1E_SET_INTRA_DCT_ONLY] =
"AV1E_SET_INTRA_DCT_ONLY",
181 [AV1E_SET_INTER_DCT_ONLY] =
"AV1E_SET_INTER_DCT_ONLY",
182 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] =
"AV1E_SET_INTRA_DEFAULT_TX_ONLY",
183 [AV1E_SET_REDUCED_TX_TYPE_SET] =
"AV1E_SET_REDUCED_TX_TYPE_SET",
184 [AV1E_SET_ENABLE_DIFF_WTD_COMP] =
"AV1E_SET_ENABLE_DIFF_WTD_COMP",
185 [AV1E_SET_ENABLE_DIST_WTD_COMP] =
"AV1E_SET_ENABLE_DIST_WTD_COMP",
186 [AV1E_SET_ENABLE_DUAL_FILTER] =
"AV1E_SET_ENABLE_DUAL_FILTER",
187 [AV1E_SET_ENABLE_INTERINTER_WEDGE] =
"AV1E_SET_ENABLE_INTERINTER_WEDGE",
188 [AV1E_SET_ENABLE_INTERINTRA_WEDGE] =
"AV1E_SET_ENABLE_INTERINTRA_WEDGE",
189 [AV1E_SET_ENABLE_MASKED_COMP] =
"AV1E_SET_ENABLE_MASKED_COMP",
190 [AV1E_SET_ENABLE_INTERINTRA_COMP] =
"AV1E_SET_ENABLE_INTERINTRA_COMP",
191 [AV1E_SET_ENABLE_OBMC] =
"AV1E_SET_ENABLE_OBMC",
192 [AV1E_SET_ENABLE_ONESIDED_COMP] =
"AV1E_SET_ENABLE_ONESIDED_COMP",
193 [AV1E_SET_REDUCED_REFERENCE_SET] =
"AV1E_SET_REDUCED_REFERENCE_SET",
194 [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
195 [AV1E_SET_ENABLE_REF_FRAME_MVS] =
"AV1E_SET_ENABLE_REF_FRAME_MVS",
196 #ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS
197 [AV1E_GET_NUM_OPERATING_POINTS] =
"AV1E_GET_NUM_OPERATING_POINTS",
199 [AV1E_GET_SEQ_LEVEL_IDX] =
"AV1E_GET_SEQ_LEVEL_IDX",
200 #ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
201 [AV1E_GET_TARGET_SEQ_LEVEL_IDX] =
"AV1E_GET_TARGET_SEQ_LEVEL_IDX",
203 [AV1_GET_NEW_FRAME_IMAGE] =
"AV1_GET_NEW_FRAME_IMAGE",
209 const char *
error = aom_codec_error(&
ctx->encoder);
210 const char *detail = aom_codec_error_detail(&
ctx->encoder);
218 const struct aom_codec_enc_cfg *cfg,
225 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
227 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
228 width,
"g_usage:", cfg->g_usage,
229 width,
"g_threads:", cfg->g_threads,
230 width,
"g_profile:", cfg->g_profile,
231 width,
"g_w:", cfg->g_w,
232 width,
"g_h:", cfg->g_h,
233 width,
"g_bit_depth:", cfg->g_bit_depth,
234 width,
"g_input_bit_depth:", cfg->g_input_bit_depth,
235 width,
"g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
236 width,
"g_error_resilient:", cfg->g_error_resilient,
237 width,
"g_pass:", cfg->g_pass,
238 width,
"g_lag_in_frames:", cfg->g_lag_in_frames);
241 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
242 width,
"rc_end_usage:", cfg->rc_end_usage,
243 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
244 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
247 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
248 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
251 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
252 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
254 " %*s%u\n %*s%u\n %*s%u\n",
255 width,
"rc_buf_sz:", cfg->rc_buf_sz,
256 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
257 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
258 av_log(avctx,
level,
"2 pass rate control settings\n"
259 " %*s%u\n %*s%u\n %*s%u\n",
260 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
261 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
262 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
264 " %*s%d\n %*s%u\n %*s%u\n",
265 width,
"kf_mode:", cfg->kf_mode,
266 width,
"kf_min_dist:", cfg->kf_min_dist,
267 width,
"kf_max_dist:", cfg->kf_max_dist);
270 width,
"tile_width_count:", cfg->tile_width_count,
271 width,
"tile_height_count:", cfg->tile_height_count);
304 aome_enc_control_id
id,
306 enum aome_enc_control_id
id,
318 res = aom_codec_control(&
ctx->encoder,
id,
val);
319 if (res != AOM_CODEC_OK) {
329 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
330 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
331 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
334 aome_enc_control_id
id,
336 enum aome_enc_control_id
id,
348 res = aom_codec_control(&
ctx->encoder,
id, ptr);
349 if (res != AOM_CODEC_OK) {
362 aome_enc_control_id
id,
364 enum aome_enc_control_id
id,
366 struct aom_image *
img)
374 res = aom_codec_control(&
ctx->encoder,
id,
img);
375 if (res != AOM_CODEC_OK) {
389 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
390 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
391 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
393 int num_operating_points;
395 int target_levels[32];
397 if (!codecctl_intp(avctx, AV1E_GET_NUM_OPERATING_POINTS,
398 &num_operating_points) &&
399 !codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) &&
400 !codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX,
402 for (
int i = 0;
i < num_operating_points;
i++) {
403 if (levels[
i] > target_levels[
i]) {
406 "Could not encode to target level %d.%d for "
407 "operating point %d. The output level is %d.%d.\n",
408 2 + (target_levels[
i] >> 2), target_levels[
i] & 3,
409 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
410 }
else if (target_levels[
i] < 31) {
413 "Output level for operating point %d is %d.%d.\n",
414 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
421 aom_codec_destroy(&
ctx->encoder);
422 aom_img_remove_metadata(&
ctx->rawimg);
432 struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *
flags,
433 aom_img_fmt_t *img_fmt)
437 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
440 enccfg->monochrome = 1;
444 *img_fmt = AOM_IMG_FMT_I420;
448 *img_fmt = AOM_IMG_FMT_I422;
453 *img_fmt = AOM_IMG_FMT_I444;
457 enccfg->monochrome = 1;
461 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
464 *img_fmt = AOM_IMG_FMT_I42016;
465 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
471 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
473 *img_fmt = AOM_IMG_FMT_I42216;
474 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
482 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
485 *img_fmt = AOM_IMG_FMT_I44416;
486 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
499 aom_color_range_t aom_cr;
515 int sb_dim = (
dim + sb_size - 1) / sb_size;
516 int tile_dim = (sb_dim + (1 << tiles_log2) - 1) >> tiles_log2;
518 return (sb_dim + tile_dim - 1) / tile_dim;
522 struct aom_codec_enc_cfg *enccfg)
525 int sb_128x128_possible, sb_size, sb_width, sb_height;
526 int uniform_rows, uniform_cols;
527 int uniform_64x64_possible, uniform_128x128_possible;
528 int tile_size, rounding,
i;
530 if (
ctx->tile_cols_log2 >= 0)
531 ctx->tile_cols = 1 <<
ctx->tile_cols_log2;
532 if (
ctx->tile_rows_log2 >= 0)
533 ctx->tile_rows = 1 <<
ctx->tile_rows_log2;
535 if (
ctx->tile_cols == 0) {
538 if (
ctx->tile_cols > 1) {
540 "columns to fill width.\n",
ctx->tile_cols);
544 if (
ctx->tile_rows == 0) {
547 ctx->tile_cols - 1) /
ctx->tile_cols, 128);
551 if (
ctx->tile_rows > 1) {
553 "rows to fill area.\n",
ctx->tile_rows);
558 if ((avctx->
width + 63) / 64 <
ctx->tile_cols ||
559 (avctx->
height + 63) / 64 <
ctx->tile_rows) {
561 "large enough to fit specified tile arrangement.\n");
567 "not allow more than %dx%d tiles.\n",
573 "not allow tiles of width greater than %d.\n",
578 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
580 if (
ctx->tile_cols == 1 &&
ctx->tile_rows == 1) {
585 sb_128x128_possible =
586 (avctx->
width + 127) / 128 >=
ctx->tile_cols &&
587 (avctx->
height + 127) / 128 >=
ctx->tile_rows;
589 ctx->tile_cols_log2 =
ctx->tile_cols == 1 ? 0 :
591 ctx->tile_rows_log2 =
ctx->tile_rows == 1 ? 0 :
595 64,
ctx->tile_cols_log2);
597 64,
ctx->tile_rows_log2);
599 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
600 uniform_64x64_possible = uniform_cols ==
ctx->tile_cols &&
601 uniform_rows ==
ctx->tile_rows;
603 if (sb_128x128_possible) {
605 128,
ctx->tile_cols_log2);
607 128,
ctx->tile_rows_log2);
609 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
610 uniform_128x128_possible = uniform_cols ==
ctx->tile_cols &&
611 uniform_rows ==
ctx->tile_rows;
614 uniform_128x128_possible = 0;
617 ctx->uniform_tiles = 1;
618 if (uniform_64x64_possible && uniform_128x128_possible) {
620 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
621 ctx->tile_cols_log2,
ctx->tile_rows_log2);
624 if (uniform_64x64_possible && !sb_128x128_possible) {
626 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
627 ctx->tile_cols_log2,
ctx->tile_rows_log2);
628 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
631 if (uniform_128x128_possible) {
633 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
634 ctx->tile_cols_log2,
ctx->tile_rows_log2);
635 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
638 ctx->uniform_tiles = 0;
640 if (sb_128x128_possible) {
642 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
645 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
648 "superblocks (tile_cols = %d, tile_rows = %d).\n",
649 sb_size, sb_size,
ctx->tile_cols,
ctx->tile_rows);
651 enccfg->tile_width_count =
ctx->tile_cols;
652 enccfg->tile_height_count =
ctx->tile_rows;
654 sb_width = (avctx->
width + sb_size - 1) / sb_size;
655 sb_height = (avctx->
height + sb_size - 1) / sb_size;
657 tile_size = sb_width /
ctx->tile_cols;
658 rounding = sb_width %
ctx->tile_cols;
659 for (
i = 0;
i <
ctx->tile_cols;
i++) {
660 enccfg->tile_widths[
i] = tile_size +
662 i >
ctx->tile_cols - 1 - (rounding + 1) / 2);
665 tile_size = sb_height /
ctx->tile_rows;
666 rounding = sb_height %
ctx->tile_rows;
667 for (
i = 0;
i <
ctx->tile_rows;
i++) {
668 enccfg->tile_heights[
i] = tile_size +
670 i >
ctx->tile_rows - 1 - (rounding + 1) / 2);
677 const struct aom_codec_iface *iface)
681 struct aom_codec_enc_cfg enccfg = { 0 };
682 aom_codec_flags_t
flags =
686 aom_img_fmt_t img_fmt;
687 aom_codec_caps_t codec_caps = aom_codec_get_caps(iface);
692 if ((res = aom_codec_enc_config_default(iface, &enccfg,
ctx->usage)) != AOM_CODEC_OK) {
694 aom_codec_err_to_string(res));
709 enccfg.g_w = avctx->
width;
710 enccfg.g_h = avctx->
height;
716 if (
ctx->lag_in_frames >= 0)
717 enccfg.g_lag_in_frames =
ctx->lag_in_frames;
720 enccfg.g_pass = AOM_RC_FIRST_PASS;
722 enccfg.g_pass = AOM_RC_LAST_PASS;
724 enccfg.g_pass = AOM_RC_ONE_PASS;
728 enccfg.rc_end_usage = AOM_CBR;
729 }
else if (
ctx->crf >= 0) {
730 enccfg.rc_end_usage = AOM_CQ;
732 enccfg.rc_end_usage = AOM_Q;
738 }
else if (enccfg.rc_end_usage != AOM_Q) {
739 enccfg.rc_end_usage = AOM_Q;
742 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
746 if (avctx->
qmin >= 0)
747 enccfg.rc_min_quantizer = avctx->
qmin;
748 if (avctx->
qmax >= 0) {
749 enccfg.rc_max_quantizer = avctx->
qmax;
750 }
else if (!
ctx->crf) {
751 enccfg.rc_max_quantizer = 0;
754 if (enccfg.rc_end_usage == AOM_CQ || enccfg.rc_end_usage == AOM_Q) {
755 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
757 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
758 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
763 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
767 if (
ctx->minsection_pct >= 0)
768 enccfg.rc_2pass_vbr_minsection_pct =
ctx->minsection_pct;
770 enccfg.rc_2pass_vbr_minsection_pct =
772 if (
ctx->maxsection_pct >= 0)
773 enccfg.rc_2pass_vbr_maxsection_pct =
ctx->maxsection_pct;
775 enccfg.rc_2pass_vbr_maxsection_pct =
782 enccfg.rc_buf_initial_sz =
784 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
786 if (
ctx->rc_undershoot_pct >= 0)
787 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
788 if (
ctx->rc_overshoot_pct >= 0)
789 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
795 enccfg.kf_max_dist = avctx->
gop_size;
797 if (enccfg.g_pass == AOM_RC_FIRST_PASS)
798 enccfg.g_lag_in_frames = 0;
799 else if (enccfg.g_pass == AOM_RC_LAST_PASS) {
800 int decode_size,
ret;
807 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
812 ctx->twopass_stats.sz);
813 ctx->twopass_stats.sz = 0;
817 ctx->twopass_stats.sz);
818 if (decode_size < 0) {
823 ctx->twopass_stats.sz = decode_size;
824 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
831 enccfg.g_profile = avctx->
profile;
833 enccfg.g_error_resilient =
ctx->error_resilient;
839 if (
ctx->still_picture) {
845 enccfg.g_lag_in_frames = 0;
847 enccfg.kf_max_dist = 0;
848 enccfg.kf_mode = AOM_KF_DISABLED;
852 res = aom_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
853 if (res != AOM_CODEC_OK) {
863 if (
ctx->auto_alt_ref >= 0)
865 if (
ctx->arnr_max_frames >= 0)
867 if (
ctx->arnr_strength >= 0)
869 if (
ctx->enable_cdef >= 0)
871 if (
ctx->enable_restoration >= 0)
872 codecctl_int(avctx, AV1E_SET_ENABLE_RESTORATION,
ctx->enable_restoration);
873 if (
ctx->enable_rect_partitions >= 0)
874 codecctl_int(avctx, AV1E_SET_ENABLE_RECT_PARTITIONS,
ctx->enable_rect_partitions);
875 if (
ctx->enable_1to4_partitions >= 0)
876 codecctl_int(avctx, AV1E_SET_ENABLE_1TO4_PARTITIONS,
ctx->enable_1to4_partitions);
877 if (
ctx->enable_ab_partitions >= 0)
878 codecctl_int(avctx, AV1E_SET_ENABLE_AB_PARTITIONS,
ctx->enable_ab_partitions);
879 if (
ctx->enable_angle_delta >= 0)
880 codecctl_int(avctx, AV1E_SET_ENABLE_ANGLE_DELTA,
ctx->enable_angle_delta);
881 if (
ctx->enable_cfl_intra >= 0)
883 if (
ctx->enable_filter_intra >= 0)
884 codecctl_int(avctx, AV1E_SET_ENABLE_FILTER_INTRA,
ctx->enable_filter_intra);
885 if (
ctx->enable_intra_edge_filter >= 0)
886 codecctl_int(avctx, AV1E_SET_ENABLE_INTRA_EDGE_FILTER,
ctx->enable_intra_edge_filter);
887 if (
ctx->enable_paeth_intra >= 0)
888 codecctl_int(avctx, AV1E_SET_ENABLE_PAETH_INTRA,
ctx->enable_paeth_intra);
889 if (
ctx->enable_smooth_intra >= 0)
890 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTRA,
ctx->enable_smooth_intra);
891 if (
ctx->enable_palette >= 0)
893 if (
ctx->enable_tx64 >= 0)
895 if (
ctx->enable_flip_idtx >= 0)
897 if (
ctx->use_intra_dct_only >= 0)
899 if (
ctx->use_inter_dct_only >= 0)
901 if (
ctx->use_intra_default_tx_only >= 0)
902 codecctl_int(avctx, AV1E_SET_INTRA_DEFAULT_TX_ONLY,
ctx->use_intra_default_tx_only);
903 if (
ctx->reduced_tx_type_set >= 0)
904 codecctl_int(avctx, AV1E_SET_REDUCED_TX_TYPE_SET,
ctx->reduced_tx_type_set);
905 if (
ctx->enable_ref_frame_mvs >= 0)
906 codecctl_int(avctx, AV1E_SET_ENABLE_REF_FRAME_MVS,
ctx->enable_ref_frame_mvs);
907 if (
ctx->enable_reduced_reference_set >= 0)
908 codecctl_int(avctx, AV1E_SET_REDUCED_REFERENCE_SET,
ctx->enable_reduced_reference_set);
909 if (
ctx->enable_diff_wtd_comp >= 0)
910 codecctl_int(avctx, AV1E_SET_ENABLE_DIFF_WTD_COMP,
ctx->enable_diff_wtd_comp);
911 if (
ctx->enable_dist_wtd_comp >= 0)
912 codecctl_int(avctx, AV1E_SET_ENABLE_DIST_WTD_COMP,
ctx->enable_dist_wtd_comp);
913 if (
ctx->enable_dual_filter >= 0)
914 codecctl_int(avctx, AV1E_SET_ENABLE_DUAL_FILTER,
ctx->enable_dual_filter);
915 if (
ctx->enable_interinter_wedge >= 0)
916 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTER_WEDGE,
ctx->enable_interinter_wedge);
917 if (
ctx->enable_masked_comp >= 0)
918 codecctl_int(avctx, AV1E_SET_ENABLE_MASKED_COMP,
ctx->enable_masked_comp);
919 if (
ctx->enable_interintra_comp >= 0)
920 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_COMP,
ctx->enable_interintra_comp);
921 if (
ctx->enable_interintra_wedge >= 0)
922 codecctl_int(avctx, AV1E_SET_ENABLE_INTERINTRA_WEDGE,
ctx->enable_interintra_wedge);
923 if (
ctx->enable_obmc >= 0)
925 if (
ctx->enable_onesided_comp >= 0)
926 codecctl_int(avctx, AV1E_SET_ENABLE_ONESIDED_COMP,
ctx->enable_onesided_comp);
927 if (
ctx->enable_smooth_interintra >= 0)
928 codecctl_int(avctx, AV1E_SET_ENABLE_SMOOTH_INTERINTRA,
ctx->enable_smooth_interintra);
945 if (
ctx->aq_mode >= 0)
947 if (
ctx->frame_parallel >= 0)
948 codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
952 if (
ctx->uniform_tiles) {
957 if (
ctx->denoise_noise_level >= 0)
958 codecctl_int(avctx, AV1E_SET_DENOISE_NOISE_LEVEL,
ctx->denoise_noise_level);
959 if (
ctx->denoise_block_size >= 0)
960 codecctl_int(avctx, AV1E_SET_DENOISE_BLOCK_SIZE,
ctx->denoise_block_size);
961 if (
ctx->enable_global_motion >= 0)
962 codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION,
ctx->enable_global_motion);
963 if (avctx->
refs >= 3) {
966 if (
ctx->row_mt >= 0)
968 if (
ctx->enable_intrabc >= 0)
971 #if AOM_ENCODER_ABI_VERSION >= 23
976 int ret = aom_codec_set_option(&
ctx->encoder, en->
key, en->
value);
977 if (
ret != AOM_CODEC_OK) {
986 aom_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
989 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
990 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
996 ctx->dovi.logctx = avctx;
1006 "not found. This is a bug, please report it.\n");
1022 if (enccfg.rc_end_usage == AOM_CBR ||
1023 enccfg.g_pass != AOM_RC_ONE_PASS) {
1035 const struct aom_codec_cx_pkt *
src)
1037 dst->pts =
src->data.frame.pts;
1038 dst->duration =
src->data.frame.duration;
1039 dst->flags =
src->data.frame.flags;
1040 dst->sz =
src->data.frame.sz;
1041 dst->buf =
src->data.frame.buf;
1042 dst->frame_number = ++
ctx->frame_number;
1043 dst->have_sse =
ctx->have_sse;
1044 if (
ctx->have_sse) {
1047 memcpy(
dst->sse,
ctx->sse,
sizeof(
dst->sse));
1074 if (!!(cx_frame->
flags & AOM_FRAME_IS_KEY)) {
1077 }
else if (cx_frame->
flags & AOM_FRAME_IS_INTRAONLY) {
1084 cx_frame->
have_sse ? 3 : 0, pict_type);
1088 for (
i = 0;
i < 3; ++
i) {
1098 "failed to send input packet\n");
1105 "failed to receive output packet\n");
1123 const struct aom_codec_cx_pkt *
pkt;
1124 const void *iter =
NULL;
1127 if (
ctx->coded_frame_list) {
1133 ctx->coded_frame_list = cx_frame->
next;
1139 while ((
pkt = aom_codec_get_cx_data(&
ctx->encoder, &iter))) {
1140 switch (
pkt->kind) {
1141 case AOM_CODEC_CX_FRAME_PKT:
1158 "Frame queue element alloc failed\n");
1164 if (!cx_frame->
buf) {
1175 case AOM_CODEC_STATS_PKT:
1177 struct aom_fixed_buf *
stats = &
ctx->twopass_stats;
1179 &
ctx->twopass_stats_size,
1194 case AOM_CODEC_PSNR_PKT:
1204 case AOM_CODEC_CUSTOM_PKT:
1216 case AOM_IMG_FMT_I420:
1217 case AOM_IMG_FMT_I42016:
1218 if (
img->bit_depth == 8)
1220 else if (
img->bit_depth == 10)
1224 case AOM_IMG_FMT_I422:
1225 case AOM_IMG_FMT_I42216:
1226 if (
img->bit_depth == 8)
1228 else if (
img->bit_depth == 10)
1232 case AOM_IMG_FMT_I444:
1233 case AOM_IMG_FMT_I44416:
1234 if (
img->bit_depth == 8)
1236 else if (
img->bit_depth == 10)
1248 struct aom_image *rawimg =
NULL;
1251 int res, coded_size;
1252 aom_enc_frame_flags_t
flags = 0;
1256 rawimg = &
ctx->rawimg;
1257 rawimg->planes[AOM_PLANE_Y] =
frame->data[0];
1258 rawimg->planes[AOM_PLANE_U] =
frame->data[1];
1259 rawimg->planes[AOM_PLANE_V] =
frame->data[2];
1260 rawimg->stride[AOM_PLANE_Y] =
frame->linesize[0];
1261 rawimg->stride[AOM_PLANE_U] =
frame->linesize[1];
1262 rawimg->stride[AOM_PLANE_V] =
frame->linesize[2];
1263 timestamp =
frame->pts;
1265 if (
frame->duration > ULONG_MAX) {
1267 "Frame duration too large: %"PRId64
"\n",
frame->duration);
1268 }
else if (
frame->duration)
1275 #if FF_API_TICKS_PER_FRAME
1282 switch (
frame->color_range) {
1284 rawimg->range = AOM_CR_STUDIO_RANGE;
1287 rawimg->range = AOM_CR_FULL_RANGE;
1291 aom_img_remove_metadata(rawimg);
1293 if (
ctx->dovi.cfg.dv_profile && sd) {
1300 res = aom_img_add_metadata(rawimg, OBU_METADATA_TYPE_ITUT_T35,
1301 t35,
size, AOM_MIF_ANY_FRAME);
1303 if (res != AOM_CODEC_OK)
1305 }
else if (
ctx->dovi.cfg.dv_profile) {
1307 "without AV_FRAME_DATA_DOVI_METADATA\n");
1312 flags |= AOM_EFLAG_FORCE_KF;
1316 if (res != AOM_CODEC_OK) {
1334 ctx->twopass_stats.sz);
1337 *got_packet = !!coded_size;
1341 struct aom_image
img;
1352 "Unhandled reconstructed frame colorspace: %d\n",
1364 if ((
img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) &&
img.bit_depth == 8)
1367 const uint8_t *
planes[4] = {
img.planes[0],
img.planes[1],
img.planes[2] };
1368 const int stride[4] = {
img.stride[0],
img.stride[1],
img.stride[2] };
1437 int supports_monochrome = aom_codec_version() >= 20001;
1438 aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
1439 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
1440 if (supports_monochrome) {
1448 if (supports_monochrome) {
1464 return aom_init(avctx, aom_codec_av1_cx());
1467 #define OFFSET(x) offsetof(AOMContext, x)
1468 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1471 {
"auto-alt-ref",
"Enable use of alternate reference "
1473 {
"lag-in-frames",
"Number of frames to look ahead at for "
1475 {
"arnr-max-frames",
"altref noise reduction max frame count",
OFFSET(arnr_max_frames),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1476 {
"arnr-strength",
"altref noise reduction filter strength",
OFFSET(arnr_strength),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1477 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE, .unit =
"aq_mode"},
1479 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"aq_mode"},
1480 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"aq_mode"},
1481 {
"cyclic",
"Cyclic Refresh Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0,
VE, .unit =
"aq_mode"},
1482 {
"error-resilience",
"Error resilience configuration",
OFFSET(error_resilient),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
VE, .unit =
"er"},
1483 {
"default",
"Improve resiliency against losses of whole frames", 0,
AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0,
VE, .unit =
"er"},
1484 {
"crf",
"Select the quality for constant quality mode", offsetof(AOMContext, crf),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63,
VE },
1485 {
"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 },
1486 {
"drop-threshold",
"Frame drop threshold", offsetof(AOMContext, drop_threshold),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
VE },
1487 {
"denoise-noise-level",
"Amount of noise to be removed",
OFFSET(denoise_noise_level),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1488 {
"denoise-block-size",
"Denoise block size ",
OFFSET(denoise_block_size),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1489 {
"undershoot-pct",
"Datarate undershoot (min) target (%)",
OFFSET(rc_undershoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1490 {
"overshoot-pct",
"Datarate overshoot (max) target (%)",
OFFSET(rc_overshoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1000,
VE},
1491 {
"minsection-pct",
"GOP min bitrate (% of target)",
OFFSET(minsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1492 {
"maxsection-pct",
"GOP max bitrate (% of target)",
OFFSET(maxsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 5000,
VE},
1493 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1495 {
"tile-columns",
"Log2 of number of tile columns to use",
OFFSET(tile_cols_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1496 {
"tile-rows",
"Log2 of number of tile rows to use",
OFFSET(tile_rows_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1499 {
"enable-global-motion",
"Enable global motion",
OFFSET(enable_global_motion),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1500 {
"enable-intrabc",
"Enable intra block copy prediction mode",
OFFSET(enable_intrabc),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1501 {
"enable-restoration",
"Enable Loop Restoration filtering",
OFFSET(enable_restoration),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1502 {
"usage",
"Quality and compression efficiency vs speed trade-off",
OFFSET(
usage),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
VE, .unit =
"usage"},
1504 {
"realtime",
"Realtime encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0,
VE, .unit =
"usage"},
1505 {
"allintra",
"All Intra encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0,
VE, .unit =
"usage"},
1506 {
"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"},
1510 {
"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 },
1513 {
"enable-rect-partitions",
"Enable rectangular partitions",
OFFSET(enable_rect_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1514 {
"enable-1to4-partitions",
"Enable 1:4/4:1 partitions",
OFFSET(enable_1to4_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1515 {
"enable-ab-partitions",
"Enable ab shape partitions",
OFFSET(enable_ab_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1516 {
"enable-angle-delta",
"Enable angle delta intra prediction",
OFFSET(enable_angle_delta),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1517 {
"enable-cfl-intra",
"Enable chroma predicted from luma intra prediction",
OFFSET(enable_cfl_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1518 {
"enable-filter-intra",
"Enable filter intra predictor",
OFFSET(enable_filter_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1519 {
"enable-intra-edge-filter",
"Enable intra edge filter",
OFFSET(enable_intra_edge_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1520 {
"enable-smooth-intra",
"Enable smooth intra prediction mode",
OFFSET(enable_smooth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1521 {
"enable-paeth-intra",
"Enable paeth predictor in intra prediction",
OFFSET(enable_paeth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1522 {
"enable-palette",
"Enable palette prediction mode",
OFFSET(enable_palette),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1523 {
"enable-flip-idtx",
"Enable extended transform type",
OFFSET(enable_flip_idtx),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1525 {
"reduced-tx-type-set",
"Use reduced set of transform types",
OFFSET(reduced_tx_type_set),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1526 {
"use-intra-dct-only",
"Use DCT only for INTRA modes",
OFFSET(use_intra_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1527 {
"use-inter-dct-only",
"Use DCT only for INTER modes",
OFFSET(use_inter_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1528 {
"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},
1529 {
"enable-ref-frame-mvs",
"Enable temporal mv prediction",
OFFSET(enable_ref_frame_mvs),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1530 {
"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},
1532 {
"enable-dual-filter",
"Enable dual filter",
OFFSET(enable_dual_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1533 {
"enable-diff-wtd-comp",
"Enable difference-weighted compound",
OFFSET(enable_diff_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1534 {
"enable-dist-wtd-comp",
"Enable distance-weighted compound",
OFFSET(enable_dist_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1535 {
"enable-onesided-comp",
"Enable one sided compound",
OFFSET(enable_onesided_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1536 {
"enable-interinter-wedge",
"Enable interinter wedge compound",
OFFSET(enable_interinter_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1537 {
"enable-interintra-wedge",
"Enable interintra wedge compound",
OFFSET(enable_interintra_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1538 {
"enable-masked-comp",
"Enable masked compound",
OFFSET(enable_masked_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1539 {
"enable-interintra-comp",
"Enable interintra compound",
OFFSET(enable_interintra_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1540 {
"enable-smooth-interintra",
"Enable smooth interintra mode",
OFFSET(enable_smooth_interintra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1541 #if AOM_ENCODER_ABI_VERSION >= 23
1542 {
"aom-params",
"Set libaom options using a :-separated list of key=value pairs",
OFFSET(aom_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
1552 {
"keyint_min",
"-1" },
1564 .
p.
name =
"libaom-av1",
1574 .p.wrapper_name =
"libaom",
1575 .priv_data_size =
sizeof(AOMContext),