00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/opt.h"
00023 #include "libavutil/pixdesc.h"
00024 #include "avcodec.h"
00025 #include "internal.h"
00026 #include <x264.h>
00027 #include <float.h>
00028 #include <math.h>
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032
00033 typedef struct X264Context {
00034 AVClass *class;
00035 x264_param_t params;
00036 x264_t *enc;
00037 x264_picture_t pic;
00038 uint8_t *sei;
00039 int sei_size;
00040 AVFrame out_pic;
00041 char *preset;
00042 char *tune;
00043 char *profile;
00044 int fastfirstpass;
00045 float crf;
00046 float crf_max;
00047 int cqp;
00048 int aq_mode;
00049 float aq_strength;
00050 char *psy_rd;
00051 int psy;
00052 int rc_lookahead;
00053 int weightp;
00054 int weightb;
00055 int ssim;
00056 int intra_refresh;
00057 int b_bias;
00058 int b_pyramid;
00059 int mixed_refs;
00060 int dct8x8;
00061 int fast_pskip;
00062 int aud;
00063 int mbtree;
00064 char *deblock;
00065 float cplxblur;
00066 char *partitions;
00067 int direct_pred;
00068 int slice_max_size;
00069 char *stats;
00070 } X264Context;
00071
00072 static void X264_log(void *p, int level, const char *fmt, va_list args)
00073 {
00074 static const int level_map[] = {
00075 [X264_LOG_ERROR] = AV_LOG_ERROR,
00076 [X264_LOG_WARNING] = AV_LOG_WARNING,
00077 [X264_LOG_INFO] = AV_LOG_INFO,
00078 [X264_LOG_DEBUG] = AV_LOG_DEBUG
00079 };
00080
00081 if (level < 0 || level > X264_LOG_DEBUG)
00082 return;
00083
00084 av_vlog(p, level_map[level], fmt, args);
00085 }
00086
00087
00088 static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size,
00089 x264_nal_t *nals, int nnal, int skip_sei)
00090 {
00091 X264Context *x4 = ctx->priv_data;
00092 uint8_t *p = buf;
00093 int i;
00094
00095
00096 if (x4->sei_size > 0 && nnal > 0) {
00097 memcpy(p, x4->sei, x4->sei_size);
00098 p += x4->sei_size;
00099 x4->sei_size = 0;
00100 }
00101
00102 for (i = 0; i < nnal; i++){
00103
00104 if (skip_sei && nals[i].i_type == NAL_SEI) {
00105 x4->sei_size = nals[i].i_payload;
00106 x4->sei = av_malloc(x4->sei_size);
00107 memcpy(x4->sei, nals[i].p_payload, nals[i].i_payload);
00108 continue;
00109 }
00110 memcpy(p, nals[i].p_payload, nals[i].i_payload);
00111 p += nals[i].i_payload;
00112 }
00113
00114 return p - buf;
00115 }
00116
00117 static int X264_frame(AVCodecContext *ctx, uint8_t *buf,
00118 int bufsize, void *data)
00119 {
00120 X264Context *x4 = ctx->priv_data;
00121 AVFrame *frame = data;
00122 x264_nal_t *nal;
00123 int nnal, i;
00124 x264_picture_t pic_out;
00125
00126 x264_picture_init( &x4->pic );
00127 x4->pic.img.i_csp = x4->params.i_csp;
00128 if (x264_bit_depth > 8)
00129 x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
00130 x4->pic.img.i_plane = 3;
00131
00132 if (frame) {
00133 for (i = 0; i < 3; i++) {
00134 x4->pic.img.plane[i] = frame->data[i];
00135 x4->pic.img.i_stride[i] = frame->linesize[i];
00136 }
00137
00138 x4->pic.i_pts = frame->pts;
00139 x4->pic.i_type =
00140 frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :
00141 frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :
00142 frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :
00143 X264_TYPE_AUTO;
00144 if (x4->params.b_tff != frame->top_field_first) {
00145 x4->params.b_tff = frame->top_field_first;
00146 x264_encoder_reconfig(x4->enc, &x4->params);
00147 }
00148 }
00149
00150 do {
00151 if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
00152 return -1;
00153
00154 bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0);
00155 if (bufsize < 0)
00156 return -1;
00157 } while (!bufsize && !frame && x264_encoder_delayed_frames(x4->enc));
00158
00159
00160 x4->out_pic.pts = pic_out.i_pts;
00161
00162 switch (pic_out.i_type) {
00163 case X264_TYPE_IDR:
00164 case X264_TYPE_I:
00165 x4->out_pic.pict_type = AV_PICTURE_TYPE_I;
00166 break;
00167 case X264_TYPE_P:
00168 x4->out_pic.pict_type = AV_PICTURE_TYPE_P;
00169 break;
00170 case X264_TYPE_B:
00171 case X264_TYPE_BREF:
00172 x4->out_pic.pict_type = AV_PICTURE_TYPE_B;
00173 break;
00174 }
00175
00176 x4->out_pic.key_frame = pic_out.b_keyframe;
00177 if (bufsize)
00178 x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
00179
00180 return bufsize;
00181 }
00182
00183 static av_cold int X264_close(AVCodecContext *avctx)
00184 {
00185 X264Context *x4 = avctx->priv_data;
00186
00187 av_freep(&avctx->extradata);
00188 av_free(x4->sei);
00189
00190 if (x4->enc)
00191 x264_encoder_close(x4->enc);
00192
00193 return 0;
00194 }
00195
00196 static int convert_pix_fmt(enum PixelFormat pix_fmt)
00197 {
00198 switch (pix_fmt) {
00199 case PIX_FMT_YUV420P:
00200 case PIX_FMT_YUVJ420P:
00201 case PIX_FMT_YUV420P9:
00202 case PIX_FMT_YUV420P10: return X264_CSP_I420;
00203 case PIX_FMT_YUV422P:
00204 case PIX_FMT_YUV422P10: return X264_CSP_I422;
00205 case PIX_FMT_YUV444P:
00206 case PIX_FMT_YUV444P9:
00207 case PIX_FMT_YUV444P10: return X264_CSP_I444;
00208 };
00209 return 0;
00210 }
00211
00212 #define PARSE_X264_OPT(name, var)\
00213 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
00214 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
00215 return AVERROR(EINVAL);\
00216 }
00217
00218 static av_cold int X264_init(AVCodecContext *avctx)
00219 {
00220 X264Context *x4 = avctx->priv_data;
00221
00222 x264_param_default(&x4->params);
00223
00224 x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
00225
00226 if (x4->preset || x4->tune)
00227 if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) {
00228 av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune);
00229 return AVERROR(EINVAL);
00230 }
00231
00232 if (avctx->level > 0)
00233 x4->params.i_level_idc = avctx->level;
00234
00235 x4->params.pf_log = X264_log;
00236 x4->params.p_log_private = avctx;
00237 x4->params.i_log_level = X264_LOG_DEBUG;
00238 x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt);
00239
00240 if (avctx->bit_rate) {
00241 x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
00242 x4->params.rc.i_rc_method = X264_RC_ABR;
00243 }
00244 x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
00245 x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
00246 x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
00247 if (avctx->flags & CODEC_FLAG_PASS2) {
00248 x4->params.rc.b_stat_read = 1;
00249 } else {
00250 #if FF_API_X264_GLOBAL_OPTS
00251 if (avctx->crf) {
00252 x4->params.rc.i_rc_method = X264_RC_CRF;
00253 x4->params.rc.f_rf_constant = avctx->crf;
00254 x4->params.rc.f_rf_constant_max = avctx->crf_max;
00255 } else if (avctx->cqp > -1) {
00256 x4->params.rc.i_rc_method = X264_RC_CQP;
00257 x4->params.rc.i_qp_constant = avctx->cqp;
00258 }
00259 #endif
00260
00261 if (x4->crf >= 0) {
00262 x4->params.rc.i_rc_method = X264_RC_CRF;
00263 x4->params.rc.f_rf_constant = x4->crf;
00264 } else if (x4->cqp >= 0) {
00265 x4->params.rc.i_rc_method = X264_RC_CQP;
00266 x4->params.rc.i_qp_constant = x4->cqp;
00267 }
00268
00269 if (x4->crf_max >= 0)
00270 x4->params.rc.f_rf_constant_max = x4->crf_max;
00271 }
00272
00273 if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
00274 (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
00275 x4->params.rc.f_vbv_buffer_init =
00276 (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
00277 }
00278
00279 x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
00280 x4->params.rc.f_pb_factor = avctx->b_quant_factor;
00281 x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
00282
00283 #if FF_API_X264_GLOBAL_OPTS
00284 if (avctx->aq_mode >= 0)
00285 x4->params.rc.i_aq_mode = avctx->aq_mode;
00286 if (avctx->aq_strength >= 0)
00287 x4->params.rc.f_aq_strength = avctx->aq_strength;
00288 if (avctx->psy_rd >= 0)
00289 x4->params.analyse.f_psy_rd = avctx->psy_rd;
00290 if (avctx->psy_trellis >= 0)
00291 x4->params.analyse.f_psy_trellis = avctx->psy_trellis;
00292 if (avctx->rc_lookahead >= 0)
00293 x4->params.rc.i_lookahead = avctx->rc_lookahead;
00294 if (avctx->weighted_p_pred >= 0)
00295 x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred;
00296 if (avctx->bframebias)
00297 x4->params.i_bframe_bias = avctx->bframebias;
00298 if (avctx->deblockalpha)
00299 x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
00300 if (avctx->deblockbeta)
00301 x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
00302 if (avctx->complexityblur >= 0)
00303 x4->params.rc.f_complexity_blur = avctx->complexityblur;
00304 if (avctx->directpred >= 0)
00305 x4->params.analyse.i_direct_mv_pred = avctx->directpred;
00306 if (avctx->partitions) {
00307 if (avctx->partitions & X264_PART_I4X4)
00308 x4->params.analyse.inter |= X264_ANALYSE_I4x4;
00309 if (avctx->partitions & X264_PART_I8X8)
00310 x4->params.analyse.inter |= X264_ANALYSE_I8x8;
00311 if (avctx->partitions & X264_PART_P8X8)
00312 x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16;
00313 if (avctx->partitions & X264_PART_P4X4)
00314 x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8;
00315 if (avctx->partitions & X264_PART_B8X8)
00316 x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16;
00317 }
00318 x4->params.analyse.b_ssim = avctx->flags2 & CODEC_FLAG2_SSIM;
00319 x4->params.b_intra_refresh = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH;
00320 x4->params.i_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? X264_B_PYRAMID_NORMAL : X264_B_PYRAMID_NONE;
00321 x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
00322 x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
00323 x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT;
00324 x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
00325 x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
00326 x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY;
00327 x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
00328 #endif
00329
00330 if (avctx->me_method == ME_EPZS)
00331 x4->params.analyse.i_me_method = X264_ME_DIA;
00332 else if (avctx->me_method == ME_HEX)
00333 x4->params.analyse.i_me_method = X264_ME_HEX;
00334 else if (avctx->me_method == ME_UMH)
00335 x4->params.analyse.i_me_method = X264_ME_UMH;
00336 else if (avctx->me_method == ME_FULL)
00337 x4->params.analyse.i_me_method = X264_ME_ESA;
00338 else if (avctx->me_method == ME_TESA)
00339 x4->params.analyse.i_me_method = X264_ME_TESA;
00340
00341 if (avctx->gop_size >= 0)
00342 x4->params.i_keyint_max = avctx->gop_size;
00343 if (avctx->max_b_frames >= 0)
00344 x4->params.i_bframe = avctx->max_b_frames;
00345 if (avctx->scenechange_threshold >= 0)
00346 x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
00347 if (avctx->qmin >= 0)
00348 x4->params.rc.i_qp_min = avctx->qmin;
00349 if (avctx->qmax >= 0)
00350 x4->params.rc.i_qp_max = avctx->qmax;
00351 if (avctx->max_qdiff >= 0)
00352 x4->params.rc.i_qp_step = avctx->max_qdiff;
00353 if (avctx->qblur >= 0)
00354 x4->params.rc.f_qblur = avctx->qblur;
00355 if (avctx->qcompress >= 0)
00356 x4->params.rc.f_qcompress = avctx->qcompress;
00357 if (avctx->refs >= 0)
00358 x4->params.i_frame_reference = avctx->refs;
00359 if (avctx->trellis >= 0)
00360 x4->params.analyse.i_trellis = avctx->trellis;
00361 if (avctx->me_range >= 0)
00362 x4->params.analyse.i_me_range = avctx->me_range;
00363 if (avctx->noise_reduction >= 0)
00364 x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
00365 if (avctx->me_subpel_quality >= 0)
00366 x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
00367 if (avctx->b_frame_strategy >= 0)
00368 x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
00369 if (avctx->keyint_min >= 0)
00370 x4->params.i_keyint_min = avctx->keyint_min;
00371 if (avctx->coder_type >= 0)
00372 x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
00373 if (avctx->me_cmp >= 0)
00374 x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
00375
00376 if (x4->aq_mode >= 0)
00377 x4->params.rc.i_aq_mode = x4->aq_mode;
00378 if (x4->aq_strength >= 0)
00379 x4->params.rc.f_aq_strength = x4->aq_strength;
00380 PARSE_X264_OPT("psy-rd", psy_rd);
00381 PARSE_X264_OPT("deblock", deblock);
00382 PARSE_X264_OPT("partitions", partitions);
00383 PARSE_X264_OPT("stats", stats);
00384 if (x4->psy >= 0)
00385 x4->params.analyse.b_psy = x4->psy;
00386 if (x4->rc_lookahead >= 0)
00387 x4->params.rc.i_lookahead = x4->rc_lookahead;
00388 if (x4->weightp >= 0)
00389 x4->params.analyse.i_weighted_pred = x4->weightp;
00390 if (x4->weightb >= 0)
00391 x4->params.analyse.b_weighted_bipred = x4->weightb;
00392 if (x4->cplxblur >= 0)
00393 x4->params.rc.f_complexity_blur = x4->cplxblur;
00394
00395 if (x4->ssim >= 0)
00396 x4->params.analyse.b_ssim = x4->ssim;
00397 if (x4->intra_refresh >= 0)
00398 x4->params.b_intra_refresh = x4->intra_refresh;
00399 if (x4->b_bias != INT_MIN)
00400 x4->params.i_bframe_bias = x4->b_bias;
00401 if (x4->b_pyramid >= 0)
00402 x4->params.i_bframe_pyramid = x4->b_pyramid;
00403 if (x4->mixed_refs >= 0)
00404 x4->params.analyse.b_mixed_references = x4->mixed_refs;
00405 if (x4->dct8x8 >= 0)
00406 x4->params.analyse.b_transform_8x8 = x4->dct8x8;
00407 if (x4->fast_pskip >= 0)
00408 x4->params.analyse.b_fast_pskip = x4->fast_pskip;
00409 if (x4->aud >= 0)
00410 x4->params.b_aud = x4->aud;
00411 if (x4->mbtree >= 0)
00412 x4->params.rc.b_mb_tree = x4->mbtree;
00413 if (x4->direct_pred >= 0)
00414 x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
00415
00416 if (x4->slice_max_size >= 0)
00417 x4->params.i_slice_max_size = x4->slice_max_size;
00418
00419 if (x4->fastfirstpass)
00420 x264_param_apply_fastfirstpass(&x4->params);
00421
00422 if (x4->profile)
00423 if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
00424 av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
00425 return AVERROR(EINVAL);
00426 }
00427
00428 x4->params.i_width = avctx->width;
00429 x4->params.i_height = avctx->height;
00430 x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num;
00431 x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
00432 x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den;
00433 x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num;
00434
00435 x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
00436
00437 x4->params.i_threads = avctx->thread_count;
00438
00439 x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
00440
00441 x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP);
00442
00443 x4->params.i_slice_count = avctx->slices;
00444
00445 x4->params.vui.b_fullrange = avctx->pix_fmt == PIX_FMT_YUVJ420P;
00446
00447 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
00448 x4->params.b_repeat_headers = 0;
00449
00450
00451 avctx->has_b_frames = x4->params.i_bframe ?
00452 x4->params.i_bframe_pyramid ? 2 : 1 : 0;
00453 if (avctx->max_b_frames < 0)
00454 avctx->max_b_frames = 0;
00455
00456 avctx->bit_rate = x4->params.rc.i_bitrate*1000;
00457 #if FF_API_X264_GLOBAL_OPTS
00458 avctx->crf = x4->params.rc.f_rf_constant;
00459 #endif
00460
00461 x4->enc = x264_encoder_open(&x4->params);
00462 if (!x4->enc)
00463 return -1;
00464
00465 avctx->coded_frame = &x4->out_pic;
00466
00467 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
00468 x264_nal_t *nal;
00469 int nnal, s, i;
00470
00471 s = x264_encoder_headers(x4->enc, &nal, &nnal);
00472
00473 for (i = 0; i < nnal; i++)
00474 if (nal[i].i_type == NAL_SEI)
00475 av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25);
00476
00477 avctx->extradata = av_malloc(s);
00478 avctx->extradata_size = encode_nals(avctx, avctx->extradata, s, nal, nnal, 1);
00479 }
00480
00481 return 0;
00482 }
00483
00484 static const enum PixelFormat pix_fmts_8bit[] = {
00485 PIX_FMT_YUV420P,
00486 PIX_FMT_YUVJ420P,
00487 PIX_FMT_YUV422P,
00488 PIX_FMT_YUV444P,
00489 PIX_FMT_NONE
00490 };
00491 static const enum PixelFormat pix_fmts_9bit[] = {
00492 PIX_FMT_YUV420P9,
00493 PIX_FMT_YUV444P9,
00494 PIX_FMT_NONE
00495 };
00496 static const enum PixelFormat pix_fmts_10bit[] = {
00497 PIX_FMT_YUV420P10,
00498 PIX_FMT_YUV422P10,
00499 PIX_FMT_YUV444P10,
00500 PIX_FMT_NONE
00501 };
00502
00503 static av_cold void X264_init_static(AVCodec *codec)
00504 {
00505 if (x264_bit_depth == 8)
00506 codec->pix_fmts = pix_fmts_8bit;
00507 else if (x264_bit_depth == 9)
00508 codec->pix_fmts = pix_fmts_9bit;
00509 else if (x264_bit_depth == 10)
00510 codec->pix_fmts = pix_fmts_10bit;
00511 }
00512
00513 #define OFFSET(x) offsetof(X264Context, x)
00514 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
00515 static const AVOption options[] = {
00516 { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE},
00517 { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
00518 { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
00519 { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), AV_OPT_TYPE_INT, { 1 }, 0, 1, VE},
00520 { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
00521 { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
00522 { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
00523 { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "aq_mode"},
00524 { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" },
00525 { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
00526 { "autovariance", "Auto-variance AQ (experimental)", 0, AV_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
00527 { "aq-strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), AV_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE},
00528 { "psy", "Use psychovisual optimizations.", OFFSET(psy), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
00529 { "psy-rd", "Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.", OFFSET(psy_rd), AV_OPT_TYPE_STRING, {0 }, 0, 0, VE},
00530 { "rc-lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
00531 { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
00532 { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "weightp" },
00533 { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" },
00534 { "simple", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" },
00535 { "smart", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" },
00536 { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
00537 { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),AV_OPT_TYPE_INT, {-1 }, -1, 1, VE },
00538 { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE },
00539 { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "b_pyramid" },
00540 { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, "b_pyramid" },
00541 { "strict", "Strictly hierarchical pyramid", 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, "b_pyramid" },
00542 { "normal", "Non-strict (not Blu-ray compatible)", 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, "b_pyramid" },
00543 { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, {-1}, -1, 1, VE },
00544 { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
00545 { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
00546 { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
00547 { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
00548 { "deblock", "Loop filter parameters, in <alpha:beta> form.", OFFSET(deblock), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
00549 { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE},
00550 { "partitions", "A comma-separated list of partitions to consider. "
00551 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all", OFFSET(partitions), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
00552 { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "direct-pred" },
00553 { "none", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
00554 { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
00555 { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
00556 { "auto", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
00557 { "slice-max-size","Limit the size of each slice in bytes", OFFSET(slice_max_size),AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE },
00558 { "stats", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
00559 { NULL },
00560 };
00561
00562 static const AVClass class = {
00563 .class_name = "libx264",
00564 .item_name = av_default_item_name,
00565 .option = options,
00566 .version = LIBAVUTIL_VERSION_INT,
00567 };
00568
00569 static const AVCodecDefault x264_defaults[] = {
00570 { "b", "0" },
00571 { "bf", "-1" },
00572 { "g", "-1" },
00573 { "qmin", "-1" },
00574 { "qmax", "-1" },
00575 { "qdiff", "-1" },
00576 { "qblur", "-1" },
00577 { "qcomp", "-1" },
00578 { "refs", "-1" },
00579 { "sc_threshold", "-1" },
00580 { "trellis", "-1" },
00581 { "nr", "-1" },
00582 { "me_range", "-1" },
00583 { "me_method", "-1" },
00584 { "subq", "-1" },
00585 { "b_strategy", "-1" },
00586 { "keyint_min", "-1" },
00587 { "coder", "-1" },
00588 { "cmp", "-1" },
00589 { "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
00590 { NULL },
00591 };
00592
00593 AVCodec ff_libx264_encoder = {
00594 .name = "libx264",
00595 .type = AVMEDIA_TYPE_VIDEO,
00596 .id = CODEC_ID_H264,
00597 .priv_data_size = sizeof(X264Context),
00598 .init = X264_init,
00599 .encode = X264_frame,
00600 .close = X264_close,
00601 .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS,
00602 .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
00603 .priv_class = &class,
00604 .defaults = x264_defaults,
00605 .init_static_data = X264_init_static,
00606 };