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>
51 #define IS_VP9(avctx) (CONFIG_LIBVPX_VP9_ENCODER && avctx->codec_id == AV_CODEC_ID_VP9)
52 #define IS_VP8(avctx) (CONFIG_LIBVPX_VP8_ENCODER && avctx->codec_id == AV_CODEC_ID_VP8)
100 #define VP8F_ERROR_RESILIENT 0x00000001
101 #define VP8F_AUTO_ALT_REF 0x00000002
149 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
150 vpx_svc_ref_frame_config_t ref_frame_config;
156 [VP8E_SET_CPUUSED] =
"VP8E_SET_CPUUSED",
157 [VP8E_SET_ENABLEAUTOALTREF] =
"VP8E_SET_ENABLEAUTOALTREF",
158 [VP8E_SET_NOISE_SENSITIVITY] =
"VP8E_SET_NOISE_SENSITIVITY",
159 [VP8E_SET_STATIC_THRESHOLD] =
"VP8E_SET_STATIC_THRESHOLD",
160 [VP8E_SET_TOKEN_PARTITIONS] =
"VP8E_SET_TOKEN_PARTITIONS",
161 [VP8E_SET_ARNR_MAXFRAMES] =
"VP8E_SET_ARNR_MAXFRAMES",
162 [VP8E_SET_ARNR_STRENGTH] =
"VP8E_SET_ARNR_STRENGTH",
163 [VP8E_SET_ARNR_TYPE] =
"VP8E_SET_ARNR_TYPE",
164 [VP8E_SET_TUNING] =
"VP8E_SET_TUNING",
165 [VP8E_SET_CQ_LEVEL] =
"VP8E_SET_CQ_LEVEL",
166 [VP8E_SET_MAX_INTRA_BITRATE_PCT] =
"VP8E_SET_MAX_INTRA_BITRATE_PCT",
167 [VP8E_SET_SHARPNESS] =
"VP8E_SET_SHARPNESS",
168 [VP8E_SET_TEMPORAL_LAYER_ID] =
"VP8E_SET_TEMPORAL_LAYER_ID",
169 [VP8E_SET_SCREEN_CONTENT_MODE] =
"VP8E_SET_SCREEN_CONTENT_MODE",
170 #if CONFIG_LIBVPX_VP9_ENCODER
171 [VP9E_SET_LOSSLESS] =
"VP9E_SET_LOSSLESS",
172 [VP9E_SET_TILE_COLUMNS] =
"VP9E_SET_TILE_COLUMNS",
173 [VP9E_SET_TILE_ROWS] =
"VP9E_SET_TILE_ROWS",
174 [VP9E_SET_FRAME_PARALLEL_DECODING] =
"VP9E_SET_FRAME_PARALLEL_DECODING",
175 [VP9E_SET_AQ_MODE] =
"VP9E_SET_AQ_MODE",
176 [VP9E_SET_COLOR_SPACE] =
"VP9E_SET_COLOR_SPACE",
177 [VP9E_SET_SVC_LAYER_ID] =
"VP9E_SET_SVC_LAYER_ID",
178 #if VPX_ENCODER_ABI_VERSION >= 12
179 [VP9E_SET_SVC_PARAMETERS] =
"VP9E_SET_SVC_PARAMETERS",
180 [VP9E_SET_SVC_REF_FRAME_CONFIG] =
"VP9E_SET_SVC_REF_FRAME_CONFIG",
182 [VP9E_SET_SVC] =
"VP9E_SET_SVC",
183 #if VPX_ENCODER_ABI_VERSION >= 11
184 [VP9E_SET_COLOR_RANGE] =
"VP9E_SET_COLOR_RANGE",
186 #if VPX_ENCODER_ABI_VERSION >= 12
187 [VP9E_SET_TARGET_LEVEL] =
"VP9E_SET_TARGET_LEVEL",
188 [VP9E_GET_LEVEL] =
"VP9E_GET_LEVEL",
190 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
191 [VP9E_SET_ROW_MT] =
"VP9E_SET_ROW_MT",
193 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
194 [VP9E_SET_TUNE_CONTENT] =
"VP9E_SET_TUNE_CONTENT",
196 #ifdef VPX_CTRL_VP9E_SET_TPL
197 [VP9E_SET_TPL] =
"VP9E_SET_TPL",
199 #ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
200 [VP9E_SET_MIN_GF_INTERVAL] =
"VP9E_SET_MIN_GF_INTERVAL",
207 const char *
error = vpx_codec_error(encoder);
208 const char *detail = vpx_codec_error_detail(encoder);
216 const struct vpx_codec_enc_cfg *cfg,
224 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
225 #
if CONFIG_LIBVPX_VP9_ENCODER
228 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
229 width,
"g_usage:", cfg->g_usage,
230 width,
"g_threads:", cfg->g_threads,
231 width,
"g_profile:", cfg->g_profile,
232 width,
"g_w:", cfg->g_w,
233 width,
"g_h:", cfg->g_h,
234 #
if CONFIG_LIBVPX_VP9_ENCODER
235 width,
"g_bit_depth:", cfg->g_bit_depth,
236 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);
243 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
244 " %*s%d\n %*s%p(%zu)\n %*s%u\n",
245 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
246 width,
"rc_resize_allowed:", cfg->rc_resize_allowed,
247 width,
"rc_resize_up_thresh:", cfg->rc_resize_up_thresh,
248 width,
"rc_resize_down_thresh:", cfg->rc_resize_down_thresh,
249 width,
"rc_end_usage:", cfg->rc_end_usage,
250 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
251 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
254 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
255 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
258 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
259 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
260 av_log(avctx,
level,
"temporal layering settings\n"
261 " %*s%u\n",
width,
"ts_number_layers:", cfg->ts_number_layers);
264 "\n %*s",
width,
"ts_target_bitrate:");
265 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
267 "%u ", cfg->ts_target_bitrate[
i]);
269 #if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
272 "\n %*s",
width,
"layer_target_bitrate:");
273 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
275 "%u ", cfg->layer_target_bitrate[
i]);
280 "\n %*s",
width,
"ts_rate_decimator:");
281 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
285 "\n %*s%u\n",
width,
"ts_periodicity:", cfg->ts_periodicity);
287 "\n %*s",
width,
"ts_layer_id:");
288 for (
i = 0;
i < VPX_TS_MAX_PERIODICITY;
i++)
292 " %*s%u\n %*s%u\n %*s%u\n",
293 width,
"rc_buf_sz:", cfg->rc_buf_sz,
294 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
295 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
296 av_log(avctx,
level,
"2 pass rate control settings\n"
297 " %*s%u\n %*s%u\n %*s%u\n",
298 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
299 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
300 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
301 #if VPX_ENCODER_ABI_VERSION >= 14
303 width,
"rc_2pass_vbr_corpus_complexity:", cfg->rc_2pass_vbr_corpus_complexity);
306 " %*s%d\n %*s%u\n %*s%u\n",
307 width,
"kf_mode:", cfg->kf_mode,
308 width,
"kf_min_dist:", cfg->kf_min_dist,
309 width,
"kf_max_dist:", cfg->kf_max_dist);
358 return (
ctx->drop_threshold > 0) || (
ctx->screen_content_mode == 2);
365 const struct vpx_codec_enc_cfg *enccfg =
ctx->encoder.config.enc;
429 "Mismatching timestamps: libvpx %"PRId64
" queued %"PRId64
"; "
430 "this is a bug, please report it\n",
pkt->
pts, fd.
pts);
465 enum vp8e_enc_control_id
id,
int val)
475 res = vpx_codec_control(&
ctx->encoder,
id,
val);
476 if (res != VPX_CODEC_OK) {
477 snprintf(buf,
sizeof(buf),
"Failed to set %s codec control",
483 if (
ctx->is_alpha &&
id != VP9E_SET_COLOR_SPACE) {
484 int res_alpha = vpx_codec_control(&
ctx->encoder_alpha,
id,
val);
485 if (res_alpha != VPX_CODEC_OK) {
486 snprintf(buf,
sizeof(buf),
"Failed to set %s alpha codec control",
496 #if VPX_ENCODER_ABI_VERSION >= 12
498 enum vp8e_enc_control_id
id,
int *
val)
508 res = vpx_codec_control(&
ctx->encoder,
id,
val);
509 if (res != VPX_CODEC_OK) {
510 snprintf(buf,
sizeof(buf),
"Failed to set %s codec control",
517 int res_alpha = vpx_codec_control(&
ctx->encoder_alpha,
id,
val);
518 if (res_alpha != VPX_CODEC_OK) {
519 snprintf(buf,
sizeof(buf),
"Failed to set %s alpha codec control",
534 #if VPX_ENCODER_ABI_VERSION >= 12
538 if (!codecctl_intp(avctx, VP9E_GET_LEVEL, &level_out))
545 vpx_codec_destroy(&
ctx->encoder);
547 vpx_codec_destroy(&
ctx->encoder_alpha);
563 char *saveptr =
NULL;
566 while (token && dest_idx < max_entries) {
567 dest[dest_idx++] = strtoul(token,
NULL, 10);
572 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
573 static void vp8_ts_parse_int64_array(
int64_t *dest,
char *
value,
size_t value_len,
int max_entries)
576 char *saveptr =
NULL;
579 while (token && dest_idx < max_entries) {
580 dest[dest_idx++] = strtoull(token,
NULL, 10);
587 int *layer_flags,
int *flag_periodicity)
589 switch (layering_mode) {
594 static const int ids[2] = { 0, 1 };
595 cfg->ts_periodicity = 2;
596 *flag_periodicity = 2;
597 cfg->ts_number_layers = 2;
598 cfg->ts_rate_decimator[0] = 2;
599 cfg->ts_rate_decimator[1] = 1;
600 memcpy(cfg->ts_layer_id, ids,
sizeof(ids));
603 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
604 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
606 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF |
607 VP8_EFLAG_NO_UPD_LAST |
608 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF;
618 static const int ids[4] = { 0, 2, 1, 2 };
619 cfg->ts_periodicity = 4;
620 *flag_periodicity = 4;
621 cfg->ts_number_layers = 3;
622 cfg->ts_rate_decimator[0] = 4;
623 cfg->ts_rate_decimator[1] = 2;
624 cfg->ts_rate_decimator[2] = 1;
625 memcpy(cfg->ts_layer_id, ids,
sizeof(ids));
632 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
633 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
635 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
636 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
637 VP8_EFLAG_NO_UPD_ARF;
639 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
640 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
642 VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_ARF |
643 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
644 VP8_EFLAG_NO_UPD_ARF;
653 static const int ids[4] = { 0, 2, 1, 2 };
654 cfg->ts_periodicity = 4;
655 *flag_periodicity = 4;
656 cfg->ts_number_layers = 3;
657 cfg->ts_rate_decimator[0] = 4;
658 cfg->ts_rate_decimator[1] = 2;
659 cfg->ts_rate_decimator[2] = 1;
660 memcpy(cfg->ts_layer_id, ids,
sizeof(ids));
666 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
667 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
669 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
670 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
672 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
673 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
675 VP8_EFLAG_NO_REF_LAST |
676 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
677 VP8_EFLAG_NO_UPD_ARF;
693 size_t value_len = strlen(
value);
694 int ts_layering_mode = 0;
699 if (!strcmp(
key,
"ts_number_layers"))
700 enccfg->ts_number_layers = strtoul(
value, &
value, 10);
701 else if (!strcmp(
key,
"ts_target_bitrate")) {
704 #if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
708 }
else if (!strcmp(
key,
"ts_rate_decimator")) {
710 }
else if (!strcmp(
key,
"ts_periodicity")) {
711 enccfg->ts_periodicity = strtoul(
value, &
value, 10);
712 }
else if (!strcmp(
key,
"ts_layer_id")) {
714 }
else if (!strcmp(
key,
"ts_layering_mode")) {
716 ts_layering_mode = strtoul(
value, &
value, 10);
719 #if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
720 enccfg->temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS;
721 enccfg->ss_number_layers = 1;
723 if (ts_layering_mode) {
733 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
734 static int vpx_ref_frame_config_set_value(vpx_svc_ref_frame_config_t *ref_frame_config,
735 int ss_number_layers,
char *
key,
char *
value)
737 size_t value_len = strlen(
value);
742 if (!strcmp(
key,
"rfc_update_buffer_slot")) {
744 }
else if (!strcmp(
key,
"rfc_update_last")) {
746 }
else if (!strcmp(
key,
"rfc_update_golden")) {
748 }
else if (!strcmp(
key,
"rfc_update_alt_ref")) {
750 }
else if (!strcmp(
key,
"rfc_lst_fb_idx")) {
752 }
else if (!strcmp(
key,
"rfc_gld_fb_idx")) {
754 }
else if (!strcmp(
key,
"rfc_alt_fb_idx")) {
756 }
else if (!strcmp(
key,
"rfc_reference_last")) {
758 }
else if (!strcmp(
key,
"rfc_reference_golden")) {
760 }
else if (!strcmp(
key,
"rfc_reference_alt_ref")) {
762 }
else if (!strcmp(
key,
"rfc_reference_duration")) {
763 vp8_ts_parse_int64_array(ref_frame_config->duration,
value, value_len, ss_number_layers);
769 static int vpx_parse_ref_frame_config_element(vpx_svc_ref_frame_config_t *ref_frame_config,
770 int ss_number_layers,
const char **buf)
772 const char key_val_sep[] =
"=";
773 const char pairs_sep[] =
":";
778 if (
key && *
key && strspn(*buf, key_val_sep)) {
784 ret = vpx_ref_frame_config_set_value(ref_frame_config, ss_number_layers,
key,
val);
794 static int vpx_parse_ref_frame_config(vpx_svc_ref_frame_config_t *ref_frame_config,
795 int ss_number_layers,
const char *str)
801 vpx_parse_ref_frame_config_element(ref_frame_config, ss_number_layers, &str);
813 #if CONFIG_LIBVPX_VP9_ENCODER
815 struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *
flags,
816 vpx_img_fmt_t *img_fmt)
820 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
824 enccfg->g_profile = 0;
825 *img_fmt = VPX_IMG_FMT_I420;
829 enccfg->g_profile = 1;
830 *img_fmt = VPX_IMG_FMT_I422;
833 enccfg->g_profile = 1;
834 *img_fmt = VPX_IMG_FMT_I440;
838 ctx->vpx_cs = VPX_CS_SRGB;
843 ctx->vpx_cs = VPX_CS_SRGB;
844 enccfg->g_profile = 1;
845 *img_fmt = VPX_IMG_FMT_I444;
850 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
851 enccfg->g_profile = 2;
852 *img_fmt = VPX_IMG_FMT_I42016;
853 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
860 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
861 enccfg->g_profile = 3;
862 *img_fmt = VPX_IMG_FMT_I42216;
863 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
869 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
870 enccfg->g_profile = 3;
871 *img_fmt = VPX_IMG_FMT_I44016;
872 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
880 ctx->vpx_cs = VPX_CS_SRGB;
887 ctx->vpx_cs = VPX_CS_SRGB;
888 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
889 enccfg->g_profile = 3;
890 *img_fmt = VPX_IMG_FMT_I44416;
891 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
904 enum vpx_color_space vpx_cs;
908 vpx_cs =
ctx->vpx_cs;
913 "RGB colorspace is not compatible with pixel format %s.\n",
933 #if VPX_ENCODER_ABI_VERSION >= 11
936 enum vpx_color_range vpx_cr;
956 struct vpx_codec_enc_cfg *enccfg)
960 avctx->
bit_rate = enccfg->rc_target_bitrate * 1000;
961 if (enccfg->rc_end_usage == VPX_CQ) {
963 "Bitrate not specified for constrained quality mode, using default of %dkbit/sec\n",
964 enccfg->rc_target_bitrate);
966 enccfg->rc_end_usage = VPX_CQ;
969 "Neither bitrate nor constrained quality specified, using default CRF of %d and bitrate of %dkbit/sec\n",
970 ctx->crf, enccfg->rc_target_bitrate);
975 #if CONFIG_LIBVPX_VP9_ENCODER
981 struct vpx_codec_enc_cfg *enccfg)
985 if (enccfg->rc_end_usage != VPX_Q &&
ctx->lossless < 0) {
986 enccfg->rc_end_usage = VPX_Q;
989 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
1000 struct vpx_codec_enc_cfg *enccfg)
1003 #if CONFIG_LIBVPX_VP9_ENCODER
1005 set_vp9_defaults(avctx, enccfg);
1013 const struct vpx_codec_iface *iface)
1016 struct vpx_codec_enc_cfg enccfg = { 0 };
1017 struct vpx_codec_enc_cfg enccfg_alpha;
1021 vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
1022 #if CONFIG_LIBVPX_VP9_ENCODER
1023 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(iface);
1024 vpx_svc_extra_cfg_t svc_params;
1036 "Pixel format '%s' is not widely supported. "
1037 "Use -strict experimental to use it anyway, or use 'yuva420p' pixel format instead.\n",
1043 if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) {
1045 vpx_codec_err_to_string(res));
1053 #if CONFIG_LIBVPX_VP9_ENCODER
1068 enccfg.g_w = avctx->
width;
1069 enccfg.g_h = avctx->
height;
1074 enccfg.g_lag_in_frames=
ctx->lag_in_frames;
1077 enccfg.g_pass = VPX_RC_FIRST_PASS;
1079 enccfg.g_pass = VPX_RC_LAST_PASS;
1081 enccfg.g_pass = VPX_RC_ONE_PASS;
1085 enccfg.rc_end_usage = VPX_CBR;
1086 }
else if (
ctx->crf >= 0) {
1087 enccfg.rc_end_usage = VPX_CQ;
1088 #if CONFIG_LIBVPX_VP9_ENCODER
1090 enccfg.rc_end_usage = VPX_Q;
1097 #if CONFIG_LIBVPX_VP9_ENCODER
1098 enccfg.ss_target_bitrate[0] = enccfg.rc_target_bitrate;
1106 enccfg.rc_min_quantizer =
1107 enccfg.rc_max_quantizer = 0;
1109 if (avctx->
qmin >= 0)
1110 enccfg.rc_min_quantizer = avctx->
qmin;
1111 if (avctx->
qmax >= 0)
1112 enccfg.rc_max_quantizer = avctx->
qmax;
1115 if (enccfg.rc_end_usage == VPX_CQ
1116 #
if CONFIG_LIBVPX_VP9_ENCODER
1117 || enccfg.rc_end_usage == VPX_Q
1120 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
1122 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
1123 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
1128 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
1133 enccfg.rc_2pass_vbr_minsection_pct =
1136 enccfg.rc_2pass_vbr_maxsection_pct =
1138 #if CONFIG_LIBVPX_VP9_ENCODER
1140 #if VPX_ENCODER_ABI_VERSION >= 14
1141 if (
ctx->corpus_complexity >= 0)
1142 enccfg.rc_2pass_vbr_corpus_complexity =
ctx->corpus_complexity;
1151 enccfg.rc_buf_initial_sz =
1153 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
1154 if (
ctx->rc_undershoot_pct >= 0)
1155 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
1156 if (
ctx->rc_overshoot_pct >= 0)
1157 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
1163 enccfg.kf_max_dist = avctx->
gop_size;
1165 if (enccfg.g_pass == VPX_RC_FIRST_PASS)
1166 enccfg.g_lag_in_frames = 0;
1167 else if (enccfg.g_pass == VPX_RC_LAST_PASS) {
1168 int decode_size,
ret;
1175 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
1179 "Stat buffer alloc (%zu bytes) failed\n",
1180 ctx->twopass_stats.sz);
1181 ctx->twopass_stats.sz = 0;
1185 ctx->twopass_stats.sz);
1186 if (decode_size < 0) {
1191 ctx->twopass_stats.sz = decode_size;
1192 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
1199 enccfg.g_profile = avctx->
profile;
1206 "Error parsing option '%s = %s'.\n",
1211 res = vpx_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
1212 if (res != VPX_CODEC_OK) {
1219 #if CONFIG_LIBVPX_VP9_ENCODER
1221 memset(&svc_params, 0,
sizeof(svc_params));
1222 for (
int i = 0;
i < enccfg.ts_number_layers; ++
i) {
1223 svc_params.max_quantizers[
i] = enccfg.rc_max_quantizer;
1224 svc_params.min_quantizers[
i] = enccfg.rc_min_quantizer;
1226 svc_params.scaling_factor_num[0] = enccfg.g_h;
1227 svc_params.scaling_factor_den[0] = enccfg.g_h;
1228 #if VPX_ENCODER_ABI_VERSION >= 12
1230 codecctl_intp(avctx, VP9E_SET_SVC_PARAMETERS, (
int *)&svc_params);
1234 if (
ctx->is_alpha) {
1235 enccfg_alpha = enccfg;
1236 enccfg_alpha.g_profile = (
flags & VPX_CODEC_USE_HIGHBITDEPTH) ? 2 : 0;
1237 res = vpx_codec_enc_init(&
ctx->encoder_alpha, iface, &enccfg_alpha,
flags);
1238 if (res != VPX_CODEC_OK) {
1248 ctx->auto_alt_ref = 1;
1249 if (
ctx->auto_alt_ref >= 0)
1252 if (
ctx->arnr_max_frames >= 0)
1254 if (
ctx->arnr_strength >= 0)
1256 if (
ctx->arnr_type >= 0)
1262 av_log(avctx,
AV_LOG_ERROR,
"Transparency encoding with auto_alt_ref does not work\n");
1266 if (
ctx->sharpness >= 0)
1270 codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY,
ctx->noise_sensitivity);
1276 if (
ctx->max_intra_rate >= 0)
1277 codecctl_int(avctx, VP8E_SET_MAX_INTRA_BITRATE_PCT,
ctx->max_intra_rate);
1279 #if CONFIG_LIBVPX_VP9_ENCODER
1281 if (
ctx->lossless >= 0)
1283 if (
ctx->tile_columns >= 0)
1285 if (
ctx->tile_rows >= 0)
1287 if (
ctx->frame_parallel >= 0)
1288 codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
1289 if (
ctx->aq_mode >= 0)
1291 res = set_colorspace(avctx);
1294 #if VPX_ENCODER_ABI_VERSION >= 11
1297 #if VPX_ENCODER_ABI_VERSION >= 12
1300 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
1301 if (
ctx->row_mt >= 0)
1304 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
1305 if (
ctx->tune_content >= 0)
1308 #ifdef VPX_CTRL_VP9E_SET_TPL
1309 if (
ctx->tpl_model >= 0)
1312 #ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
1313 if (
ctx->min_gf_interval >= 0)
1319 if (
ctx->screen_content_mode == 2 &&
ctx->is_alpha) {
1321 "Transparency encoding with screen mode with aggressive rate control not supported\n");
1324 codecctl_int(avctx, VP8E_SET_SCREEN_CONTENT_MODE,
ctx->screen_content_mode);
1330 vpx_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
1332 #if CONFIG_LIBVPX_VP9_ENCODER
1334 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
1341 if (enccfg.rc_end_usage == VPX_CBR ||
1342 enccfg.g_pass != VPX_RC_ONE_PASS) {
1353 const struct vpx_codec_cx_pkt *
src,
1356 dst->pts =
src->data.frame.pts;
1357 dst->flags =
src->data.frame.flags;
1358 dst->sz =
src->data.frame.sz;
1359 dst->buf =
src->data.frame.buf;
1362 if (!(
dst->flags & VPX_FRAME_IS_INVISIBLE)) {
1363 dst->have_sse =
ctx->have_sse;
1364 if (
ctx->have_sse) {
1369 memcpy(
dst->sse,
ctx->sse,
sizeof(
dst->sse));
1397 if (!!(cx_frame->
flags & VPX_FRAME_IS_KEY)) {
1404 ret = vpx_codec_control(&
ctx->encoder, VP8E_GET_LAST_QUANTIZER_64, &
quality);
1405 if (
ret != VPX_CODEC_OK)
1408 cx_frame->
have_sse ? 3 : 0, pict_type);
1412 for (
int i = 0;
i < 3; ++
i)
1416 if (alpha_cx_frame) {
1419 alpha_cx_frame->
sz + 8);
1425 memcpy(side_data + 8, alpha_cx_frame->
buf, alpha_cx_frame->
sz);
1446 const struct vpx_codec_cx_pkt *
pkt;
1447 const void *iter =
NULL;
1450 if (!
ctx->is_alpha && *frame_list) {
1456 *frame_list = cx_frame->
next;
1462 while (
pkt = vpx_codec_get_cx_data(encoder, &iter)) {
1463 switch (
pkt->kind) {
1464 case VPX_CODEC_CX_FRAME_PKT:
1465 if (!
ctx->is_alpha && !
size) {
1480 "Frame queue element alloc failed\n");
1486 if (!cx_frame->
buf) {
1488 "Data buffer alloc (%zu bytes) failed\n",
1497 case VPX_CODEC_STATS_PKT: {
1498 struct vpx_fixed_buf *
stats = &
ctx->twopass_stats;
1503 &
ctx->twopass_stats_size,
1518 case VPX_CODEC_PSNR_PKT:
1528 case VPX_CODEC_CUSTOM_PKT:
1538 vpx_roi_map_t *roi_map,
int block_size,
int segment_cnt)
1543 #define MAX_DELTA_Q 63
1558 memset(roi_map, 0,
sizeof(*roi_map));
1569 if (!self_size || sd->
size % self_size) {
1573 nb_rois = sd->
size / self_size;
1579 for (
int i = 0;
i < nb_rois;
i++) {
1593 if (!segment_mapping[mapping_index]) {
1594 if (segment_id == segment_cnt) {
1596 "ROI only supports %d segments (and segment 0 is reserved for non-ROIs), skipping the left ones.\n",
1601 segment_mapping[mapping_index] = segment_id + 1;
1602 roi_map->delta_q[segment_id] =
delta_q;
1607 roi_map->rows = (frame_height + block_size - 1) / block_size;
1608 roi_map->cols = (frame_width + block_size - 1) / block_size;
1609 roi_map->roi_map =
av_calloc(roi_map->rows * roi_map->cols,
sizeof(*roi_map->roi_map));
1610 if (!roi_map->roi_map) {
1618 for (
int i = nb_rois - 1;
i >= 0;
i--) {
1621 int starty, endy, startx, endx;
1625 starty =
av_clip(roi->
top / block_size, 0, roi_map->rows);
1626 endy =
av_clip((roi->
bottom + block_size - 1) / block_size, 0, roi_map->rows);
1627 startx =
av_clip(roi->
left / block_size, 0, roi_map->cols);
1628 endx =
av_clip((roi->
right + block_size - 1) / block_size, 0, roi_map->cols);
1634 if (mapping_value) {
1635 for (
int y = starty; y < endy; y++)
1636 for (
int x = startx; x < endx; x++)
1637 roi_map->roi_map[x + y * roi_map->cols] = mapping_value - 1;
1648 #ifdef VPX_CTRL_VP9E_SET_ROI_MAP
1649 int version = vpx_codec_version();
1650 int major = VPX_VERSION_MAJOR(
version);
1651 int minor = VPX_VERSION_MINOR(
version);
1652 int patch = VPX_VERSION_PATCH(
version);
1654 if (major > 1 || (major == 1 && minor > 8) || (major == 1 && minor == 8 && patch >= 1)) {
1655 vpx_roi_map_t roi_map;
1656 const int segment_cnt = 8;
1657 const int block_size = 8;
1660 if (
ctx->aq_mode > 0 ||
ctx->cpu_used < 5 ||
ctx->deadline != VPX_DL_REALTIME) {
1661 if (!
ctx->roi_warned) {
1662 ctx->roi_warned = 1;
1664 "and deadline is REALTIME, so skipping ROI.\n");
1669 ret =
set_roi_map(avctx, sd, frame_width, frame_height, &roi_map, block_size, segment_cnt);
1675 memset(roi_map.ref_frame, -1,
sizeof(roi_map.ref_frame));
1677 if (vpx_codec_control(&
ctx->encoder, VP9E_SET_ROI_MAP, &roi_map)) {
1686 if (!
ctx->roi_warned) {
1687 ctx->roi_warned = 1;
1688 av_log(avctx,
AV_LOG_WARNING,
"ROI is not supported, please upgrade libvpx to version >= 1.8.1. "
1689 "You may need to rebuild ffmpeg.\n");
1696 vpx_roi_map_t roi_map;
1697 const int segment_cnt = 4;
1698 const int block_size = 16;
1701 int ret =
set_roi_map(avctx, sd, frame_width, frame_height, &roi_map, block_size, segment_cnt);
1707 if (vpx_codec_control(&
ctx->encoder, VP8E_SET_ROI_MAP, &roi_map)) {
1719 struct vpx_image *rawimg_alpha = &
ctx->rawimg_alpha;
1720 unsigned char **
planes = rawimg_alpha->planes;
1721 int *
stride = rawimg_alpha->stride;
1723 if (!
planes[VPX_PLANE_U] ||
1725 width != (
int)rawimg_alpha->d_w ||
1726 height != (
int)rawimg_alpha->d_h) {
1727 vpx_img_fmt_t alpha_fmt =
ctx->rawimg.bit_depth > 8 ?
1728 VPX_IMG_FMT_I42016 : VPX_IMG_FMT_I420;
1732 vpx_img_wrap(rawimg_alpha, alpha_fmt,
width,
height, 1,
1739 if (
ctx->rawimg.bit_depth > 8) {
1740 int val = 0x80 << (
ctx->rawimg.bit_depth - 8);
1758 struct vpx_image *rawimg =
NULL;
1759 struct vpx_image *rawimg_alpha =
NULL;
1761 int res, coded_size;
1762 vpx_enc_frame_flags_t
flags = 0;
1763 const struct vpx_codec_enc_cfg *enccfg =
ctx->encoder.config.enc;
1764 vpx_svc_layer_id_t layer_id;
1765 int layer_id_valid = 0;
1768 if (avctx->
qmax >= 0 && enccfg->rc_max_quantizer != avctx->
qmax) {
1769 struct vpx_codec_enc_cfg cfg = *enccfg;
1770 cfg.rc_max_quantizer = avctx->
qmax;
1771 res = vpx_codec_enc_config_set(&
ctx->encoder, &cfg);
1772 if (res != VPX_CODEC_OK) {
1780 rawimg = &
ctx->rawimg;
1781 rawimg->planes[VPX_PLANE_Y] =
frame->data[0];
1782 rawimg->planes[VPX_PLANE_U] =
frame->data[1];
1783 rawimg->planes[VPX_PLANE_V] =
frame->data[2];
1784 rawimg->stride[VPX_PLANE_Y] =
frame->linesize[0];
1785 rawimg->stride[VPX_PLANE_U] =
frame->linesize[1];
1786 rawimg->stride[VPX_PLANE_V] =
frame->linesize[2];
1787 if (
ctx->is_alpha) {
1788 rawimg_alpha = &
ctx->rawimg_alpha;
1792 rawimg_alpha->planes[VPX_PLANE_Y] =
frame->data[3];
1793 rawimg_alpha->stride[VPX_PLANE_Y] =
frame->linesize[3];
1795 timestamp =
frame->pts;
1796 #if VPX_IMAGE_ABI_VERSION >= 4
1797 switch (
frame->color_range) {
1799 rawimg->range = VPX_CR_STUDIO_RANGE;
1802 rawimg->range = VPX_CR_FULL_RANGE;
1807 flags |= VPX_EFLAG_FORCE_KF;
1808 if (
frame->metadata) {
1814 memset(&layer_id, 0,
sizeof(layer_id));
1818 layer_id.temporal_layer_id = strtoul(en->
value,
NULL, 10);
1819 #ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT
1820 layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id;
1824 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
1829 int ret = vpx_parse_ref_frame_config(&
ctx->ref_frame_config,
1830 enccfg->ss_number_layers, en->
value);
1833 "Error parsing ref_frame_config option %s.\n", en->
value);
1837 codecctl_intp(avctx, VP9E_SET_SVC_REF_FRAME_CONFIG, (
int *)&
ctx->ref_frame_config);
1840 "Ignoring ref-frame-config for a non-VP9 codec\n");
1863 if (enccfg->ts_number_layers > 1 &&
ctx->ts_layer_flags) {
1864 if (
flags & VPX_EFLAG_FORCE_KF) {
1866 ctx->current_temporal_idx = 0;
1867 flags = VPX_EFLAG_FORCE_KF;
1873 flags |=
ctx->ts_layer_flags[
ctx->current_temporal_idx];
1875 memset(&layer_id, 0,
sizeof(layer_id));
1876 #if VPX_ENCODER_ABI_VERSION >= 12
1877 layer_id.spatial_layer_id = 0;
1879 layer_id.temporal_layer_id = enccfg->ts_layer_id[
ctx->current_temporal_idx];
1880 #ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT
1881 layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id;
1886 if (layer_id_valid) {
1888 codecctl_int(avctx, VP8E_SET_TEMPORAL_LAYER_ID, layer_id.temporal_layer_id);
1890 #if CONFIG_LIBVPX_VP9_ENCODER && VPX_ENCODER_ABI_VERSION >= 12
1892 codecctl_intp(avctx, VP9E_SET_SVC_LAYER_ID, (
int *)&layer_id);
1899 "Frame duration too large: %"PRId64
"\n",
frame->duration);
1908 res = vpx_codec_encode(&
ctx->encoder, rawimg, timestamp,
1910 if (res != VPX_CODEC_OK) {
1915 if (
ctx->is_alpha) {
1916 res = vpx_codec_encode(&
ctx->encoder_alpha, rawimg_alpha, timestamp,
1918 if (res != VPX_CODEC_OK) {
1925 if (
ctx->is_alpha) {
1928 if (
ctx->coded_frame_list &&
ctx->alpha_coded_frame_list) {
1933 coded_size =
storeframe(avctx, cx_frame, alpha_cx_frame,
pkt);
1936 ctx->coded_frame_list = cx_frame->
next;
1937 ctx->alpha_coded_frame_list = alpha_cx_frame->
next;
1953 ctx->twopass_stats.sz);
1954 }
else if (enccfg->ts_number_layers > 1 &&
ctx->ts_layer_flags) {
1955 ctx->current_temporal_idx = (
ctx->current_temporal_idx + 1) % enccfg->ts_periodicity;
1958 *got_packet = !!coded_size;
1962 #define OFFSET(x) offsetof(VPxContext, x)
1963 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1965 #define COMMON_OPTIONS \
1966 { "lag-in-frames", "Number of frames to look ahead for " \
1967 "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1968 { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1969 { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1970 { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "arnr_type"}, \
1971 { "backward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, .unit = "arnr_type" }, \
1972 { "forward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, .unit = "arnr_type" }, \
1973 { "centered", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, .unit = "arnr_type" }, \
1974 { "tune", "Tune the encoding to a specific scenario", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "tune"}, \
1975 { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_PSNR}, 0, 0, VE, .unit = "tune"}, \
1976 { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_SSIM}, 0, 0, VE, .unit = "tune"}, \
1977 { "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"}, \
1978 { "best", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_BEST_QUALITY}, 0, 0, VE, .unit = "quality"}, \
1979 { "good", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_GOOD_QUALITY}, 0, 0, VE, .unit = "quality"}, \
1980 { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_REALTIME}, 0, 0, VE, .unit = "quality"}, \
1981 { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, .unit = "er"}, \
1982 { "max-intra-rate", "Maximum I-frame bitrate (pct) 0=unlimited", OFFSET(max_intra_rate), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1983 { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, .unit = "er"}, \
1984 { "partitions", "The frame partitions are independently decodable " \
1985 "by the bool decoder, meaning that partitions can be decoded even " \
1986 "though earlier partitions have been lost. Note that intra prediction" \
1987 " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, .unit = "er"}, \
1988 { "crf", "Select the quality for constant quality mode", offsetof(VPxContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \
1989 { "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 }, \
1990 { "drop-threshold", "Frame drop threshold", offsetof(VPxContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE }, \
1991 { "noise-sensitivity", "Noise sensitivity", OFFSET(noise_sensitivity), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 4, VE}, \
1992 { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, VE }, \
1993 { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1000, VE }, \
1994 { "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}, \
1996 #define LEGACY_OPTIONS \
1997 {"speed", "", offsetof(VPxContext, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
1998 {"quality", "", offsetof(VPxContext, deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, .unit = "quality"}, \
1999 {"vp8flags", "", offsetof(VPxContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, UINT_MAX, VE, .unit = "flags"}, \
2000 {"error_resilient", "enable error resilience", 0, AV_OPT_TYPE_CONST, {.i64 = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, .unit = "flags"}, \
2001 {"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"}, \
2002 {"arnr_max_frames", "altref noise reduction max frame count", offsetof(VPxContext, arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 15, VE}, \
2003 {"arnr_strength", "altref noise reduction filter strength", offsetof(VPxContext, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
2004 {"arnr_type", "altref noise reduction filter type", offsetof(VPxContext, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
2005 {"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}, \
2006 {"sharpness", "Increase sharpness at the expense of lower PSNR", offsetof(VPxContext, sharpness), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, VE},
2008 #if CONFIG_LIBVPX_VP8_ENCODER
2009 static const AVOption vp8_options[] = {
2011 {
"auto-alt-ref",
"Enable use of alternate reference "
2014 {
"screen-content-mode",
"Encoder screen content mode",
OFFSET(screen_content_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2,
VE},
2020 #if CONFIG_LIBVPX_VP9_ENCODER
2021 static const AVOption vp9_options[] = {
2023 {
"auto-alt-ref",
"Enable use of alternate reference "
2027 {
"tile-columns",
"Number of tile columns to use, log2",
OFFSET(tile_columns),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
2029 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL,{.i64 = -1}, -1, 1,
VE},
2030 #if VPX_ENCODER_ABI_VERSION >= 12
2031 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE, .unit =
"aq_mode"},
2033 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3,
VE, .unit =
"aq_mode"},
2036 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"aq_mode" },
2037 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"aq_mode" },
2038 {
"cyclic",
"Cyclic Refresh Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0,
VE, .unit =
"aq_mode" },
2039 #if VPX_ENCODER_ABI_VERSION >= 12
2040 {
"equator360",
"360 video Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0,
VE, .unit =
"aq_mode" },
2043 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
2046 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
2047 #if VPX_ENCODER_ABI_VERSION >= 14
2048 {
"tune-content",
"Tune content type",
OFFSET(tune_content),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2,
VE, .unit =
"tune_content" },
2050 {
"tune-content",
"Tune content type",
OFFSET(tune_content),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1,
VE, .unit =
"tune_content" },
2052 {
"default",
"Regular video content", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0,
VE, .unit =
"tune_content" },
2053 {
"screen",
"Screen capture content", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"tune_content" },
2054 #if VPX_ENCODER_ABI_VERSION >= 14
2055 {
"film",
"Film content; improves grain retention", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"tune_content" },
2058 #if VPX_ENCODER_ABI_VERSION >= 14
2059 {
"corpus-complexity",
"corpus vbr complexity midpoint",
OFFSET(corpus_complexity),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 10000,
VE },
2061 #ifdef VPX_CTRL_VP9E_SET_TPL
2064 #ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
2065 {
"min-gf-interval",
"Minimum golden/alternate reference frame interval",
OFFSET(min_gf_interval),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE },
2072 #undef COMMON_OPTIONS
2073 #undef LEGACY_OPTIONS
2080 {
"keyint_min",
"-1" },
2084 #if CONFIG_LIBVPX_VP8_ENCODER
2087 return vpx_init(avctx, vpx_codec_vp8_cx());
2090 static const AVClass class_vp8 = {
2093 .option = vp8_options,
2105 .priv_data_size =
sizeof(VPxContext),
2114 .p.priv_class = &class_vp8,
2116 .p.wrapper_name =
"libvpx",
2120 #if CONFIG_LIBVPX_VP9_ENCODER
2123 return vpx_init(avctx, vpx_codec_vp9_cx());
2175 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
2176 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
2177 *
out = vp9_pix_fmts_highbd;
2180 *
out = vp9_pix_fmts_highcol;
2189 static const AVClass class_vp9 = {
2192 .option = vp9_options,
2197 .
p.
name =
"libvpx-vp9",
2205 .p.priv_class = &class_vp9,
2206 .p.wrapper_name =
"libvpx",
2207 .priv_data_size =
sizeof(VPxContext),
2216 .get_supported_config = vp9_get_supported_config,