31 #define X264_API_IMPORTS 1
84 static const int level_map[] = {
91 if (level < 0 || level > X264_LOG_DEBUG)
94 av_vlog(p, level_map[level], fmt, args);
99 x264_nal_t *nals,
int nnal)
108 for (i = 0; i < nnal; i++)
109 size += nals[i].i_payload;
123 for (i = 0; i < nnal; i++){
124 memcpy(p, nals[i].p_payload, nals[i].i_payload);
125 p += nals[i].i_payload;
137 x264_picture_t pic_out;
140 x264_picture_init( &x4->
pic );
142 if (x264_bit_depth > 8)
143 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
144 x4->
pic.img.i_plane = 3;
147 for (i = 0; i < 3; i++) {
148 x4->
pic.img.plane[i] = frame->
data[i];
152 x4->
pic.i_pts = frame->
pts;
160 x264_encoder_reconfig(x4->
enc, &x4->
params);
166 x264_encoder_reconfig(x4->
enc, &x4->
params);
174 switch (stereo->
type) {
198 if (fpa_type != x4->
params.i_frame_packing) {
199 x4->
params.i_frame_packing = fpa_type;
200 x264_encoder_reconfig(x4->
enc, &x4->
params);
205 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic:
NULL, &pic_out) < 0)
211 }
while (!ret && !frame && x264_encoder_delayed_frames(x4->
enc));
213 pkt->
pts = pic_out.i_pts;
214 pkt->
dts = pic_out.i_dts;
216 switch (pic_out.i_type) {
246 x264_encoder_close(x4->
enc);
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);\
282 x264_param_default(&x4->
params);
292 if (avctx->
level > 0)
296 x4->
params.p_log_private = avctx;
297 x4->
params.i_log_level = X264_LOG_DEBUG;
302 x4->
params.rc.i_rc_method = X264_RC_ABR;
308 x4->
params.rc.b_stat_read = 1;
311 x4->
params.rc.i_rc_method = X264_RC_CRF;
313 }
else if (x4->
cqp >= 0) {
314 x4->
params.rc.i_rc_method = X264_RC_CQP;
324 x4->
params.rc.f_vbv_buffer_init =
334 x4->
params.analyse.i_me_method = X264_ME_DIA;
336 x4->
params.analyse.i_me_method = X264_ME_HEX;
338 x4->
params.analyse.i_me_method = X264_ME_UMH;
340 x4->
params.analyse.i_me_method = X264_ME_ESA;
342 x4->
params.analyse.i_me_method = X264_ME_TESA;
350 if (avctx->
qmin >= 0)
352 if (avctx->
qmax >= 0)
356 if (avctx->
qblur >= 0)
360 if (avctx->
refs >= 0)
404 x4->
params.b_vfr_input = 0;
406 if (x4->
b_bias != INT_MIN)
427 x264_param_apply_fastfirstpass(&x4->
params);
433 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
460 x4->
params.b_repeat_headers = 0;
470 "Error parsing option '%s = %s'.\n",
480 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
486 x4->
enc = x264_encoder_open(&x4->
params);
499 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
502 for (i = 0; i < nnal; i++) {
504 if (nal[i].i_type ==
NAL_SEI) {
508 memcpy(x4->
sei, nal[i].p_payload, nal[i].i_payload);
511 memcpy(p, nal[i].p_payload, nal[i].i_payload);
512 p += nal[i].i_payload;
544 if (x264_bit_depth == 8)
546 else if (x264_bit_depth == 9)
548 else if (x264_bit_depth == 10)
552 #define OFFSET(x) offsetof(X264Context, x)
553 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
555 {
"preset",
"Set the encoding preset (cf. x264 --fullhelp)",
OFFSET(preset),
AV_OPT_TYPE_STRING, { .str =
"medium" }, 0, 0,
VE},
558 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE},
559 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
560 {
"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 },
561 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
564 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
565 {
"autovariance",
"Auto-variance AQ (experimental)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
566 {
"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},
568 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
569 {
"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 },
570 {
"weightb",
"Weighted prediction for B-frames.",
OFFSET(weightb),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
571 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"weightp" },
576 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
577 {
"bluray-compat",
"Bluray compatibility workarounds.",
OFFSET(bluray_compat) ,
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
578 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
579 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"b_pyramid" },
581 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
582 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
583 {
"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 },
589 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
590 {
"partitions",
"A comma-separated list of partitions to consider. "
591 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
592 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"direct-pred" },
597 {
"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 },
599 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
604 {
"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 },
619 {
"i_qfactor",
"-1" },
626 {
"sc_threshold",
"-1" },
629 {
"me_range",
"-1" },
630 {
"me_method",
"-1" },
632 {
"b_strategy",
"-1" },
633 {
"keyint_min",
"-1" },
637 {
"thread_type",
"0" },
638 {
"flags",
"+cgop" },
639 {
"rc_init_occupancy",
"-1" },
653 .priv_class = &
class,