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>
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)
80typedef struct VPxEncoderContext {
101#define VP8F_ERROR_RESILIENT 0x00000001
102#define VP8F_AUTO_ALT_REF 0x00000002
150#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
151 vpx_svc_ref_frame_config_t ref_frame_config;
157 [VP8E_SET_CPUUSED] =
"VP8E_SET_CPUUSED",
158 [VP8E_SET_ENABLEAUTOALTREF] =
"VP8E_SET_ENABLEAUTOALTREF",
159 [VP8E_SET_NOISE_SENSITIVITY] =
"VP8E_SET_NOISE_SENSITIVITY",
160 [VP8E_SET_STATIC_THRESHOLD] =
"VP8E_SET_STATIC_THRESHOLD",
161 [VP8E_SET_TOKEN_PARTITIONS] =
"VP8E_SET_TOKEN_PARTITIONS",
162 [VP8E_SET_ARNR_MAXFRAMES] =
"VP8E_SET_ARNR_MAXFRAMES",
163 [VP8E_SET_ARNR_STRENGTH] =
"VP8E_SET_ARNR_STRENGTH",
164 [VP8E_SET_ARNR_TYPE] =
"VP8E_SET_ARNR_TYPE",
165 [VP8E_SET_TUNING] =
"VP8E_SET_TUNING",
166 [VP8E_SET_CQ_LEVEL] =
"VP8E_SET_CQ_LEVEL",
167 [VP8E_SET_MAX_INTRA_BITRATE_PCT] =
"VP8E_SET_MAX_INTRA_BITRATE_PCT",
168 [VP8E_SET_SHARPNESS] =
"VP8E_SET_SHARPNESS",
169 [VP8E_SET_TEMPORAL_LAYER_ID] =
"VP8E_SET_TEMPORAL_LAYER_ID",
170 [VP8E_SET_SCREEN_CONTENT_MODE] =
"VP8E_SET_SCREEN_CONTENT_MODE",
171#if CONFIG_LIBVPX_VP9_ENCODER
172 [VP9E_SET_LOSSLESS] =
"VP9E_SET_LOSSLESS",
173 [VP9E_SET_TILE_COLUMNS] =
"VP9E_SET_TILE_COLUMNS",
174 [VP9E_SET_TILE_ROWS] =
"VP9E_SET_TILE_ROWS",
175 [VP9E_SET_FRAME_PARALLEL_DECODING] =
"VP9E_SET_FRAME_PARALLEL_DECODING",
176 [VP9E_SET_AQ_MODE] =
"VP9E_SET_AQ_MODE",
177 [VP9E_SET_COLOR_SPACE] =
"VP9E_SET_COLOR_SPACE",
178 [VP9E_SET_SVC_LAYER_ID] =
"VP9E_SET_SVC_LAYER_ID",
179#if VPX_ENCODER_ABI_VERSION >= 12
180 [VP9E_SET_SVC_PARAMETERS] =
"VP9E_SET_SVC_PARAMETERS",
181 [VP9E_SET_SVC_REF_FRAME_CONFIG] =
"VP9E_SET_SVC_REF_FRAME_CONFIG",
183 [VP9E_SET_SVC] =
"VP9E_SET_SVC",
184#if VPX_ENCODER_ABI_VERSION >= 11
185 [VP9E_SET_COLOR_RANGE] =
"VP9E_SET_COLOR_RANGE",
187#if VPX_ENCODER_ABI_VERSION >= 12
188 [VP9E_SET_TARGET_LEVEL] =
"VP9E_SET_TARGET_LEVEL",
189 [VP9E_GET_LEVEL] =
"VP9E_GET_LEVEL",
191#ifdef VPX_CTRL_VP9E_SET_ROW_MT
192 [VP9E_SET_ROW_MT] =
"VP9E_SET_ROW_MT",
194#ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
195 [VP9E_SET_TUNE_CONTENT] =
"VP9E_SET_TUNE_CONTENT",
197#ifdef VPX_CTRL_VP9E_SET_TPL
198 [VP9E_SET_TPL] =
"VP9E_SET_TPL",
200#ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
201 [VP9E_SET_MIN_GF_INTERVAL] =
"VP9E_SET_MIN_GF_INTERVAL",
208 const char *
error = vpx_codec_error(encoder);
209 const char *detail = vpx_codec_error_detail(encoder);
217 const struct vpx_codec_enc_cfg *
cfg,
225 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
226#
if CONFIG_LIBVPX_VP9_ENCODER
229 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
231 width,
"g_threads:",
cfg->g_threads,
232 width,
"g_profile:",
cfg->g_profile,
235#
if CONFIG_LIBVPX_VP9_ENCODER
236 width,
"g_bit_depth:",
cfg->g_bit_depth,
237 width,
"g_input_bit_depth:",
cfg->g_input_bit_depth,
239 width,
"g_timebase:",
cfg->g_timebase.num,
cfg->g_timebase.den,
240 width,
"g_error_resilient:",
cfg->g_error_resilient,
242 width,
"g_lag_in_frames:",
cfg->g_lag_in_frames);
244 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
245 " %*s%d\n %*s%p(%zu)\n %*s%u\n",
246 width,
"rc_dropframe_thresh:",
cfg->rc_dropframe_thresh,
247 width,
"rc_resize_allowed:",
cfg->rc_resize_allowed,
248 width,
"rc_resize_up_thresh:",
cfg->rc_resize_up_thresh,
249 width,
"rc_resize_down_thresh:",
cfg->rc_resize_down_thresh,
250 width,
"rc_end_usage:",
cfg->rc_end_usage,
251 width,
"rc_twopass_stats_in:",
cfg->rc_twopass_stats_in.buf,
cfg->rc_twopass_stats_in.sz,
252 width,
"rc_target_bitrate:",
cfg->rc_target_bitrate);
255 width,
"rc_min_quantizer:",
cfg->rc_min_quantizer,
256 width,
"rc_max_quantizer:",
cfg->rc_max_quantizer);
259 width,
"rc_undershoot_pct:",
cfg->rc_undershoot_pct,
260 width,
"rc_overshoot_pct:",
cfg->rc_overshoot_pct);
261 av_log(avctx,
level,
"temporal layering settings\n"
262 " %*s%u\n",
width,
"ts_number_layers:",
cfg->ts_number_layers);
265 "\n %*s",
width,
"ts_target_bitrate:");
266 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
268 "%u ",
cfg->ts_target_bitrate[
i]);
270#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
273 "\n %*s",
width,
"layer_target_bitrate:");
274 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
276 "%u ",
cfg->layer_target_bitrate[
i]);
281 "\n %*s",
width,
"ts_rate_decimator:");
282 for (
i = 0;
i < VPX_TS_MAX_LAYERS;
i++)
286 "\n %*s%u\n",
width,
"ts_periodicity:",
cfg->ts_periodicity);
288 "\n %*s",
width,
"ts_layer_id:");
289 for (
i = 0;
i < VPX_TS_MAX_PERIODICITY;
i++)
293 " %*s%u\n %*s%u\n %*s%u\n",
294 width,
"rc_buf_sz:",
cfg->rc_buf_sz,
295 width,
"rc_buf_initial_sz:",
cfg->rc_buf_initial_sz,
296 width,
"rc_buf_optimal_sz:",
cfg->rc_buf_optimal_sz);
297 av_log(avctx,
level,
"2 pass rate control settings\n"
298 " %*s%u\n %*s%u\n %*s%u\n",
299 width,
"rc_2pass_vbr_bias_pct:",
cfg->rc_2pass_vbr_bias_pct,
300 width,
"rc_2pass_vbr_minsection_pct:",
cfg->rc_2pass_vbr_minsection_pct,
301 width,
"rc_2pass_vbr_maxsection_pct:",
cfg->rc_2pass_vbr_maxsection_pct);
302#if VPX_ENCODER_ABI_VERSION >= 14
304 width,
"rc_2pass_vbr_corpus_complexity:",
cfg->rc_2pass_vbr_corpus_complexity);
307 " %*s%d\n %*s%u\n %*s%u\n",
309 width,
"kf_min_dist:",
cfg->kf_min_dist,
310 width,
"kf_max_dist:",
cfg->kf_max_dist);
360 return (
ctx->drop_threshold > 0) || (
ctx->screen_content_mode == 2);
367 const struct vpx_codec_enc_cfg *enccfg =
ctx->encoder.config.enc;
440 "Mismatching timestamps: libvpx %"PRId64
" queued %"PRId64
"; "
441 "this is a bug, please report it\n",
pkt->pts, fd.
pts);
486 enum vp8e_enc_control_id
id,
int val)
496 res = vpx_codec_control(&
ctx->encoder,
id,
val);
497 if (res != VPX_CODEC_OK) {
498 snprintf(buf,
sizeof(buf),
"Failed to set %s codec control",
504 if (
ctx->is_alpha &&
id != VP9E_SET_COLOR_SPACE) {
505 int res_alpha = vpx_codec_control(&
ctx->encoder_alpha,
id,
val);
506 if (res_alpha != VPX_CODEC_OK) {
507 snprintf(buf,
sizeof(buf),
"Failed to set %s alpha codec control",
517#if VPX_ENCODER_ABI_VERSION >= 12
519 enum vp8e_enc_control_id
id,
int *
val)
529 res = vpx_codec_control(&
ctx->encoder,
id,
val);
530 if (res != VPX_CODEC_OK) {
531 snprintf(buf,
sizeof(buf),
"Failed to set %s codec control",
538 int res_alpha = vpx_codec_control(&
ctx->encoder_alpha,
id,
val);
539 if (res_alpha != VPX_CODEC_OK) {
540 snprintf(buf,
sizeof(buf),
"Failed to set %s alpha codec control",
555#if VPX_ENCODER_ABI_VERSION >= 12
559 if (!codecctl_intp(avctx, VP9E_GET_LEVEL, &level_out))
566 vpx_codec_destroy(&
ctx->encoder);
568 vpx_codec_destroy(&
ctx->encoder_alpha);
584 char *saveptr =
NULL;
587 while (token && dest_idx < max_entries) {
588 dest[dest_idx++] = strtoul(token,
NULL, 10);
593#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
594static void vp8_ts_parse_int64_array(
int64_t *dest,
char *
value,
size_t value_len,
int max_entries)
597 char *saveptr =
NULL;
600 while (token && dest_idx < max_entries) {
601 dest[dest_idx++] = strtoull(token,
NULL, 10);
608 int *layer_flags,
int *flag_periodicity)
610 switch (layering_mode) {
615 static const int ids[2] = { 0, 1 };
616 cfg->ts_periodicity = 2;
617 *flag_periodicity = 2;
618 cfg->ts_number_layers = 2;
619 cfg->ts_rate_decimator[0] = 2;
620 cfg->ts_rate_decimator[1] = 1;
621 memcpy(
cfg->ts_layer_id, ids,
sizeof(ids));
624 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
625 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
627 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF |
628 VP8_EFLAG_NO_UPD_LAST |
629 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF;
639 static const int ids[4] = { 0, 2, 1, 2 };
640 cfg->ts_periodicity = 4;
641 *flag_periodicity = 4;
642 cfg->ts_number_layers = 3;
643 cfg->ts_rate_decimator[0] = 4;
644 cfg->ts_rate_decimator[1] = 2;
645 cfg->ts_rate_decimator[2] = 1;
646 memcpy(
cfg->ts_layer_id, ids,
sizeof(ids));
653 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
654 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
656 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
657 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
658 VP8_EFLAG_NO_UPD_ARF;
660 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
661 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
663 VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_ARF |
664 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
665 VP8_EFLAG_NO_UPD_ARF;
674 static const int ids[4] = { 0, 2, 1, 2 };
675 cfg->ts_periodicity = 4;
676 *flag_periodicity = 4;
677 cfg->ts_number_layers = 3;
678 cfg->ts_rate_decimator[0] = 4;
679 cfg->ts_rate_decimator[1] = 2;
680 cfg->ts_rate_decimator[2] = 1;
681 memcpy(
cfg->ts_layer_id, ids,
sizeof(ids));
687 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
688 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
690 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
691 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF;
693 VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
694 VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
696 VP8_EFLAG_NO_REF_LAST |
697 VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
698 VP8_EFLAG_NO_UPD_ARF;
714 size_t value_len = strlen(
value);
715 int ts_layering_mode = 0;
720 if (!strcmp(
key,
"ts_number_layers"))
721 enccfg->ts_number_layers = strtoul(
value, &
value, 10);
722 else if (!strcmp(
key,
"ts_target_bitrate")) {
725#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
729 }
else if (!strcmp(
key,
"ts_rate_decimator")) {
731 }
else if (!strcmp(
key,
"ts_periodicity")) {
732 enccfg->ts_periodicity = strtoul(
value, &
value, 10);
733 }
else if (!strcmp(
key,
"ts_layer_id")) {
735 }
else if (!strcmp(
key,
"ts_layering_mode")) {
737 ts_layering_mode = strtoul(
value, &
value, 10);
740#if (VPX_ENCODER_ABI_VERSION >= 12) && CONFIG_LIBVPX_VP9_ENCODER
741 enccfg->temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_BYPASS;
742 enccfg->ss_number_layers = 1;
744 if (ts_layering_mode) {
754#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
755static int vpx_ref_frame_config_set_value(vpx_svc_ref_frame_config_t *ref_frame_config,
756 int ss_number_layers,
char *
key,
char *
value)
758 size_t value_len = strlen(
value);
763 if (!strcmp(
key,
"rfc_update_buffer_slot")) {
765 }
else if (!strcmp(
key,
"rfc_update_last")) {
767 }
else if (!strcmp(
key,
"rfc_update_golden")) {
769 }
else if (!strcmp(
key,
"rfc_update_alt_ref")) {
771 }
else if (!strcmp(
key,
"rfc_lst_fb_idx")) {
773 }
else if (!strcmp(
key,
"rfc_gld_fb_idx")) {
775 }
else if (!strcmp(
key,
"rfc_alt_fb_idx")) {
777 }
else if (!strcmp(
key,
"rfc_reference_last")) {
779 }
else if (!strcmp(
key,
"rfc_reference_golden")) {
781 }
else if (!strcmp(
key,
"rfc_reference_alt_ref")) {
783 }
else if (!strcmp(
key,
"rfc_reference_duration")) {
784 vp8_ts_parse_int64_array(ref_frame_config->duration,
value, value_len, ss_number_layers);
790static int vpx_parse_ref_frame_config_element(vpx_svc_ref_frame_config_t *ref_frame_config,
791 int ss_number_layers,
const char **buf)
793 const char key_val_sep[] =
"=";
794 const char pairs_sep[] =
":";
799 if (
key && *
key && strspn(*buf, key_val_sep)) {
805 ret = vpx_ref_frame_config_set_value(ref_frame_config, ss_number_layers,
key,
val);
815static int vpx_parse_ref_frame_config(vpx_svc_ref_frame_config_t *ref_frame_config,
816 int ss_number_layers,
const char *str)
822 vpx_parse_ref_frame_config_element(ref_frame_config, ss_number_layers, &str);
834#if CONFIG_LIBVPX_VP9_ENCODER
836 struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *
flags,
837 vpx_img_fmt_t *img_fmt)
841 enccfg->g_bit_depth = enccfg->g_input_bit_depth =
desc->comp[0].depth;
845 enccfg->g_profile = 0;
846 *img_fmt = VPX_IMG_FMT_I420;
850 enccfg->g_profile = 1;
851 *img_fmt = VPX_IMG_FMT_I422;
854 enccfg->g_profile = 1;
855 *img_fmt = VPX_IMG_FMT_I440;
859 ctx->vpx_cs = VPX_CS_SRGB;
864 ctx->vpx_cs = VPX_CS_SRGB;
865 enccfg->g_profile = 1;
866 *img_fmt = VPX_IMG_FMT_I444;
871 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
872 enccfg->g_profile = 2;
873 *img_fmt = VPX_IMG_FMT_I42016;
874 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
881 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
882 enccfg->g_profile = 3;
883 *img_fmt = VPX_IMG_FMT_I42216;
884 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
890 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
891 enccfg->g_profile = 3;
892 *img_fmt = VPX_IMG_FMT_I44016;
893 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
901 ctx->vpx_cs = VPX_CS_SRGB;
908 ctx->vpx_cs = VPX_CS_SRGB;
909 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
910 enccfg->g_profile = 3;
911 *img_fmt = VPX_IMG_FMT_I44416;
912 *
flags |= VPX_CODEC_USE_HIGHBITDEPTH;
925 enum vpx_color_space vpx_cs;
929 vpx_cs =
ctx->vpx_cs;
934 "RGB colorspace is not compatible with pixel format %s.\n",
954#if VPX_ENCODER_ABI_VERSION >= 11
957 enum vpx_color_range vpx_cr;
977 struct vpx_codec_enc_cfg *enccfg)
981 avctx->
bit_rate = enccfg->rc_target_bitrate * 1000;
982 if (enccfg->rc_end_usage == VPX_CQ) {
984 "Bitrate not specified for constrained quality mode, using default of %dkbit/sec\n",
985 enccfg->rc_target_bitrate);
987 enccfg->rc_end_usage = VPX_CQ;
990 "Neither bitrate nor constrained quality specified, using default CRF of %d and bitrate of %dkbit/sec\n",
991 ctx->crf, enccfg->rc_target_bitrate);
996#if CONFIG_LIBVPX_VP9_ENCODER
1002 struct vpx_codec_enc_cfg *enccfg)
1006 if (enccfg->rc_end_usage != VPX_Q &&
ctx->lossless < 0) {
1007 enccfg->rc_end_usage = VPX_Q;
1010 "Neither bitrate nor constrained quality specified, using default CRF of %d\n",
1021 struct vpx_codec_enc_cfg *enccfg)
1024#if CONFIG_LIBVPX_VP9_ENCODER
1026 set_vp9_defaults(avctx, enccfg);
1034 const struct vpx_codec_iface *iface)
1037 struct vpx_codec_enc_cfg enccfg = { 0 };
1038 struct vpx_codec_enc_cfg enccfg_alpha;
1042 vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
1043#if CONFIG_LIBVPX_VP9_ENCODER
1044 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(iface);
1045 vpx_svc_extra_cfg_t svc_params;
1057 "Pixel format '%s' is not widely supported. "
1058 "Use -strict experimental to use it anyway, or use 'yuva420p' pixel format instead.\n",
1064 if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) {
1066 vpx_codec_err_to_string(res));
1074#if CONFIG_LIBVPX_VP9_ENCODER
1089 enccfg.g_w = avctx->
width;
1090 enccfg.g_h = avctx->
height;
1095 enccfg.g_lag_in_frames=
ctx->lag_in_frames;
1098 enccfg.g_pass = VPX_RC_FIRST_PASS;
1100 enccfg.g_pass = VPX_RC_LAST_PASS;
1102 enccfg.g_pass = VPX_RC_ONE_PASS;
1106 enccfg.rc_end_usage = VPX_CBR;
1107 }
else if (
ctx->crf >= 0) {
1108 enccfg.rc_end_usage = VPX_CQ;
1109#if CONFIG_LIBVPX_VP9_ENCODER
1111 enccfg.rc_end_usage = VPX_Q;
1118#if CONFIG_LIBVPX_VP9_ENCODER
1119 enccfg.ss_target_bitrate[0] = enccfg.rc_target_bitrate;
1127 enccfg.rc_min_quantizer =
1128 enccfg.rc_max_quantizer = 0;
1130 if (avctx->
qmin >= 0)
1131 enccfg.rc_min_quantizer = avctx->
qmin;
1132 if (avctx->
qmax >= 0)
1133 enccfg.rc_max_quantizer = avctx->
qmax;
1136 if (enccfg.rc_end_usage == VPX_CQ
1137#
if CONFIG_LIBVPX_VP9_ENCODER
1138 || enccfg.rc_end_usage == VPX_Q
1141 if (
ctx->crf < enccfg.rc_min_quantizer ||
ctx->crf > enccfg.rc_max_quantizer) {
1143 "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
1144 ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
1149 enccfg.rc_dropframe_thresh =
ctx->drop_threshold;
1154 enccfg.rc_2pass_vbr_minsection_pct =
1157 enccfg.rc_2pass_vbr_maxsection_pct =
1159#if CONFIG_LIBVPX_VP9_ENCODER
1161#if VPX_ENCODER_ABI_VERSION >= 14
1162 if (
ctx->corpus_complexity >= 0)
1163 enccfg.rc_2pass_vbr_corpus_complexity =
ctx->corpus_complexity;
1172 enccfg.rc_buf_initial_sz =
1174 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
1175 if (
ctx->rc_undershoot_pct >= 0)
1176 enccfg.rc_undershoot_pct =
ctx->rc_undershoot_pct;
1177 if (
ctx->rc_overshoot_pct >= 0)
1178 enccfg.rc_overshoot_pct =
ctx->rc_overshoot_pct;
1184 enccfg.kf_max_dist = avctx->
gop_size;
1186 if (enccfg.g_pass == VPX_RC_FIRST_PASS)
1187 enccfg.g_lag_in_frames = 0;
1188 else if (enccfg.g_pass == VPX_RC_LAST_PASS) {
1189 int decode_size, ret;
1196 ctx->twopass_stats.sz = strlen(avctx->
stats_in) * 3 / 4;
1200 "Stat buffer alloc (%zu bytes) failed\n",
1201 ctx->twopass_stats.sz);
1202 ctx->twopass_stats.sz = 0;
1206 ctx->twopass_stats.sz);
1207 if (decode_size < 0) {
1212 ctx->twopass_stats.sz = decode_size;
1213 enccfg.rc_twopass_stats_in =
ctx->twopass_stats;
1220 enccfg.g_profile = avctx->
profile;
1227 "Error parsing option '%s = %s'.\n",
1232 res = vpx_codec_enc_init(&
ctx->encoder, iface, &enccfg,
flags);
1233 if (res != VPX_CODEC_OK) {
1240#if CONFIG_LIBVPX_VP9_ENCODER
1242 memset(&svc_params, 0,
sizeof(svc_params));
1243 for (
int i = 0;
i < enccfg.ts_number_layers; ++
i) {
1244 svc_params.max_quantizers[
i] = enccfg.rc_max_quantizer;
1245 svc_params.min_quantizers[
i] = enccfg.rc_min_quantizer;
1247 svc_params.scaling_factor_num[0] = enccfg.g_h;
1248 svc_params.scaling_factor_den[0] = enccfg.g_h;
1249#if VPX_ENCODER_ABI_VERSION >= 12
1251 codecctl_intp(avctx, VP9E_SET_SVC_PARAMETERS, (
int *)&svc_params);
1255 if (
ctx->is_alpha) {
1256 enccfg_alpha = enccfg;
1257 enccfg_alpha.g_profile = (
flags & VPX_CODEC_USE_HIGHBITDEPTH) ? 2 : 0;
1258 res = vpx_codec_enc_init(&
ctx->encoder_alpha, iface, &enccfg_alpha,
flags);
1259 if (res != VPX_CODEC_OK) {
1269 ctx->auto_alt_ref = 1;
1270 if (
ctx->auto_alt_ref >= 0)
1273 if (
ctx->arnr_max_frames >= 0)
1275 if (
ctx->arnr_strength >= 0)
1277 if (
ctx->arnr_type >= 0)
1283 av_log(avctx,
AV_LOG_ERROR,
"Transparency encoding with auto_alt_ref does not work\n");
1287 if (
ctx->sharpness >= 0)
1291 codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY,
ctx->noise_sensitivity);
1297 if (
ctx->max_intra_rate >= 0)
1298 codecctl_int(avctx, VP8E_SET_MAX_INTRA_BITRATE_PCT,
ctx->max_intra_rate);
1300#if CONFIG_LIBVPX_VP9_ENCODER
1302 if (
ctx->lossless >= 0)
1304 if (
ctx->tile_columns >= 0)
1306 if (
ctx->tile_rows >= 0)
1308 if (
ctx->frame_parallel >= 0)
1309 codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING,
ctx->frame_parallel);
1310 if (
ctx->aq_mode >= 0)
1312 res = set_colorspace(avctx);
1315#if VPX_ENCODER_ABI_VERSION >= 11
1318#if VPX_ENCODER_ABI_VERSION >= 12
1321#ifdef VPX_CTRL_VP9E_SET_ROW_MT
1322 if (
ctx->row_mt >= 0)
1325#ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
1326 if (
ctx->tune_content >= 0)
1329#ifdef VPX_CTRL_VP9E_SET_TPL
1330 if (
ctx->tpl_model >= 0)
1333#ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
1334 if (
ctx->min_gf_interval >= 0)
1340 if (
ctx->screen_content_mode == 2 &&
ctx->is_alpha) {
1342 "Transparency encoding with screen mode with aggressive rate control not supported\n");
1345 codecctl_int(avctx, VP8E_SET_SCREEN_CONTENT_MODE,
ctx->screen_content_mode);
1351 vpx_img_wrap(&
ctx->rawimg, img_fmt, avctx->
width, avctx->
height, 1,
1353#if CONFIG_LIBVPX_VP9_ENCODER
1355 ctx->rawimg.bit_depth = enccfg.g_bit_depth;
1362 if (enccfg.rc_end_usage == VPX_CBR ||
1363 enccfg.g_pass != VPX_RC_ONE_PASS) {
1374 const struct vpx_codec_cx_pkt *
src,
1377 dst->pts =
src->data.frame.pts;
1378 dst->flags =
src->data.frame.flags;
1379 dst->sz =
src->data.frame.sz;
1380 dst->buf =
src->data.frame.buf;
1383 if (!(
dst->flags & VPX_FRAME_IS_INVISIBLE)) {
1384 dst->have_sse =
ctx->have_sse;
1385 if (
ctx->have_sse) {
1390 memcpy(
dst->sse,
ctx->sse,
sizeof(
dst->sse));
1415 memcpy(
pkt->data, cx_frame->
buf,
pkt->size);
1418 if (!!(cx_frame->
flags & VPX_FRAME_IS_KEY)) {
1425 ret = vpx_codec_control(&
ctx->encoder, VP8E_GET_LAST_QUANTIZER_64, &
quality);
1426 if (ret != VPX_CODEC_OK)
1429 cx_frame->
have_sse ? 3 : 0, pict_type);
1433 for (
int i = 0;
i < 3; ++
i)
1437 if (alpha_cx_frame) {
1440 alpha_cx_frame->
sz + 8);
1446 memcpy(side_data + 8, alpha_cx_frame->
buf, alpha_cx_frame->
sz);
1467 const struct vpx_codec_cx_pkt *
pkt;
1468 const void *iter =
NULL;
1471 if (!
ctx->is_alpha && *frame_list) {
1477 *frame_list = cx_frame->
next;
1483 while (
pkt = vpx_codec_get_cx_data(encoder, &iter)) {
1484 switch (
pkt->kind) {
1485 case VPX_CODEC_CX_FRAME_PKT:
1486 if (!
ctx->is_alpha && !
size) {
1501 "Frame queue element alloc failed\n");
1507 if (!cx_frame->
buf) {
1509 "Data buffer alloc (%zu bytes) failed\n",
1514 memcpy(cx_frame->
buf,
pkt->data.frame.buf,
pkt->data.frame.sz);
1518 case VPX_CODEC_STATS_PKT: {
1519 struct vpx_fixed_buf *
stats = &
ctx->twopass_stats;
1524 &
ctx->twopass_stats_size,
1526 pkt->data.twopass_stats.sz);
1535 pkt->data.twopass_stats.buf,
pkt->data.twopass_stats.sz);
1536 stats->sz +=
pkt->data.twopass_stats.sz;
1539 case VPX_CODEC_PSNR_PKT:
1543 ctx->sse[0] =
pkt->data.psnr.sse[0];
1544 ctx->sse[1] =
pkt->data.psnr.sse[1];
1545 ctx->sse[2] =
pkt->data.psnr.sse[2];
1546 ctx->sse[3] =
pkt->data.psnr.sse[3];
1549 case VPX_CODEC_CUSTOM_PKT:
1559 vpx_roi_map_t *roi_map,
int block_size,
int segment_cnt)
1564#define MAX_DELTA_Q 63
1579 memset(roi_map, 0,
sizeof(*roi_map));
1590 if (!self_size || sd->
size % self_size) {
1594 nb_rois = sd->
size / self_size;
1600 for (
int i = 0;
i < nb_rois;
i++) {
1614 if (!segment_mapping[mapping_index]) {
1615 if (segment_id == segment_cnt) {
1617 "ROI only supports %d segments (and segment 0 is reserved for non-ROIs), skipping the left ones.\n",
1622 segment_mapping[mapping_index] = segment_id + 1;
1623 roi_map->delta_q[segment_id] =
delta_q;
1628 roi_map->rows = (frame_height + block_size - 1) / block_size;
1629 roi_map->cols = (frame_width + block_size - 1) / block_size;
1630 roi_map->roi_map =
av_calloc(roi_map->rows * roi_map->cols,
sizeof(*roi_map->roi_map));
1631 if (!roi_map->roi_map) {
1639 for (
int i = nb_rois - 1;
i >= 0;
i--) {
1642 int starty, endy, startx, endx;
1646 starty =
av_clip(roi->
top / block_size, 0, roi_map->rows);
1647 endy =
av_clip((roi->
bottom + block_size - 1) / block_size, 0, roi_map->rows);
1648 startx =
av_clip(roi->
left / block_size, 0, roi_map->cols);
1649 endx =
av_clip((roi->
right + block_size - 1) / block_size, 0, roi_map->cols);
1655 if (mapping_value) {
1656 for (
int y = starty; y < endy; y++)
1657 for (
int x = startx; x < endx; x++)
1658 roi_map->roi_map[x + y * roi_map->cols] = mapping_value - 1;
1669#ifdef VPX_CTRL_VP9E_SET_ROI_MAP
1670 int version = vpx_codec_version();
1671 int major = VPX_VERSION_MAJOR(
version);
1672 int minor = VPX_VERSION_MINOR(
version);
1673 int patch = VPX_VERSION_PATCH(
version);
1675 if (major > 1 || (major == 1 && minor > 8) || (major == 1 && minor == 8 && patch >= 1)) {
1676 vpx_roi_map_t roi_map;
1677 const int segment_cnt = 8;
1678 const int block_size = 8;
1681 if (
ctx->aq_mode > 0 ||
ctx->cpu_used < 5 ||
ctx->deadline != VPX_DL_REALTIME) {
1682 if (!
ctx->roi_warned) {
1683 ctx->roi_warned = 1;
1685 "and deadline is REALTIME, so skipping ROI.\n");
1690 ret =
set_roi_map(avctx, sd, frame_width, frame_height, &roi_map, block_size, segment_cnt);
1696 memset(roi_map.ref_frame, -1,
sizeof(roi_map.ref_frame));
1698 if (vpx_codec_control(&
ctx->encoder, VP9E_SET_ROI_MAP, &roi_map)) {
1707 if (!
ctx->roi_warned) {
1708 ctx->roi_warned = 1;
1709 av_log(avctx,
AV_LOG_WARNING,
"ROI is not supported, please upgrade libvpx to version >= 1.8.1. "
1710 "You may need to rebuild ffmpeg.\n");
1717 vpx_roi_map_t roi_map;
1718 const int segment_cnt = 4;
1719 const int block_size = 16;
1722 int ret =
set_roi_map(avctx, sd, frame_width, frame_height, &roi_map, block_size, segment_cnt);
1728 if (vpx_codec_control(&
ctx->encoder, VP8E_SET_ROI_MAP, &roi_map)) {
1740 struct vpx_image *rawimg_alpha = &
ctx->rawimg_alpha;
1741 unsigned char **
planes = rawimg_alpha->planes;
1742 int *
stride = rawimg_alpha->stride;
1744 if (!
planes[VPX_PLANE_U] ||
1746 width != (
int)rawimg_alpha->d_w ||
1747 height != (
int)rawimg_alpha->d_h) {
1748 vpx_img_fmt_t alpha_fmt =
ctx->rawimg.bit_depth > 8 ?
1749 VPX_IMG_FMT_I42016 : VPX_IMG_FMT_I420;
1753 vpx_img_wrap(rawimg_alpha, alpha_fmt,
width,
height, 1,
1760 if (
ctx->rawimg.bit_depth > 8) {
1761 int val = 0x80 << (
ctx->rawimg.bit_depth - 8);
1779 struct vpx_image *rawimg =
NULL;
1780 struct vpx_image *rawimg_alpha =
NULL;
1782 int res, coded_size;
1783 vpx_enc_frame_flags_t
flags = 0;
1784 const struct vpx_codec_enc_cfg *enccfg =
ctx->encoder.config.enc;
1785 vpx_svc_layer_id_t layer_id;
1786 int layer_id_valid = 0;
1789 if (avctx->
qmax >= 0 && enccfg->rc_max_quantizer != avctx->
qmax) {
1790 struct vpx_codec_enc_cfg
cfg = *enccfg;
1791 cfg.rc_max_quantizer = avctx->
qmax;
1792 res = vpx_codec_enc_config_set(&
ctx->encoder, &
cfg);
1793 if (res != VPX_CODEC_OK) {
1801 rawimg = &
ctx->rawimg;
1802 rawimg->planes[VPX_PLANE_Y] =
frame->data[0];
1803 rawimg->planes[VPX_PLANE_U] =
frame->data[1];
1804 rawimg->planes[VPX_PLANE_V] =
frame->data[2];
1805 rawimg->stride[VPX_PLANE_Y] =
frame->linesize[0];
1806 rawimg->stride[VPX_PLANE_U] =
frame->linesize[1];
1807 rawimg->stride[VPX_PLANE_V] =
frame->linesize[2];
1808 if (
ctx->is_alpha) {
1809 rawimg_alpha = &
ctx->rawimg_alpha;
1813 rawimg_alpha->planes[VPX_PLANE_Y] =
frame->data[3];
1814 rawimg_alpha->stride[VPX_PLANE_Y] =
frame->linesize[3];
1816 timestamp =
frame->pts;
1817#if VPX_IMAGE_ABI_VERSION >= 4
1818 switch (
frame->color_range) {
1820 rawimg->range = VPX_CR_STUDIO_RANGE;
1823 rawimg->range = VPX_CR_FULL_RANGE;
1828 flags |= VPX_EFLAG_FORCE_KF;
1829 if (
frame->metadata) {
1835 memset(&layer_id, 0,
sizeof(layer_id));
1839 layer_id.temporal_layer_id = strtoul(en->
value,
NULL, 10);
1840#ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT
1841 layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id;
1845#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT)
1850 int ret = vpx_parse_ref_frame_config(&
ctx->ref_frame_config,
1851 enccfg->ss_number_layers, en->
value);
1854 "Error parsing ref_frame_config option %s.\n", en->
value);
1858 codecctl_intp(avctx, VP9E_SET_SVC_REF_FRAME_CONFIG, (
int *)&
ctx->ref_frame_config);
1861 "Ignoring ref-frame-config for a non-VP9 codec\n");
1884 if (enccfg->ts_number_layers > 1 &&
ctx->ts_layer_flags) {
1885 if (
flags & VPX_EFLAG_FORCE_KF) {
1887 ctx->current_temporal_idx = 0;
1888 flags = VPX_EFLAG_FORCE_KF;
1894 flags |=
ctx->ts_layer_flags[
ctx->current_temporal_idx];
1896 memset(&layer_id, 0,
sizeof(layer_id));
1897#if VPX_ENCODER_ABI_VERSION >= 12
1898 layer_id.spatial_layer_id = 0;
1900 layer_id.temporal_layer_id = enccfg->ts_layer_id[
ctx->current_temporal_idx];
1901#ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT
1902 layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id;
1907 if (layer_id_valid) {
1909 codecctl_int(avctx, VP8E_SET_TEMPORAL_LAYER_ID, layer_id.temporal_layer_id);
1911#if CONFIG_LIBVPX_VP9_ENCODER && VPX_ENCODER_ABI_VERSION >= 12
1913 codecctl_intp(avctx, VP9E_SET_SVC_LAYER_ID, (
int *)&layer_id);
1920 "Frame duration too large: %"PRId64
"\n",
frame->duration);
1929 res = vpx_codec_encode(&
ctx->encoder, rawimg, timestamp,
1931 if (res != VPX_CODEC_OK) {
1936 if (
ctx->is_alpha) {
1937 res = vpx_codec_encode(&
ctx->encoder_alpha, rawimg_alpha, timestamp,
1939 if (res != VPX_CODEC_OK) {
1946 if (
ctx->is_alpha) {
1949 if (
ctx->coded_frame_list &&
ctx->alpha_coded_frame_list) {
1954 coded_size =
storeframe(avctx, cx_frame, alpha_cx_frame,
pkt);
1957 ctx->coded_frame_list = cx_frame->
next;
1958 ctx->alpha_coded_frame_list = alpha_cx_frame->
next;
1974 ctx->twopass_stats.sz);
1975 }
else if (enccfg->ts_number_layers > 1 &&
ctx->ts_layer_flags) {
1976 ctx->current_temporal_idx = (
ctx->current_temporal_idx + 1) % enccfg->ts_periodicity;
1979 *got_packet = !!coded_size;
1983#define OFFSET(x) offsetof(VPxContext, x)
1984#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1986#define COMMON_OPTIONS \
1987 { "lag-in-frames", "Number of frames to look ahead for " \
1988 "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1989 { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1990 { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1991 { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "arnr_type"}, \
1992 { "backward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, .unit = "arnr_type" }, \
1993 { "forward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, .unit = "arnr_type" }, \
1994 { "centered", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, .unit = "arnr_type" }, \
1995 { "tune", "Tune the encoding to a specific scenario", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "tune"}, \
1996 { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_PSNR}, 0, 0, VE, .unit = "tune"}, \
1997 { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_SSIM}, 0, 0, VE, .unit = "tune"}, \
1998 { "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"}, \
1999 { "best", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_BEST_QUALITY}, 0, 0, VE, .unit = "quality"}, \
2000 { "good", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_GOOD_QUALITY}, 0, 0, VE, .unit = "quality"}, \
2001 { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_REALTIME}, 0, 0, VE, .unit = "quality"}, \
2002 { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, .unit = "er"}, \
2003 { "max-intra-rate", "Maximum I-frame bitrate (pct) 0=unlimited", OFFSET(max_intra_rate), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
2004 { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, .unit = "er"}, \
2005 { "partitions", "The frame partitions are independently decodable " \
2006 "by the bool decoder, meaning that partitions can be decoded even " \
2007 "though earlier partitions have been lost. Note that intra prediction" \
2008 " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, .unit = "er"}, \
2009 { "crf", "Select the quality for constant quality mode", offsetof(VPxContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \
2010 { "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 }, \
2011 { "drop-threshold", "Frame drop threshold", offsetof(VPxContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE }, \
2012 { "noise-sensitivity", "Noise sensitivity", OFFSET(noise_sensitivity), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 4, VE}, \
2013 { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, VE }, \
2014 { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1000, VE }, \
2015 { "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}, \
2017#define LEGACY_OPTIONS \
2018 {"speed", "", offsetof(VPxContext, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
2019 {"quality", "", offsetof(VPxContext, deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, .unit = "quality"}, \
2020 {"vp8flags", "", offsetof(VPxContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, UINT_MAX, VE, .unit = "flags"}, \
2021 {"error_resilient", "enable error resilience", 0, AV_OPT_TYPE_CONST, {.i64 = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, .unit = "flags"}, \
2022 {"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"}, \
2023 {"arnr_max_frames", "altref noise reduction max frame count", offsetof(VPxContext, arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 15, VE}, \
2024 {"arnr_strength", "altref noise reduction filter strength", offsetof(VPxContext, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
2025 {"arnr_type", "altref noise reduction filter type", offsetof(VPxContext, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
2026 {"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}, \
2027 {"sharpness", "Increase sharpness at the expense of lower PSNR", offsetof(VPxContext, sharpness), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, VE},
2029#if CONFIG_LIBVPX_VP8_ENCODER
2030static const AVOption vp8_options[] = {
2032 {
"auto-alt-ref",
"Enable use of alternate reference "
2035 {
"screen-content-mode",
"Encoder screen content mode",
OFFSET(screen_content_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2,
VE},
2041#if CONFIG_LIBVPX_VP9_ENCODER
2042static const AVOption vp9_options[] = {
2044 {
"auto-alt-ref",
"Enable use of alternate reference "
2048 {
"tile-columns",
"Number of tile columns to use, log2",
OFFSET(tile_columns),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6,
VE},
2050 {
"frame-parallel",
"Enable frame parallel decodability features",
OFFSET(frame_parallel),
AV_OPT_TYPE_BOOL,{.i64 = -1}, -1, 1,
VE},
2051#if VPX_ENCODER_ABI_VERSION >= 12
2052 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4,
VE, .unit =
"aq_mode"},
2054 {
"aq-mode",
"adaptive quantization mode",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3,
VE, .unit =
"aq_mode"},
2057 {
"variance",
"Variance based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"aq_mode" },
2058 {
"complexity",
"Complexity based Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"aq_mode" },
2059 {
"cyclic",
"Cyclic Refresh Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0,
VE, .unit =
"aq_mode" },
2060#if VPX_ENCODER_ABI_VERSION >= 12
2061 {
"equator360",
"360 video Aq", 0,
AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0,
VE, .unit =
"aq_mode" },
2064#ifdef VPX_CTRL_VP9E_SET_ROW_MT
2067#ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT
2068#if VPX_ENCODER_ABI_VERSION >= 14
2069 {
"tune-content",
"Tune content type",
OFFSET(tune_content),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2,
VE, .unit =
"tune_content" },
2071 {
"tune-content",
"Tune content type",
OFFSET(tune_content),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1,
VE, .unit =
"tune_content" },
2073 {
"default",
"Regular video content", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0,
VE, .unit =
"tune_content" },
2074 {
"screen",
"Screen capture content", 0,
AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0,
VE, .unit =
"tune_content" },
2075#if VPX_ENCODER_ABI_VERSION >= 14
2076 {
"film",
"Film content; improves grain retention", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0,
VE, .unit =
"tune_content" },
2079#if VPX_ENCODER_ABI_VERSION >= 14
2080 {
"corpus-complexity",
"corpus vbr complexity midpoint",
OFFSET(corpus_complexity),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, 10000,
VE },
2082#ifdef VPX_CTRL_VP9E_SET_TPL
2085#ifdef VPX_CTRL_VP9E_SET_MIN_GF_INTERVAL
2086 {
"min-gf-interval",
"Minimum golden/alternate reference frame interval",
OFFSET(min_gf_interval),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
VE },
2093#undef COMMON_OPTIONS
2094#undef LEGACY_OPTIONS
2101 {
"keyint_min",
"-1" },
2105#if CONFIG_LIBVPX_VP8_ENCODER
2108 return vpx_init(avctx, vpx_codec_vp8_cx());
2111static const AVClass class_vp8 = {
2112 .class_name =
"libvpx-vp8 encoder",
2114 .option = vp8_options,
2135 .p.priv_class = &class_vp8,
2137 .p.wrapper_name =
"libvpx",
2141#if CONFIG_LIBVPX_VP9_ENCODER
2144 return vpx_init(avctx, vpx_codec_vp9_cx());
2196 vpx_codec_caps_t codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
2197 if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
2198 *
out = vp9_pix_fmts_highbd;
2201 *
out = vp9_pix_fmts_highcol;
2210static const AVClass class_vp9 = {
2211 .class_name =
"libvpx-vp9 encoder",
2213 .option = vp9_options,
2218 .p.name =
"libvpx-vp9",
2226 .p.priv_class = &class_vp9,
2227 .p.wrapper_name =
"libvpx",
2237 .get_supported_config = vp9_get_supported_config,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_libvpx_vp8_encoder
const FFCodec ff_libvpx_vp9_encoder
static const FFCodecDefault defaults[]
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_default_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out_configs, int *out_num_configs)
Libavcodec external API header.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
common internal and external API header
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#define AV_PROFILE_UNKNOWN
int(* init)(AVBSFContext *ctx)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
static CheckasmStats stats
static CheckasmConfig cfg
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_CODEC_FLAG_PSNR
error[?
#define AV_CODEC_FLAG_COPY_OPAQUE
@ AV_CODEC_CONFIG_PIX_FORMAT
AVPixelFormat, terminated by AV_PIX_FMT_NONE.
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
@ AV_PKT_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
HDR dynamic metadata associated with a video frame.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
int av_fifo_peek(const AVFifo *f, void *buf, size_t nb_elems, size_t offset)
Read data from a FIFO without modifying FIFO state.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
void av_fifo_drain2(AVFifo *f, size_t size)
Discard the specified amount of data from an AVFifo.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
@ AV_FRAME_DATA_DYNAMIC_HDR_PLUS
HDR dynamic metadata associated with a video frame.
@ AV_FRAME_DATA_DYNAMIC_HDR_SMPTE_2094_APP5
HDR dynamic metadata associated with a video frame.
@ AV_FRAME_DATA_REGIONS_OF_INTEREST
Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of array element is ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
#define LIBAVUTIL_VERSION_INT
static int set_pix_fmt(AVCodecContext *avctx, struct aom_image *img)
static const char *const ctlidstr[]
static void set_color_range(AVCodecContext *avctx)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int vpx_free(AVCodecContext *avctx)
static int vpx_ts_param_parse(VPxContext *ctx, struct vpx_codec_enc_cfg *enccfg, char *key, char *value, enum AVCodecID codec_id)
#define VP8F_ERROR_RESILIENT
Enable measures appropriate for streaming over lossy links.
static int queue_frames(AVCodecContext *avctx, struct vpx_codec_ctx *encoder, struct FrameListData **frame_list, AVPacket *pkt_out)
Queue multiple output frames from the encoder, returning the front-most.
#define VP8F_AUTO_ALT_REF
Enable automatic alternate reference frame generation.
static av_cold void fifo_free(AVFifo **fifo)
static av_cold int vpx_init(AVCodecContext *avctx, const struct vpx_codec_iface *iface)
static int frame_data_apply(AVCodecContext *avctx, AVFifo *fifo, AVPacket *pkt)
static av_cold void dump_enc_cfg(AVCodecContext *avctx, const struct vpx_codec_enc_cfg *cfg, int level)
static av_cold void free_coded_frame(struct FrameListData *cx_frame)
static void set_temporal_layer_pattern(int layering_mode, vpx_codec_enc_cfg_t *cfg, int *layer_flags, int *flag_periodicity)
static int vp9_encode_set_roi(AVCodecContext *avctx, int frame_width, int frame_height, const AVFrameSideData *sd)
static av_cold int vpx_free(AVCodecContext *avctx)
static void set_vpx_defaults(AVCodecContext *avctx, struct vpx_codec_enc_cfg *enccfg)
Called when the bitrate is not set.
static int encoder_can_drop_frames(AVCodecContext *avctx)
static int set_roi_map(AVCodecContext *avctx, const AVFrameSideData *sd, int frame_width, int frame_height, vpx_roi_map_t *roi_map, int block_size, int segment_cnt)
static void frame_data_uninit(FrameData *fd)
static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static int frame_data_submit(AVCodecContext *avctx, AVFifo *fifo, const AVFrame *frame)
static void set_vp8_defaults(AVCodecContext *avctx, struct vpx_codec_enc_cfg *enccfg)
Set the target bitrate to VPX library default.
static int realloc_alpha_uv(AVCodecContext *avctx, int width, int height)
static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, struct FrameListData *alpha_cx_frame, AVPacket *pkt)
Store coded frame information in format suitable for return from encode2().
static void vp8_ts_parse_int_array(int *dest, char *value, size_t value_len, int max_entries)
static int vp8_encode_set_roi(AVCodecContext *avctx, int frame_width, int frame_height, const AVFrameSideData *sd)
static void cx_pktcpy(struct FrameListData *dst, const struct vpx_codec_cx_pkt *src, VPxContext *ctx)
static void coded_frame_add(void *list, struct FrameListData *cx_frame)
static av_cold void log_encoder_error(void *logctx, struct vpx_codec_ctx *encoder, const char *desc)
static av_cold void free_frame_list(struct FrameListData *list)
static av_cold int codecctl_int(AVCodecContext *avctx, enum vp8e_enc_control_id id, int val)
static const struct @257111027162314367033347246032313251342043035002 planes[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static int sse(const MPVEncContext *const s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUVA422P10
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GBRAP10
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P10
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
const AVProfile ff_vp9_profiles[]
static av_cold int vp8_init(AVFormatContext *s, int st_index, PayloadContext *vp8)
static av_cold int vp9_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
size_t size
Size of data in bytes.
This structure describes the bitrate properties of an encoded bitstream.
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
char * stats_out
pass1 encoding statistics output buffer
int rc_buffer_size
decoder bitstream buffer size
enum AVColorRange color_range
MPEG vs JPEG YUV range.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
int qmin
minimum quantizer
int keyint_min
minimum GOP size
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
int64_t bit_rate
the average bitrate
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
enum AVColorSpace colorspace
YUV colorspace type.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int64_t rc_max_rate
maximum bitrate
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int qmax
maximum quantizer
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
int64_t rc_min_rate
minimum bitrate
uint64_t error[AV_NUM_DATA_POINTERS]
error
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
int slices
Number of slices.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Structure describing a single Region Of Interest.
uint32_t self_size
Must be set to the size of this data structure (that is, sizeof(AVRegionOfInterest)).
AVRational qoffset
Quantisation offset.
int top
Distance in pixels from the top edge of the frame to the top and bottom edges and from the left edge ...
AVBufferRef * hdr_smpte2094_app5
AVBufferRef * frame_opaque_ref
Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
int64_t pts
time stamp to show frame (in timebase units)
struct FrameListData * next
size_t sz
length of compressed data
void * buf
compressed data buffer
int have_sse
true if we have pending sse[]
uint32_t flags
flags for this frame
unsigned twopass_stats_size
struct vpx_codec_ctx encoder_alpha
struct vpx_fixed_buf twopass_stats
struct vpx_image rawimg_alpha
struct vpx_codec_ctx encoder
int roi_warned
If the driver does not support ROI then warn the first time we encounter a frame with ROI side data.
AVDictionary * vpx_ts_parameters
struct FrameListData * alpha_coded_frame_list
int have_sse
true if we have pending sse[]
struct FrameListData * coded_frame_list
int flags
VP8 specific flags, see VP8F_* below.
#define av_malloc_array(a, b)
static void error(const char *err)
static const uint8_t quality[]