2 * H.264 encoding using the x264 library
3 * Copyright (C) 2005 Mans Rullgard <mans@mansr.com>
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/internal.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/pixdesc.h"
35 typedef struct X264Context {
77 static void X264_log(void *p, int level, const char *fmt, va_list args)
79 static const int level_map[] = {
80 [X264_LOG_ERROR] = AV_LOG_ERROR,
81 [X264_LOG_WARNING] = AV_LOG_WARNING,
82 [X264_LOG_INFO] = AV_LOG_INFO,
83 [X264_LOG_DEBUG] = AV_LOG_DEBUG
86 if (level < 0 || level > X264_LOG_DEBUG)
89 av_vlog(p, level_map[level], fmt, args);
93 static int encode_nals(AVCodecContext *ctx, AVPacket *pkt,
94 x264_nal_t *nals, int nnal)
96 X264Context *x4 = ctx->priv_data;
98 int i, size = x4->sei_size, ret;
103 for (i = 0; i < nnal; i++)
104 size += nals[i].i_payload;
106 if ((ret = ff_alloc_packet2(ctx, pkt, size)) < 0)
111 /* Write the SEI as part of the first frame. */
112 if (x4->sei_size > 0 && nnal > 0) {
113 if (x4->sei_size > size) {
114 av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n");
117 memcpy(p, x4->sei, x4->sei_size);
123 for (i = 0; i < nnal; i++){
124 memcpy(p, nals[i].p_payload, nals[i].i_payload);
125 p += nals[i].i_payload;
131 static int avfmt2_num_planes(int avfmt)
134 case PIX_FMT_YUV420P:
135 case PIX_FMT_YUVJ420P:
136 case PIX_FMT_YUV420P9:
137 case PIX_FMT_YUV420P10:
138 case PIX_FMT_YUV444P:
150 static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
153 X264Context *x4 = ctx->priv_data;
156 x264_picture_t pic_out;
158 x264_picture_init( &x4->pic );
159 x4->pic.img.i_csp = x4->params.i_csp;
160 if (x264_bit_depth > 8)
161 x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
162 x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt);
165 for (i = 0; i < x4->pic.img.i_plane; i++) {
166 x4->pic.img.plane[i] = frame->data[i];
167 x4->pic.img.i_stride[i] = frame->linesize[i];
170 x4->pic.i_pts = frame->pts;
172 frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME :
173 frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P :
174 frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B :
176 if (x4->params.b_tff != frame->top_field_first) {
177 x4->params.b_tff = frame->top_field_first;
178 x264_encoder_reconfig(x4->enc, &x4->params);
180 if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den ||
181 x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) {
182 x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;
183 x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num;
184 x264_encoder_reconfig(x4->enc, &x4->params);
189 if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)
192 ret = encode_nals(ctx, pkt, nal, nnal);
195 } while (!ret && !frame && x264_encoder_delayed_frames(x4->enc));
197 pkt->pts = pic_out.i_pts;
198 pkt->dts = pic_out.i_dts;
200 switch (pic_out.i_type) {
203 x4->out_pic.pict_type = AV_PICTURE_TYPE_I;
206 x4->out_pic.pict_type = AV_PICTURE_TYPE_P;
210 x4->out_pic.pict_type = AV_PICTURE_TYPE_B;
214 pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;
216 x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
222 static av_cold int X264_close(AVCodecContext *avctx)
224 X264Context *x4 = avctx->priv_data;
226 av_freep(&avctx->extradata);
230 x264_encoder_close(x4->enc);
235 #define OPT_STR(opt, param) \
238 if (param && (ret = x264_param_parse(&x4->params, opt, param)) < 0) { \
239 if(ret == X264_PARAM_BAD_NAME) \
240 av_log(avctx, AV_LOG_ERROR, \
241 "bad option '%s': '%s'\n", opt, param); \
243 av_log(avctx, AV_LOG_ERROR, \
244 "bad value for '%s': '%s'\n", opt, param); \
249 static int convert_pix_fmt(enum PixelFormat pix_fmt)
252 case PIX_FMT_YUV420P:
253 case PIX_FMT_YUVJ420P:
254 case PIX_FMT_YUV420P9:
255 case PIX_FMT_YUV420P10: return X264_CSP_I420;
256 case PIX_FMT_YUV422P:
257 case PIX_FMT_YUV422P10: return X264_CSP_I422;
258 case PIX_FMT_YUV444P:
259 case PIX_FMT_YUV444P9:
260 case PIX_FMT_YUV444P10: return X264_CSP_I444;
272 #define PARSE_X264_OPT(name, var)\
273 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
274 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
275 return AVERROR(EINVAL);\
278 static av_cold int X264_init(AVCodecContext *avctx)
280 X264Context *x4 = avctx->priv_data;
283 x264_param_default(&x4->params);
285 x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
287 x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
288 x4->params.rc.f_pb_factor = avctx->b_quant_factor;
289 x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
290 if (x4->preset || x4->tune)
291 if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) {
293 av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune);
294 av_log(avctx, AV_LOG_INFO, "Possible presets:");
295 for (i = 0; x264_preset_names[i]; i++)
296 av_log(avctx, AV_LOG_INFO, " %s", x264_preset_names[i]);
297 av_log(avctx, AV_LOG_INFO, "\n");
298 av_log(avctx, AV_LOG_INFO, "Possible tunes:");
299 for (i = 0; x264_tune_names[i]; i++)
300 av_log(avctx, AV_LOG_INFO, " %s", x264_tune_names[i]);
301 av_log(avctx, AV_LOG_INFO, "\n");
302 return AVERROR(EINVAL);
305 if (avctx->level > 0)
306 x4->params.i_level_idc = avctx->level;
308 x4->params.pf_log = X264_log;
309 x4->params.p_log_private = avctx;
310 x4->params.i_log_level = X264_LOG_DEBUG;
311 x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt);
313 OPT_STR("weightp", x4->wpredp);
315 if (avctx->bit_rate) {
316 x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
317 x4->params.rc.i_rc_method = X264_RC_ABR;
319 x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
320 x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
321 x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
322 if (avctx->flags & CODEC_FLAG_PASS2) {
323 x4->params.rc.b_stat_read = 1;
326 x4->params.rc.i_rc_method = X264_RC_CRF;
327 x4->params.rc.f_rf_constant = x4->crf;
328 } else if (x4->cqp >= 0) {
329 x4->params.rc.i_rc_method = X264_RC_CQP;
330 x4->params.rc.i_qp_constant = x4->cqp;
333 if (x4->crf_max >= 0)
334 x4->params.rc.f_rf_constant_max = x4->crf_max;
337 if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
338 (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
339 x4->params.rc.f_vbv_buffer_init =
340 (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
343 OPT_STR("level", x4->level);
346 const char *p= x4->x264opts;
348 char param[256]={0}, val[256]={0};
349 if(sscanf(p, "%255[^:=]=%255[^:]", param, val) == 1){
358 if (avctx->me_method == ME_EPZS)
359 x4->params.analyse.i_me_method = X264_ME_DIA;
360 else if (avctx->me_method == ME_HEX)
361 x4->params.analyse.i_me_method = X264_ME_HEX;
362 else if (avctx->me_method == ME_UMH)
363 x4->params.analyse.i_me_method = X264_ME_UMH;
364 else if (avctx->me_method == ME_FULL)
365 x4->params.analyse.i_me_method = X264_ME_ESA;
366 else if (avctx->me_method == ME_TESA)
367 x4->params.analyse.i_me_method = X264_ME_TESA;
369 if (avctx->gop_size >= 0)
370 x4->params.i_keyint_max = avctx->gop_size;
371 if (avctx->max_b_frames >= 0)
372 x4->params.i_bframe = avctx->max_b_frames;
373 if (avctx->scenechange_threshold >= 0)
374 x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
375 if (avctx->qmin >= 0)
376 x4->params.rc.i_qp_min = avctx->qmin;
377 if (avctx->qmax >= 0)
378 x4->params.rc.i_qp_max = avctx->qmax;
379 if (avctx->max_qdiff >= 0)
380 x4->params.rc.i_qp_step = avctx->max_qdiff;
381 if (avctx->qblur >= 0)
382 x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
383 if (avctx->qcompress >= 0)
384 x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
385 if (avctx->refs >= 0)
386 x4->params.i_frame_reference = avctx->refs;
387 if (avctx->trellis >= 0)
388 x4->params.analyse.i_trellis = avctx->trellis;
389 if (avctx->me_range >= 0)
390 x4->params.analyse.i_me_range = avctx->me_range;
391 if (avctx->noise_reduction >= 0)
392 x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
393 if (avctx->me_subpel_quality >= 0)
394 x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
395 if (avctx->b_frame_strategy >= 0)
396 x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
397 if (avctx->keyint_min >= 0)
398 x4->params.i_keyint_min = avctx->keyint_min;
399 if (avctx->coder_type >= 0)
400 x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
401 if (avctx->me_cmp >= 0)
402 x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
404 if (x4->aq_mode >= 0)
405 x4->params.rc.i_aq_mode = x4->aq_mode;
406 if (x4->aq_strength >= 0)
407 x4->params.rc.f_aq_strength = x4->aq_strength;
408 PARSE_X264_OPT("psy-rd", psy_rd);
409 PARSE_X264_OPT("deblock", deblock);
410 PARSE_X264_OPT("partitions", partitions);
411 PARSE_X264_OPT("stats", stats);
413 x4->params.analyse.b_psy = x4->psy;
414 if (x4->rc_lookahead >= 0)
415 x4->params.rc.i_lookahead = x4->rc_lookahead;
416 if (x4->weightp >= 0)
417 x4->params.analyse.i_weighted_pred = x4->weightp;
418 if (x4->weightb >= 0)
419 x4->params.analyse.b_weighted_bipred = x4->weightb;
420 if (x4->cplxblur >= 0)
421 x4->params.rc.f_complexity_blur = x4->cplxblur;
424 x4->params.analyse.b_ssim = x4->ssim;
425 if (x4->intra_refresh >= 0)
426 x4->params.b_intra_refresh = x4->intra_refresh;
427 if (x4->b_bias != INT_MIN)
428 x4->params.i_bframe_bias = x4->b_bias;
429 if (x4->b_pyramid >= 0)
430 x4->params.i_bframe_pyramid = x4->b_pyramid;
431 if (x4->mixed_refs >= 0)
432 x4->params.analyse.b_mixed_references = x4->mixed_refs;
434 x4->params.analyse.b_transform_8x8 = x4->dct8x8;
435 if (x4->fast_pskip >= 0)
436 x4->params.analyse.b_fast_pskip = x4->fast_pskip;
438 x4->params.b_aud = x4->aud;
440 x4->params.rc.b_mb_tree = x4->mbtree;
441 if (x4->direct_pred >= 0)
442 x4->params.analyse.i_direct_mv_pred = x4->direct_pred;
444 if (x4->slice_max_size >= 0)
445 x4->params.i_slice_max_size = x4->slice_max_size;
448 * Allow x264 to be instructed through AVCodecContext about the maximum
449 * size of the RTP payload. For example, this enables the production of
450 * payload suitable for the H.264 RTP packetization-mode 0 i.e. single
451 * NAL unit per RTP packet.
453 if (avctx->rtp_payload_size)
454 x4->params.i_slice_max_size = avctx->rtp_payload_size;
457 if (x4->fastfirstpass)
458 x264_param_apply_fastfirstpass(&x4->params);
461 if (x264_param_apply_profile(&x4->params, x4->profile) < 0) {
463 av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile);
464 av_log(avctx, AV_LOG_INFO, "Possible profiles:");
465 for (i = 0; x264_profile_names[i]; i++)
466 av_log(avctx, AV_LOG_INFO, " %s", x264_profile_names[i]);
467 av_log(avctx, AV_LOG_INFO, "\n");
468 return AVERROR(EINVAL);
471 x4->params.i_width = avctx->width;
472 x4->params.i_height = avctx->height;
473 av_reduce(&sw, &sh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096);
474 x4->params.vui.i_sar_width = sw;
475 x4->params.vui.i_sar_height = sh;
476 x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den;
477 x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num;
479 x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
481 x4->params.i_threads = avctx->thread_count;
482 if (avctx->thread_type)
483 x4->params.b_sliced_threads = avctx->thread_type == FF_THREAD_SLICE;
485 x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
487 // x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP);
489 x4->params.i_slice_count = avctx->slices;
491 x4->params.vui.b_fullrange = avctx->pix_fmt == PIX_FMT_YUVJ420P;
493 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
494 x4->params.b_repeat_headers = 0;
496 // update AVCodecContext with x264 parameters
497 avctx->has_b_frames = x4->params.i_bframe ?
498 x4->params.i_bframe_pyramid ? 2 : 1 : 0;
499 if (avctx->max_b_frames < 0)
500 avctx->max_b_frames = 0;
502 avctx->bit_rate = x4->params.rc.i_bitrate*1000;
504 x4->enc = x264_encoder_open(&x4->params);
508 avctx->coded_frame = &x4->out_pic;
510 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
515 s = x264_encoder_headers(x4->enc, &nal, &nnal);
516 avctx->extradata = p = av_malloc(s);
518 for (i = 0; i < nnal; i++) {
519 /* Don't put the SEI in extradata. */
520 if (nal[i].i_type == NAL_SEI) {
521 av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25);
522 x4->sei_size = nal[i].i_payload;
523 x4->sei = av_malloc(x4->sei_size);
524 memcpy(x4->sei, nal[i].p_payload, nal[i].i_payload);
527 memcpy(p, nal[i].p_payload, nal[i].i_payload);
528 p += nal[i].i_payload;
530 avctx->extradata_size = p - avctx->extradata;
536 static const enum PixelFormat pix_fmts_8bit[] = {
543 static const enum PixelFormat pix_fmts_9bit[] = {
548 static const enum PixelFormat pix_fmts_10bit[] = {
554 static const enum PixelFormat pix_fmts_8bit_rgb[] = {
562 static av_cold void X264_init_static(AVCodec *codec)
564 if (x264_bit_depth == 8)
565 codec->pix_fmts = pix_fmts_8bit;
566 else if (x264_bit_depth == 9)
567 codec->pix_fmts = pix_fmts_9bit;
568 else if (x264_bit_depth == 10)
569 codec->pix_fmts = pix_fmts_10bit;
572 #define OFFSET(x) offsetof(X264Context, x)
573 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
574 static const AVOption options[] = {
575 { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE},
576 { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
577 { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
578 { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE},
579 {"level", "Specify level (as defined by Annex A)", OFFSET(level), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
580 {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
581 {"wpredp", "Weighted prediction for P-frames", OFFSET(wpredp), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
582 {"x264opts", "x264 options", OFFSET(x264opts), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
583 { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE },
584 { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE },
585 { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
586 { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "aq_mode"},
587 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" },
588 { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
589 { "autovariance", "Auto-variance AQ (experimental)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" },
590 { "aq-strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), AV_OPT_TYPE_FLOAT, {.dbl = -1}, -1, FLT_MAX, VE},
591 { "psy", "Use psychovisual optimizations.", OFFSET(psy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
592 { "psy-rd", "Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.", OFFSET(psy_rd), AV_OPT_TYPE_STRING, {0 }, 0, 0, VE},
593 { "rc-lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
594 { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
595 { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "weightp" },
596 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" },
597 { "simple", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" },
598 { "smart", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" },
599 { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
600 { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
601 { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX, VE },
602 { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "b_pyramid" },
603 { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, "b_pyramid" },
604 { "strict", "Strictly hierarchical pyramid", 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, "b_pyramid" },
605 { "normal", "Non-strict (not Blu-ray compatible)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, "b_pyramid" },
606 { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 1, VE },
607 { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE},
608 { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE},
609 { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE},
610 { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE},
611 { "deblock", "Loop filter parameters, in <alpha:beta> form.", OFFSET(deblock), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
612 { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE},
613 { "partitions", "A comma-separated list of partitions to consider. "
614 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all", OFFSET(partitions), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
615 { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, "direct-pred" },
616 { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
617 { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
618 { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
619 { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
620 { "slice-max-size","Limit the size of each slice in bytes", OFFSET(slice_max_size),AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
621 { "stats", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
625 static const AVClass class = {
626 .class_name = "libx264",
627 .item_name = av_default_item_name,
629 .version = LIBAVUTIL_VERSION_INT,
632 static const AVClass rgbclass = {
633 .class_name = "libx264rgb",
634 .item_name = av_default_item_name,
636 .version = LIBAVUTIL_VERSION_INT,
639 static const AVCodecDefault x264_defaults[] = {
649 // { "rc_lookahead", "-1" },
651 { "sc_threshold", "-1" },
654 { "me_range", "-1" },
655 { "me_method", "-1" },
657 { "b_strategy", "-1" },
658 { "keyint_min", "-1" },
661 { "threads", AV_STRINGIFY(X264_THREADS_AUTO) },
662 { "thread_type", "0" },
666 AVCodec ff_libx264_encoder = {
668 .type = AVMEDIA_TYPE_VIDEO,
669 .id = AV_CODEC_ID_H264,
670 .priv_data_size = sizeof(X264Context),
672 .encode2 = X264_frame,
674 .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS,
675 .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
676 .priv_class = &class,
677 .defaults = x264_defaults,
678 .init_static_data = X264_init_static,
681 AVCodec ff_libx264rgb_encoder = {
682 .name = "libx264rgb",
683 .type = AVMEDIA_TYPE_VIDEO,
684 .id = AV_CODEC_ID_H264,
685 .priv_data_size = sizeof(X264Context),
687 .encode2 = X264_frame,
689 .capabilities = CODEC_CAP_DELAY,
690 .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
691 .priv_class = &rgbclass,
692 .defaults = x264_defaults,
693 .pix_fmts = pix_fmts_8bit_rgb,