81 static const int level_map[] = {
88 if (level < 0 || level > X264_LOG_DEBUG)
91 av_vlog(p, level_map[level], fmt, args);
96 x264_nal_t *nals,
int nnal)
105 for (i = 0; i < nnal; i++)
106 size += nals[i].i_payload;
125 for (i = 0; i < nnal; i++){
126 memcpy(p, nals[i].p_payload, nals[i].i_payload);
127 p += nals[i].i_payload;
158 x264_picture_t pic_out = {0};
160 x264_picture_init( &x4->
pic );
162 if (x264_bit_depth > 8)
163 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
167 for (i = 0; i < x4->
pic.img.i_plane; i++) {
168 x4->
pic.img.plane[i] = frame->
data[i];
172 x4->
pic.i_pts = frame->
pts;
180 x264_encoder_reconfig(x4->
enc, &x4->
params);
186 x264_encoder_reconfig(x4->
enc, &x4->
params);
191 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic: NULL, &pic_out) < 0)
197 }
while (!ret && !frame && x264_encoder_delayed_frames(x4->
enc));
199 pkt->
pts = pic_out.i_pts;
200 pkt->
dts = pic_out.i_dts;
202 switch (pic_out.i_type) {
232 x264_encoder_close(x4->
enc);
237 #define OPT_STR(opt, param) \
240 if (param!=NULL && (ret = x264_param_parse(&x4->params, opt, param)) < 0) { \
241 if(ret == X264_PARAM_BAD_NAME) \
242 av_log(avctx, AV_LOG_ERROR, \
243 "bad option '%s': '%s'\n", opt, param); \
245 av_log(avctx, AV_LOG_ERROR, \
246 "bad value for '%s': '%s'\n", opt, param); \
274 #define PARSE_X264_OPT(name, var)\
275 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
276 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
277 return AVERROR(EINVAL);\
285 x264_param_default(&x4->
params);
296 for (i = 0; x264_preset_names[i]; i++)
300 for (i = 0; x264_tune_names[i]; i++)
306 if (avctx->
level > 0)
310 x4->
params.p_log_private = avctx;
311 x4->
params.i_log_level = X264_LOG_DEBUG;
318 x4->
params.rc.i_rc_method = X264_RC_ABR;
324 x4->
params.rc.b_stat_read = 1;
327 x4->
params.rc.i_rc_method = X264_RC_CRF;
329 }
else if (x4->
cqp >= 0) {
330 x4->
params.rc.i_rc_method = X264_RC_CQP;
340 x4->
params.rc.f_vbv_buffer_init =
349 char param[256]={0},
val[256]={0};
350 if(sscanf(p,
"%255[^:=]=%255[^:]", param,
val) == 1){
363 x4->
params.analyse.i_me_method = X264_ME_DIA;
365 x4->
params.analyse.i_me_method = X264_ME_HEX;
367 x4->
params.analyse.i_me_method = X264_ME_UMH;
369 x4->
params.analyse.i_me_method = X264_ME_ESA;
371 x4->
params.analyse.i_me_method = X264_ME_TESA;
379 if (avctx->
qmin >= 0)
381 if (avctx->
qmax >= 0)
385 if (avctx->
qblur >= 0)
389 if (avctx->
refs >= 0)
431 if (x4->
b_bias != INT_MIN)
462 x264_param_apply_fastfirstpass(&x4->
params);
493 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
497 for (i = 0; x264_profile_names[i]; i++)
506 x4->
params.vui.i_sar_width = sw;
507 x4->
params.vui.i_sar_height = sh;
526 x4->
params.b_repeat_headers = 0;
536 "Error parsing option '%s = %s'.\n",
546 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
552 x4->
enc = x264_encoder_open(&x4->
params);
563 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
566 for (i = 0; i < nnal; i++) {
568 if (nal[i].i_type ==
NAL_SEI) {
572 memcpy(x4->
sei, nal[i].p_payload, nal[i].i_payload);
575 memcpy(p, nal[i].p_payload, nal[i].i_payload);
576 p += nal[i].i_payload;
612 if (x264_bit_depth == 8)
614 else if (x264_bit_depth == 9)
616 else if (x264_bit_depth == 10)
620 #define OFFSET(x) offsetof(X264Context, x)
621 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
626 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE},
631 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
632 {
"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 },
633 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
635 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_NONE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
636 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
637 {
"autovariance",
"Auto-variance AQ (experimental)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
638 {
"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},
640 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
641 {
"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 },
642 {
"weightb",
"Weighted prediction for B-frames.",
OFFSET(weightb),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
643 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"weightp" },
644 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_NONE}, INT_MIN, INT_MAX,
VE,
"weightp" },
645 {
"simple", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX,
VE,
"weightp" },
646 {
"smart", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SMART}, INT_MIN, INT_MAX,
VE,
"weightp" },
648 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
649 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
650 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"b_pyramid" },
651 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
652 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
653 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
654 {
"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 },
660 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
661 {
"partitions",
"A comma-separated list of partitions to consider. "
662 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
663 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"direct-pred" },
664 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_NONE }, 0, 0,
VE,
"direct-pred" },
665 {
"spatial", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_SPATIAL }, 0, 0,
VE,
"direct-pred" },
666 {
"temporal", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_TEMPORAL }, 0, 0,
VE,
"direct-pred" },
667 {
"auto", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_AUTO }, 0, 0,
VE,
"direct-pred" },
668 {
"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 },
670 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
672 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX,
VE,
"nal-hrd" },
673 {
"vbr", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR}, INT_MIN, INT_MAX,
VE,
"nal-hrd" },
674 {
"cbr", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR}, INT_MIN, INT_MAX,
VE,
"nal-hrd" },
675 {
"x264-params",
"Override the x264 configuration using a :-separated list of key=value parameters",
OFFSET(x264_params),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE },
698 {
"i_qfactor",
"-1" },
706 {
"sc_threshold",
"-1" },
709 {
"me_range",
"-1" },
710 {
"me_method",
"-1" },
712 {
"b_strategy",
"-1" },
713 {
"keyint_min",
"-1" },
717 {
"thread_type",
"0" },
718 {
"flags",
"+cgop" },
719 {
"rc_init_occupancy",
"-1" },
739 .
name =
"libx264rgb",