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