28 #define AOM_DISABLE_CTRL_TYPECHECKS 1
29 #include <aom/aom_encoder.h>
30 #include <aom/aomcx.h>
144 #define OFFSET(x) offsetof(AOMContext, x)
147 [AOME_SET_CPUUSED] =
"AOME_SET_CPUUSED",
148 [AOME_SET_CQ_LEVEL] =
"AOME_SET_CQ_LEVEL",
149 [AOME_SET_ENABLEAUTOALTREF] =
"AOME_SET_ENABLEAUTOALTREF",
150 [AOME_SET_ARNR_MAXFRAMES] =
"AOME_SET_ARNR_MAXFRAMES",
151 [AOME_SET_ARNR_STRENGTH] =
"AOME_SET_ARNR_STRENGTH",
152 [AOME_SET_STATIC_THRESHOLD] =
"AOME_SET_STATIC_THRESHOLD",
153 [AV1E_SET_COLOR_RANGE] =
"AV1E_SET_COLOR_RANGE",
154 [AV1E_SET_COLOR_PRIMARIES] =
"AV1E_SET_COLOR_PRIMARIES",
155 [AV1E_SET_MATRIX_COEFFICIENTS] =
"AV1E_SET_MATRIX_COEFFICIENTS",
156 [AV1E_SET_TRANSFER_CHARACTERISTICS] =
"AV1E_SET_TRANSFER_CHARACTERISTICS",
157 [AV1E_SET_AQ_MODE] =
"AV1E_SET_AQ_MODE",
158 [AV1E_SET_FRAME_PARALLEL_DECODING] =
"AV1E_SET_FRAME_PARALLEL_DECODING",
159 [AV1E_SET_SUPERBLOCK_SIZE] =
"AV1E_SET_SUPERBLOCK_SIZE",
160 [AV1E_SET_TILE_COLUMNS] =
"AV1E_SET_TILE_COLUMNS",
161 [AV1E_SET_TILE_ROWS] =
"AV1E_SET_TILE_ROWS",
162 [AV1E_SET_ENABLE_RESTORATION] =
"AV1E_SET_ENABLE_RESTORATION",
163 [AV1E_SET_ROW_MT] =
"AV1E_SET_ROW_MT",
164 [AV1E_SET_DENOISE_NOISE_LEVEL] =
"AV1E_SET_DENOISE_NOISE_LEVEL",
165 [AV1E_SET_DENOISE_BLOCK_SIZE] =
"AV1E_SET_DENOISE_BLOCK_SIZE",
166 [AV1E_SET_MAX_REFERENCE_FRAMES] =
"AV1E_SET_MAX_REFERENCE_FRAMES",
167 [AV1E_SET_ENABLE_GLOBAL_MOTION] =
"AV1E_SET_ENABLE_GLOBAL_MOTION",
168 [AV1E_SET_ENABLE_INTRABC] =
"AV1E_SET_ENABLE_INTRABC",
169 [AV1E_SET_ENABLE_CDEF] =
"AV1E_SET_ENABLE_CDEF",
170 [AOME_SET_TUNING] =
"AOME_SET_TUNING",
171 [AV1E_SET_ENABLE_1TO4_PARTITIONS] =
"AV1E_SET_ENABLE_1TO4_PARTITIONS",
172 [AV1E_SET_ENABLE_AB_PARTITIONS] =
"AV1E_SET_ENABLE_AB_PARTITIONS",
173 [AV1E_SET_ENABLE_RECT_PARTITIONS] =
"AV1E_SET_ENABLE_RECT_PARTITIONS",
174 [AV1E_SET_ENABLE_ANGLE_DELTA] =
"AV1E_SET_ENABLE_ANGLE_DELTA",
175 [AV1E_SET_ENABLE_CFL_INTRA] =
"AV1E_SET_ENABLE_CFL_INTRA",
176 [AV1E_SET_ENABLE_FILTER_INTRA] =
"AV1E_SET_ENABLE_FILTER_INTRA",
177 [AV1E_SET_ENABLE_INTRA_EDGE_FILTER] =
"AV1E_SET_ENABLE_INTRA_EDGE_FILTER",
178 [AV1E_SET_ENABLE_PAETH_INTRA] =
"AV1E_SET_ENABLE_PAETH_INTRA",
179 [AV1E_SET_ENABLE_SMOOTH_INTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTRA",
180 [AV1E_SET_ENABLE_PALETTE] =
"AV1E_SET_ENABLE_PALETTE",
181 [AV1E_SET_ENABLE_FLIP_IDTX] =
"AV1E_SET_ENABLE_FLIP_IDTX",
182 [AV1E_SET_ENABLE_TX64] =
"AV1E_SET_ENABLE_TX64",
183 [AV1E_SET_INTRA_DCT_ONLY] =
"AV1E_SET_INTRA_DCT_ONLY",
184 [AV1E_SET_INTER_DCT_ONLY] =
"AV1E_SET_INTER_DCT_ONLY",
185 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] =
"AV1E_SET_INTRA_DEFAULT_TX_ONLY",
186 [AV1E_SET_REDUCED_TX_TYPE_SET] =
"AV1E_SET_REDUCED_TX_TYPE_SET",
187 [AV1E_SET_ENABLE_DIFF_WTD_COMP] =
"AV1E_SET_ENABLE_DIFF_WTD_COMP",
188 [AV1E_SET_ENABLE_DIST_WTD_COMP] =
"AV1E_SET_ENABLE_DIST_WTD_COMP",
189 [AV1E_SET_ENABLE_DUAL_FILTER] =
"AV1E_SET_ENABLE_DUAL_FILTER",
190 [AV1E_SET_ENABLE_INTERINTER_WEDGE] =
"AV1E_SET_ENABLE_INTERINTER_WEDGE",
191 [AV1E_SET_ENABLE_INTERINTRA_WEDGE] =
"AV1E_SET_ENABLE_INTERINTRA_WEDGE",
192 [AV1E_SET_ENABLE_MASKED_COMP] =
"AV1E_SET_ENABLE_MASKED_COMP",
193 [AV1E_SET_ENABLE_INTERINTRA_COMP] =
"AV1E_SET_ENABLE_INTERINTRA_COMP",
194 [AV1E_SET_ENABLE_OBMC] =
"AV1E_SET_ENABLE_OBMC",
195 [AV1E_SET_ENABLE_ONESIDED_COMP] =
"AV1E_SET_ENABLE_ONESIDED_COMP",
196 [AV1E_SET_REDUCED_REFERENCE_SET] =
"AV1E_SET_REDUCED_REFERENCE_SET",
197 [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
198 [AV1E_SET_ENABLE_REF_FRAME_MVS] =
"AV1E_SET_ENABLE_REF_FRAME_MVS",
199 #ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS
200 [AV1E_GET_NUM_OPERATING_POINTS] =
"AV1E_GET_NUM_OPERATING_POINTS",
202 [AV1E_GET_SEQ_LEVEL_IDX] =
"AV1E_GET_SEQ_LEVEL_IDX",
203 #ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
204 [AV1E_GET_TARGET_SEQ_LEVEL_IDX] =
"AV1E_GET_TARGET_SEQ_LEVEL_IDX",
206 [AV1_GET_NEW_FRAME_IMAGE] =
"AV1_GET_NEW_FRAME_IMAGE",
212 const char *
error = aom_codec_error(&
ctx->encoder);
213 const char *detail = aom_codec_error_detail(&
ctx->encoder);
221 const struct aom_codec_enc_cfg *cfg,
228 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
230 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
231 width,
"g_usage:", cfg->g_usage,
232 width,
"g_threads:", cfg->g_threads,
233 width,
"g_profile:", cfg->g_profile,
234 width,
"g_w:", cfg->g_w,
235 width,
"g_h:", cfg->g_h,
236 width,
"g_bit_depth:", cfg->g_bit_depth,
237 width,
"g_input_bit_depth:", cfg->g_input_bit_depth,
238 width,
"g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
239 width,
"g_error_resilient:", cfg->g_error_resilient,
240 width,
"g_pass:", cfg->g_pass,
241 width,
"g_lag_in_frames:", cfg->g_lag_in_frames);
244 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
245 width,
"rc_end_usage:", cfg->rc_end_usage,
246 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
247 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
250 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
251 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
254 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
255 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
257 " %*s%u\n %*s%u\n %*s%u\n",
258 width,
"rc_buf_sz:", cfg->rc_buf_sz,
259 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
260 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
261 av_log(avctx,
level,
"2 pass rate control settings\n"
262 " %*s%u\n %*s%u\n %*s%u\n",
263 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
264 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
265 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
267 " %*s%d\n %*s%u\n %*s%u\n",
268 width,
"kf_mode:", cfg->kf_mode,
269 width,
"kf_min_dist:", cfg->kf_min_dist,
270 width,
"kf_max_dist:", cfg->kf_max_dist);
273 width,
"tile_width_count:", cfg->tile_width_count,
274 width,
"tile_height_count:", cfg->tile_height_count);
307 aome_enc_control_id
id,
309 enum aome_enc_control_id
id,
321 res = aom_codec_control(&
ctx->encoder,
id,
val);
322 if (res != AOM_CODEC_OK) {
348 uint8_t *hdr_plus_buf;
350 const size_t hdr_plus_buf_size = payload_size + 6;
351 hdr_plus_buf =
av_malloc(hdr_plus_buf_size);
355 uint8_t *payload = hdr_plus_buf;
359 bytestream_put_be16(&payload, 0x0001);
360 bytestream_put_byte(&payload, 0x04);
369 res = aom_img_add_metadata(
img, OBU_METADATA_TYPE_ITUT_T35,
370 hdr_plus_buf, hdr_plus_buf_size, AOM_MIF_ANY_FRAME);
379 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
380 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
381 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
384 aome_enc_control_id
id,
386 enum aome_enc_control_id
id,
398 res = aom_codec_control(&
ctx->encoder,
id, ptr);
399 if (res != AOM_CODEC_OK) {
412 aome_enc_control_id
id,
414 enum aome_enc_control_id
id,
416 struct aom_image *
img)
424 res = aom_codec_control(&
ctx->encoder,
id,
img);
425 if (res != AOM_CODEC_OK) {
439 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
440 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
441 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
443 int num_operating_points;
445 int target_levels[32];
447 if (!codecctl_intp(avctx, AV1E_GET_NUM_OPERATING_POINTS,
448 &num_operating_points) &&
449 !codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) &&
450 !codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX,
452 for (
int i = 0;
i < num_operating_points;
i++) {
453 if (levels[
i] > target_levels[
i]) {
456 "Could not encode to target level %d.%d for "
457 "operating point %d. The output level is %d.%d.\n",
458 2 + (target_levels[
i] >> 2), target_levels[
i] & 3,
459 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
460 }
else if (target_levels[
i] < 31) {
463 "Output level for operating point %d is %d.%d.\n",
464 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
471 aom_codec_destroy(&
ctx->encoder);
472 aom_img_remove_metadata(&
ctx->rawimg);
482 struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *
flags,
483 aom_img_fmt_t *img_fmt)
486 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
489 enccfg->monochrome = 1;
493 *img_fmt = AOM_IMG_FMT_I420;
497 *img_fmt = AOM_IMG_FMT_I422;
502 *img_fmt = AOM_IMG_FMT_I444;
506 enccfg->monochrome = 1;
510 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
513 *img_fmt = AOM_IMG_FMT_I42016;
514 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
520 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
522 *img_fmt = AOM_IMG_FMT_I42216;
523 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
531 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
534 *img_fmt = AOM_IMG_FMT_I44416;
535 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
548 aom_color_range_t aom_cr;
564 int sb_dim = (
dim + sb_size - 1) / sb_size;
565 int tile_dim = (sb_dim + (1 << tiles_log2) - 1) >> tiles_log2;
567 return (sb_dim + tile_dim - 1) / tile_dim;
571 struct aom_codec_enc_cfg *enccfg)
574 int sb_128x128_possible, sb_size, sb_width, sb_height;
575 int uniform_rows, uniform_cols;
576 int uniform_64x64_possible, uniform_128x128_possible;
577 int tile_size, rounding,
i;
579 if (
ctx->tile_cols_log2 >= 0)
580 ctx->tile_cols = 1 <<
ctx->tile_cols_log2;
581 if (
ctx->tile_rows_log2 >= 0)
582 ctx->tile_rows = 1 <<
ctx->tile_rows_log2;
584 if (
ctx->tile_cols == 0) {
587 if (
ctx->tile_cols > 1) {
589 "columns to fill width.\n",
ctx->tile_cols);
593 if (
ctx->tile_rows == 0) {
596 ctx->tile_cols - 1) /
ctx->tile_cols, 128);
600 if (
ctx->tile_rows > 1) {
602 "rows to fill area.\n",
ctx->tile_rows);
607 if ((avctx->
width + 63) / 64 <
ctx->tile_cols ||
608 (avctx->
height + 63) / 64 <
ctx->tile_rows) {
610 "large enough to fit specified tile arrangement.\n");
616 "not allow more than %dx%d tiles.\n",
622 "not allow tiles of width greater than %d.\n",
627 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
629 if (
ctx->tile_cols == 1 &&
ctx->tile_rows == 1) {
634 sb_128x128_possible =
635 (avctx->
width + 127) / 128 >=
ctx->tile_cols &&
636 (avctx->
height + 127) / 128 >=
ctx->tile_rows;
638 ctx->tile_cols_log2 =
ctx->tile_cols == 1 ? 0 :
640 ctx->tile_rows_log2 =
ctx->tile_rows == 1 ? 0 :
644 64,
ctx->tile_cols_log2);
646 64,
ctx->tile_rows_log2);
648 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
649 uniform_64x64_possible = uniform_cols ==
ctx->tile_cols &&
650 uniform_rows ==
ctx->tile_rows;
652 if (sb_128x128_possible) {
654 128,
ctx->tile_cols_log2);
656 128,
ctx->tile_rows_log2);
658 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
659 uniform_128x128_possible = uniform_cols ==
ctx->tile_cols &&
660 uniform_rows ==
ctx->tile_rows;
663 uniform_128x128_possible = 0;
666 ctx->uniform_tiles = 1;
667 if (uniform_64x64_possible && uniform_128x128_possible) {
669 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
670 ctx->tile_cols_log2,
ctx->tile_rows_log2);
673 if (uniform_64x64_possible && !sb_128x128_possible) {
675 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
676 ctx->tile_cols_log2,
ctx->tile_rows_log2);
677 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
680 if (uniform_128x128_possible) {
682 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
683 ctx->tile_cols_log2,
ctx->tile_rows_log2);
684 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
687 ctx->uniform_tiles = 0;
689 if (sb_128x128_possible) {
691 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
694 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
697 "superblocks (tile_cols = %d, tile_rows = %d).\n",
698 sb_size, sb_size,
ctx->tile_cols,
ctx->tile_rows);
700 enccfg->tile_width_count =
ctx->tile_cols;
701 enccfg->tile_height_count =
ctx->tile_rows;
703 sb_width = (avctx->
width + sb_size - 1) / sb_size;
704 sb_height = (avctx->
height + sb_size - 1) / sb_size;
706 tile_size = sb_width /
ctx->tile_cols;
707 rounding = sb_width %
ctx->tile_cols;
708 for (
i = 0;
i <
ctx->tile_cols;
i++) {
709 enccfg->tile_widths[
i] = tile_size +
711 i >
ctx->tile_cols - 1 - (rounding + 1) / 2);
714 tile_size = sb_height /
ctx->tile_rows;
715 rounding = sb_height %
ctx->tile_rows;
716 for (
i = 0;
i <
ctx->tile_rows;
i++) {
717 enccfg->tile_heights[
i] = tile_size +
719 i >
ctx->tile_rows - 1 - (rounding + 1) / 2);
726 static const struct {
730 { AOME_SET_ENABLEAUTOALTREF,
OFFSET(auto_alt_ref) },
731 { AOME_SET_ARNR_MAXFRAMES,
OFFSET(arnr_max_frames) },
732 { AOME_SET_ARNR_STRENGTH,
OFFSET(arnr_strength) },
733 { AV1E_SET_ENABLE_CDEF,
OFFSET(enable_cdef) },
734 { AV1E_SET_ENABLE_RESTORATION,
OFFSET(enable_restoration) },
735 { AV1E_SET_ENABLE_RECT_PARTITIONS,
OFFSET(enable_rect_partitions) },
736 { AV1E_SET_ENABLE_1TO4_PARTITIONS,
OFFSET(enable_1to4_partitions) },
737 { AV1E_SET_ENABLE_AB_PARTITIONS,
OFFSET(enable_ab_partitions) },
738 { AV1E_SET_ENABLE_ANGLE_DELTA,
OFFSET(enable_angle_delta) },
739 { AV1E_SET_ENABLE_CFL_INTRA,
OFFSET(enable_cfl_intra) },
740 { AV1E_SET_ENABLE_FILTER_INTRA,
OFFSET(enable_filter_intra) },
741 { AV1E_SET_ENABLE_INTRA_EDGE_FILTER,
OFFSET(enable_intra_edge_filter) },
742 { AV1E_SET_ENABLE_PAETH_INTRA,
OFFSET(enable_paeth_intra) },
743 { AV1E_SET_ENABLE_SMOOTH_INTRA,
OFFSET(enable_smooth_intra) },
744 { AV1E_SET_ENABLE_PALETTE,
OFFSET(enable_palette) },
745 { AV1E_SET_ENABLE_TX64,
OFFSET(enable_tx64) },
746 { AV1E_SET_ENABLE_FLIP_IDTX,
OFFSET(enable_flip_idtx) },
747 { AV1E_SET_INTRA_DCT_ONLY,
OFFSET(use_intra_dct_only) },
748 { AV1E_SET_INTER_DCT_ONLY,
OFFSET(use_inter_dct_only) },
749 { AV1E_SET_INTRA_DEFAULT_TX_ONLY,
OFFSET(use_intra_default_tx_only) },
750 { AV1E_SET_REDUCED_TX_TYPE_SET,
OFFSET(reduced_tx_type_set) },
751 { AV1E_SET_ENABLE_REF_FRAME_MVS,
OFFSET(enable_ref_frame_mvs) },
752 { AV1E_SET_REDUCED_REFERENCE_SET,
OFFSET(enable_reduced_reference_set) },
753 { AV1E_SET_ENABLE_DIFF_WTD_COMP,
OFFSET(enable_diff_wtd_comp) },
754 { AV1E_SET_ENABLE_DIST_WTD_COMP,
OFFSET(enable_dist_wtd_comp) },
755 { AV1E_SET_ENABLE_DUAL_FILTER,
OFFSET(enable_dual_filter) },
756 { AV1E_SET_ENABLE_INTERINTER_WEDGE,
OFFSET(enable_interinter_wedge) },
757 { AV1E_SET_ENABLE_MASKED_COMP,
OFFSET(enable_masked_comp) },
758 { AV1E_SET_ENABLE_INTERINTRA_COMP,
OFFSET(enable_interintra_comp) },
759 { AV1E_SET_ENABLE_INTERINTRA_WEDGE,
OFFSET(enable_interintra_wedge) },
760 { AV1E_SET_ENABLE_OBMC,
OFFSET(enable_obmc) },
761 { AV1E_SET_ENABLE_ONESIDED_COMP,
OFFSET(enable_onesided_comp) },
762 { AV1E_SET_ENABLE_SMOOTH_INTERINTRA,
OFFSET(enable_smooth_interintra) },
766 const struct aom_codec_iface *iface)
770 struct aom_codec_enc_cfg enccfg = { 0 };
771 aom_codec_flags_t
flags =
774 aom_img_fmt_t img_fmt;
775 aom_codec_caps_t codec_caps = aom_codec_get_caps(iface);
780 if ((res = aom_codec_enc_config_default(iface, &enccfg,
ctx->usage)) != AOM_CODEC_OK) {
782 aom_codec_err_to_string(res));
797 enccfg.g_w = avctx->
width;
798 enccfg.g_h = avctx->
height;
804 if (
ctx->lag_in_frames >= 0)
805 enccfg.g_lag_in_frames =
ctx->lag_in_frames;
808 enccfg.g_pass = AOM_RC_FIRST_PASS;
810 enccfg.g_pass = AOM_RC_LAST_PASS;
812 enccfg.g_pass = AOM_RC_ONE_PASS;
816 enccfg.rc_end_usage = AOM_CBR;
817 }
else if (
ctx->crf >= 0) {
818 enccfg.rc_end_usage = AOM_CQ;
820 enccfg.rc_end_usage = AOM_Q;
826 }
else if (enccfg.rc_end_usage != AOM_Q) {
827 enccfg.rc_end_usage = AOM_Q;
830 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
834 if (avctx->
qmin >= 0)
835 enccfg.rc_min_quantizer = avctx->
qmin;
836 if (avctx->
qmax >= 0) {
837 enccfg.rc_max_quantizer = avctx->
qmax;
838 }
else if (!
ctx->crf) {
839 enccfg.rc_max_quantizer = 0;
842 if (enccfg.rc_end_usage == AOM_CQ || enccfg.rc_end_usage == AOM_Q) {
843 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
845 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
846 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
851 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
855 if (
ctx->minsection_pct >= 0)
856 enccfg.rc_2pass_vbr_minsection_pct =
ctx->minsection_pct;
858 enccfg.rc_2pass_vbr_minsection_pct =
860 if (
ctx->maxsection_pct >= 0)
861 enccfg.rc_2pass_vbr_maxsection_pct =
ctx->maxsection_pct;
863 enccfg.rc_2pass_vbr_maxsection_pct =
870 enccfg.rc_buf_initial_sz =
872 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
874 if (
ctx->rc_undershoot_pct >= 0)
875 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
876 if (
ctx->rc_overshoot_pct >= 0)
877 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
883 enccfg.kf_max_dist = avctx->
gop_size;
885 if (enccfg.g_pass == AOM_RC_FIRST_PASS)
886 enccfg.g_lag_in_frames = 0;
887 else if (enccfg.g_pass == AOM_RC_LAST_PASS) {
888 int decode_size,
ret;
895 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
900 ctx->twopass_stats.sz);
901 ctx->twopass_stats.sz = 0;
905 ctx->twopass_stats.sz);
906 if (decode_size < 0) {
911 ctx->twopass_stats.sz = decode_size;
912 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
919 enccfg.g_profile = avctx->
profile;
921 enccfg.g_error_resilient =
ctx->error_resilient;
927 if (
ctx->still_picture) {
933 enccfg.g_lag_in_frames = 0;
935 enccfg.kf_max_dist = 0;
936 enccfg.kf_mode = AOM_KF_DISABLED;
940 res = aom_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
941 if (res != AOM_CODEC_OK) {
972 if (
ctx->aq_mode >= 0)
974 if (
ctx->frame_parallel >= 0)
975 codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
979 if (
ctx->uniform_tiles) {
984 if (
ctx->denoise_noise_level >= 0)
985 codecctl_int(avctx, AV1E_SET_DENOISE_NOISE_LEVEL,
ctx->denoise_noise_level);
986 if (
ctx->denoise_block_size >= 0)
987 codecctl_int(avctx, AV1E_SET_DENOISE_BLOCK_SIZE,
ctx->denoise_block_size);
988 if (
ctx->enable_global_motion >= 0)
989 codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION,
ctx->enable_global_motion);
990 if (avctx->
refs >= 3) {
993 if (
ctx->row_mt >= 0)
995 if (
ctx->enable_intrabc >= 0)
998 #if AOM_ENCODER_ABI_VERSION >= 23
1003 int ret = aom_codec_set_option(&
ctx->encoder, en->
key, en->
value);
1004 if (
ret != AOM_CODEC_OK) {
1013 aom_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
1016 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
1017 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
1019 ctx->dovi.logctx = avctx;
1029 "not found. This is a bug, please report it.\n");
1049 if (enccfg.rc_end_usage == AOM_CBR ||
1050 enccfg.g_pass != AOM_RC_ONE_PASS) {
1062 const struct aom_codec_cx_pkt *
src)
1064 dst->pts =
src->data.frame.pts;
1065 dst->duration =
src->data.frame.duration;
1066 dst->flags =
src->data.frame.flags;
1067 dst->sz =
src->data.frame.sz;
1068 dst->buf =
src->data.frame.buf;
1069 dst->frame_number = ++
ctx->frame_number;
1070 dst->have_sse =
ctx->have_sse;
1071 if (
ctx->have_sse) {
1074 memcpy(
dst->sse,
ctx->sse,
sizeof(
dst->sse));
1101 if (!!(cx_frame->
flags & AOM_FRAME_IS_KEY)) {
1104 }
else if (cx_frame->
flags & AOM_FRAME_IS_INTRAONLY) {
1111 cx_frame->
have_sse ? 3 : 0, pict_type);
1115 for (
i = 0;
i < 3; ++
i) {
1125 "failed to send input packet\n");
1132 "failed to receive output packet\n");
1150 const struct aom_codec_cx_pkt *
pkt;
1151 const void *iter =
NULL;
1154 if (
ctx->coded_frame_list) {
1160 ctx->coded_frame_list = cx_frame->
next;
1166 while ((
pkt = aom_codec_get_cx_data(&
ctx->encoder, &iter))) {
1167 switch (
pkt->kind) {
1168 case AOM_CODEC_CX_FRAME_PKT:
1185 "Frame queue element alloc failed\n");
1191 if (!cx_frame->
buf) {
1202 case AOM_CODEC_STATS_PKT:
1204 struct aom_fixed_buf *
stats = &
ctx->twopass_stats;
1206 &
ctx->twopass_stats_size,
1221 case AOM_CODEC_PSNR_PKT:
1231 case AOM_CODEC_CUSTOM_PKT:
1243 case AOM_IMG_FMT_I420:
1244 case AOM_IMG_FMT_I42016:
1245 if (
img->bit_depth == 8)
1247 else if (
img->bit_depth == 10)
1251 case AOM_IMG_FMT_I422:
1252 case AOM_IMG_FMT_I42216:
1253 if (
img->bit_depth == 8)
1255 else if (
img->bit_depth == 10)
1259 case AOM_IMG_FMT_I444:
1260 case AOM_IMG_FMT_I44416:
1261 if (
img->bit_depth == 8)
1263 else if (
img->bit_depth == 10)
1275 struct aom_image *rawimg =
NULL;
1278 int res, coded_size;
1279 aom_enc_frame_flags_t
flags = 0;
1283 rawimg = &
ctx->rawimg;
1284 aom_img_remove_metadata(rawimg);
1285 rawimg->planes[AOM_PLANE_Y] =
frame->data[0];
1286 rawimg->planes[AOM_PLANE_U] =
frame->data[1];
1287 rawimg->planes[AOM_PLANE_V] =
frame->data[2];
1288 rawimg->stride[AOM_PLANE_Y] =
frame->linesize[0];
1289 rawimg->stride[AOM_PLANE_U] =
frame->linesize[1];
1290 rawimg->stride[AOM_PLANE_V] =
frame->linesize[2];
1291 timestamp =
frame->pts;
1293 if (
frame->duration > ULONG_MAX) {
1295 "Frame duration too large: %"PRId64
"\n",
frame->duration);
1296 }
else if (
frame->duration)
1304 switch (
frame->color_range) {
1306 rawimg->range = AOM_CR_STUDIO_RANGE;
1309 rawimg->range = AOM_CR_FULL_RANGE;
1313 aom_img_remove_metadata(rawimg);
1315 if (
ctx->dovi.cfg.dv_profile && sd) {
1322 res = aom_img_add_metadata(rawimg, OBU_METADATA_TYPE_ITUT_T35,
1323 t35,
size, AOM_MIF_ANY_FRAME);
1325 if (res != AOM_CODEC_OK)
1327 }
else if (
ctx->dovi.cfg.dv_profile) {
1329 "without AV_FRAME_DATA_DOVI_METADATA\n");
1334 flags |= AOM_EFLAG_FORCE_KF;
1342 if (res != AOM_CODEC_OK) {
1360 ctx->twopass_stats.sz);
1363 *got_packet = !!coded_size;
1367 struct aom_image
img;
1378 "Unhandled reconstructed frame colorspace: %d\n",
1390 if ((
img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) &&
img.bit_depth == 8)
1393 const uint8_t *
planes[4] = {
img.planes[0],
img.planes[1],
img.planes[2] };
1394 const int stride[4] = {
img.stride[0],
img.stride[1],
img.stride[2] };
1463 int supports_monochrome = aom_codec_version() >= 20001;
1464 aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
1465 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
1466 if (supports_monochrome) {
1474 if (supports_monochrome) {
1490 return aom_init(avctx, aom_codec_av1_cx());
1493 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1496 {
"auto-alt-ref",
"Enable use of alternate reference "
1498 {
"lag-in-frames",
"Number of frames to look ahead at for "
1500 {
"arnr-max-frames",
"altref noise reduction max frame count",
OFFSET(arnr_max_frames),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1501 {
"arnr-strength",
"altref noise reduction filter strength",
OFFSET(arnr_strength),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1502 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE, .unit =
"aq_mode"},
1504 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"aq_mode"},
1505 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"aq_mode"},
1506 {
"cyclic",
"Cyclic Refresh Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0,
VE, .unit =
"aq_mode"},
1507 {
"error-resilience",
"Error resilience configuration",
OFFSET(error_resilient),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
VE, .unit =
"er"},
1508 {
"default",
"Improve resiliency against losses of whole frames", 0,
AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0,
VE, .unit =
"er"},
1509 {
"crf",
"Select the quality for constant quality mode", offsetof(AOMContext, crf),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63,
VE },
1510 {
"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 },
1511 {
"drop-threshold",
"Frame drop threshold", offsetof(AOMContext, drop_threshold),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
VE },
1512 {
"denoise-noise-level",
"Amount of noise to be removed",
OFFSET(denoise_noise_level),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1513 {
"denoise-block-size",
"Denoise block size ",
OFFSET(denoise_block_size),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1514 {
"undershoot-pct",
"Datarate undershoot (min) target (%)",
OFFSET(rc_undershoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1515 {
"overshoot-pct",
"Datarate overshoot (max) target (%)",
OFFSET(rc_overshoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1000,
VE},
1516 {
"minsection-pct",
"GOP min bitrate (% of target)",
OFFSET(minsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1517 {
"maxsection-pct",
"GOP max bitrate (% of target)",
OFFSET(maxsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 5000,
VE},
1518 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1520 {
"tile-columns",
"Log2 of number of tile columns to use",
OFFSET(tile_cols_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1521 {
"tile-rows",
"Log2 of number of tile rows to use",
OFFSET(tile_rows_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1524 {
"enable-global-motion",
"Enable global motion",
OFFSET(enable_global_motion),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1525 {
"enable-intrabc",
"Enable intra block copy prediction mode",
OFFSET(enable_intrabc),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1526 {
"enable-restoration",
"Enable Loop Restoration filtering",
OFFSET(enable_restoration),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1527 {
"usage",
"Quality and compression efficiency vs speed trade-off",
OFFSET(
usage),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
VE, .unit =
"usage"},
1529 {
"realtime",
"Realtime encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0,
VE, .unit =
"usage"},
1530 {
"allintra",
"All Intra encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0,
VE, .unit =
"usage"},
1531 {
"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"},
1535 {
"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 },
1538 {
"enable-rect-partitions",
"Enable rectangular partitions",
OFFSET(enable_rect_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1539 {
"enable-1to4-partitions",
"Enable 1:4/4:1 partitions",
OFFSET(enable_1to4_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1540 {
"enable-ab-partitions",
"Enable ab shape partitions",
OFFSET(enable_ab_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1541 {
"enable-angle-delta",
"Enable angle delta intra prediction",
OFFSET(enable_angle_delta),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1542 {
"enable-cfl-intra",
"Enable chroma predicted from luma intra prediction",
OFFSET(enable_cfl_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1543 {
"enable-filter-intra",
"Enable filter intra predictor",
OFFSET(enable_filter_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1544 {
"enable-intra-edge-filter",
"Enable intra edge filter",
OFFSET(enable_intra_edge_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1545 {
"enable-smooth-intra",
"Enable smooth intra prediction mode",
OFFSET(enable_smooth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1546 {
"enable-paeth-intra",
"Enable paeth predictor in intra prediction",
OFFSET(enable_paeth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1547 {
"enable-palette",
"Enable palette prediction mode",
OFFSET(enable_palette),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1548 {
"enable-flip-idtx",
"Enable extended transform type",
OFFSET(enable_flip_idtx),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1550 {
"reduced-tx-type-set",
"Use reduced set of transform types",
OFFSET(reduced_tx_type_set),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1551 {
"use-intra-dct-only",
"Use DCT only for INTRA modes",
OFFSET(use_intra_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1552 {
"use-inter-dct-only",
"Use DCT only for INTER modes",
OFFSET(use_inter_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1553 {
"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},
1554 {
"enable-ref-frame-mvs",
"Enable temporal mv prediction",
OFFSET(enable_ref_frame_mvs),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1555 {
"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},
1557 {
"enable-dual-filter",
"Enable dual filter",
OFFSET(enable_dual_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1558 {
"enable-diff-wtd-comp",
"Enable difference-weighted compound",
OFFSET(enable_diff_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1559 {
"enable-dist-wtd-comp",
"Enable distance-weighted compound",
OFFSET(enable_dist_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1560 {
"enable-onesided-comp",
"Enable one sided compound",
OFFSET(enable_onesided_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1561 {
"enable-interinter-wedge",
"Enable interinter wedge compound",
OFFSET(enable_interinter_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1562 {
"enable-interintra-wedge",
"Enable interintra wedge compound",
OFFSET(enable_interintra_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1563 {
"enable-masked-comp",
"Enable masked compound",
OFFSET(enable_masked_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1564 {
"enable-interintra-comp",
"Enable interintra compound",
OFFSET(enable_interintra_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1565 {
"enable-smooth-interintra",
"Enable smooth interintra mode",
OFFSET(enable_smooth_interintra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1566 #if AOM_ENCODER_ABI_VERSION >= 23
1567 {
"aom-params",
"Set libaom options using a :-separated list of key=value pairs",
OFFSET(aom_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
1577 {
"keyint_min",
"-1" },
1589 .
p.
name =
"libaom-av1",
1599 .p.wrapper_name =
"libaom",
1600 .priv_data_size =
sizeof(AOMContext),