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