80 static const int level_map[] = {
87 if (level < 0 || level > X264_LOG_DEBUG)
90 av_vlog(p, level_map[level], fmt, args);
95 x264_nal_t *nals,
int nnal)
104 for (i = 0; i < nnal; i++)
105 size += nals[i].i_payload;
124 for (i = 0; i < nnal; i++){
125 memcpy(p, nals[i].p_payload, nals[i].i_payload);
126 p += nals[i].i_payload;
157 x264_picture_t pic_out;
159 x264_picture_init( &x4->
pic );
161 if (x264_bit_depth > 8)
162 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
166 for (i = 0; i < x4->
pic.img.i_plane; i++) {
167 x4->
pic.img.plane[i] = frame->
data[i];
171 x4->
pic.i_pts = frame->
pts;
179 x264_encoder_reconfig(x4->
enc, &x4->
params);
185 x264_encoder_reconfig(x4->
enc, &x4->
params);
190 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic:
NULL, &pic_out) < 0)
196 }
while (!ret && !frame && x264_encoder_delayed_frames(x4->
enc));
198 pkt->
pts = pic_out.i_pts;
199 pkt->
dts = pic_out.i_dts;
201 switch (pic_out.i_type) {
231 x264_encoder_close(x4->
enc);
236 #define OPT_STR(opt, param) \
239 if (param && (ret = x264_param_parse(&x4->params, opt, param)) < 0) { \
240 if(ret == X264_PARAM_BAD_NAME) \
241 av_log(avctx, AV_LOG_ERROR, \
242 "bad option '%s': '%s'\n", opt, param); \
244 av_log(avctx, AV_LOG_ERROR, \
245 "bad value for '%s': '%s'\n", opt, param); \
273 #define PARSE_X264_OPT(name, var)\
274 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
275 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
276 return AVERROR(EINVAL);\
284 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){
360 x4->
params.analyse.i_me_method = X264_ME_DIA;
362 x4->
params.analyse.i_me_method = X264_ME_HEX;
364 x4->
params.analyse.i_me_method = X264_ME_UMH;
366 x4->
params.analyse.i_me_method = X264_ME_ESA;
368 x4->
params.analyse.i_me_method = X264_ME_TESA;
376 if (avctx->
qmin >= 0)
378 if (avctx->
qmax >= 0)
382 if (avctx->
qblur >= 0)
386 if (avctx->
refs >= 0)
428 if (x4->
b_bias != INT_MIN)
459 x264_param_apply_fastfirstpass(&x4->
params);
490 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
494 for (i = 0; x264_profile_names[i]; i++)
503 x4->
params.vui.i_sar_width = sw;
504 x4->
params.vui.i_sar_height = sh;
523 x4->
params.b_repeat_headers = 0;
527 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
533 x4->
enc = x264_encoder_open(&x4->
params);
544 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
547 for (i = 0; i < nnal; i++) {
549 if (nal[i].i_type ==
NAL_SEI) {
553 memcpy(x4->
sei, nal[i].p_payload, nal[i].i_payload);
556 memcpy(p, nal[i].p_payload, nal[i].i_payload);
557 p += nal[i].i_payload;
593 if (x264_bit_depth == 8)
595 else if (x264_bit_depth == 9)
597 else if (x264_bit_depth == 10)
601 #define OFFSET(x) offsetof(X264Context, x)
602 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
604 {
"preset",
"Set the encoding preset (cf. x264 --fullhelp)",
OFFSET(preset),
AV_OPT_TYPE_STRING, { .str =
"medium" }, 0, 0,
VE},
607 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE},
612 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
613 {
"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 },
614 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
617 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
618 {
"autovariance",
"Auto-variance AQ (experimental)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
619 {
"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},
621 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
622 {
"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 },
623 {
"weightb",
"Weighted prediction for B-frames.",
OFFSET(weightb),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
624 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"weightp" },
629 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
630 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
631 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"b_pyramid" },
633 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
634 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
635 {
"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 },
641 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
642 {
"partitions",
"A comma-separated list of partitions to consider. "
643 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
644 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"direct-pred" },
649 {
"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 },
651 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
685 {
"sc_threshold",
"-1" },
688 {
"me_range",
"-1" },
689 {
"me_method",
"-1" },
691 {
"b_strategy",
"-1" },
692 {
"keyint_min",
"-1" },
696 {
"thread_type",
"0" },
697 {
"flags",
"+cgop" },
698 {
"rc_init_occupancy",
"-1" },
712 .priv_class = &
class,
718 .
name =
"libx264rgb",