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