74 static const int level_map[] = {
81 if (level < 0 || level > X264_LOG_DEBUG)
84 av_vlog(p, level_map[level], fmt, args);
89 x264_nal_t *nals,
int nnal,
int skip_sei)
102 for (i = 0; i < nnal; i++){
104 if (skip_sei && nals[i].i_type ==
NAL_SEI) {
107 memcpy(x4->
sei, nals[i].p_payload, nals[i].i_payload);
110 memcpy(p, nals[i].p_payload, nals[i].i_payload);
111 p += nals[i].i_payload;
118 int bufsize,
void *
data)
124 x264_picture_t pic_out;
126 x264_picture_init( &x4->
pic );
128 if (x264_bit_depth > 8)
129 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
130 x4->
pic.img.i_plane = 3;
133 for (i = 0; i < 3; i++) {
134 x4->
pic.img.plane[i] = frame->
data[i];
138 x4->
pic.i_pts = frame->
pts;
146 x264_encoder_reconfig(x4->
enc, &x4->
params);
151 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic:
NULL, &pic_out) < 0)
154 bufsize =
encode_nals(ctx, buf, bufsize, nal, nnal, 0);
157 }
while (!bufsize && !frame && x264_encoder_delayed_frames(x4->
enc));
162 switch (pic_out.i_type) {
191 x264_encoder_close(x4->
enc);
212 #define PARSE_X264_OPT(name, var)\
213 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
214 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
215 return AVERROR(EINVAL);\
222 x264_param_default(&x4->
params);
232 if (avctx->
level > 0)
236 x4->
params.p_log_private = avctx;
237 x4->
params.i_log_level = X264_LOG_DEBUG;
242 x4->
params.rc.i_rc_method = X264_RC_ABR;
248 x4->
params.rc.b_stat_read = 1;
250 #if FF_API_X264_GLOBAL_OPTS
252 x4->
params.rc.i_rc_method = X264_RC_CRF;
253 x4->
params.rc.f_rf_constant = avctx->crf;
254 x4->
params.rc.f_rf_constant_max = avctx->crf_max;
255 }
else if (avctx->cqp > -1) {
256 x4->
params.rc.i_rc_method = X264_RC_CQP;
257 x4->
params.rc.i_qp_constant = avctx->cqp;
262 x4->
params.rc.i_rc_method = X264_RC_CRF;
264 }
else if (x4->
cqp >= 0) {
265 x4->
params.rc.i_rc_method = X264_RC_CQP;
275 x4->
params.rc.f_vbv_buffer_init =
283 #if FF_API_X264_GLOBAL_OPTS
284 if (avctx->aq_mode >= 0)
285 x4->
params.rc.i_aq_mode = avctx->aq_mode;
286 if (avctx->aq_strength >= 0)
287 x4->
params.rc.f_aq_strength = avctx->aq_strength;
288 if (avctx->psy_rd >= 0)
289 x4->
params.analyse.f_psy_rd = avctx->psy_rd;
290 if (avctx->psy_trellis >= 0)
291 x4->
params.analyse.f_psy_trellis = avctx->psy_trellis;
292 if (avctx->rc_lookahead >= 0)
293 x4->
params.rc.i_lookahead = avctx->rc_lookahead;
294 if (avctx->weighted_p_pred >= 0)
295 x4->
params.analyse.i_weighted_pred = avctx->weighted_p_pred;
296 if (avctx->bframebias)
297 x4->
params.i_bframe_bias = avctx->bframebias;
298 if (avctx->deblockalpha)
299 x4->
params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
300 if (avctx->deblockbeta)
301 x4->
params.i_deblocking_filter_beta = avctx->deblockbeta;
302 if (avctx->complexityblur >= 0)
303 x4->
params.rc.f_complexity_blur = avctx->complexityblur;
304 if (avctx->directpred >= 0)
305 x4->
params.analyse.i_direct_mv_pred = avctx->directpred;
306 if (avctx->partitions) {
307 if (avctx->partitions & X264_PART_I4X4)
308 x4->
params.analyse.inter |= X264_ANALYSE_I4x4;
309 if (avctx->partitions & X264_PART_I8X8)
310 x4->
params.analyse.inter |= X264_ANALYSE_I8x8;
311 if (avctx->partitions & X264_PART_P8X8)
312 x4->
params.analyse.inter |= X264_ANALYSE_PSUB16x16;
313 if (avctx->partitions & X264_PART_P4X4)
314 x4->
params.analyse.inter |= X264_ANALYSE_PSUB8x8;
315 if (avctx->partitions & X264_PART_B8X8)
316 x4->
params.analyse.inter |= X264_ANALYSE_BSUB16x16;
318 x4->
params.analyse.b_ssim = avctx->
flags2 & CODEC_FLAG2_SSIM;
319 x4->
params.b_intra_refresh = avctx->
flags2 & CODEC_FLAG2_INTRA_REFRESH;
320 x4->
params.i_bframe_pyramid = avctx->
flags2 & CODEC_FLAG2_BPYRAMID ? X264_B_PYRAMID_NORMAL : X264_B_PYRAMID_NONE;
321 x4->
params.analyse.b_weighted_bipred = avctx->
flags2 & CODEC_FLAG2_WPRED;
322 x4->
params.analyse.b_mixed_references = avctx->
flags2 & CODEC_FLAG2_MIXED_REFS;
323 x4->
params.analyse.b_transform_8x8 = avctx->
flags2 & CODEC_FLAG2_8X8DCT;
324 x4->
params.analyse.b_fast_pskip = avctx->
flags2 & CODEC_FLAG2_FASTPSKIP;
326 x4->
params.analyse.b_psy = avctx->
flags2 & CODEC_FLAG2_PSY;
327 x4->
params.rc.b_mb_tree = !!(avctx->
flags2 & CODEC_FLAG2_MBTREE);
331 x4->
params.analyse.i_me_method = X264_ME_DIA;
333 x4->
params.analyse.i_me_method = X264_ME_HEX;
335 x4->
params.analyse.i_me_method = X264_ME_UMH;
337 x4->
params.analyse.i_me_method = X264_ME_ESA;
339 x4->
params.analyse.i_me_method = X264_ME_TESA;
347 if (avctx->
qmin >= 0)
349 if (avctx->
qmax >= 0)
353 if (avctx->
qblur >= 0)
357 if (avctx->
refs >= 0)
399 if (x4->
b_bias != INT_MIN)
420 x264_param_apply_fastfirstpass(&x4->
params);
423 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
448 x4->
params.b_repeat_headers = 0;
452 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
457 #if FF_API_X264_GLOBAL_OPTS
458 avctx->crf = x4->
params.rc.f_rf_constant;
461 x4->
enc = x264_encoder_open(&x4->
params);
471 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
473 for (i = 0; i < nnal; i++)
505 if (x264_bit_depth == 8)
507 else if (x264_bit_depth == 9)
509 else if (x264_bit_depth == 10)
513 #define OFFSET(x) offsetof(X264Context, x)
514 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
516 {
"preset",
"Set the encoding preset (cf. x264 --fullhelp)",
OFFSET(preset),
AV_OPT_TYPE_STRING, { .str =
"medium" }, 0, 0,
VE},
519 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_INT, { 1 }, 0, 1,
VE},
521 {
"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 },
522 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX,
VE },
525 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
526 {
"autovariance",
"Auto-variance AQ (experimental)", 0,
AV_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
527 {
"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},
529 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
530 {
"rc-lookahead",
"Number of frames to look ahead for frametype and ratecontrol",
OFFSET(rc_lookahead),
AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX,
VE },
532 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX,
VE,
"weightp" },
537 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_INT, {-1 }, -1, 1,
VE },
538 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX,
VE },
539 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX,
VE,
"b_pyramid" },
541 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
542 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
543 {
"mixed-refs",
"One reference per partition, as opposed to one reference per macroblock",
OFFSET(mixed_refs),
AV_OPT_TYPE_INT, {-1}, -1, 1,
VE },
549 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX,
VE},
550 {
"partitions",
"A comma-separated list of partitions to consider. "
551 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
552 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX,
VE,
"direct-pred" },
557 {
"slice-max-size",
"Limit the size of each slice in bytes",
OFFSET(slice_max_size),
AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX,
VE },
579 {
"sc_threshold",
"-1" },
582 {
"me_range",
"-1" },
583 {
"me_method",
"-1" },
585 {
"b_strategy",
"-1" },
586 {
"keyint_min",
"-1" },
603 .priv_class = &
class,