00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #define VPX_DISABLE_CTRL_TYPECHECKS 1
00027 #define VPX_CODEC_DISABLE_COMPAT 1
00028 #include <vpx/vpx_encoder.h>
00029 #include <vpx/vp8cx.h>
00030
00031 #include "avcodec.h"
00032 #include "internal.h"
00033 #include "libavutil/base64.h"
00034 #include "libavutil/mathematics.h"
00035 #include "libavutil/opt.h"
00036
00041 struct FrameListData {
00042 void *buf;
00043 size_t sz;
00044 int64_t pts;
00046 unsigned long duration;
00048 uint32_t flags;
00049 struct FrameListData *next;
00050 };
00051
00052 typedef struct VP8EncoderContext {
00053 AVClass *class;
00054 struct vpx_codec_ctx encoder;
00055 struct vpx_image rawimg;
00056 struct vpx_fixed_buf twopass_stats;
00057 int deadline;
00058 struct FrameListData *coded_frame_list;
00059
00060 int cpu_used;
00061 int auto_alt_ref;
00062
00063 int arnr_max_frames;
00064 int arnr_strength;
00065 int arnr_type;
00066
00067 int lag_in_frames;
00068 int error_resilient;
00069 int crf;
00070 } VP8Context;
00071
00073 static const char *ctlidstr[] = {
00074 [VP8E_UPD_ENTROPY] = "VP8E_UPD_ENTROPY",
00075 [VP8E_UPD_REFERENCE] = "VP8E_UPD_REFERENCE",
00076 [VP8E_USE_REFERENCE] = "VP8E_USE_REFERENCE",
00077 [VP8E_SET_ROI_MAP] = "VP8E_SET_ROI_MAP",
00078 [VP8E_SET_ACTIVEMAP] = "VP8E_SET_ACTIVEMAP",
00079 [VP8E_SET_SCALEMODE] = "VP8E_SET_SCALEMODE",
00080 [VP8E_SET_CPUUSED] = "VP8E_SET_CPUUSED",
00081 [VP8E_SET_ENABLEAUTOALTREF] = "VP8E_SET_ENABLEAUTOALTREF",
00082 [VP8E_SET_NOISE_SENSITIVITY] = "VP8E_SET_NOISE_SENSITIVITY",
00083 [VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS",
00084 [VP8E_SET_STATIC_THRESHOLD] = "VP8E_SET_STATIC_THRESHOLD",
00085 [VP8E_SET_TOKEN_PARTITIONS] = "VP8E_SET_TOKEN_PARTITIONS",
00086 [VP8E_GET_LAST_QUANTIZER] = "VP8E_GET_LAST_QUANTIZER",
00087 [VP8E_SET_ARNR_MAXFRAMES] = "VP8E_SET_ARNR_MAXFRAMES",
00088 [VP8E_SET_ARNR_STRENGTH] = "VP8E_SET_ARNR_STRENGTH",
00089 [VP8E_SET_ARNR_TYPE] = "VP8E_SET_ARNR_TYPE",
00090 [VP8E_SET_CQ_LEVEL] = "VP8E_SET_CQ_LEVEL",
00091 };
00092
00093 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
00094 {
00095 VP8Context *ctx = avctx->priv_data;
00096 const char *error = vpx_codec_error(&ctx->encoder);
00097 const char *detail = vpx_codec_error_detail(&ctx->encoder);
00098
00099 av_log(avctx, AV_LOG_ERROR, "%s: %s\n", desc, error);
00100 if (detail)
00101 av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n", detail);
00102 }
00103
00104 static av_cold void dump_enc_cfg(AVCodecContext *avctx,
00105 const struct vpx_codec_enc_cfg *cfg)
00106 {
00107 int width = -30;
00108 int level = AV_LOG_DEBUG;
00109
00110 av_log(avctx, level, "vpx_codec_enc_cfg\n");
00111 av_log(avctx, level, "generic settings\n"
00112 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
00113 " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
00114 width, "g_usage:", cfg->g_usage,
00115 width, "g_threads:", cfg->g_threads,
00116 width, "g_profile:", cfg->g_profile,
00117 width, "g_w:", cfg->g_w,
00118 width, "g_h:", cfg->g_h,
00119 width, "g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
00120 width, "g_error_resilient:", cfg->g_error_resilient,
00121 width, "g_pass:", cfg->g_pass,
00122 width, "g_lag_in_frames:", cfg->g_lag_in_frames);
00123 av_log(avctx, level, "rate control settings\n"
00124 " %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
00125 " %*s%d\n %*s%p(%zu)\n %*s%u\n",
00126 width, "rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
00127 width, "rc_resize_allowed:", cfg->rc_resize_allowed,
00128 width, "rc_resize_up_thresh:", cfg->rc_resize_up_thresh,
00129 width, "rc_resize_down_thresh:", cfg->rc_resize_down_thresh,
00130 width, "rc_end_usage:", cfg->rc_end_usage,
00131 width, "rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
00132 width, "rc_target_bitrate:", cfg->rc_target_bitrate);
00133 av_log(avctx, level, "quantizer settings\n"
00134 " %*s%u\n %*s%u\n",
00135 width, "rc_min_quantizer:", cfg->rc_min_quantizer,
00136 width, "rc_max_quantizer:", cfg->rc_max_quantizer);
00137 av_log(avctx, level, "bitrate tolerance\n"
00138 " %*s%u\n %*s%u\n",
00139 width, "rc_undershoot_pct:", cfg->rc_undershoot_pct,
00140 width, "rc_overshoot_pct:", cfg->rc_overshoot_pct);
00141 av_log(avctx, level, "decoder buffer model\n"
00142 " %*s%u\n %*s%u\n %*s%u\n",
00143 width, "rc_buf_sz:", cfg->rc_buf_sz,
00144 width, "rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
00145 width, "rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
00146 av_log(avctx, level, "2 pass rate control settings\n"
00147 " %*s%u\n %*s%u\n %*s%u\n",
00148 width, "rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
00149 width, "rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
00150 width, "rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
00151 av_log(avctx, level, "keyframing settings\n"
00152 " %*s%d\n %*s%u\n %*s%u\n",
00153 width, "kf_mode:", cfg->kf_mode,
00154 width, "kf_min_dist:", cfg->kf_min_dist,
00155 width, "kf_max_dist:", cfg->kf_max_dist);
00156 av_log(avctx, level, "\n");
00157 }
00158
00159 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
00160 {
00161 struct FrameListData **p = list;
00162
00163 while (*p != NULL)
00164 p = &(*p)->next;
00165 *p = cx_frame;
00166 cx_frame->next = NULL;
00167 }
00168
00169 static av_cold void free_coded_frame(struct FrameListData *cx_frame)
00170 {
00171 av_freep(&cx_frame->buf);
00172 av_freep(&cx_frame);
00173 }
00174
00175 static av_cold void free_frame_list(struct FrameListData *list)
00176 {
00177 struct FrameListData *p = list;
00178
00179 while (p) {
00180 list = list->next;
00181 free_coded_frame(p);
00182 p = list;
00183 }
00184 }
00185
00186 static av_cold int codecctl_int(AVCodecContext *avctx,
00187 enum vp8e_enc_control_id id, int val)
00188 {
00189 VP8Context *ctx = avctx->priv_data;
00190 char buf[80];
00191 int width = -30;
00192 int res;
00193
00194 snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
00195 av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, val);
00196
00197 res = vpx_codec_control(&ctx->encoder, id, val);
00198 if (res != VPX_CODEC_OK) {
00199 snprintf(buf, sizeof(buf), "Failed to set %s codec control",
00200 ctlidstr[id]);
00201 log_encoder_error(avctx, buf);
00202 }
00203
00204 return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL);
00205 }
00206
00207 static av_cold int vp8_free(AVCodecContext *avctx)
00208 {
00209 VP8Context *ctx = avctx->priv_data;
00210
00211 vpx_codec_destroy(&ctx->encoder);
00212 av_freep(&ctx->twopass_stats.buf);
00213 av_freep(&avctx->coded_frame);
00214 av_freep(&avctx->stats_out);
00215 free_frame_list(ctx->coded_frame_list);
00216 return 0;
00217 }
00218
00219 static av_cold int vp8_init(AVCodecContext *avctx)
00220 {
00221 VP8Context *ctx = avctx->priv_data;
00222 const struct vpx_codec_iface *iface = &vpx_codec_vp8_cx_algo;
00223 struct vpx_codec_enc_cfg enccfg;
00224 int res;
00225
00226 av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
00227 av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config());
00228
00229 if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) {
00230 av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n",
00231 vpx_codec_err_to_string(res));
00232 return AVERROR(EINVAL);
00233 }
00234 dump_enc_cfg(avctx, &enccfg);
00235
00236 enccfg.g_w = avctx->width;
00237 enccfg.g_h = avctx->height;
00238 enccfg.g_timebase.num = avctx->time_base.num;
00239 enccfg.g_timebase.den = avctx->time_base.den;
00240 enccfg.g_threads = avctx->thread_count;
00241 #if FF_API_X264_GLOBAL_OPTS
00242 if(avctx->rc_lookahead >= 0)
00243 enccfg.g_lag_in_frames= FFMIN(avctx->rc_lookahead, 25);
00244 if (ctx->lag_in_frames >= 0)
00245 enccfg.g_lag_in_frames = ctx->lag_in_frames;
00246 #else
00247 enccfg.g_lag_in_frames= ctx->lag_in_frames;
00248 #endif
00249
00250 if (avctx->flags & CODEC_FLAG_PASS1)
00251 enccfg.g_pass = VPX_RC_FIRST_PASS;
00252 else if (avctx->flags & CODEC_FLAG_PASS2)
00253 enccfg.g_pass = VPX_RC_LAST_PASS;
00254 else
00255 enccfg.g_pass = VPX_RC_ONE_PASS;
00256
00257 if (avctx->rc_min_rate == avctx->rc_max_rate &&
00258 avctx->rc_min_rate == avctx->bit_rate)
00259 enccfg.rc_end_usage = VPX_CBR;
00260 #if FF_API_X264_GLOBAL_OPTS
00261 else if (avctx->crf || ctx->crf > 0)
00262 #else
00263 else if (ctx->crf)
00264 #endif
00265 enccfg.rc_end_usage = VPX_CQ;
00266 enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
00267 AV_ROUND_NEAR_INF);
00268 if (avctx->qmin > 0)
00269 enccfg.rc_min_quantizer = avctx->qmin;
00270 if (avctx->qmax > 0)
00271 enccfg.rc_max_quantizer = avctx->qmax;
00272 enccfg.rc_dropframe_thresh = avctx->frame_skip_threshold;
00273
00274
00275 enccfg.rc_2pass_vbr_bias_pct = round(avctx->qcompress * 100);
00276 enccfg.rc_2pass_vbr_minsection_pct =
00277 avctx->rc_min_rate * 100LL / avctx->bit_rate;
00278 if (avctx->rc_max_rate)
00279 enccfg.rc_2pass_vbr_maxsection_pct =
00280 avctx->rc_max_rate * 100LL / avctx->bit_rate;
00281
00282 if (avctx->rc_buffer_size)
00283 enccfg.rc_buf_sz =
00284 avctx->rc_buffer_size * 1000LL / avctx->bit_rate;
00285 if (avctx->rc_initial_buffer_occupancy)
00286 enccfg.rc_buf_initial_sz =
00287 avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
00288 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
00289 enccfg.rc_undershoot_pct = round(avctx->rc_buffer_aggressivity * 100);
00290
00291
00292 if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
00293 enccfg.kf_min_dist = avctx->keyint_min;
00294 if (avctx->gop_size >= 0)
00295 enccfg.kf_max_dist = avctx->gop_size;
00296
00297 if (enccfg.g_pass == VPX_RC_FIRST_PASS)
00298 enccfg.g_lag_in_frames = 0;
00299 else if (enccfg.g_pass == VPX_RC_LAST_PASS) {
00300 int decode_size;
00301
00302 if (!avctx->stats_in) {
00303 av_log(avctx, AV_LOG_ERROR, "No stats file for second pass\n");
00304 return AVERROR_INVALIDDATA;
00305 }
00306
00307 ctx->twopass_stats.sz = strlen(avctx->stats_in) * 3 / 4;
00308 ctx->twopass_stats.buf = av_malloc(ctx->twopass_stats.sz);
00309 if (!ctx->twopass_stats.buf) {
00310 av_log(avctx, AV_LOG_ERROR,
00311 "Stat buffer alloc (%zu bytes) failed\n",
00312 ctx->twopass_stats.sz);
00313 return AVERROR(ENOMEM);
00314 }
00315 decode_size = av_base64_decode(ctx->twopass_stats.buf, avctx->stats_in,
00316 ctx->twopass_stats.sz);
00317 if (decode_size < 0) {
00318 av_log(avctx, AV_LOG_ERROR, "Stat buffer decode failed\n");
00319 return AVERROR_INVALIDDATA;
00320 }
00321
00322 ctx->twopass_stats.sz = decode_size;
00323 enccfg.rc_twopass_stats_in = ctx->twopass_stats;
00324 }
00325
00326
00327
00328
00329 if (avctx->profile != FF_PROFILE_UNKNOWN)
00330 enccfg.g_profile = avctx->profile;
00331
00332 enccfg.g_error_resilient = ctx->error_resilient;
00333
00334 dump_enc_cfg(avctx, &enccfg);
00335
00336 res = vpx_codec_enc_init(&ctx->encoder, iface, &enccfg, 0);
00337 if (res != VPX_CODEC_OK) {
00338 log_encoder_error(avctx, "Failed to initialize encoder");
00339 return AVERROR(EINVAL);
00340 }
00341
00342
00343 av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n");
00344 if (ctx->cpu_used != INT_MIN)
00345 codecctl_int(avctx, VP8E_SET_CPUUSED, ctx->cpu_used);
00346 if (ctx->auto_alt_ref >= 0)
00347 codecctl_int(avctx, VP8E_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
00348 if (ctx->arnr_max_frames >= 0)
00349 codecctl_int(avctx, VP8E_SET_ARNR_MAXFRAMES, ctx->arnr_max_frames);
00350 if (ctx->arnr_strength >= 0)
00351 codecctl_int(avctx, VP8E_SET_ARNR_STRENGTH, ctx->arnr_strength);
00352 if (ctx->arnr_type >= 0)
00353 codecctl_int(avctx, VP8E_SET_ARNR_TYPE, ctx->arnr_type);
00354 codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction);
00355 codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->slices));
00356 codecctl_int(avctx, VP8E_SET_STATIC_THRESHOLD, avctx->mb_threshold);
00357 #if FF_API_X264_GLOBAL_OPTS
00358 codecctl_int(avctx, VP8E_SET_CQ_LEVEL, (int)avctx->crf);
00359 if (ctx->crf >= 0)
00360 codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf);
00361 #else
00362 codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf);
00363 #endif
00364
00365 av_log(avctx, AV_LOG_DEBUG, "Using deadline: %d\n", ctx->deadline);
00366
00367
00368 vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
00369 (unsigned char*)1);
00370
00371 avctx->coded_frame = avcodec_alloc_frame();
00372 if (!avctx->coded_frame) {
00373 av_log(avctx, AV_LOG_ERROR, "Error allocating coded frame\n");
00374 vp8_free(avctx);
00375 return AVERROR(ENOMEM);
00376 }
00377 return 0;
00378 }
00379
00380 static inline void cx_pktcpy(struct FrameListData *dst,
00381 const struct vpx_codec_cx_pkt *src)
00382 {
00383 dst->pts = src->data.frame.pts;
00384 dst->duration = src->data.frame.duration;
00385 dst->flags = src->data.frame.flags;
00386 dst->sz = src->data.frame.sz;
00387 dst->buf = src->data.frame.buf;
00388 }
00389
00398 static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
00399 uint8_t *buf, int buf_size, AVFrame *coded_frame)
00400 {
00401 if ((int) cx_frame->sz <= buf_size) {
00402 buf_size = cx_frame->sz;
00403 memcpy(buf, cx_frame->buf, buf_size);
00404 coded_frame->pts = cx_frame->pts;
00405 coded_frame->key_frame = !!(cx_frame->flags & VPX_FRAME_IS_KEY);
00406
00407 if (coded_frame->key_frame)
00408 coded_frame->pict_type = AV_PICTURE_TYPE_I;
00409 else
00410 coded_frame->pict_type = AV_PICTURE_TYPE_P;
00411 } else {
00412 av_log(avctx, AV_LOG_ERROR,
00413 "Compressed frame larger than storage provided! (%zu/%d)\n",
00414 cx_frame->sz, buf_size);
00415 return AVERROR(EINVAL);
00416 }
00417 return buf_size;
00418 }
00419
00428 static int queue_frames(AVCodecContext *avctx, uint8_t *buf, int buf_size,
00429 AVFrame *coded_frame)
00430 {
00431 VP8Context *ctx = avctx->priv_data;
00432 const struct vpx_codec_cx_pkt *pkt;
00433 const void *iter = NULL;
00434 int size = 0;
00435
00436 if (ctx->coded_frame_list) {
00437 struct FrameListData *cx_frame = ctx->coded_frame_list;
00438
00439 size = storeframe(avctx, cx_frame, buf, buf_size, coded_frame);
00440 if (size < 0)
00441 return AVERROR(EINVAL);
00442 ctx->coded_frame_list = cx_frame->next;
00443 free_coded_frame(cx_frame);
00444 }
00445
00446
00447
00448 while ((pkt = vpx_codec_get_cx_data(&ctx->encoder, &iter))) {
00449 switch (pkt->kind) {
00450 case VPX_CODEC_CX_FRAME_PKT:
00451 if (!size) {
00452 struct FrameListData cx_frame;
00453
00454
00455
00456 assert(!ctx->coded_frame_list);
00457 cx_pktcpy(&cx_frame, pkt);
00458 size = storeframe(avctx, &cx_frame, buf, buf_size, coded_frame);
00459 if (size < 0)
00460 return AVERROR(EINVAL);
00461 } else {
00462 struct FrameListData *cx_frame =
00463 av_malloc(sizeof(struct FrameListData));
00464
00465 if (!cx_frame) {
00466 av_log(avctx, AV_LOG_ERROR,
00467 "Frame queue element alloc failed\n");
00468 return AVERROR(ENOMEM);
00469 }
00470 cx_pktcpy(cx_frame, pkt);
00471 cx_frame->buf = av_malloc(cx_frame->sz);
00472
00473 if (!cx_frame->buf) {
00474 av_log(avctx, AV_LOG_ERROR,
00475 "Data buffer alloc (%zu bytes) failed\n",
00476 cx_frame->sz);
00477 return AVERROR(ENOMEM);
00478 }
00479 memcpy(cx_frame->buf, pkt->data.frame.buf, pkt->data.frame.sz);
00480 coded_frame_add(&ctx->coded_frame_list, cx_frame);
00481 }
00482 break;
00483 case VPX_CODEC_STATS_PKT: {
00484 struct vpx_fixed_buf *stats = &ctx->twopass_stats;
00485 stats->buf = av_realloc_f(stats->buf, 1,
00486 stats->sz + pkt->data.twopass_stats.sz);
00487 if (!stats->buf) {
00488 av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
00489 return AVERROR(ENOMEM);
00490 }
00491 memcpy((uint8_t*)stats->buf + stats->sz,
00492 pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
00493 stats->sz += pkt->data.twopass_stats.sz;
00494 break;
00495 }
00496 case VPX_CODEC_PSNR_PKT:
00497 case VPX_CODEC_CUSTOM_PKT:
00498
00499 break;
00500 }
00501 }
00502
00503 return size;
00504 }
00505
00506 static int vp8_encode(AVCodecContext *avctx, uint8_t *buf, int buf_size,
00507 void *data)
00508 {
00509 VP8Context *ctx = avctx->priv_data;
00510 AVFrame *frame = data;
00511 struct vpx_image *rawimg = NULL;
00512 int64_t timestamp = 0;
00513 int res, coded_size;
00514
00515 if (frame) {
00516 rawimg = &ctx->rawimg;
00517 rawimg->planes[VPX_PLANE_Y] = frame->data[0];
00518 rawimg->planes[VPX_PLANE_U] = frame->data[1];
00519 rawimg->planes[VPX_PLANE_V] = frame->data[2];
00520 rawimg->stride[VPX_PLANE_Y] = frame->linesize[0];
00521 rawimg->stride[VPX_PLANE_U] = frame->linesize[1];
00522 rawimg->stride[VPX_PLANE_V] = frame->linesize[2];
00523 timestamp = frame->pts;
00524 }
00525
00526 res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
00527 avctx->ticks_per_frame, 0, ctx->deadline);
00528 if (res != VPX_CODEC_OK) {
00529 log_encoder_error(avctx, "Error encoding frame");
00530 return AVERROR_INVALIDDATA;
00531 }
00532 coded_size = queue_frames(avctx, buf, buf_size, avctx->coded_frame);
00533
00534 if (!frame && avctx->flags & CODEC_FLAG_PASS1) {
00535 unsigned int b64_size = AV_BASE64_SIZE(ctx->twopass_stats.sz);
00536
00537 avctx->stats_out = av_malloc(b64_size);
00538 if (!avctx->stats_out) {
00539 av_log(avctx, AV_LOG_ERROR, "Stat buffer alloc (%d bytes) failed\n",
00540 b64_size);
00541 return AVERROR(ENOMEM);
00542 }
00543 av_base64_encode(avctx->stats_out, b64_size, ctx->twopass_stats.buf,
00544 ctx->twopass_stats.sz);
00545 }
00546 return coded_size;
00547 }
00548
00549 #define OFFSET(x) offsetof(VP8Context, x)
00550 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
00551 static const AVOption options[] = {
00552 { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE},
00553 { "auto-alt-ref", "Enable use of alternate reference "
00554 "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {-1}, -1, 1, VE},
00555 { "lag-in-frames", "Number of frames to look ahead for "
00556 "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE},
00557 { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE},
00558 { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE},
00559 { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE, "arnr_type"},
00560 { "backward", NULL, 0, AV_OPT_TYPE_CONST, {1}, 0, 0, VE, "arnr_type" },
00561 { "forward", NULL, 0, AV_OPT_TYPE_CONST, {2}, 0, 0, VE, "arnr_type" },
00562 { "centered", NULL, 0, AV_OPT_TYPE_CONST, {3}, 0, 0, VE, "arnr_type" },
00563 { "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"},
00564 { "best", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_BEST_QUALITY}, 0, 0, VE, "quality"},
00565 { "good", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"},
00566 { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_REALTIME}, 0, 0, VE, "quality"},
00567 { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, VE, "er"},
00568 #ifdef VPX_ERROR_RESILIENT_DEFAULT
00569 { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"},
00570 { "partitions", "The frame partitions are independently decodable "
00571 "by the bool decoder, meaning that partitions can be decoded even "
00572 "though earlier partitions have been lost. Note that intra predicition"
00573 " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"},
00574 #endif
00575 {"speed", "", offsetof(VP8Context, cpu_used), AV_OPT_TYPE_INT, {.dbl = 3}, -16, 16, VE},
00576 {"quality", "", offsetof(VP8Context, deadline), AV_OPT_TYPE_INT, {.dbl = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"},
00577 {"best", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = VPX_DL_BEST_QUALITY}, INT_MIN, INT_MAX, VE, "quality"},
00578 {"good", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"},
00579 {"realtime", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = VPX_DL_REALTIME}, INT_MIN, INT_MAX, VE, "quality"},
00580 {"arnr_max_frames", "altref noise reduction max frame count", offsetof(VP8Context, arnr_max_frames), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 15, VE},
00581 {"arnr_strength", "altref noise reduction filter strength", offsetof(VP8Context, arnr_strength), AV_OPT_TYPE_INT, {.dbl = 3}, 0, 6, VE},
00582 {"arnr_type", "altref noise reduction filter type", offsetof(VP8Context, arnr_type), AV_OPT_TYPE_INT, {.dbl = 3}, 1, 3, VE},
00583 #if FF_API_X264_GLOBAL_OPTS
00584 {"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 25, VE},
00585 {"crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 63, VE},
00586 #else
00587 {"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.dbl = 25}, 0, 25, VE},
00588 {"crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 63, VE},
00589 #endif
00590 {NULL}
00591 };
00592
00593 static const AVClass class = {
00594 .class_name = "libvpx encoder",
00595 .item_name = av_default_item_name,
00596 .option = options,
00597 .version = LIBAVUTIL_VERSION_INT,
00598 };
00599
00600 static const AVCodecDefault defaults[] = {
00601 { "qmin", "-1" },
00602 { "qmax", "-1" },
00603 { "g", "-1" },
00604 { "keyint_min", "-1" },
00605 { NULL },
00606 };
00607
00608 AVCodec ff_libvpx_encoder = {
00609 .name = "libvpx",
00610 .type = AVMEDIA_TYPE_VIDEO,
00611 .id = CODEC_ID_VP8,
00612 .priv_data_size = sizeof(VP8Context),
00613 .init = vp8_init,
00614 .encode = vp8_encode,
00615 .close = vp8_free,
00616 .capabilities = CODEC_CAP_DELAY,
00617 .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
00618 .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"),
00619 .priv_class = &class,
00620 .defaults = defaults,
00621 };