26 #define VPX_DISABLE_CTRL_TYPECHECKS 1
27 #define VPX_CODEC_DISABLE_COMPAT 1
28 #include <vpx/vpx_encoder.h>
29 #include <vpx/vp8cx.h>
84 #define VP8F_ERROR_RESILIENT 0x00000001
85 #define VP8F_AUTO_ALT_REF 0x00000002
123 [VP8E_SET_CPUUSED] =
"VP8E_SET_CPUUSED",
124 [VP8E_SET_ENABLEAUTOALTREF] =
"VP8E_SET_ENABLEAUTOALTREF",
125 [VP8E_SET_NOISE_SENSITIVITY] =
"VP8E_SET_NOISE_SENSITIVITY",
126 [VP8E_SET_STATIC_THRESHOLD] =
"VP8E_SET_STATIC_THRESHOLD",
127 [VP8E_SET_TOKEN_PARTITIONS] =
"VP8E_SET_TOKEN_PARTITIONS",
128 [VP8E_SET_ARNR_MAXFRAMES] =
"VP8E_SET_ARNR_MAXFRAMES",
129 [VP8E_SET_ARNR_STRENGTH] =
"VP8E_SET_ARNR_STRENGTH",
130 [VP8E_SET_ARNR_TYPE] =
"VP8E_SET_ARNR_TYPE",
131 [VP8E_SET_TUNING] =
"VP8E_SET_TUNING",
132 [VP8E_SET_CQ_LEVEL] =
"VP8E_SET_CQ_LEVEL",
133 [VP8E_SET_MAX_INTRA_BITRATE_PCT] =
"VP8E_SET_MAX_INTRA_BITRATE_PCT",
134 [VP8E_SET_SHARPNESS] =
"VP8E_SET_SHARPNESS",
135 #if CONFIG_LIBVPX_VP9_ENCODER
136 [VP9E_SET_LOSSLESS] =
"VP9E_SET_LOSSLESS",
137 [VP9E_SET_TILE_COLUMNS] =
"VP9E_SET_TILE_COLUMNS",
138 [VP9E_SET_TILE_ROWS] =
"VP9E_SET_TILE_ROWS",
139 [VP9E_SET_FRAME_PARALLEL_DECODING] =
"VP9E_SET_FRAME_PARALLEL_DECODING",
140 [VP9E_SET_AQ_MODE] =
"VP9E_SET_AQ_MODE",
141 [VP9E_SET_COLOR_SPACE] =
"VP9E_SET_COLOR_SPACE",
142 #if VPX_ENCODER_ABI_VERSION >= 11
143 [VP9E_SET_COLOR_RANGE] =
"VP9E_SET_COLOR_RANGE",
145 #if VPX_ENCODER_ABI_VERSION >= 12
146 [VP9E_SET_TARGET_LEVEL] =
"VP9E_SET_TARGET_LEVEL",
147 [VP9E_GET_LEVEL] =
"VP9E_GET_LEVEL",
149 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
150 [VP9E_SET_ROW_MT] =
"VP9E_SET_ROW_MT",
152 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
153 [VP9E_SET_TUNE_CONTENT] =
"VP9E_SET_TUNE_CONTENT",
155 #ifdef VPX_CTRL_VP9E_SET_TPL
156 [VP9E_SET_TPL] =
"VP9E_SET_TPL",
164 const char *
error = vpx_codec_error(&
ctx->encoder);
165 const char *detail = vpx_codec_error_detail(&
ctx->encoder);
173 const struct vpx_codec_enc_cfg *cfg)
181 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
182 #
if CONFIG_LIBVPX_VP9_ENCODER
185 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
186 width,
"g_usage:", cfg->g_usage,
187 width,
"g_threads:", cfg->g_threads,
188 width,
"g_profile:", cfg->g_profile,
189 width,
"g_w:", cfg->g_w,
190 width,
"g_h:", cfg->g_h,
191 #
if CONFIG_LIBVPX_VP9_ENCODER
192 width,
"g_bit_depth:", cfg->g_bit_depth,
193 width,
"g_input_bit_depth:", cfg->g_input_bit_depth,
195 width,
"g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
196 width,
"g_error_resilient:", cfg->g_error_resilient,
197 width,
"g_pass:", cfg->g_pass,
198 width,
"g_lag_in_frames:", cfg->g_lag_in_frames);
200 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
202 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
203 width,
"rc_resize_allowed:", cfg->rc_resize_allowed,
204 width,
"rc_resize_up_thresh:", cfg->rc_resize_up_thresh,
205 width,
"rc_resize_down_thresh:", cfg->rc_resize_down_thresh,
206 width,
"rc_end_usage:", cfg->rc_end_usage,
207 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
208 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
211 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
212 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
215 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
216 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
217 av_log(avctx,
level,
"temporal layering settings\n"
218 " %*s%u\n",
width,
"ts_number_layers:", cfg->ts_number_layers);
220 "\n %*s",
width,
"ts_target_bitrate:");
221 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
225 "\n %*s",
width,
"ts_rate_decimator:");
226 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
230 "\n %*s%u\n",
width,
"ts_periodicity:", cfg->ts_periodicity);
232 "\n %*s",
width,
"ts_layer_id:");
233 for (
i = 0;
i < VPX_TS_MAX_PERIODICITY;
i++)
237 " %*s%u\n %*s%u\n %*s%u\n",
238 width,
"rc_buf_sz:", cfg->rc_buf_sz,
239 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
240 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
241 av_log(avctx,
level,
"2 pass rate control settings\n"
242 " %*s%u\n %*s%u\n %*s%u\n",
243 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
244 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
245 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
246 #if VPX_ENCODER_ABI_VERSION >= 14
248 width,
"rc_2pass_vbr_corpus_complexity:", cfg->rc_2pass_vbr_corpus_complexity);
251 " %*s%d\n %*s%u\n %*s%u\n",
252 width,
"kf_mode:", cfg->kf_mode,
253 width,
"kf_min_dist:", cfg->kf_min_dist,
254 width,
"kf_max_dist:", cfg->kf_max_dist);
288 enum vp8e_enc_control_id
id,
int val)
298 res = vpx_codec_control(&
ctx->encoder,
id,
val);
299 if (res != VPX_CODEC_OK) {
305 return res == VPX_CODEC_OK ? 0 :
AVERROR(EINVAL);
308 #if VPX_ENCODER_ABI_VERSION >= 12
310 enum vp8e_enc_control_id
id,
int *
val)
320 res = vpx_codec_control(&
ctx->encoder,
id,
val);
321 if (res != VPX_CODEC_OK) {
327 return res == VPX_CODEC_OK ? 0 :
AVERROR(EINVAL);
335 #if VPX_ENCODER_ABI_VERSION >= 12
339 if (!codecctl_intp(avctx, VP9E_GET_LEVEL, &level_out))
344 vpx_codec_destroy(&
ctx->encoder);
346 vpx_codec_destroy(&
ctx->encoder_alpha);
356 char *saveptr =
NULL;
359 while (token && dest_idx < max_entries) {
360 dest[dest_idx++] = strtoul(token,
NULL, 10);
367 size_t value_len = strlen(
value);
372 if (!strcmp(
key,
"ts_number_layers"))
373 enccfg->ts_number_layers = strtoul(
value, &
value, 10);
374 else if (!strcmp(
key,
"ts_target_bitrate"))
376 else if (!strcmp(
key,
"ts_rate_decimator"))
378 else if (!strcmp(
key,
"ts_periodicity"))
379 enccfg->ts_periodicity = strtoul(
value, &
value, 10);
380 else if (!strcmp(
key,
"ts_layer_id"))
386 #if CONFIG_LIBVPX_VP9_ENCODER
388 struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *
flags,
389 vpx_img_fmt_t *img_fmt)
392 enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
396 enccfg->g_profile = 0;
397 *img_fmt = VPX_IMG_FMT_I420;
400 enccfg->g_profile = 1;
401 *img_fmt = VPX_IMG_FMT_I422;
404 enccfg->g_profile = 1;
405 *img_fmt = VPX_IMG_FMT_I440;
408 ctx->vpx_cs = VPX_CS_SRGB;
410 enccfg->g_profile = 1;
411 *img_fmt = VPX_IMG_FMT_I444;
415 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
416 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
418 enccfg->g_profile = 2;
419 *img_fmt = VPX_IMG_FMT_I42016;
420 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
426 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
427 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
429 enccfg->g_profile = 3;
430 *img_fmt = VPX_IMG_FMT_I42216;
431 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
437 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
438 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
440 enccfg->g_profile = 3;
441 *img_fmt = VPX_IMG_FMT_I44016;
442 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
448 ctx->vpx_cs = VPX_CS_SRGB;
451 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
452 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
455 enccfg->g_profile = 3;
456 *img_fmt = VPX_IMG_FMT_I44416;
457 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
470 enum vpx_color_space vpx_cs;
474 vpx_cs =
ctx->vpx_cs;
494 #if VPX_ENCODER_ABI_VERSION >= 11
497 enum vpx_color_range vpx_cr;
514 const struct vpx_codec_iface *iface)
517 struct vpx_codec_enc_cfg enccfg = { 0 };
518 struct vpx_codec_enc_cfg enccfg_alpha;
522 vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
523 #if CONFIG_LIBVPX_VP9_ENCODER
524 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(iface);
533 if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) {
535 vpx_codec_err_to_string(res));
539 #if CONFIG_LIBVPX_VP9_ENCODER
554 enccfg.g_w = avctx->
width;
555 enccfg.g_h = avctx->
height;
560 enccfg.g_lag_in_frames=
ctx->lag_in_frames;
563 enccfg.g_pass = VPX_RC_FIRST_PASS;
565 enccfg.g_pass = VPX_RC_LAST_PASS;
567 enccfg.g_pass = VPX_RC_ONE_PASS;
571 enccfg.rc_end_usage = VPX_CBR;
572 }
else if (
ctx->crf >= 0) {
573 enccfg.rc_end_usage = VPX_CQ;
574 #if CONFIG_LIBVPX_VP9_ENCODER
576 enccfg.rc_end_usage = VPX_Q;
583 #if CONFIG_LIBVPX_VP9_ENCODER
584 }
else if (enccfg.rc_end_usage == VPX_Q) {
587 if (enccfg.rc_end_usage == VPX_CQ) {
588 enccfg.rc_target_bitrate = 1000000;
590 avctx->
bit_rate = enccfg.rc_target_bitrate * 1000;
592 "Neither bitrate nor constrained quality specified, using default bitrate of %dkbit/sec\n",
593 enccfg.rc_target_bitrate);
598 enccfg.rc_min_quantizer =
599 enccfg.rc_max_quantizer = 0;
601 if (avctx->
qmin >= 0)
602 enccfg.rc_min_quantizer = avctx->
qmin;
603 if (avctx->
qmax >= 0)
604 enccfg.rc_max_quantizer = avctx->
qmax;
607 if (enccfg.rc_end_usage == VPX_CQ
608 #
if CONFIG_LIBVPX_VP9_ENCODER
609 || enccfg.rc_end_usage == VPX_Q
612 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
614 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
615 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
620 #if FF_API_PRIVATE_OPT
626 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
631 enccfg.rc_2pass_vbr_minsection_pct =
634 enccfg.rc_2pass_vbr_maxsection_pct =
636 #if CONFIG_LIBVPX_VP9_ENCODER
638 #if VPX_ENCODER_ABI_VERSION >= 14
639 if (
ctx->corpus_complexity >= 0)
640 enccfg.rc_2pass_vbr_corpus_complexity =
ctx->corpus_complexity;
649 enccfg.rc_buf_initial_sz =
651 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
652 if (
ctx->rc_undershoot_pct >= 0)
653 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
654 if (
ctx->rc_overshoot_pct >= 0)
655 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
661 enccfg.kf_max_dist = avctx->
gop_size;
663 if (enccfg.g_pass == VPX_RC_FIRST_PASS)
664 enccfg.g_lag_in_frames = 0;
665 else if (enccfg.g_pass == VPX_RC_LAST_PASS) {
666 int decode_size,
ret;
673 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
678 ctx->twopass_stats.sz);
679 ctx->twopass_stats.sz = 0;
683 ctx->twopass_stats.sz);
684 if (decode_size < 0) {
689 ctx->twopass_stats.sz = decode_size;
690 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
697 enccfg.g_profile = avctx->
profile;
709 "Error parsing option '%s = %s'.\n",
719 res = vpx_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
720 if (res != VPX_CODEC_OK) {
726 enccfg_alpha = enccfg;
727 res = vpx_codec_enc_init(&
ctx->encoder_alpha, iface, &enccfg_alpha,
flags);
728 if (res != VPX_CODEC_OK) {
738 ctx->auto_alt_ref = 1;
739 if (
ctx->auto_alt_ref >= 0)
742 if (
ctx->arnr_max_frames >= 0)
744 if (
ctx->arnr_strength >= 0)
746 if (
ctx->arnr_type >= 0)
752 av_log(avctx,
AV_LOG_ERROR,
"Transparency encoding with auto_alt_ref does not work\n");
756 if (
ctx->sharpness >= 0)
760 #if FF_API_PRIVATE_OPT
766 codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY,
ctx->noise_sensitivity);
772 if (
ctx->max_intra_rate >= 0)
773 codecctl_int(avctx, VP8E_SET_MAX_INTRA_BITRATE_PCT,
ctx->max_intra_rate);
775 #if CONFIG_LIBVPX_VP9_ENCODER
777 if (
ctx->lossless >= 0)
779 if (
ctx->tile_columns >= 0)
781 if (
ctx->tile_rows >= 0)
783 if (
ctx->frame_parallel >= 0)
784 codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
785 if (
ctx->aq_mode >= 0)
787 set_colorspace(avctx);
788 #if VPX_ENCODER_ABI_VERSION >= 11
791 #if VPX_ENCODER_ABI_VERSION >= 12
794 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
795 if (
ctx->row_mt >= 0)
798 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
799 if (
ctx->tune_content >= 0)
802 #ifdef VPX_CTRL_VP9E_SET_TPL
803 if (
ctx->tpl_model >= 0)
812 vpx_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
814 #if CONFIG_LIBVPX_VP9_ENCODER
816 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
820 vpx_img_wrap(&
ctx->rawimg_alpha, VPX_IMG_FMT_I420, avctx->
width, avctx->
height, 1,
827 if (enccfg.rc_end_usage == VPX_CBR ||
828 enccfg.g_pass != VPX_RC_ONE_PASS) {
839 const struct vpx_codec_cx_pkt *
src,
840 const struct vpx_codec_cx_pkt *src_alpha,
843 dst->
pts =
src->data.frame.pts;
846 dst->
sz =
src->data.frame.sz;
847 dst->
buf =
src->data.frame.buf;
850 if (!(dst->
flags & VPX_FRAME_IS_INVISIBLE)) {
858 memcpy(dst->
sse,
ctx->sse,
sizeof(dst->
sse));
865 dst->
buf_alpha = src_alpha->data.frame.buf;
866 dst->
sz_alpha = src_alpha->data.frame.sz;
889 #if FF_API_CODED_FRAME
896 if (!!(cx_frame->
flags & VPX_FRAME_IS_KEY)) {
898 #if FF_API_CODED_FRAME
906 #if FF_API_CODED_FRAME
914 cx_frame->
have_sse ? 3 : 0, pict_type);
919 #if FF_API_CODED_FRAME
927 for (
i = 0;
i < 3; ++
i) {
960 const struct vpx_codec_cx_pkt *
pkt;
961 const struct vpx_codec_cx_pkt *pkt_alpha =
NULL;
962 const void *iter =
NULL;
963 const void *iter_alpha =
NULL;
966 if (
ctx->coded_frame_list) {
972 ctx->coded_frame_list = cx_frame->
next;
978 while ((
pkt = vpx_codec_get_cx_data(&
ctx->encoder, &iter)) &&
980 (pkt_alpha = vpx_codec_get_cx_data(&
ctx->encoder_alpha, &iter_alpha)))) {
982 case VPX_CODEC_CX_FRAME_PKT:
999 "Frame queue element alloc failed\n");
1005 if (!cx_frame->
buf) {
1013 if (
ctx->is_alpha) {
1022 memcpy(cx_frame->
buf_alpha, pkt_alpha->data.frame.buf, pkt_alpha->data.frame.sz);
1027 case VPX_CODEC_STATS_PKT: {
1028 struct vpx_fixed_buf *
stats = &
ctx->twopass_stats;
1032 pkt->
data.twopass_stats.sz)) < 0) {
1042 case VPX_CODEC_PSNR_PKT:
1050 case VPX_CODEC_CUSTOM_PKT:
1063 struct vpx_image *rawimg =
NULL;
1064 struct vpx_image *rawimg_alpha =
NULL;
1065 int64_t timestamp = 0;
1066 int res, coded_size;
1067 vpx_enc_frame_flags_t
flags = 0;
1070 rawimg = &
ctx->rawimg;
1071 rawimg->planes[VPX_PLANE_Y] =
frame->data[0];
1072 rawimg->planes[VPX_PLANE_U] =
frame->data[1];
1073 rawimg->planes[VPX_PLANE_V] =
frame->data[2];
1074 rawimg->stride[VPX_PLANE_Y] =
frame->linesize[0];
1075 rawimg->stride[VPX_PLANE_U] =
frame->linesize[1];
1076 rawimg->stride[VPX_PLANE_V] =
frame->linesize[2];
1077 if (
ctx->is_alpha) {
1079 rawimg_alpha = &
ctx->rawimg_alpha;
1080 rawimg_alpha->planes[VPX_PLANE_Y] =
frame->data[3];
1083 if (!u_plane || !v_plane) {
1088 memset(u_plane, 0x80,
frame->linesize[1] *
frame->height);
1089 rawimg_alpha->planes[VPX_PLANE_U] = u_plane;
1090 memset(v_plane, 0x80,
frame->linesize[2] *
frame->height);
1091 rawimg_alpha->planes[VPX_PLANE_V] = v_plane;
1092 rawimg_alpha->stride[VPX_PLANE_Y] =
frame->linesize[0];
1093 rawimg_alpha->stride[VPX_PLANE_U] =
frame->linesize[1];
1094 rawimg_alpha->stride[VPX_PLANE_V] =
frame->linesize[2];
1096 timestamp =
frame->pts;
1097 #if VPX_IMAGE_ABI_VERSION >= 4
1098 switch (
frame->color_range) {
1100 rawimg->range = VPX_CR_STUDIO_RANGE;
1103 rawimg->range = VPX_CR_FULL_RANGE;
1108 flags |= VPX_EFLAG_FORCE_KF;
1117 res = vpx_codec_encode(&
ctx->encoder, rawimg, timestamp,
1119 if (res != VPX_CODEC_OK) {
1124 if (
ctx->is_alpha) {
1125 res = vpx_codec_encode(&
ctx->encoder_alpha, rawimg_alpha, timestamp,
1127 if (res != VPX_CODEC_OK) {
1145 ctx->twopass_stats.sz);
1149 av_freep(&rawimg_alpha->planes[VPX_PLANE_U]);
1150 av_freep(&rawimg_alpha->planes[VPX_PLANE_V]);
1153 *got_packet = !!coded_size;
1157 #define OFFSET(x) offsetof(VPxContext, x)
1158 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1160 #define COMMON_OPTIONS \
1161 { "lag-in-frames", "Number of frames to look ahead for " \
1162 "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1163 { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1164 { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1165 { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "arnr_type"}, \
1166 { "backward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "arnr_type" }, \
1167 { "forward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "arnr_type" }, \
1168 { "centered", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "arnr_type" }, \
1169 { "tune", "Tune the encoding to a specific scenario", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "tune"}, \
1170 { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_PSNR}, 0, 0, VE, "tune"}, \
1171 { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_SSIM}, 0, 0, VE, "tune"}, \
1172 { "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
1173 { "best", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_BEST_QUALITY}, 0, 0, VE, "quality"}, \
1174 { "good", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"}, \
1175 { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_REALTIME}, 0, 0, VE, "quality"}, \
1176 { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"}, \
1177 { "max-intra-rate", "Maximum I-frame bitrate (pct) 0=unlimited", OFFSET(max_intra_rate), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1178 { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"}, \
1179 { "partitions", "The frame partitions are independently decodable " \
1180 "by the bool decoder, meaning that partitions can be decoded even " \
1181 "though earlier partitions have been lost. Note that intra predicition" \
1182 " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"}, \
1183 { "crf", "Select the quality for constant quality mode", offsetof(VPxContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \
1184 { "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 }, \
1185 { "drop-threshold", "Frame drop threshold", offsetof(VPxContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE }, \
1186 { "noise-sensitivity", "Noise sensitivity", OFFSET(noise_sensitivity), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 4, VE}, \
1187 { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, VE }, \
1188 { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1000, VE }, \
1190 #define LEGACY_OPTIONS \
1191 {"speed", "", offsetof(VPxContext, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
1192 {"quality", "", offsetof(VPxContext, deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
1193 {"vp8flags", "", offsetof(VPxContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, UINT_MAX, VE, "flags"}, \
1194 {"error_resilient", "enable error resilience", 0, AV_OPT_TYPE_CONST, {.i64 = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, "flags"}, \
1195 {"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, "flags"}, \
1196 {"arnr_max_frames", "altref noise reduction max frame count", offsetof(VPxContext, arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 15, VE}, \
1197 {"arnr_strength", "altref noise reduction filter strength", offsetof(VPxContext, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
1198 {"arnr_type", "altref noise reduction filter type", offsetof(VPxContext, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
1199 {"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}, \
1200 {"sharpness", "Increase sharpness at the expense of lower PSNR", offsetof(VPxContext, sharpness), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, VE},
1202 #if CONFIG_LIBVPX_VP8_ENCODER
1203 static const AVOption vp8_options[] = {
1205 {
"auto-alt-ref",
"Enable use of alternate reference "
1208 {
"ts-parameters",
"Temporal scaling configuration using a "
1215 #if CONFIG_LIBVPX_VP9_ENCODER
1216 static const AVOption vp9_options[] = {
1218 {
"auto-alt-ref",
"Enable use of alternate reference "
1222 {
"tile-columns",
"Number of tile columns to use, log2",
OFFSET(tile_columns),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
1224 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL,{.i64 = -1}, -1, 1,
VE},
1225 #if VPX_ENCODER_ABI_VERSION >= 12
1226 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE,
"aq_mode"},
1228 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3,
VE,
"aq_mode"},
1231 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE,
"aq_mode" },
1232 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE,
"aq_mode" },
1234 #if VPX_ENCODER_ABI_VERSION >= 12
1238 #ifdef VPX_CTRL_VP9E_SET_ROW_MT
1241 #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
1242 #if VPX_ENCODER_ABI_VERSION >= 14
1243 {
"tune-content",
"Tune content type",
OFFSET(tune_content),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2,
VE,
"tune_content" },
1245 {
"tune-content",
"Tune content type",
OFFSET(tune_content),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1,
VE,
"tune_content" },
1247 {
"default",
"Regular video content", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0,
VE,
"tune_content" },
1248 {
"screen",
"Screen capture content", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE,
"tune_content" },
1249 #if VPX_ENCODER_ABI_VERSION >= 14
1250 {
"film",
"Film content; improves grain retention", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE,
"tune_content" },
1253 #if VPX_ENCODER_ABI_VERSION >= 14
1254 {
"corpus-complexity",
"corpus vbr complexity midpoint",
OFFSET(corpus_complexity),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 10000,
VE },
1256 #ifdef VPX_CTRL_VP9E_SET_TPL
1264 #undef COMMON_OPTIONS
1265 #undef LEGACY_OPTIONS
1271 {
"keyint_min",
"-1" },
1275 #if CONFIG_LIBVPX_VP8_ENCODER
1278 return vpx_init(avctx, vpx_codec_vp8_cx());
1281 static const AVClass class_vp8 = {
1284 .option = vp8_options,
1293 .priv_data_size =
sizeof(VPxContext),
1299 .priv_class = &class_vp8,
1301 .wrapper_name =
"libvpx",
1305 #if CONFIG_LIBVPX_VP9_ENCODER
1308 return vpx_init(avctx, vpx_codec_vp9_cx());
1311 static const AVClass class_vp9 = {
1314 .option = vp9_options,
1319 .
name =
"libvpx-vp9",
1323 .priv_data_size =
sizeof(VPxContext),
1329 .priv_class = &class_vp9,
1332 .wrapper_name =
"libvpx",