28 #define AOM_DISABLE_CTRL_TYPECHECKS 1
29 #include <aom/aom_encoder.h>
30 #include <aom/aomcx.h>
146 #define OFFSET(x) offsetof(AOMContext, x)
149 [AOME_SET_CPUUSED] =
"AOME_SET_CPUUSED",
150 [AOME_SET_CQ_LEVEL] =
"AOME_SET_CQ_LEVEL",
151 [AOME_SET_ENABLEAUTOALTREF] =
"AOME_SET_ENABLEAUTOALTREF",
152 [AOME_SET_ARNR_MAXFRAMES] =
"AOME_SET_ARNR_MAXFRAMES",
153 [AOME_SET_ARNR_STRENGTH] =
"AOME_SET_ARNR_STRENGTH",
154 [AOME_SET_STATIC_THRESHOLD] =
"AOME_SET_STATIC_THRESHOLD",
155 [AV1E_SET_COLOR_RANGE] =
"AV1E_SET_COLOR_RANGE",
156 [AV1E_SET_COLOR_PRIMARIES] =
"AV1E_SET_COLOR_PRIMARIES",
157 [AV1E_SET_MATRIX_COEFFICIENTS] =
"AV1E_SET_MATRIX_COEFFICIENTS",
158 [AV1E_SET_TRANSFER_CHARACTERISTICS] =
"AV1E_SET_TRANSFER_CHARACTERISTICS",
159 [AV1E_SET_AQ_MODE] =
"AV1E_SET_AQ_MODE",
160 [AV1E_SET_FRAME_PARALLEL_DECODING] =
"AV1E_SET_FRAME_PARALLEL_DECODING",
161 [AV1E_SET_SUPERBLOCK_SIZE] =
"AV1E_SET_SUPERBLOCK_SIZE",
162 [AV1E_SET_TILE_COLUMNS] =
"AV1E_SET_TILE_COLUMNS",
163 [AV1E_SET_TILE_ROWS] =
"AV1E_SET_TILE_ROWS",
164 [AV1E_SET_ENABLE_RESTORATION] =
"AV1E_SET_ENABLE_RESTORATION",
165 [AV1E_SET_ROW_MT] =
"AV1E_SET_ROW_MT",
166 [AV1E_SET_DENOISE_NOISE_LEVEL] =
"AV1E_SET_DENOISE_NOISE_LEVEL",
167 [AV1E_SET_DENOISE_BLOCK_SIZE] =
"AV1E_SET_DENOISE_BLOCK_SIZE",
168 [AV1E_SET_MAX_REFERENCE_FRAMES] =
"AV1E_SET_MAX_REFERENCE_FRAMES",
169 [AV1E_SET_ENABLE_GLOBAL_MOTION] =
"AV1E_SET_ENABLE_GLOBAL_MOTION",
170 [AV1E_SET_ENABLE_INTRABC] =
"AV1E_SET_ENABLE_INTRABC",
171 [AV1E_SET_ENABLE_CDEF] =
"AV1E_SET_ENABLE_CDEF",
172 [AOME_SET_TUNING] =
"AOME_SET_TUNING",
173 [AV1E_SET_ENABLE_1TO4_PARTITIONS] =
"AV1E_SET_ENABLE_1TO4_PARTITIONS",
174 [AV1E_SET_ENABLE_AB_PARTITIONS] =
"AV1E_SET_ENABLE_AB_PARTITIONS",
175 [AV1E_SET_ENABLE_RECT_PARTITIONS] =
"AV1E_SET_ENABLE_RECT_PARTITIONS",
176 [AV1E_SET_ENABLE_ANGLE_DELTA] =
"AV1E_SET_ENABLE_ANGLE_DELTA",
177 [AV1E_SET_ENABLE_CFL_INTRA] =
"AV1E_SET_ENABLE_CFL_INTRA",
178 [AV1E_SET_ENABLE_FILTER_INTRA] =
"AV1E_SET_ENABLE_FILTER_INTRA",
179 [AV1E_SET_ENABLE_INTRA_EDGE_FILTER] =
"AV1E_SET_ENABLE_INTRA_EDGE_FILTER",
180 [AV1E_SET_ENABLE_PAETH_INTRA] =
"AV1E_SET_ENABLE_PAETH_INTRA",
181 [AV1E_SET_ENABLE_SMOOTH_INTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTRA",
182 [AV1E_SET_ENABLE_PALETTE] =
"AV1E_SET_ENABLE_PALETTE",
183 [AV1E_SET_ENABLE_FLIP_IDTX] =
"AV1E_SET_ENABLE_FLIP_IDTX",
184 [AV1E_SET_ENABLE_TX64] =
"AV1E_SET_ENABLE_TX64",
185 [AV1E_SET_INTRA_DCT_ONLY] =
"AV1E_SET_INTRA_DCT_ONLY",
186 [AV1E_SET_INTER_DCT_ONLY] =
"AV1E_SET_INTER_DCT_ONLY",
187 [AV1E_SET_INTRA_DEFAULT_TX_ONLY] =
"AV1E_SET_INTRA_DEFAULT_TX_ONLY",
188 [AV1E_SET_REDUCED_TX_TYPE_SET] =
"AV1E_SET_REDUCED_TX_TYPE_SET",
189 [AV1E_SET_ENABLE_DIFF_WTD_COMP] =
"AV1E_SET_ENABLE_DIFF_WTD_COMP",
190 [AV1E_SET_ENABLE_DIST_WTD_COMP] =
"AV1E_SET_ENABLE_DIST_WTD_COMP",
191 [AV1E_SET_ENABLE_DUAL_FILTER] =
"AV1E_SET_ENABLE_DUAL_FILTER",
192 [AV1E_SET_ENABLE_INTERINTER_WEDGE] =
"AV1E_SET_ENABLE_INTERINTER_WEDGE",
193 [AV1E_SET_ENABLE_INTERINTRA_WEDGE] =
"AV1E_SET_ENABLE_INTERINTRA_WEDGE",
194 [AV1E_SET_ENABLE_MASKED_COMP] =
"AV1E_SET_ENABLE_MASKED_COMP",
195 [AV1E_SET_ENABLE_INTERINTRA_COMP] =
"AV1E_SET_ENABLE_INTERINTRA_COMP",
196 [AV1E_SET_ENABLE_OBMC] =
"AV1E_SET_ENABLE_OBMC",
197 [AV1E_SET_ENABLE_ONESIDED_COMP] =
"AV1E_SET_ENABLE_ONESIDED_COMP",
198 [AV1E_SET_REDUCED_REFERENCE_SET] =
"AV1E_SET_REDUCED_REFERENCE_SET",
199 [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] =
"AV1E_SET_ENABLE_SMOOTH_INTERINTRA",
200 [AV1E_SET_ENABLE_REF_FRAME_MVS] =
"AV1E_SET_ENABLE_REF_FRAME_MVS",
201 #ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS
202 [AV1E_GET_NUM_OPERATING_POINTS] =
"AV1E_GET_NUM_OPERATING_POINTS",
204 [AV1E_GET_SEQ_LEVEL_IDX] =
"AV1E_GET_SEQ_LEVEL_IDX",
205 #ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX
206 [AV1E_GET_TARGET_SEQ_LEVEL_IDX] =
"AV1E_GET_TARGET_SEQ_LEVEL_IDX",
208 [AV1_GET_NEW_FRAME_IMAGE] =
"AV1_GET_NEW_FRAME_IMAGE",
214 const char *
error = aom_codec_error(&
ctx->encoder);
215 const char *detail = aom_codec_error_detail(&
ctx->encoder);
223 const struct aom_codec_enc_cfg *cfg,
230 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
232 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
233 width,
"g_usage:", cfg->g_usage,
234 width,
"g_threads:", cfg->g_threads,
235 width,
"g_profile:", cfg->g_profile,
236 width,
"g_w:", cfg->g_w,
237 width,
"g_h:", cfg->g_h,
238 width,
"g_bit_depth:", cfg->g_bit_depth,
239 width,
"g_input_bit_depth:", cfg->g_input_bit_depth,
240 width,
"g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
241 width,
"g_error_resilient:", cfg->g_error_resilient,
242 width,
"g_pass:", cfg->g_pass,
243 width,
"g_lag_in_frames:", cfg->g_lag_in_frames);
246 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
247 width,
"rc_end_usage:", cfg->rc_end_usage,
248 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
249 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
252 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
253 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
256 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
257 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
259 " %*s%u\n %*s%u\n %*s%u\n",
260 width,
"rc_buf_sz:", cfg->rc_buf_sz,
261 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
262 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
263 av_log(avctx,
level,
"2 pass rate control settings\n"
264 " %*s%u\n %*s%u\n %*s%u\n",
265 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
266 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
267 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
269 " %*s%d\n %*s%u\n %*s%u\n",
270 width,
"kf_mode:", cfg->kf_mode,
271 width,
"kf_min_dist:", cfg->kf_min_dist,
272 width,
"kf_max_dist:", cfg->kf_max_dist);
275 width,
"tile_width_count:", cfg->tile_width_count,
276 width,
"tile_height_count:", cfg->tile_height_count);
309 aome_enc_control_id
id,
311 enum aome_enc_control_id
id,
323 res = aom_codec_control(&
ctx->encoder,
id,
val);
324 if (res != AOM_CODEC_OK) {
350 uint8_t *hdr_plus_buf;
352 const size_t hdr_plus_buf_size = payload_size + 6;
353 hdr_plus_buf =
av_malloc(hdr_plus_buf_size);
357 uint8_t *payload = hdr_plus_buf;
361 bytestream_put_be16(&payload, 0x0001);
362 bytestream_put_byte(&payload, 0x04);
371 res = aom_img_add_metadata(
img, OBU_METADATA_TYPE_ITUT_T35,
372 hdr_plus_buf, hdr_plus_buf_size, AOM_MIF_ANY_FRAME);
381 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
382 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
383 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
386 aome_enc_control_id
id,
388 enum aome_enc_control_id
id,
400 res = aom_codec_control(&
ctx->encoder,
id, ptr);
401 if (res != AOM_CODEC_OK) {
414 aome_enc_control_id
id,
416 enum aome_enc_control_id
id,
418 struct aom_image *
img)
426 res = aom_codec_control(&
ctx->encoder,
id,
img);
427 if (res != AOM_CODEC_OK) {
441 #if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \
442 defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \
443 defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX)
445 int num_operating_points;
447 int target_levels[32];
449 if (!codecctl_intp(avctx, AV1E_GET_NUM_OPERATING_POINTS,
450 &num_operating_points) &&
451 !codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) &&
452 !codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX,
454 for (
int i = 0;
i < num_operating_points;
i++) {
455 if (levels[
i] > target_levels[
i]) {
458 "Could not encode to target level %d.%d for "
459 "operating point %d. The output level is %d.%d.\n",
460 2 + (target_levels[
i] >> 2), target_levels[
i] & 3,
461 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
462 }
else if (target_levels[
i] < 31) {
465 "Output level for operating point %d is %d.%d.\n",
466 i, 2 + (levels[
i] >> 2), levels[
i] & 3);
473 aom_codec_destroy(&
ctx->encoder);
474 aom_img_remove_metadata(&
ctx->rawimg);
484 struct aom_codec_enc_cfg *enccfg, aom_codec_flags_t *
flags,
485 aom_img_fmt_t *img_fmt)
489 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
492 enccfg->monochrome = 1;
496 *img_fmt = AOM_IMG_FMT_I420;
500 *img_fmt = AOM_IMG_FMT_I422;
505 *img_fmt = AOM_IMG_FMT_I444;
509 enccfg->monochrome = 1;
513 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
516 *img_fmt = AOM_IMG_FMT_I42016;
517 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
523 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
525 *img_fmt = AOM_IMG_FMT_I42216;
526 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
534 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
537 *img_fmt = AOM_IMG_FMT_I44416;
538 *
flags |= AOM_CODEC_USE_HIGHBITDEPTH;
551 aom_color_range_t aom_cr;
567 int sb_dim = (
dim + sb_size - 1) / sb_size;
568 int tile_dim = (sb_dim + (1 << tiles_log2) - 1) >> tiles_log2;
570 return (sb_dim + tile_dim - 1) / tile_dim;
574 struct aom_codec_enc_cfg *enccfg)
577 int sb_128x128_possible, sb_size, sb_width, sb_height;
578 int uniform_rows, uniform_cols;
579 int uniform_64x64_possible, uniform_128x128_possible;
580 int tile_size, rounding,
i;
582 if (
ctx->tile_cols_log2 >= 0)
583 ctx->tile_cols = 1 <<
ctx->tile_cols_log2;
584 if (
ctx->tile_rows_log2 >= 0)
585 ctx->tile_rows = 1 <<
ctx->tile_rows_log2;
587 if (
ctx->tile_cols == 0) {
590 if (
ctx->tile_cols > 1) {
592 "columns to fill width.\n",
ctx->tile_cols);
596 if (
ctx->tile_rows == 0) {
599 ctx->tile_cols - 1) /
ctx->tile_cols, 128);
603 if (
ctx->tile_rows > 1) {
605 "rows to fill area.\n",
ctx->tile_rows);
610 if ((avctx->
width + 63) / 64 <
ctx->tile_cols ||
611 (avctx->
height + 63) / 64 <
ctx->tile_rows) {
613 "large enough to fit specified tile arrangement.\n");
619 "not allow more than %dx%d tiles.\n",
625 "not allow tiles of width greater than %d.\n",
630 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC;
632 if (
ctx->tile_cols == 1 &&
ctx->tile_rows == 1) {
637 sb_128x128_possible =
638 (avctx->
width + 127) / 128 >=
ctx->tile_cols &&
639 (avctx->
height + 127) / 128 >=
ctx->tile_rows;
641 ctx->tile_cols_log2 =
ctx->tile_cols == 1 ? 0 :
643 ctx->tile_rows_log2 =
ctx->tile_rows == 1 ? 0 :
647 64,
ctx->tile_cols_log2);
649 64,
ctx->tile_rows_log2);
651 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
652 uniform_64x64_possible = uniform_cols ==
ctx->tile_cols &&
653 uniform_rows ==
ctx->tile_rows;
655 if (sb_128x128_possible) {
657 128,
ctx->tile_cols_log2);
659 128,
ctx->tile_rows_log2);
661 "-> %dx%d tiles.\n", uniform_cols, uniform_rows);
662 uniform_128x128_possible = uniform_cols ==
ctx->tile_cols &&
663 uniform_rows ==
ctx->tile_rows;
666 uniform_128x128_possible = 0;
669 ctx->uniform_tiles = 1;
670 if (uniform_64x64_possible && uniform_128x128_possible) {
672 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
673 ctx->tile_cols_log2,
ctx->tile_rows_log2);
676 if (uniform_64x64_possible && !sb_128x128_possible) {
678 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
679 ctx->tile_cols_log2,
ctx->tile_rows_log2);
680 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
683 if (uniform_128x128_possible) {
685 "superblocks (tile_cols_log2 = %d, tile_rows_log2 = %d).\n",
686 ctx->tile_cols_log2,
ctx->tile_rows_log2);
687 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
690 ctx->uniform_tiles = 0;
692 if (sb_128x128_possible) {
694 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_128X128;
697 ctx->superblock_size = AOM_SUPERBLOCK_SIZE_64X64;
700 "superblocks (tile_cols = %d, tile_rows = %d).\n",
701 sb_size, sb_size,
ctx->tile_cols,
ctx->tile_rows);
703 enccfg->tile_width_count =
ctx->tile_cols;
704 enccfg->tile_height_count =
ctx->tile_rows;
706 sb_width = (avctx->
width + sb_size - 1) / sb_size;
707 sb_height = (avctx->
height + sb_size - 1) / sb_size;
709 tile_size = sb_width /
ctx->tile_cols;
710 rounding = sb_width %
ctx->tile_cols;
711 for (
i = 0;
i <
ctx->tile_cols;
i++) {
712 enccfg->tile_widths[
i] = tile_size +
714 i >
ctx->tile_cols - 1 - (rounding + 1) / 2);
717 tile_size = sb_height /
ctx->tile_rows;
718 rounding = sb_height %
ctx->tile_rows;
719 for (
i = 0;
i <
ctx->tile_rows;
i++) {
720 enccfg->tile_heights[
i] = tile_size +
722 i >
ctx->tile_rows - 1 - (rounding + 1) / 2);
729 static const struct {
733 { AOME_SET_ENABLEAUTOALTREF,
OFFSET(auto_alt_ref) },
734 { AOME_SET_ARNR_MAXFRAMES,
OFFSET(arnr_max_frames) },
735 { AOME_SET_ARNR_STRENGTH,
OFFSET(arnr_strength) },
736 { AV1E_SET_ENABLE_CDEF,
OFFSET(enable_cdef) },
737 { AV1E_SET_ENABLE_RESTORATION,
OFFSET(enable_restoration) },
738 { AV1E_SET_ENABLE_RECT_PARTITIONS,
OFFSET(enable_rect_partitions) },
739 { AV1E_SET_ENABLE_1TO4_PARTITIONS,
OFFSET(enable_1to4_partitions) },
740 { AV1E_SET_ENABLE_AB_PARTITIONS,
OFFSET(enable_ab_partitions) },
741 { AV1E_SET_ENABLE_ANGLE_DELTA,
OFFSET(enable_angle_delta) },
742 { AV1E_SET_ENABLE_CFL_INTRA,
OFFSET(enable_cfl_intra) },
743 { AV1E_SET_ENABLE_FILTER_INTRA,
OFFSET(enable_filter_intra) },
744 { AV1E_SET_ENABLE_INTRA_EDGE_FILTER,
OFFSET(enable_intra_edge_filter) },
745 { AV1E_SET_ENABLE_PAETH_INTRA,
OFFSET(enable_paeth_intra) },
746 { AV1E_SET_ENABLE_SMOOTH_INTRA,
OFFSET(enable_smooth_intra) },
747 { AV1E_SET_ENABLE_PALETTE,
OFFSET(enable_palette) },
748 { AV1E_SET_ENABLE_TX64,
OFFSET(enable_tx64) },
749 { AV1E_SET_ENABLE_FLIP_IDTX,
OFFSET(enable_flip_idtx) },
750 { AV1E_SET_INTRA_DCT_ONLY,
OFFSET(use_intra_dct_only) },
751 { AV1E_SET_INTER_DCT_ONLY,
OFFSET(use_inter_dct_only) },
752 { AV1E_SET_INTRA_DEFAULT_TX_ONLY,
OFFSET(use_intra_default_tx_only) },
753 { AV1E_SET_REDUCED_TX_TYPE_SET,
OFFSET(reduced_tx_type_set) },
754 { AV1E_SET_ENABLE_REF_FRAME_MVS,
OFFSET(enable_ref_frame_mvs) },
755 { AV1E_SET_REDUCED_REFERENCE_SET,
OFFSET(enable_reduced_reference_set) },
756 { AV1E_SET_ENABLE_DIFF_WTD_COMP,
OFFSET(enable_diff_wtd_comp) },
757 { AV1E_SET_ENABLE_DIST_WTD_COMP,
OFFSET(enable_dist_wtd_comp) },
758 { AV1E_SET_ENABLE_DUAL_FILTER,
OFFSET(enable_dual_filter) },
759 { AV1E_SET_ENABLE_INTERINTER_WEDGE,
OFFSET(enable_interinter_wedge) },
760 { AV1E_SET_ENABLE_MASKED_COMP,
OFFSET(enable_masked_comp) },
761 { AV1E_SET_ENABLE_INTERINTRA_COMP,
OFFSET(enable_interintra_comp) },
762 { AV1E_SET_ENABLE_INTERINTRA_WEDGE,
OFFSET(enable_interintra_wedge) },
763 { AV1E_SET_ENABLE_OBMC,
OFFSET(enable_obmc) },
764 { AV1E_SET_ENABLE_ONESIDED_COMP,
OFFSET(enable_onesided_comp) },
765 { AV1E_SET_ENABLE_SMOOTH_INTERINTRA,
OFFSET(enable_smooth_interintra) },
769 const struct aom_codec_iface *iface)
773 struct aom_codec_enc_cfg enccfg = { 0 };
774 aom_codec_flags_t
flags =
777 aom_img_fmt_t img_fmt;
778 aom_codec_caps_t codec_caps = aom_codec_get_caps(iface);
783 if ((res = aom_codec_enc_config_default(iface, &enccfg,
ctx->usage)) != AOM_CODEC_OK) {
785 aom_codec_err_to_string(res));
800 enccfg.g_w = avctx->
width;
801 enccfg.g_h = avctx->
height;
807 if (
ctx->lag_in_frames >= 0)
808 enccfg.g_lag_in_frames =
ctx->lag_in_frames;
811 enccfg.g_pass = AOM_RC_FIRST_PASS;
813 enccfg.g_pass = AOM_RC_LAST_PASS;
815 enccfg.g_pass = AOM_RC_ONE_PASS;
819 enccfg.rc_end_usage = AOM_CBR;
820 }
else if (
ctx->crf >= 0) {
821 enccfg.rc_end_usage = AOM_CQ;
823 enccfg.rc_end_usage = AOM_Q;
829 }
else if (enccfg.rc_end_usage != AOM_Q) {
830 enccfg.rc_end_usage = AOM_Q;
833 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
837 if (avctx->
qmin >= 0)
838 enccfg.rc_min_quantizer = avctx->
qmin;
839 if (avctx->
qmax >= 0) {
840 enccfg.rc_max_quantizer = avctx->
qmax;
841 }
else if (!
ctx->crf) {
842 enccfg.rc_max_quantizer = 0;
845 if (enccfg.rc_end_usage == AOM_CQ || enccfg.rc_end_usage == AOM_Q) {
846 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
848 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
849 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
854 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
858 if (
ctx->minsection_pct >= 0)
859 enccfg.rc_2pass_vbr_minsection_pct =
ctx->minsection_pct;
861 enccfg.rc_2pass_vbr_minsection_pct =
863 if (
ctx->maxsection_pct >= 0)
864 enccfg.rc_2pass_vbr_maxsection_pct =
ctx->maxsection_pct;
866 enccfg.rc_2pass_vbr_maxsection_pct =
873 enccfg.rc_buf_initial_sz =
875 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
877 if (
ctx->rc_undershoot_pct >= 0)
878 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
879 if (
ctx->rc_overshoot_pct >= 0)
880 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
886 enccfg.kf_max_dist = avctx->
gop_size;
888 if (enccfg.g_pass == AOM_RC_FIRST_PASS)
889 enccfg.g_lag_in_frames = 0;
890 else if (enccfg.g_pass == AOM_RC_LAST_PASS) {
891 int decode_size,
ret;
898 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
903 ctx->twopass_stats.sz);
904 ctx->twopass_stats.sz = 0;
908 ctx->twopass_stats.sz);
909 if (decode_size < 0) {
914 ctx->twopass_stats.sz = decode_size;
915 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
922 enccfg.g_profile = avctx->
profile;
924 enccfg.g_error_resilient =
ctx->error_resilient;
930 if (
ctx->still_picture) {
936 enccfg.g_lag_in_frames = 0;
938 enccfg.kf_max_dist = 0;
939 enccfg.kf_mode = AOM_KF_DISABLED;
943 res = aom_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
944 if (res != AOM_CODEC_OK) {
975 if (
ctx->aq_mode >= 0)
977 if (
ctx->frame_parallel >= 0)
978 codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
982 if (
ctx->uniform_tiles) {
987 if (
ctx->denoise_noise_level >= 0)
988 codecctl_int(avctx, AV1E_SET_DENOISE_NOISE_LEVEL,
ctx->denoise_noise_level);
989 if (
ctx->denoise_block_size >= 0)
990 codecctl_int(avctx, AV1E_SET_DENOISE_BLOCK_SIZE,
ctx->denoise_block_size);
991 if (
ctx->enable_global_motion >= 0)
992 codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION,
ctx->enable_global_motion);
993 if (avctx->
refs >= 3) {
996 if (
ctx->row_mt >= 0)
998 if (
ctx->enable_intrabc >= 0)
1001 #if AOM_ENCODER_ABI_VERSION >= 23
1006 int ret = aom_codec_set_option(&
ctx->encoder, en->
key, en->
value);
1007 if (
ret != AOM_CODEC_OK) {
1016 aom_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
1019 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
1020 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
1022 ctx->dovi.logctx = avctx;
1032 "not found. This is a bug, please report it.\n");
1052 if (enccfg.rc_end_usage == AOM_CBR ||
1053 enccfg.g_pass != AOM_RC_ONE_PASS) {
1065 const struct aom_codec_cx_pkt *
src)
1067 dst->pts =
src->data.frame.pts;
1068 dst->duration =
src->data.frame.duration;
1069 dst->flags =
src->data.frame.flags;
1070 dst->sz =
src->data.frame.sz;
1071 dst->buf =
src->data.frame.buf;
1072 dst->frame_number = ++
ctx->frame_number;
1073 dst->have_sse =
ctx->have_sse;
1074 if (
ctx->have_sse) {
1077 memcpy(
dst->sse,
ctx->sse,
sizeof(
dst->sse));
1104 if (!!(cx_frame->
flags & AOM_FRAME_IS_KEY)) {
1107 }
else if (cx_frame->
flags & AOM_FRAME_IS_INTRAONLY) {
1114 cx_frame->
have_sse ? 3 : 0, pict_type);
1118 for (
i = 0;
i < 3; ++
i) {
1128 "failed to send input packet\n");
1135 "failed to receive output packet\n");
1153 const struct aom_codec_cx_pkt *
pkt;
1154 const void *iter =
NULL;
1157 if (
ctx->coded_frame_list) {
1163 ctx->coded_frame_list = cx_frame->
next;
1169 while ((
pkt = aom_codec_get_cx_data(&
ctx->encoder, &iter))) {
1170 switch (
pkt->kind) {
1171 case AOM_CODEC_CX_FRAME_PKT:
1188 "Frame queue element alloc failed\n");
1194 if (!cx_frame->
buf) {
1205 case AOM_CODEC_STATS_PKT:
1207 struct aom_fixed_buf *
stats = &
ctx->twopass_stats;
1209 &
ctx->twopass_stats_size,
1224 case AOM_CODEC_PSNR_PKT:
1234 case AOM_CODEC_CUSTOM_PKT:
1246 case AOM_IMG_FMT_I420:
1247 case AOM_IMG_FMT_I42016:
1248 if (
img->bit_depth == 8)
1250 else if (
img->bit_depth == 10)
1254 case AOM_IMG_FMT_I422:
1255 case AOM_IMG_FMT_I42216:
1256 if (
img->bit_depth == 8)
1258 else if (
img->bit_depth == 10)
1262 case AOM_IMG_FMT_I444:
1263 case AOM_IMG_FMT_I44416:
1264 if (
img->bit_depth == 8)
1266 else if (
img->bit_depth == 10)
1278 struct aom_image *rawimg =
NULL;
1281 int res, coded_size;
1282 aom_enc_frame_flags_t
flags = 0;
1286 rawimg = &
ctx->rawimg;
1287 aom_img_remove_metadata(rawimg);
1288 rawimg->planes[AOM_PLANE_Y] =
frame->data[0];
1289 rawimg->planes[AOM_PLANE_U] =
frame->data[1];
1290 rawimg->planes[AOM_PLANE_V] =
frame->data[2];
1291 rawimg->stride[AOM_PLANE_Y] =
frame->linesize[0];
1292 rawimg->stride[AOM_PLANE_U] =
frame->linesize[1];
1293 rawimg->stride[AOM_PLANE_V] =
frame->linesize[2];
1294 timestamp =
frame->pts;
1296 if (
frame->duration > ULONG_MAX) {
1298 "Frame duration too large: %"PRId64
"\n",
frame->duration);
1299 }
else if (
frame->duration)
1307 switch (
frame->color_range) {
1309 rawimg->range = AOM_CR_STUDIO_RANGE;
1312 rawimg->range = AOM_CR_FULL_RANGE;
1316 aom_img_remove_metadata(rawimg);
1318 if (
ctx->dovi.cfg.dv_profile && sd) {
1325 res = aom_img_add_metadata(rawimg, OBU_METADATA_TYPE_ITUT_T35,
1326 t35,
size, AOM_MIF_ANY_FRAME);
1328 if (res != AOM_CODEC_OK)
1330 }
else if (
ctx->dovi.cfg.dv_profile) {
1332 "without AV_FRAME_DATA_DOVI_METADATA\n");
1337 flags |= AOM_EFLAG_FORCE_KF;
1345 if (res != AOM_CODEC_OK) {
1363 ctx->twopass_stats.sz);
1366 *got_packet = !!coded_size;
1370 struct aom_image
img;
1381 "Unhandled reconstructed frame colorspace: %d\n",
1393 if ((
img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) &&
img.bit_depth == 8)
1396 const uint8_t *
planes[4] = {
img.planes[0],
img.planes[1],
img.planes[2] };
1397 const int stride[4] = {
img.stride[0],
img.stride[1],
img.stride[2] };
1466 int supports_monochrome = aom_codec_version() >= 20001;
1467 aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
1468 if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) {
1469 if (supports_monochrome) {
1477 if (supports_monochrome) {
1493 return aom_init(avctx, aom_codec_av1_cx());
1496 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1499 {
"auto-alt-ref",
"Enable use of alternate reference "
1501 {
"lag-in-frames",
"Number of frames to look ahead at for "
1503 {
"arnr-max-frames",
"altref noise reduction max frame count",
OFFSET(arnr_max_frames),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1504 {
"arnr-strength",
"altref noise reduction filter strength",
OFFSET(arnr_strength),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1505 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE, .unit =
"aq_mode"},
1507 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"aq_mode"},
1508 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"aq_mode"},
1509 {
"cyclic",
"Cyclic Refresh Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0,
VE, .unit =
"aq_mode"},
1510 {
"error-resilience",
"Error resilience configuration",
OFFSET(error_resilient),
AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX,
VE, .unit =
"er"},
1511 {
"default",
"Improve resiliency against losses of whole frames", 0,
AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0,
VE, .unit =
"er"},
1512 {
"crf",
"Select the quality for constant quality mode", offsetof(AOMContext, crf),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63,
VE },
1513 {
"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 },
1514 {
"drop-threshold",
"Frame drop threshold", offsetof(AOMContext, drop_threshold),
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX,
VE },
1515 {
"denoise-noise-level",
"Amount of noise to be removed",
OFFSET(denoise_noise_level),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1516 {
"denoise-block-size",
"Denoise block size ",
OFFSET(denoise_block_size),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE},
1517 {
"undershoot-pct",
"Datarate undershoot (min) target (%)",
OFFSET(rc_undershoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1518 {
"overshoot-pct",
"Datarate overshoot (max) target (%)",
OFFSET(rc_overshoot_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1000,
VE},
1519 {
"minsection-pct",
"GOP min bitrate (% of target)",
OFFSET(minsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100,
VE},
1520 {
"maxsection-pct",
"GOP max bitrate (% of target)",
OFFSET(maxsection_pct),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 5000,
VE},
1521 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1523 {
"tile-columns",
"Log2 of number of tile columns to use",
OFFSET(tile_cols_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1524 {
"tile-rows",
"Log2 of number of tile rows to use",
OFFSET(tile_rows_log2),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1527 {
"enable-global-motion",
"Enable global motion",
OFFSET(enable_global_motion),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1528 {
"enable-intrabc",
"Enable intra block copy prediction mode",
OFFSET(enable_intrabc),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1529 {
"enable-restoration",
"Enable Loop Restoration filtering",
OFFSET(enable_restoration),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1530 {
"usage",
"Quality and compression efficiency vs speed trade-off",
OFFSET(
usage),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
VE, .unit =
"usage"},
1532 {
"realtime",
"Realtime encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0,
VE, .unit =
"usage"},
1533 {
"allintra",
"All Intra encoding", 0,
AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0,
VE, .unit =
"usage"},
1534 {
"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"},
1538 {
"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 },
1541 {
"enable-rect-partitions",
"Enable rectangular partitions",
OFFSET(enable_rect_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1542 {
"enable-1to4-partitions",
"Enable 1:4/4:1 partitions",
OFFSET(enable_1to4_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1543 {
"enable-ab-partitions",
"Enable ab shape partitions",
OFFSET(enable_ab_partitions),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1544 {
"enable-angle-delta",
"Enable angle delta intra prediction",
OFFSET(enable_angle_delta),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1545 {
"enable-cfl-intra",
"Enable chroma predicted from luma intra prediction",
OFFSET(enable_cfl_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1546 {
"enable-filter-intra",
"Enable filter intra predictor",
OFFSET(enable_filter_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1547 {
"enable-intra-edge-filter",
"Enable intra edge filter",
OFFSET(enable_intra_edge_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1548 {
"enable-smooth-intra",
"Enable smooth intra prediction mode",
OFFSET(enable_smooth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1549 {
"enable-paeth-intra",
"Enable paeth predictor in intra prediction",
OFFSET(enable_paeth_intra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1550 {
"enable-palette",
"Enable palette prediction mode",
OFFSET(enable_palette),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1551 {
"enable-flip-idtx",
"Enable extended transform type",
OFFSET(enable_flip_idtx),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1553 {
"reduced-tx-type-set",
"Use reduced set of transform types",
OFFSET(reduced_tx_type_set),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1554 {
"use-intra-dct-only",
"Use DCT only for INTRA modes",
OFFSET(use_intra_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1555 {
"use-inter-dct-only",
"Use DCT only for INTER modes",
OFFSET(use_inter_dct_only),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1556 {
"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},
1557 {
"enable-ref-frame-mvs",
"Enable temporal mv prediction",
OFFSET(enable_ref_frame_mvs),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1558 {
"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},
1560 {
"enable-dual-filter",
"Enable dual filter",
OFFSET(enable_dual_filter),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1561 {
"enable-diff-wtd-comp",
"Enable difference-weighted compound",
OFFSET(enable_diff_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1562 {
"enable-dist-wtd-comp",
"Enable distance-weighted compound",
OFFSET(enable_dist_wtd_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1563 {
"enable-onesided-comp",
"Enable one sided compound",
OFFSET(enable_onesided_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1564 {
"enable-interinter-wedge",
"Enable interinter wedge compound",
OFFSET(enable_interinter_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1565 {
"enable-interintra-wedge",
"Enable interintra wedge compound",
OFFSET(enable_interintra_wedge),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1566 {
"enable-masked-comp",
"Enable masked compound",
OFFSET(enable_masked_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1567 {
"enable-interintra-comp",
"Enable interintra compound",
OFFSET(enable_interintra_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1568 {
"enable-smooth-interintra",
"Enable smooth interintra mode",
OFFSET(enable_smooth_interintra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
VE},
1569 #if AOM_ENCODER_ABI_VERSION >= 23
1570 {
"aom-params",
"Set libaom options using a :-separated list of key=value pairs",
OFFSET(aom_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
1580 {
"keyint_min",
"-1" },
1592 .
p.
name =
"libaom-av1",
1602 .p.wrapper_name =
"libaom",
1603 .priv_data_size =
sizeof(AOMContext),