77 static const int level_map[] = {
84 if (level < 0 || level > X264_LOG_DEBUG)
87 av_vlog(p, level_map[level], fmt, args);
92 x264_nal_t *nals,
int nnal)
101 for (i = 0; i < nnal; i++)
102 size += nals[i].i_payload;
116 for (i = 0; i < nnal; i++){
117 memcpy(p, nals[i].p_payload, nals[i].i_payload);
118 p += nals[i].i_payload;
130 x264_picture_t pic_out;
132 x264_picture_init( &x4->
pic );
134 if (x264_bit_depth > 8)
135 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
136 x4->
pic.img.i_plane = 3;
139 for (i = 0; i < 3; i++) {
140 x4->
pic.img.plane[i] = frame->
data[i];
144 x4->
pic.i_pts = frame->
pts;
152 x264_encoder_reconfig(x4->
enc, &x4->
params);
158 x264_encoder_reconfig(x4->
enc, &x4->
params);
163 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic:
NULL, &pic_out) < 0)
169 }
while (!ret && !frame && x264_encoder_delayed_frames(x4->
enc));
171 pkt->
pts = pic_out.i_pts;
172 pkt->
dts = pic_out.i_dts;
174 switch (pic_out.i_type) {
204 x264_encoder_close(x4->
enc);
225 #define PARSE_X264_OPT(name, var)\
226 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
227 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
228 return AVERROR(EINVAL);\
235 x264_param_default(&x4->
params);
245 if (avctx->
level > 0)
249 x4->
params.p_log_private = avctx;
250 x4->
params.i_log_level = X264_LOG_DEBUG;
255 x4->
params.rc.i_rc_method = X264_RC_ABR;
261 x4->
params.rc.b_stat_read = 1;
264 x4->
params.rc.i_rc_method = X264_RC_CRF;
266 }
else if (x4->
cqp >= 0) {
267 x4->
params.rc.i_rc_method = X264_RC_CQP;
277 x4->
params.rc.f_vbv_buffer_init =
286 x4->
params.analyse.i_me_method = X264_ME_DIA;
288 x4->
params.analyse.i_me_method = X264_ME_HEX;
290 x4->
params.analyse.i_me_method = X264_ME_UMH;
292 x4->
params.analyse.i_me_method = X264_ME_ESA;
294 x4->
params.analyse.i_me_method = X264_ME_TESA;
302 if (avctx->
qmin >= 0)
304 if (avctx->
qmax >= 0)
308 if (avctx->
qblur >= 0)
312 if (avctx->
refs >= 0)
354 if (x4->
b_bias != INT_MIN)
375 x264_param_apply_fastfirstpass(&x4->
params);
381 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
408 x4->
params.b_repeat_headers = 0;
412 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
418 x4->
enc = x264_encoder_open(&x4->
params);
429 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
432 for (i = 0; i < nnal; i++) {
434 if (nal[i].i_type ==
NAL_SEI) {
438 memcpy(x4->
sei, nal[i].p_payload, nal[i].i_payload);
441 memcpy(p, nal[i].p_payload, nal[i].i_payload);
442 p += nal[i].i_payload;
471 if (x264_bit_depth == 8)
473 else if (x264_bit_depth == 9)
475 else if (x264_bit_depth == 10)
479 #define OFFSET(x) offsetof(X264Context, x)
480 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
482 {
"preset",
"Set the encoding preset (cf. x264 --fullhelp)",
OFFSET(preset),
AV_OPT_TYPE_STRING, { .str =
"medium" }, 0, 0,
VE},
485 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE},
486 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
487 {
"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 },
488 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
491 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
492 {
"autovariance",
"Auto-variance AQ (experimental)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
493 {
"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},
495 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
496 {
"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 },
497 {
"weightb",
"Weighted prediction for B-frames.",
OFFSET(weightb),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
498 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"weightp" },
503 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
504 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
505 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"b_pyramid" },
507 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
508 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
509 {
"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 },
515 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
516 {
"partitions",
"A comma-separated list of partitions to consider. "
517 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
518 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"direct-pred" },
523 {
"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 },
525 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
550 {
"sc_threshold",
"-1" },
553 {
"me_range",
"-1" },
554 {
"me_method",
"-1" },
556 {
"b_strategy",
"-1" },
557 {
"keyint_min",
"-1" },
561 {
"thread_type",
"0" },
562 {
"flags",
"+cgop" },
563 {
"rc_init_occupancy",
"-1" },
577 .priv_class = &
class,