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>
61 typedef struct VP8EncoderContext {
63 struct vpx_codec_ctx encoder;
64 struct vpx_image rawimg;
65 struct vpx_codec_ctx encoder_alpha;
66 struct vpx_image rawimg_alpha;
68 struct vpx_fixed_buf twopass_stats;
80 #define VP8F_ERROR_RESILIENT 0x00000001
81 #define VP8F_AUTO_ALT_REF 0x00000002
105 [VP8E_UPD_ENTROPY] =
"VP8E_UPD_ENTROPY",
106 [VP8E_UPD_REFERENCE] =
"VP8E_UPD_REFERENCE",
107 [VP8E_USE_REFERENCE] =
"VP8E_USE_REFERENCE",
108 [VP8E_SET_ROI_MAP] =
"VP8E_SET_ROI_MAP",
109 [VP8E_SET_ACTIVEMAP] =
"VP8E_SET_ACTIVEMAP",
110 [VP8E_SET_SCALEMODE] =
"VP8E_SET_SCALEMODE",
111 [VP8E_SET_CPUUSED] =
"VP8E_SET_CPUUSED",
112 [VP8E_SET_ENABLEAUTOALTREF] =
"VP8E_SET_ENABLEAUTOALTREF",
113 [VP8E_SET_NOISE_SENSITIVITY] =
"VP8E_SET_NOISE_SENSITIVITY",
114 [VP8E_SET_SHARPNESS] =
"VP8E_SET_SHARPNESS",
115 [VP8E_SET_STATIC_THRESHOLD] =
"VP8E_SET_STATIC_THRESHOLD",
116 [VP8E_SET_TOKEN_PARTITIONS] =
"VP8E_SET_TOKEN_PARTITIONS",
117 [VP8E_GET_LAST_QUANTIZER] =
"VP8E_GET_LAST_QUANTIZER",
118 [VP8E_SET_ARNR_MAXFRAMES] =
"VP8E_SET_ARNR_MAXFRAMES",
119 [VP8E_SET_ARNR_STRENGTH] =
"VP8E_SET_ARNR_STRENGTH",
120 [VP8E_SET_ARNR_TYPE] =
"VP8E_SET_ARNR_TYPE",
121 [VP8E_SET_CQ_LEVEL] =
"VP8E_SET_CQ_LEVEL",
122 [VP8E_SET_MAX_INTRA_BITRATE_PCT] =
"VP8E_SET_MAX_INTRA_BITRATE_PCT",
123 #if CONFIG_LIBVPX_VP9_ENCODER
124 [VP9E_SET_LOSSLESS] =
"VP9E_SET_LOSSLESS",
125 [VP9E_SET_TILE_COLUMNS] =
"VP9E_SET_TILE_COLUMNS",
126 [VP9E_SET_TILE_ROWS] =
"VP9E_SET_TILE_ROWS",
127 [VP9E_SET_FRAME_PARALLEL_DECODING] =
"VP9E_SET_FRAME_PARALLEL_DECODING",
128 [VP9E_SET_AQ_MODE] =
"VP9E_SET_AQ_MODE",
135 const char *error = vpx_codec_error(&ctx->
encoder);
136 const char *detail = vpx_codec_error_detail(&ctx->
encoder);
144 const struct vpx_codec_enc_cfg *cfg)
149 av_log(avctx, level,
"vpx_codec_enc_cfg\n");
150 av_log(avctx, level,
"generic settings\n"
151 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
152 #
if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
155 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
156 width,
"g_usage:", cfg->g_usage,
157 width,
"g_threads:", cfg->g_threads,
158 width,
"g_profile:", cfg->g_profile,
159 width,
"g_w:", cfg->g_w,
160 width,
"g_h:", cfg->g_h,
161 #
if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
162 width,
"g_bit_depth:", cfg->g_bit_depth,
163 width,
"g_input_bit_depth:", cfg->g_input_bit_depth,
165 width,
"g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
166 width,
"g_error_resilient:", cfg->g_error_resilient,
167 width,
"g_pass:", cfg->g_pass,
168 width,
"g_lag_in_frames:", cfg->g_lag_in_frames);
169 av_log(avctx, level,
"rate control settings\n"
170 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
172 width,
"rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
173 width,
"rc_resize_allowed:", cfg->rc_resize_allowed,
174 width,
"rc_resize_up_thresh:", cfg->rc_resize_up_thresh,
175 width,
"rc_resize_down_thresh:", cfg->rc_resize_down_thresh,
176 width,
"rc_end_usage:", cfg->rc_end_usage,
177 width,
"rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
178 width,
"rc_target_bitrate:", cfg->rc_target_bitrate);
179 av_log(avctx, level,
"quantizer settings\n"
181 width,
"rc_min_quantizer:", cfg->rc_min_quantizer,
182 width,
"rc_max_quantizer:", cfg->rc_max_quantizer);
183 av_log(avctx, level,
"bitrate tolerance\n"
185 width,
"rc_undershoot_pct:", cfg->rc_undershoot_pct,
186 width,
"rc_overshoot_pct:", cfg->rc_overshoot_pct);
187 av_log(avctx, level,
"decoder buffer model\n"
188 " %*s%u\n %*s%u\n %*s%u\n",
189 width,
"rc_buf_sz:", cfg->rc_buf_sz,
190 width,
"rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
191 width,
"rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
192 av_log(avctx, level,
"2 pass rate control settings\n"
193 " %*s%u\n %*s%u\n %*s%u\n",
194 width,
"rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
195 width,
"rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
196 width,
"rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
197 av_log(avctx, level,
"keyframing settings\n"
198 " %*s%d\n %*s%u\n %*s%u\n",
199 width,
"kf_mode:", cfg->kf_mode,
200 width,
"kf_min_dist:", cfg->kf_min_dist,
201 width,
"kf_max_dist:", cfg->kf_max_dist);
202 av_log(avctx, level,
"\n");
235 enum vp8e_enc_control_id
id,
int val)
245 res = vpx_codec_control(&ctx->
encoder,
id, val);
246 if (res != VPX_CODEC_OK) {
247 snprintf(buf,
sizeof(buf),
"Failed to set %s codec control",
252 return res == VPX_CODEC_OK ? 0 :
AVERROR(EINVAL);
259 vpx_codec_destroy(&ctx->
encoder);
269 #if CONFIG_LIBVPX_VP9_ENCODER
271 struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *
flags,
272 vpx_img_fmt_t *img_fmt)
274 #ifdef VPX_IMG_FMT_HIGHBITDEPTH
275 enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
279 enccfg->g_profile = 0;
280 *img_fmt = VPX_IMG_FMT_I420;
283 enccfg->g_profile = 1;
284 *img_fmt = VPX_IMG_FMT_I422;
286 #if VPX_IMAGE_ABI_VERSION >= 3
288 enccfg->g_profile = 1;
289 *img_fmt = VPX_IMG_FMT_I440;
293 enccfg->g_profile = 1;
294 *img_fmt = VPX_IMG_FMT_I444;
296 #ifdef VPX_IMG_FMT_HIGHBITDEPTH
299 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
300 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
302 enccfg->g_profile = 2;
303 *img_fmt = VPX_IMG_FMT_I42016;
304 *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
310 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
311 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
313 enccfg->g_profile = 3;
314 *img_fmt = VPX_IMG_FMT_I42216;
315 *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
319 #if VPX_IMAGE_ABI_VERSION >= 3
322 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
323 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
325 enccfg->g_profile = 3;
326 *img_fmt = VPX_IMG_FMT_I44016;
327 *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
334 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
335 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
337 enccfg->g_profile = 3;
338 *img_fmt = VPX_IMG_FMT_I44416;
339 *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
353 const struct vpx_codec_iface *iface)
356 struct vpx_codec_enc_cfg enccfg;
357 struct vpx_codec_enc_cfg enccfg_alpha;
360 vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
361 #if CONFIG_LIBVPX_VP9_ENCODER
362 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(iface);
371 if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) {
373 vpx_codec_err_to_string(res));
377 #if CONFIG_LIBVPX_VP9_ENCODER
379 if (
set_pix_fmt(avctx, codec_caps, &enccfg, &flags, &img_fmt))
392 enccfg.g_w = avctx->
width;
393 enccfg.g_h = avctx->
height;
400 enccfg.g_pass = VPX_RC_FIRST_PASS;
402 enccfg.g_pass = VPX_RC_LAST_PASS;
404 enccfg.g_pass = VPX_RC_ONE_PASS;
408 enccfg.rc_end_usage = VPX_CBR;
409 }
else if (ctx->
crf >= 0) {
410 enccfg.rc_end_usage = VPX_CQ;
411 #if CONFIG_LIBVPX_VP9_ENCODER
413 enccfg.rc_end_usage = VPX_Q;
420 #if CONFIG_LIBVPX_VP9_ENCODER
421 }
else if (enccfg.rc_end_usage == VPX_Q) {
424 if (enccfg.rc_end_usage == VPX_CQ) {
425 enccfg.rc_target_bitrate = 1000000;
427 avctx->
bit_rate = enccfg.rc_target_bitrate * 1000;
429 "Neither bitrate nor constrained quality specified, using default bitrate of %dkbit/sec\n",
430 enccfg.rc_target_bitrate);
435 enccfg.rc_min_quantizer =
436 enccfg.rc_max_quantizer = 0;
438 if (avctx->
qmin >= 0)
439 enccfg.rc_min_quantizer = avctx->
qmin;
440 if (avctx->
qmax >= 0)
441 enccfg.rc_max_quantizer = avctx->
qmax;
444 if (enccfg.rc_end_usage == VPX_CQ
445 #
if CONFIG_LIBVPX_VP9_ENCODER
446 || enccfg.rc_end_usage == VPX_Q
449 if (ctx->
crf < enccfg.rc_min_quantizer || ctx->
crf > enccfg.rc_max_quantizer) {
451 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
452 ctx->
crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
462 enccfg.rc_2pass_vbr_minsection_pct =
465 enccfg.rc_2pass_vbr_maxsection_pct =
472 enccfg.rc_buf_initial_sz =
474 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
481 enccfg.kf_max_dist = avctx->
gop_size;
483 if (enccfg.g_pass == VPX_RC_FIRST_PASS)
484 enccfg.g_lag_in_frames = 0;
485 else if (enccfg.g_pass == VPX_RC_LAST_PASS) {
486 int decode_size,
ret;
504 if (decode_size < 0) {
517 enccfg.g_profile = avctx->
profile;
523 res = vpx_codec_enc_init(&ctx->
encoder, iface, &enccfg, flags);
524 if (res != VPX_CODEC_OK) {
530 enccfg_alpha = enccfg;
531 res = vpx_codec_enc_init(&ctx->
encoder_alpha, iface, &enccfg_alpha, flags);
532 if (res != VPX_CODEC_OK) {
559 "use the static-thresh private option instead.\n");
570 #if CONFIG_LIBVPX_VP9_ENCODER
590 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
592 ctx->
rawimg.bit_depth = enccfg.g_bit_depth;
609 const struct vpx_codec_cx_pkt *
src,
610 const struct vpx_codec_cx_pkt *src_alpha,
613 dst->
pts = src->data.frame.pts;
614 dst->
duration = src->data.frame.duration;
615 dst->
flags = src->data.frame.flags;
616 dst->
sz = src->data.frame.sz;
617 dst->
buf = src->data.frame.buf;
620 if (!(dst->
flags & VPX_FRAME_IS_INVISIBLE)) {
628 memcpy(dst->
sse, ctx->
sse,
sizeof(dst->
sse));
635 dst->
buf_alpha = src_alpha->data.frame.buf;
636 dst->
sz_alpha = src_alpha->data.frame.sz;
658 coded_frame->
pts = cx_frame->
pts;
670 coded_frame->
error[0] = cx_frame->
sse[1];
671 coded_frame->
error[1] = cx_frame->
sse[2];
672 coded_frame->
error[2] = cx_frame->
sse[3];
673 coded_frame->
error[3] = 0;
674 for (i = 0; i < 4; ++i) {
709 const struct vpx_codec_cx_pkt *
pkt;
710 const struct vpx_codec_cx_pkt *pkt_alpha =
NULL;
711 const void *iter =
NULL;
712 const void *iter_alpha =
NULL;
718 size =
storeframe(avctx, cx_frame, pkt_out, coded_frame);
727 while ((pkt = vpx_codec_get_cx_data(&ctx->
encoder, &iter)) &&
731 case VPX_CODEC_CX_FRAME_PKT:
738 cx_pktcpy(&cx_frame, pkt, pkt_alpha, ctx);
739 size =
storeframe(avctx, &cx_frame, pkt_out, coded_frame);
748 "Frame queue element alloc failed\n");
751 cx_pktcpy(cx_frame, pkt, pkt_alpha, ctx);
754 if (!cx_frame->
buf) {
761 memcpy(cx_frame->
buf, pkt->data.frame.buf, pkt->data.frame.sz);
771 memcpy(cx_frame->
buf_alpha, pkt_alpha->data.frame.buf, pkt_alpha->data.frame.sz);
776 case VPX_CODEC_STATS_PKT: {
781 pkt->data.twopass_stats.sz)) < 0) {
786 memcpy((
uint8_t*)stats->buf + stats->sz,
787 pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
788 stats->sz += pkt->data.twopass_stats.sz;
791 case VPX_CODEC_PSNR_PKT:
793 ctx->
sse[0] = pkt->data.psnr.sse[0];
794 ctx->
sse[1] = pkt->data.psnr.sse[1];
795 ctx->
sse[2] = pkt->data.psnr.sse[2];
796 ctx->
sse[3] = pkt->data.psnr.sse[3];
799 case VPX_CODEC_CUSTOM_PKT:
812 struct vpx_image *rawimg =
NULL;
813 struct vpx_image *rawimg_alpha =
NULL;
814 int64_t timestamp = 0;
816 vpx_enc_frame_flags_t flags = 0;
820 rawimg->planes[VPX_PLANE_Y] = frame->
data[0];
821 rawimg->planes[VPX_PLANE_U] = frame->
data[1];
822 rawimg->planes[VPX_PLANE_V] = frame->
data[2];
823 rawimg->stride[VPX_PLANE_Y] = frame->
linesize[0];
824 rawimg->stride[VPX_PLANE_U] = frame->
linesize[1];
825 rawimg->stride[VPX_PLANE_V] = frame->
linesize[2];
829 rawimg_alpha->planes[VPX_PLANE_Y] = frame->
data[3];
832 if (!u_plane || !v_plane) {
838 rawimg_alpha->planes[VPX_PLANE_U] = u_plane;
840 rawimg_alpha->planes[VPX_PLANE_V] = v_plane;
841 rawimg_alpha->stride[VPX_PLANE_Y] = frame->
linesize[0];
842 rawimg_alpha->stride[VPX_PLANE_U] = frame->
linesize[1];
843 rawimg_alpha->stride[VPX_PLANE_V] = frame->
linesize[2];
845 timestamp = frame->
pts;
847 flags |= VPX_EFLAG_FORCE_KF;
850 res = vpx_codec_encode(&ctx->
encoder, rawimg, timestamp,
852 if (res != VPX_CODEC_OK) {
858 res = vpx_codec_encode(&ctx->
encoder_alpha, rawimg_alpha, timestamp,
860 if (res != VPX_CODEC_OK) {
882 av_freep(&rawimg_alpha->planes[VPX_PLANE_U]);
883 av_freep(&rawimg_alpha->planes[VPX_PLANE_V]);
886 *got_packet = !!coded_size;
890 #define OFFSET(x) offsetof(VP8Context, x)
891 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
893 #ifndef VPX_ERROR_RESILIENT_DEFAULT
894 #define VPX_ERROR_RESILIENT_DEFAULT 1
895 #define VPX_ERROR_RESILIENT_PARTITIONS 2
898 #define COMMON_OPTIONS \
899 { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
900 { "auto-alt-ref", "Enable use of alternate reference " \
901 "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE}, \
902 { "lag-in-frames", "Number of frames to look ahead for " \
903 "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
904 { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
905 { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
906 { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "arnr_type"}, \
907 { "backward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "arnr_type" }, \
908 { "forward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "arnr_type" }, \
909 { "centered", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "arnr_type" }, \
910 { "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
911 { "best", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_BEST_QUALITY}, 0, 0, VE, "quality"}, \
912 { "good", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"}, \
913 { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_REALTIME}, 0, 0, VE, "quality"}, \
914 { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"}, \
915 { "max-intra-rate", "Maximum I-frame bitrate (pct) 0=unlimited", OFFSET(max_intra_rate), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
916 { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"}, \
917 { "partitions", "The frame partitions are independently decodable " \
918 "by the bool decoder, meaning that partitions can be decoded even " \
919 "though earlier partitions have been lost. Note that intra predicition" \
920 " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"}, \
921 { "crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \
922 { "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 }, \
924 #define LEGACY_OPTIONS \
925 {"speed", "", offsetof(VP8Context, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
926 {"quality", "", offsetof(VP8Context, deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
927 {"vp8flags", "", offsetof(VP8Context, flags), FF_OPT_TYPE_FLAGS, {.i64 = 0}, 0, UINT_MAX, VE, "flags"}, \
928 {"error_resilient", "enable error resilience", 0, FF_OPT_TYPE_CONST, {.dbl = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, "flags"}, \
929 {"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, FF_OPT_TYPE_CONST, {.dbl = VP8F_AUTO_ALT_REF}, INT_MIN, INT_MAX, VE, "flags"}, \
930 {"arnr_max_frames", "altref noise reduction max frame count", offsetof(VP8Context, arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 15, VE}, \
931 {"arnr_strength", "altref noise reduction filter strength", offsetof(VP8Context, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
932 {"arnr_type", "altref noise reduction filter type", offsetof(VP8Context, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
933 {"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.i64 = 25}, 0, 25, VE}, \
935 #if CONFIG_LIBVPX_VP8_ENCODER
936 static const AVOption vp8_options[] = {
943 #if CONFIG_LIBVPX_VP9_ENCODER
944 static const AVOption vp9_options[] = {
947 {
"tile-columns",
"Number of tile columns to use, log2",
OFFSET(tile_columns),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
948 {
"tile-rows",
"Number of tile rows to use, log2",
OFFSET(tile_rows),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2,
VE},
949 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1,
VE},
950 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3,
VE,
"aq_mode"},
952 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE,
"aq_mode" }, \
953 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE,
"aq_mode" }, \
960 #undef COMMON_OPTIONS
961 #undef LEGACY_OPTIONS
967 {
"keyint_min",
"-1" },
971 #if CONFIG_LIBVPX_VP8_ENCODER
974 return vpx_init(avctx, vpx_codec_vp8_cx());
977 static const AVClass class_vp8 = {
980 .option = vp8_options,
984 AVCodec ff_libvpx_vp8_encoder = {
995 .priv_class = &class_vp8,
1000 #if CONFIG_LIBVPX_VP9_ENCODER
1003 return vpx_init(avctx, vpx_codec_vp9_cx());
1006 static const AVClass class_vp9 = {
1009 .option = vp9_options,
1013 AVCodec ff_libvpx_vp9_encoder = {
1014 .
name =
"libvpx-vp9",
1023 .priv_class = &class_vp9,
1024 .defaults = defaults,
struct vpx_image rawimg_alpha
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
const char const char void * val
planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_free_packet(AVPacket *pkt)
Free a packet.
This structure describes decoded (raw) audio or video data.
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
struct vpx_codec_ctx encoder
uint64_t error[AV_NUM_DATA_POINTERS]
error
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
AVFrame * coded_frame
the picture in the bitstream
static av_cold int init(AVCodecContext *avctx)
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
size_t sz
length of compressed data
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
struct vpx_codec_ctx encoder_alpha
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define VP8F_AUTO_ALT_REF
Enable automatic alternate reference frame generation.
#define CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
attribute_deprecated float rc_buffer_aggressivity
static av_cold int codecctl_int(AVCodecContext *avctx, enum vp8e_enc_control_id id, int val)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int64_t pts
time stamp to show frame (in timebase units)
static void coded_frame_add(void *list, struct FrameListData *cx_frame)
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
#define FF_PROFILE_UNKNOWN
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static av_cold void init_static_data(void)
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define AV_LOG_VERBOSE
Detailed information.
char * stats_out
pass1 encoding statistics output buffer
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int frame_skip_threshold
frame skip threshold
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int qmax
maximum quantizer
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Round to nearest and halfway cases away from zero.
int rc_max_rate
maximum bitrate
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
static av_always_inline av_const double round(double x)
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
Libavcodec external API header.
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int rc_buffer_size
decoder bitstream buffer size
static void cx_pktcpy(struct FrameListData *dst, const struct vpx_codec_cx_pkt *src, const struct vpx_codec_cx_pkt *src_alpha, VP8Context *ctx)
static av_cold void dump_enc_cfg(AVCodecContext *avctx, const struct vpx_codec_enc_cfg *cfg)
int bit_rate
the average bitrate
enum AVPictureType pict_type
Picture type of the frame.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
int width
picture width / height.
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
static av_cold int vp8_free(AVCodecContext *avctx)
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
attribute_deprecated int mb_threshold
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
struct FrameListData * next
#define VP8F_ERROR_RESILIENT
Enable measures appropriate for streaming over lossy links.
static av_cold int vpx_init(AVCodecContext *avctx, const struct vpx_codec_iface *iface)
int flags
VP8 specific flags, see VP8F_* below.
static const AVCodecDefault defaults[]
#define AV_LOG_INFO
Standard information.
uint64_t error[AV_NUM_DATA_POINTERS]
error
av_cold void ff_vp9_init_static(AVCodec *codec)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_cold int vp9_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
main external API structure.
int qmin
minimum quantizer
static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, AVPacket *pkt, AVFrame *coded_frame)
Store coded frame information in format suitable for return from encode2().
planar YUV 4:4:0,24bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian
Data found in BlockAdditional element of matroska container.
Describe the class of an AVClass context structure.
uint32_t flags
flags for this frame
static av_cold void free_coded_frame(struct FrameListData *cx_frame)
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
static int set_pix_fmt(AVCodecContext *avctx, struct vpx_image *img)
static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
void * buf
compressed data buffer
int have_sse
true if we have pending sse[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int noise_reduction
noise reduction strength
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
static const char *const ctlidstr[]
String mappings for enum vp8e_enc_control_id.
struct vpx_fixed_buf twopass_stats
static av_cold int vp8_init(AVFormatContext *s, int st_index, PayloadContext *vp8)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
common internal and external API header
static av_cold void free_frame_list(struct FrameListData *list)
int slices
Number of slices.
#define FF_ENABLE_DEPRECATION_WARNINGS
Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
int key_frame
1 -> keyframe, 0-> not
unsigned long duration
duration to show frame (in timebase units)
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
int have_sse
true if we have pending sse[]
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out, AVFrame *coded_frame)
Queue multiple output frames from the encoder, returning the front-most.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
int rc_min_rate
minimum bitrate
AVPixelFormat
Pixel format.
This structure stores compressed data.
struct FrameListData * coded_frame_list
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int keyint_min
minimum GOP size