26 #include "config_components.h"
28 #define VPX_DISABLE_CTRL_TYPECHECKS 1
29 #define VPX_CODEC_DISABLE_COMPAT 1
30 #include <vpx/vpx_encoder.h>
31 #include <vpx/vp8cx.h>
98 #define VP8F_ERROR_RESILIENT 0x00000001
99 #define VP8F_AUTO_ALT_REF 0x00000002
147 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
148 vpx_svc_ref_frame_config_t ref_frame_config;
154 [VP8E_SET_CPUUSED] =
"VP8E_SET_CPUUSED",
155 [VP8E_SET_ENABLEAUTOALTREF] =
"VP8E_SET_ENABLEAUTOALTREF",
156 [VP8E_SET_NOISE_SENSITIVITY] =
"VP8E_SET_NOISE_SENSITIVITY",
157 [VP8E_SET_STATIC_THRESHOLD] =
"VP8E_SET_STATIC_THRESHOLD",
158 [VP8E_SET_TOKEN_PARTITIONS] =
"VP8E_SET_TOKEN_PARTITIONS",
159 [VP8E_SET_ARNR_MAXFRAMES] =
"VP8E_SET_ARNR_MAXFRAMES",
160 [VP8E_SET_ARNR_STRENGTH] =
"VP8E_SET_ARNR_STRENGTH",
161 [VP8E_SET_ARNR_TYPE] =
"VP8E_SET_ARNR_TYPE",
162 [VP8E_SET_TUNING] =
"VP8E_SET_TUNING",
163 [VP8E_SET_CQ_LEVEL] =
"VP8E_SET_CQ_LEVEL",
164 [VP8E_SET_MAX_INTRA_BITRATE_PCT] =
"VP8E_SET_MAX_INTRA_BITRATE_PCT",
165 [VP8E_SET_SHARPNESS] =
"VP8E_SET_SHARPNESS",
166 [VP8E_SET_TEMPORAL_LAYER_ID] =
"VP8E_SET_TEMPORAL_LAYER_ID",
167 [VP8E_SET_SCREEN_CONTENT_MODE] =
"VP8E_SET_SCREEN_CONTENT_MODE",
168 #if CONFIG_LIBVPX_VP9_ENCODER
169 [VP9E_SET_LOSSLESS] =
"VP9E_SET_LOSSLESS",
170 [VP9E_SET_TILE_COLUMNS] =
"VP9E_SET_TILE_COLUMNS",
171 [VP9E_SET_TILE_ROWS] =
"VP9E_SET_TILE_ROWS",
172 [VP9E_SET_FRAME_PARALLEL_DECODING] =
"VP9E_SET_FRAME_PARALLEL_DECODING",
173 [VP9E_SET_AQ_MODE] =
"VP9E_SET_AQ_MODE",
174 [VP9E_SET_COLOR_SPACE] =
"VP9E_SET_COLOR_SPACE",
175 [VP9E_SET_SVC_LAYER_ID] =
"VP9E_SET_SVC_LAYER_ID",
176 #if VPX_ENCODER_ABI_VERSION >= 12
177 [VP9E_SET_SVC_PARAMETERS] =
"VP9E_SET_SVC_PARAMETERS",
178 [VP9E_SET_SVC_REF_FRAME_CONFIG] =
"VP9E_SET_SVC_REF_FRAME_CONFIG",
180 [VP9E_SET_SVC] =
"VP9E_SET_SVC",
181 #if VPX_ENCODER_ABI_VERSION >= 11
182 [VP9E_SET_COLOR_RANGE] =
"VP9E_SET_COLOR_RANGE",
184 #if VPX_ENCODER_ABI_VERSION >= 12
185 [VP9E_SET_TARGET_LEVEL] =
"VP9E_SET_TARGET_LEVEL",
186 [VP9E_GET_LEVEL] =
"VP9E_GET_LEVEL",
188 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
189 [VP9E_SET_ROW_MT] =
"VP9E_SET_ROW_MT",
191 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
192 [VP9E_SET_TUNE_CONTENT] =
"VP9E_SET_TUNE_CONTENT",
194 #ifdef VPX_CTRL_VP9E_SET_TPL
195 [VP9E_SET_TPL] =
"VP9E_SET_TPL",
197 #ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
198 [VP9E_SET_MIN_GF_INTERVAL] =
"VP9E_SET_MIN_GF_INTERVAL",
206 const char *
error = vpx_codec_error(&
ctx->encoder);
207 const char *detail = vpx_codec_error_detail(&
ctx->encoder);
215 const struct vpx_codec_enc_cfg *cfg,
223 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
224 #
if CONFIG_LIBVPX_VP9_ENCODER
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 #
if CONFIG_LIBVPX_VP9_ENCODER
234 width,
"g_bit_depth:", cfg->g_bit_depth,
235 width,
"g_input_bit_depth:", cfg->g_input_bit_depth,
237 width,
"g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
238 width,
"g_error_resilient:", cfg->g_error_resilient,
239 width,
"g_pass:", cfg->g_pass,
240 width,
"g_lag_in_frames:", cfg->g_lag_in_frames);
242 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
244 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
245 width,
"rc_resize_allowed:", cfg->rc_resize_allowed,
246 width,
"rc_resize_up_thresh:", cfg->rc_resize_up_thresh,
247 width,
"rc_resize_down_thresh:", cfg->rc_resize_down_thresh,
248 width,
"rc_end_usage:", cfg->rc_end_usage,
249 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
250 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
253 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
254 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
257 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
258 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
259 av_log(avctx,
level,
"temporal layering settings\n"
260 " %*s%u\n",
width,
"ts_number_layers:", cfg->ts_number_layers);
263 "\n %*s",
width,
"ts_target_bitrate:");
264 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
266 "%u ", cfg->ts_target_bitrate[
i]);
268 #if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
271 "\n %*s",
width,
"layer_target_bitrate:");
272 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
274 "%u ", cfg->layer_target_bitrate[
i]);
279 "\n %*s",
width,
"ts_rate_decimator:");
280 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
284 "\n %*s%u\n",
width,
"ts_periodicity:", cfg->ts_periodicity);
286 "\n %*s",
width,
"ts_layer_id:");
287 for (
i = 0;
i < VPX_TS_MAX_PERIODICITY;
i++)
291 " %*s%u\n %*s%u\n %*s%u\n",
292 width,
"rc_buf_sz:", cfg->rc_buf_sz,
293 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
294 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
295 av_log(avctx,
level,
"2 pass rate control settings\n"
296 " %*s%u\n %*s%u\n %*s%u\n",
297 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
298 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
299 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
300 #if VPX_ENCODER_ABI_VERSION >= 14
302 width,
"rc_2pass_vbr_corpus_complexity:", cfg->rc_2pass_vbr_corpus_complexity);
305 " %*s%d\n %*s%u\n %*s%u\n",
306 width,
"kf_mode:", cfg->kf_mode,
307 width,
"kf_min_dist:", cfg->kf_min_dist,
308 width,
"kf_max_dist:", cfg->kf_max_dist);
357 const struct vpx_codec_enc_cfg *enccfg =
ctx->encoder.config.enc;
364 #if CONFIG_LIBVPX_VP9_ENCODER
404 "Mismatching timestamps: libvpx %"PRId64
" queued %"PRId64
"; "
405 "this is a bug, please report it\n",
pkt->
pts, fd.
pts);
434 enum vp8e_enc_control_id
id,
int val)
444 res = vpx_codec_control(&
ctx->encoder,
id,
val);
445 if (res != VPX_CODEC_OK) {
446 snprintf(buf,
sizeof(buf),
"Failed to set %s codec control",
453 int res_alpha = vpx_codec_control(&
ctx->encoder_alpha,
id,
val);
454 if (res_alpha != VPX_CODEC_OK) {
455 snprintf(buf,
sizeof(buf),
"Failed to set %s alpha codec control",
465 #if VPX_ENCODER_ABI_VERSION >= 12
467 enum vp8e_enc_control_id
id,
int *
val)
477 res = vpx_codec_control(&
ctx->encoder,
id,
val);
478 if (res != VPX_CODEC_OK) {
479 snprintf(buf,
sizeof(buf),
"Failed to set %s codec control",
486 int res_alpha = vpx_codec_control(&
ctx->encoder_alpha,
id,
val);
487 if (res_alpha != VPX_CODEC_OK) {
488 snprintf(buf,
sizeof(buf),
"Failed to set %s alpha codec control",
503 #if VPX_ENCODER_ABI_VERSION >= 12
507 if (!codecctl_intp(avctx, VP9E_GET_LEVEL, &level_out))
514 vpx_codec_destroy(&
ctx->encoder);
516 vpx_codec_destroy(&
ctx->encoder_alpha);
532 char *saveptr =
NULL;
535 while (token && dest_idx < max_entries) {
536 dest[dest_idx++] = strtoul(token,
NULL, 10);
541 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
542 static void vp8_ts_parse_int64_array(
int64_t *dest,
char *
value,
size_t value_len,
int max_entries)
545 char *saveptr =
NULL;
548 while (token && dest_idx < max_entries) {
549 dest[dest_idx++] = strtoull(token,
NULL, 10);
556 int *layer_flags,
int *flag_periodicity)
558 switch (layering_mode) {
563 static const int ids[2] = { 0, 1 };
564 cfg->ts_periodicity = 2;
565 *flag_periodicity = 2;
566 cfg->ts_number_layers = 2;
567 cfg->ts_rate_decimator[0] = 2;
568 cfg->ts_rate_decimator[1] = 1;
569 memcpy(cfg->ts_layer_id, ids,
sizeof(ids));
572 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
573 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
575 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF |
576 VP8_EFLAG_NO_UPD_LAST |
577 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF;
587 static const int ids[4] = { 0, 2, 1, 2 };
588 cfg->ts_periodicity = 4;
589 *flag_periodicity = 4;
590 cfg->ts_number_layers = 3;
591 cfg->ts_rate_decimator[0] = 4;
592 cfg->ts_rate_decimator[1] = 2;
593 cfg->ts_rate_decimator[2] = 1;
594 memcpy(cfg->ts_layer_id, ids,
sizeof(ids));
601 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
602 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
604 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
605 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
606 VP8_EFLAG_NO_UPD_ARF;
608 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
609 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
611 VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_ARF |
612 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
613 VP8_EFLAG_NO_UPD_ARF;
622 static const int ids[4] = { 0, 2, 1, 2 };
623 cfg->ts_periodicity = 4;
624 *flag_periodicity = 4;
625 cfg->ts_number_layers = 3;
626 cfg->ts_rate_decimator[0] = 4;
627 cfg->ts_rate_decimator[1] = 2;
628 cfg->ts_rate_decimator[2] = 1;
629 memcpy(cfg->ts_layer_id, ids,
sizeof(ids));
635 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
636 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
638 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
639 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
641 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
642 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
644 VP8_EFLAG_NO_REF_LAST |
645 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
646 VP8_EFLAG_NO_UPD_ARF;
662 size_t value_len = strlen(
value);
663 int ts_layering_mode = 0;
668 if (!strcmp(
key,
"ts_number_layers"))
669 enccfg->ts_number_layers = strtoul(
value, &
value, 10);
670 else if (!strcmp(
key,
"ts_target_bitrate")) {
673 #if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
677 }
else if (!strcmp(
key,
"ts_rate_decimator")) {
679 }
else if (!strcmp(
key,
"ts_periodicity")) {
680 enccfg->ts_periodicity = strtoul(
value, &
value, 10);
681 }
else if (!strcmp(
key,
"ts_layer_id")) {
683 }
else if (!strcmp(
key,
"ts_layering_mode")) {
688 #if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
689 enccfg->temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS;
690 enccfg->ss_number_layers = 1;
692 if (ts_layering_mode) {
702 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
703 static int vpx_ref_frame_config_set_value(vpx_svc_ref_frame_config_t *ref_frame_config,
704 int ss_number_layers,
char *
key,
char *
value)
706 size_t value_len = strlen(
value);
711 if (!strcmp(
key,
"rfc_update_buffer_slot")) {
713 }
else if (!strcmp(
key,
"rfc_update_last")) {
715 }
else if (!strcmp(
key,
"rfc_update_golden")) {
717 }
else if (!strcmp(
key,
"rfc_update_alt_ref")) {
719 }
else if (!strcmp(
key,
"rfc_lst_fb_idx")) {
721 }
else if (!strcmp(
key,
"rfc_gld_fb_idx")) {
723 }
else if (!strcmp(
key,
"rfc_alt_fb_idx")) {
725 }
else if (!strcmp(
key,
"rfc_reference_last")) {
727 }
else if (!strcmp(
key,
"rfc_reference_golden")) {
729 }
else if (!strcmp(
key,
"rfc_reference_alt_ref")) {
731 }
else if (!strcmp(
key,
"rfc_reference_duration")) {
732 vp8_ts_parse_int64_array(ref_frame_config->duration,
value, value_len, ss_number_layers);
738 static int vpx_parse_ref_frame_config_element(vpx_svc_ref_frame_config_t *ref_frame_config,
739 int ss_number_layers,
const char **buf)
741 const char key_val_sep[] =
"=";
742 const char pairs_sep[] =
":";
747 if (
key && *
key && strspn(*buf, key_val_sep)) {
753 ret = vpx_ref_frame_config_set_value(ref_frame_config, ss_number_layers,
key,
val);
763 static int vpx_parse_ref_frame_config(vpx_svc_ref_frame_config_t *ref_frame_config,
764 int ss_number_layers,
const char *str)
770 vpx_parse_ref_frame_config_element(ref_frame_config, ss_number_layers, &str);
782 #if CONFIG_LIBVPX_VP9_ENCODER
784 struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *
flags,
785 vpx_img_fmt_t *img_fmt)
789 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
793 enccfg->g_profile = 0;
794 *img_fmt = VPX_IMG_FMT_I420;
797 enccfg->g_profile = 1;
798 *img_fmt = VPX_IMG_FMT_I422;
801 enccfg->g_profile = 1;
802 *img_fmt = VPX_IMG_FMT_I440;
805 ctx->vpx_cs = VPX_CS_SRGB;
807 enccfg->g_profile = 1;
808 *img_fmt = VPX_IMG_FMT_I444;
812 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
813 enccfg->g_profile = 2;
814 *img_fmt = VPX_IMG_FMT_I42016;
815 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
821 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
822 enccfg->g_profile = 3;
823 *img_fmt = VPX_IMG_FMT_I42216;
824 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
830 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
831 enccfg->g_profile = 3;
832 *img_fmt = VPX_IMG_FMT_I44016;
833 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
839 ctx->vpx_cs = VPX_CS_SRGB;
842 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
843 enccfg->g_profile = 3;
844 *img_fmt = VPX_IMG_FMT_I44416;
845 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
858 enum vpx_color_space vpx_cs;
862 vpx_cs =
ctx->vpx_cs;
882 #if VPX_ENCODER_ABI_VERSION >= 11
885 enum vpx_color_range vpx_cr;
905 struct vpx_codec_enc_cfg *enccfg)
909 avctx->
bit_rate = enccfg->rc_target_bitrate * 1000;
910 if (enccfg->rc_end_usage == VPX_CQ) {
912 "Bitrate not specified for constrained quality mode, using default of %dkbit/sec\n",
913 enccfg->rc_target_bitrate);
915 enccfg->rc_end_usage = VPX_CQ;
918 "Neither bitrate nor constrained quality specified, using default CRF of %d and bitrate of %dkbit/sec\n",
919 ctx->crf, enccfg->rc_target_bitrate);
924 #if CONFIG_LIBVPX_VP9_ENCODER
930 struct vpx_codec_enc_cfg *enccfg)
934 if (enccfg->rc_end_usage != VPX_Q &&
ctx->lossless < 0) {
935 enccfg->rc_end_usage = VPX_Q;
938 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
949 struct vpx_codec_enc_cfg *enccfg)
952 #if CONFIG_LIBVPX_VP9_ENCODER
954 set_vp9_defaults(avctx, enccfg);
962 const struct vpx_codec_iface *iface)
965 struct vpx_codec_enc_cfg enccfg = { 0 };
966 struct vpx_codec_enc_cfg enccfg_alpha;
970 vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
971 #if CONFIG_LIBVPX_VP9_ENCODER
972 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(iface);
973 vpx_svc_extra_cfg_t svc_params;
983 if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) {
985 vpx_codec_err_to_string(res));
993 #if CONFIG_LIBVPX_VP9_ENCODER
1008 enccfg.g_w = avctx->
width;
1009 enccfg.g_h = avctx->
height;
1014 enccfg.g_lag_in_frames=
ctx->lag_in_frames;
1017 enccfg.g_pass = VPX_RC_FIRST_PASS;
1019 enccfg.g_pass = VPX_RC_LAST_PASS;
1021 enccfg.g_pass = VPX_RC_ONE_PASS;
1025 enccfg.rc_end_usage = VPX_CBR;
1026 }
else if (
ctx->crf >= 0) {
1027 enccfg.rc_end_usage = VPX_CQ;
1028 #if CONFIG_LIBVPX_VP9_ENCODER
1030 enccfg.rc_end_usage = VPX_Q;
1037 #if CONFIG_LIBVPX_VP9_ENCODER
1038 enccfg.ss_target_bitrate[0] = enccfg.rc_target_bitrate;
1046 enccfg.rc_min_quantizer =
1047 enccfg.rc_max_quantizer = 0;
1049 if (avctx->
qmin >= 0)
1050 enccfg.rc_min_quantizer = avctx->
qmin;
1051 if (avctx->
qmax >= 0)
1052 enccfg.rc_max_quantizer = avctx->
qmax;
1055 if (enccfg.rc_end_usage == VPX_CQ
1056 #
if CONFIG_LIBVPX_VP9_ENCODER
1057 || enccfg.rc_end_usage == VPX_Q
1060 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
1062 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
1063 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
1068 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
1073 enccfg.rc_2pass_vbr_minsection_pct =
1076 enccfg.rc_2pass_vbr_maxsection_pct =
1078 #if CONFIG_LIBVPX_VP9_ENCODER
1080 #if VPX_ENCODER_ABI_VERSION >= 14
1081 if (
ctx->corpus_complexity >= 0)
1082 enccfg.rc_2pass_vbr_corpus_complexity =
ctx->corpus_complexity;
1091 enccfg.rc_buf_initial_sz =
1093 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
1094 if (
ctx->rc_undershoot_pct >= 0)
1095 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
1096 if (
ctx->rc_overshoot_pct >= 0)
1097 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
1103 enccfg.kf_max_dist = avctx->
gop_size;
1105 if (enccfg.g_pass == VPX_RC_FIRST_PASS)
1106 enccfg.g_lag_in_frames = 0;
1107 else if (enccfg.g_pass == VPX_RC_LAST_PASS) {
1108 int decode_size,
ret;
1115 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
1120 ctx->twopass_stats.sz);
1121 ctx->twopass_stats.sz = 0;
1125 ctx->twopass_stats.sz);
1126 if (decode_size < 0) {
1131 ctx->twopass_stats.sz = decode_size;
1132 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
1139 enccfg.g_profile = avctx->
profile;
1146 "Error parsing option '%s = %s'.\n",
1151 res = vpx_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
1152 if (res != VPX_CODEC_OK) {
1159 #if CONFIG_LIBVPX_VP9_ENCODER
1161 memset(&svc_params, 0,
sizeof(svc_params));
1162 for (
int i = 0;
i < enccfg.ts_number_layers; ++
i) {
1163 svc_params.max_quantizers[
i] = enccfg.rc_max_quantizer;
1164 svc_params.min_quantizers[
i] = enccfg.rc_min_quantizer;
1166 svc_params.scaling_factor_num[0] = enccfg.g_h;
1167 svc_params.scaling_factor_den[0] = enccfg.g_h;
1168 #if VPX_ENCODER_ABI_VERSION >= 12
1170 codecctl_intp(avctx, VP9E_SET_SVC_PARAMETERS, (
int *)&svc_params);
1174 if (
ctx->is_alpha) {
1175 enccfg_alpha = enccfg;
1176 res = vpx_codec_enc_init(&
ctx->encoder_alpha, iface, &enccfg_alpha,
flags);
1177 if (res != VPX_CODEC_OK) {
1187 ctx->auto_alt_ref = 1;
1188 if (
ctx->auto_alt_ref >= 0)
1191 if (
ctx->arnr_max_frames >= 0)
1193 if (
ctx->arnr_strength >= 0)
1195 if (
ctx->arnr_type >= 0)
1201 av_log(avctx,
AV_LOG_ERROR,
"Transparency encoding with auto_alt_ref does not work\n");
1205 if (
ctx->sharpness >= 0)
1209 codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY,
ctx->noise_sensitivity);
1215 if (
ctx->max_intra_rate >= 0)
1216 codecctl_int(avctx, VP8E_SET_MAX_INTRA_BITRATE_PCT,
ctx->max_intra_rate);
1218 #if CONFIG_LIBVPX_VP9_ENCODER
1220 if (
ctx->lossless >= 0)
1222 if (
ctx->tile_columns >= 0)
1224 if (
ctx->tile_rows >= 0)
1226 if (
ctx->frame_parallel >= 0)
1227 codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
1228 if (
ctx->aq_mode >= 0)
1230 set_colorspace(avctx);
1231 #if VPX_ENCODER_ABI_VERSION >= 11
1234 #if VPX_ENCODER_ABI_VERSION >= 12
1237 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
1238 if (
ctx->row_mt >= 0)
1241 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
1242 if (
ctx->tune_content >= 0)
1245 #ifdef VPX_CTRL_VP9E_SET_TPL
1246 if (
ctx->tpl_model >= 0)
1249 #ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
1250 if (
ctx->min_gf_interval >= 0)
1256 if (
ctx->screen_content_mode == 2 &&
ctx->is_alpha) {
1258 "Transparency encoding with screen mode with aggressive rate control not supported\n");
1261 codecctl_int(avctx, VP8E_SET_SCREEN_CONTENT_MODE,
ctx->screen_content_mode);
1267 vpx_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
1269 #if CONFIG_LIBVPX_VP9_ENCODER
1271 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
1278 if (enccfg.rc_end_usage == VPX_CBR ||
1279 enccfg.g_pass != VPX_RC_ONE_PASS) {
1290 const struct vpx_codec_cx_pkt *
src,
1293 dst->
pts =
src->data.frame.pts;
1294 dst->
flags =
src->data.frame.flags;
1295 dst->
sz =
src->data.frame.sz;
1296 dst->
buf =
src->data.frame.buf;
1299 if (!(dst->
flags & VPX_FRAME_IS_INVISIBLE)) {
1301 if (
ctx->have_sse) {
1306 memcpy(dst->
sse,
ctx->sse,
sizeof(dst->
sse));
1334 if (!!(cx_frame->
flags & VPX_FRAME_IS_KEY)) {
1341 ret = vpx_codec_control(&
ctx->encoder, VP8E_GET_LAST_QUANTIZER_64, &
quality);
1342 if (
ret != VPX_CODEC_OK)
1345 cx_frame->
have_sse ? 3 : 0, pict_type);
1349 for (
int i = 0;
i < 3; ++
i)
1353 if (alpha_cx_frame) {
1356 alpha_cx_frame->
sz + 8);
1362 memcpy(side_data + 8, alpha_cx_frame->
buf, alpha_cx_frame->
sz);
1383 const struct vpx_codec_cx_pkt *
pkt;
1384 const void *iter =
NULL;
1387 if (!
ctx->is_alpha && *frame_list) {
1393 *frame_list = cx_frame->
next;
1399 while (
pkt = vpx_codec_get_cx_data(encoder, &iter)) {
1400 switch (
pkt->kind) {
1401 case VPX_CODEC_CX_FRAME_PKT:
1402 if (!
ctx->is_alpha && !
size) {
1417 "Frame queue element alloc failed\n");
1423 if (!cx_frame->
buf) {
1434 case VPX_CODEC_STATS_PKT: {
1435 struct vpx_fixed_buf *
stats = &
ctx->twopass_stats;
1440 &
ctx->twopass_stats_size,
1455 case VPX_CODEC_PSNR_PKT:
1465 case VPX_CODEC_CUSTOM_PKT:
1475 vpx_roi_map_t *roi_map,
int block_size,
int segment_cnt)
1480 #define MAX_DELTA_Q 63
1495 memset(roi_map, 0,
sizeof(*roi_map));
1506 if (!self_size || sd->
size % self_size) {
1510 nb_rois = sd->
size / self_size;
1516 for (
int i = 0;
i < nb_rois;
i++) {
1530 if (!segment_mapping[mapping_index]) {
1531 if (segment_id == segment_cnt) {
1533 "ROI only supports %d segments (and segment 0 is reserved for non-ROIs), skipping the left ones.\n",
1538 segment_mapping[mapping_index] = segment_id + 1;
1539 roi_map->delta_q[segment_id] =
delta_q;
1544 roi_map->rows = (frame_height + block_size - 1) / block_size;
1545 roi_map->cols = (frame_width + block_size - 1) / block_size;
1546 roi_map->roi_map =
av_calloc(roi_map->rows * roi_map->cols,
sizeof(*roi_map->roi_map));
1547 if (!roi_map->roi_map) {
1555 for (
int i = nb_rois - 1;
i >= 0;
i--) {
1558 int starty, endy, startx, endx;
1562 starty =
av_clip(roi->
top / block_size, 0, roi_map->rows);
1563 endy =
av_clip((roi->
bottom + block_size - 1) / block_size, 0, roi_map->rows);
1564 startx =
av_clip(roi->
left / block_size, 0, roi_map->cols);
1565 endx =
av_clip((roi->
right + block_size - 1) / block_size, 0, roi_map->cols);
1571 if (mapping_value) {
1572 for (
int y = starty; y < endy; y++)
1573 for (
int x = startx; x < endx; x++)
1574 roi_map->roi_map[x + y * roi_map->cols] = mapping_value - 1;
1585 #ifdef VPX_CTRL_VP9E_SET_ROI_MAP
1586 int version = vpx_codec_version();
1587 int major = VPX_VERSION_MAJOR(
version);
1588 int minor = VPX_VERSION_MINOR(
version);
1589 int patch = VPX_VERSION_PATCH(
version);
1591 if (major > 1 || (major == 1 && minor > 8) || (major == 1 && minor == 8 && patch >= 1)) {
1592 vpx_roi_map_t roi_map;
1593 const int segment_cnt = 8;
1594 const int block_size = 8;
1597 if (
ctx->aq_mode > 0 ||
ctx->cpu_used < 5 ||
ctx->deadline != VPX_DL_REALTIME) {
1598 if (!
ctx->roi_warned) {
1599 ctx->roi_warned = 1;
1601 "and deadline is REALTIME, so skipping ROI.\n");
1606 ret =
set_roi_map(avctx, sd, frame_width, frame_height, &roi_map, block_size, segment_cnt);
1612 memset(roi_map.ref_frame, -1,
sizeof(roi_map.ref_frame));
1614 if (vpx_codec_control(&
ctx->encoder, VP9E_SET_ROI_MAP, &roi_map)) {
1623 if (!
ctx->roi_warned) {
1624 ctx->roi_warned = 1;
1625 av_log(avctx,
AV_LOG_WARNING,
"ROI is not supported, please upgrade libvpx to version >= 1.8.1. "
1626 "You may need to rebuild ffmpeg.\n");
1633 vpx_roi_map_t roi_map;
1634 const int segment_cnt = 4;
1635 const int block_size = 16;
1638 int ret =
set_roi_map(avctx, sd, frame_width, frame_height, &roi_map, block_size, segment_cnt);
1644 if (vpx_codec_control(&
ctx->encoder, VP8E_SET_ROI_MAP, &roi_map)) {
1656 struct vpx_image *rawimg_alpha = &
ctx->rawimg_alpha;
1657 unsigned char **
planes = rawimg_alpha->planes;
1658 int *
stride = rawimg_alpha->stride;
1660 if (!
planes[VPX_PLANE_U] ||
1662 width != (
int)rawimg_alpha->d_w ||
1663 height != (
int)rawimg_alpha->d_h) {
1667 vpx_img_wrap(rawimg_alpha, VPX_IMG_FMT_I420,
width,
height, 1,
1685 struct vpx_image *rawimg =
NULL;
1686 struct vpx_image *rawimg_alpha =
NULL;
1688 int res, coded_size;
1689 vpx_enc_frame_flags_t
flags = 0;
1690 const struct vpx_codec_enc_cfg *enccfg =
ctx->encoder.config.enc;
1691 vpx_svc_layer_id_t layer_id;
1692 int layer_id_valid = 0;
1695 if (avctx->
qmax >= 0 && enccfg->rc_max_quantizer != avctx->
qmax) {
1696 struct vpx_codec_enc_cfg cfg = *enccfg;
1697 cfg.rc_max_quantizer = avctx->
qmax;
1698 res = vpx_codec_enc_config_set(&
ctx->encoder, &cfg);
1699 if (res != VPX_CODEC_OK) {
1707 rawimg = &
ctx->rawimg;
1708 rawimg->planes[VPX_PLANE_Y] =
frame->
data[0];
1709 rawimg->planes[VPX_PLANE_U] =
frame->
data[1];
1710 rawimg->planes[VPX_PLANE_V] =
frame->
data[2];
1714 if (
ctx->is_alpha) {
1715 rawimg_alpha = &
ctx->rawimg_alpha;
1719 rawimg_alpha->planes[VPX_PLANE_Y] =
frame->
data[3];
1723 #if VPX_IMAGE_ABI_VERSION >= 4
1726 rawimg->range = VPX_CR_STUDIO_RANGE;
1729 rawimg->range = VPX_CR_FULL_RANGE;
1734 flags |= VPX_EFLAG_FORCE_KF;
1741 memset(&layer_id, 0,
sizeof(layer_id));
1745 layer_id.temporal_layer_id = strtoul(en->
value,
NULL, 10);
1746 #ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT
1747 layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id;
1751 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
1756 int ret = vpx_parse_ref_frame_config(&
ctx->ref_frame_config,
1757 enccfg->ss_number_layers, en->
value);
1760 "Error parsing ref_frame_config option %s.\n", en->
value);
1764 codecctl_intp(avctx, VP9E_SET_SVC_REF_FRAME_CONFIG, (
int *)&
ctx->ref_frame_config);
1767 "Ignoring ref-frame-config for a non-VP9 codec\n");
1790 if (enccfg->ts_number_layers > 1 &&
ctx->ts_layer_flags) {
1791 if (
flags & VPX_EFLAG_FORCE_KF) {
1793 ctx->current_temporal_idx = 0;
1794 flags = VPX_EFLAG_FORCE_KF;
1800 flags |=
ctx->ts_layer_flags[
ctx->current_temporal_idx];
1802 memset(&layer_id, 0,
sizeof(layer_id));
1803 #if VPX_ENCODER_ABI_VERSION >= 12
1804 layer_id.spatial_layer_id = 0;
1806 layer_id.temporal_layer_id = enccfg->ts_layer_id[
ctx->current_temporal_idx];
1807 #ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT
1808 layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id;
1813 if (layer_id_valid) {
1815 codecctl_int(avctx, VP8E_SET_TEMPORAL_LAYER_ID, layer_id.temporal_layer_id);
1817 #if CONFIG_LIBVPX_VP9_ENCODER && VPX_ENCODER_ABI_VERSION >= 12
1819 codecctl_intp(avctx, VP9E_SET_SVC_LAYER_ID, (
int *)&layer_id);
1834 #if FF_API_TICKS_PER_FRAME
1841 res = vpx_codec_encode(&
ctx->encoder, rawimg, timestamp,
1843 if (res != VPX_CODEC_OK) {
1848 if (
ctx->is_alpha) {
1849 res = vpx_codec_encode(&
ctx->encoder_alpha, rawimg_alpha, timestamp,
1851 if (res != VPX_CODEC_OK) {
1858 if (
ctx->is_alpha) {
1861 if (
ctx->coded_frame_list &&
ctx->alpha_coded_frame_list) {
1866 coded_size =
storeframe(avctx, cx_frame, alpha_cx_frame,
pkt);
1869 ctx->coded_frame_list = cx_frame->
next;
1870 ctx->alpha_coded_frame_list = alpha_cx_frame->
next;
1886 ctx->twopass_stats.sz);
1887 }
else if (enccfg->ts_number_layers > 1 &&
ctx->ts_layer_flags) {
1888 ctx->current_temporal_idx = (
ctx->current_temporal_idx + 1) % enccfg->ts_periodicity;
1891 *got_packet = !!coded_size;
1895 #define OFFSET(x) offsetof(VPxContext, x)
1896 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1898 #define COMMON_OPTIONS \
1899 { "lag-in-frames", "Number of frames to look ahead for " \
1900 "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1901 { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1902 { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1903 { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "arnr_type"}, \
1904 { "backward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, .unit = "arnr_type" }, \
1905 { "forward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, .unit = "arnr_type" }, \
1906 { "centered", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, .unit = "arnr_type" }, \
1907 { "tune", "Tune the encoding to a specific scenario", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "tune"}, \
1908 { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_PSNR}, 0, 0, VE, .unit = "tune"}, \
1909 { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_SSIM}, 0, 0, VE, .unit = "tune"}, \
1910 { "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, .unit = "quality"}, \
1911 { "best", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_BEST_QUALITY}, 0, 0, VE, .unit = "quality"}, \
1912 { "good", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_GOOD_QUALITY}, 0, 0, VE, .unit = "quality"}, \
1913 { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_REALTIME}, 0, 0, VE, .unit = "quality"}, \
1914 { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, .unit = "er"}, \
1915 { "max-intra-rate", "Maximum I-frame bitrate (pct) 0=unlimited", OFFSET(max_intra_rate), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1916 { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, .unit = "er"}, \
1917 { "partitions", "The frame partitions are independently decodable " \
1918 "by the bool decoder, meaning that partitions can be decoded even " \
1919 "though earlier partitions have been lost. Note that intra prediction" \
1920 " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, .unit = "er"}, \
1921 { "crf", "Select the quality for constant quality mode", offsetof(VPxContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \
1922 { "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 }, \
1923 { "drop-threshold", "Frame drop threshold", offsetof(VPxContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE }, \
1924 { "noise-sensitivity", "Noise sensitivity", OFFSET(noise_sensitivity), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 4, VE}, \
1925 { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, VE }, \
1926 { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1000, VE }, \
1927 { "ts-parameters", "Temporal scaling configuration using a :-separated list of key=value parameters", OFFSET(vpx_ts_parameters), AV_OPT_TYPE_DICT, {.str=NULL}, 0, 0, VE}, \
1929 #define LEGACY_OPTIONS \
1930 {"speed", "", offsetof(VPxContext, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
1931 {"quality", "", offsetof(VPxContext, deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, .unit = "quality"}, \
1932 {"vp8flags", "", offsetof(VPxContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, UINT_MAX, VE, .unit = "flags"}, \
1933 {"error_resilient", "enable error resilience", 0, AV_OPT_TYPE_CONST, {.i64 = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, .unit = "flags"}, \
1934 {"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, AV_OPT_TYPE_CONST, {.i64 = VP8F_AUTO_ALT_REF}, INT_MIN, INT_MAX, VE, .unit = "flags"}, \
1935 {"arnr_max_frames", "altref noise reduction max frame count", offsetof(VPxContext, arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 15, VE}, \
1936 {"arnr_strength", "altref noise reduction filter strength", offsetof(VPxContext, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
1937 {"arnr_type", "altref noise reduction filter type", offsetof(VPxContext, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
1938 {"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VPxContext, lag_in_frames), AV_OPT_TYPE_INT, {.i64 = 25}, 0, 25, VE}, \
1939 {"sharpness", "Increase sharpness at the expense of lower PSNR", offsetof(VPxContext, sharpness), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, VE},
1941 #if CONFIG_LIBVPX_VP8_ENCODER
1942 static const AVOption vp8_options[] = {
1944 {
"auto-alt-ref",
"Enable use of alternate reference "
1947 {
"screen-content-mode",
"Encoder screen content mode",
OFFSET(screen_content_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2,
VE},
1953 #if CONFIG_LIBVPX_VP9_ENCODER
1954 static const AVOption vp9_options[] = {
1956 {
"auto-alt-ref",
"Enable use of alternate reference "
1960 {
"tile-columns",
"Number of tile columns to use, log2",
OFFSET(tile_columns),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1962 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL,{.i64 = -1}, -1, 1,
VE},
1963 #if VPX_ENCODER_ABI_VERSION >= 12
1964 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE, .unit =
"aq_mode"},
1966 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3,
VE, .unit =
"aq_mode"},
1969 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"aq_mode" },
1970 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"aq_mode" },
1971 {
"cyclic",
"Cyclic Refresh Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0,
VE, .unit =
"aq_mode" },
1972 #if VPX_ENCODER_ABI_VERSION >= 12
1973 {
"equator360",
"360 video Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0,
VE, .unit =
"aq_mode" },
1976 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
1979 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
1980 #if VPX_ENCODER_ABI_VERSION >= 14
1981 {
"tune-content",
"Tune content type",
OFFSET(tune_content),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2,
VE, .unit =
"tune_content" },
1983 {
"tune-content",
"Tune content type",
OFFSET(tune_content),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1,
VE, .unit =
"tune_content" },
1985 {
"default",
"Regular video content", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0,
VE, .unit =
"tune_content" },
1986 {
"screen",
"Screen capture content", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"tune_content" },
1987 #if VPX_ENCODER_ABI_VERSION >= 14
1988 {
"film",
"Film content; improves grain retention", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"tune_content" },
1991 #if VPX_ENCODER_ABI_VERSION >= 14
1992 {
"corpus-complexity",
"corpus vbr complexity midpoint",
OFFSET(corpus_complexity),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 10000,
VE },
1994 #ifdef VPX_CTRL_VP9E_SET_TPL
1997 #ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
1998 {
"min-gf-interval",
"Minimum golden/alternate reference frame interval",
OFFSET(min_gf_interval),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE },
2005 #undef COMMON_OPTIONS
2006 #undef LEGACY_OPTIONS
2013 {
"keyint_min",
"-1" },
2017 #if CONFIG_LIBVPX_VP8_ENCODER
2020 return vpx_init(avctx, vpx_codec_vp8_cx());
2023 static const AVClass class_vp8 = {
2026 .option = vp8_options,
2038 .priv_data_size =
sizeof(VPxContext),
2046 .p.priv_class = &class_vp8,
2048 .p.wrapper_name =
"libvpx",
2052 #if CONFIG_LIBVPX_VP9_ENCODER
2055 return vpx_init(avctx, vpx_codec_vp9_cx());
2090 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
2091 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH)
2092 codec->
p.
pix_fmts = vp9_pix_fmts_highbd;
2094 codec->
p.
pix_fmts = vp9_pix_fmts_highcol;
2097 static const AVClass class_vp9 = {
2100 .option = vp9_options,
2105 .
p.
name =
"libvpx-vp9",
2113 .p.priv_class = &class_vp9,
2114 .p.wrapper_name =
"libvpx",
2115 .priv_data_size =
sizeof(VPxContext),
2123 .init_static_data = vp9_init_static,