31 #define X264_API_IMPORTS 1
87 static const int level_map[] = {
94 if (level < 0 || level > X264_LOG_DEBUG)
97 av_vlog(p, level_map[level], fmt, args);
102 x264_nal_t *nals,
int nnal)
111 for (i = 0; i < nnal; i++)
112 size += nals[i].i_payload;
131 for (i = 0; i < nnal; i++){
132 memcpy(p, nals[i].p_payload, nals[i].i_payload);
133 p += nals[i].i_payload;
164 x264_picture_t pic_out = {0};
167 x264_picture_init( &x4->
pic );
169 if (x264_bit_depth > 8)
170 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
174 for (i = 0; i < x4->
pic.img.i_plane; i++) {
175 x4->
pic.img.plane[i] = frame->
data[i];
179 x4->
pic.i_pts = frame->
pts;
187 x264_encoder_reconfig(x4->
enc, &x4->
params);
193 x264_encoder_reconfig(x4->
enc, &x4->
params);
201 switch (stereo->
type) {
225 if (fpa_type != x4->
params.i_frame_packing) {
226 x4->
params.i_frame_packing = fpa_type;
227 x264_encoder_reconfig(x4->
enc, &x4->
params);
232 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic: NULL, &pic_out) < 0)
238 }
while (!ret && !frame && x264_encoder_delayed_frames(x4->
enc));
240 pkt->
pts = pic_out.i_pts;
241 pkt->
dts = pic_out.i_dts;
243 switch (pic_out.i_type) {
273 x264_encoder_close(x4->
enc);
280 #define OPT_STR(opt, param) \
283 if (param!=NULL && (ret = x264_param_parse(&x4->params, opt, param)) < 0) { \
284 if(ret == X264_PARAM_BAD_NAME) \
285 av_log(avctx, AV_LOG_ERROR, \
286 "bad option '%s': '%s'\n", opt, param); \
288 av_log(avctx, AV_LOG_ERROR, \
289 "bad value for '%s': '%s'\n", opt, param); \
322 #define PARSE_X264_OPT(name, var)\
323 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
324 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
325 return AVERROR(EINVAL);\
333 x264_param_default(&x4->
params);
344 for (i = 0; x264_preset_names[i]; i++)
348 for (i = 0; x264_tune_names[i]; i++)
354 if (avctx->
level > 0)
358 x4->
params.p_log_private = avctx;
359 x4->
params.i_log_level = X264_LOG_DEBUG;
366 x4->
params.rc.i_rc_method = X264_RC_ABR;
372 x4->
params.rc.b_stat_read = 1;
375 x4->
params.rc.i_rc_method = X264_RC_CRF;
377 }
else if (x4->
cqp >= 0) {
378 x4->
params.rc.i_rc_method = X264_RC_CQP;
388 x4->
params.rc.f_vbv_buffer_init =
397 char param[256]={0},
val[256]={0};
398 if(sscanf(p,
"%255[^:=]=%255[^:]", param,
val) == 1){
411 x4->
params.analyse.i_me_method = X264_ME_DIA;
413 x4->
params.analyse.i_me_method = X264_ME_HEX;
415 x4->
params.analyse.i_me_method = X264_ME_UMH;
417 x4->
params.analyse.i_me_method = X264_ME_ESA;
419 x4->
params.analyse.i_me_method = X264_ME_TESA;
427 if (avctx->
qmin >= 0)
429 if (avctx->
qmax >= 0)
433 if (avctx->
qblur >= 0)
437 if (avctx->
refs >= 0)
481 x4->
params.b_vfr_input = 0;
483 if (x4->
b_bias != INT_MIN)
514 x264_param_apply_fastfirstpass(&x4->
params);
545 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
549 for (i = 0; x264_profile_names[i]; i++)
558 x4->
params.vui.i_sar_width = sw;
559 x4->
params.vui.i_sar_height = sh;
590 x4->
params.b_repeat_headers = 0;
600 "Error parsing option '%s = %s'.\n",
610 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
616 x4->
enc = x264_encoder_open(&x4->
params);
629 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
632 for (i = 0; i < nnal; i++) {
634 if (nal[i].i_type ==
NAL_SEI) {
638 memcpy(x4->
sei, nal[i].p_payload, nal[i].i_payload);
641 memcpy(p, nal[i].p_payload, nal[i].i_payload);
642 p += nal[i].i_payload;
683 if (x264_bit_depth == 8)
685 else if (x264_bit_depth == 9)
687 else if (x264_bit_depth == 10)
691 #define OFFSET(x) offsetof(X264Context, x)
692 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
697 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE},
702 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
703 {
"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 },
704 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
706 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_NONE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
707 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
708 {
"autovariance",
"Auto-variance AQ (experimental)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
709 {
"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},
711 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
712 {
"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 },
713 {
"weightb",
"Weighted prediction for B-frames.",
OFFSET(weightb),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
714 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"weightp" },
715 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_NONE}, INT_MIN, INT_MAX,
VE,
"weightp" },
716 {
"simple", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX,
VE,
"weightp" },
717 {
"smart", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SMART}, INT_MIN, INT_MAX,
VE,
"weightp" },
719 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
720 {
"bluray-compat",
"Bluray compatibility workarounds.",
OFFSET(bluray_compat) ,
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
721 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
722 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"b_pyramid" },
723 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
724 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
725 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
726 {
"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 },
732 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
733 {
"partitions",
"A comma-separated list of partitions to consider. "
734 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
735 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"direct-pred" },
736 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_NONE }, 0, 0,
VE,
"direct-pred" },
737 {
"spatial", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_SPATIAL }, 0, 0,
VE,
"direct-pred" },
738 {
"temporal", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_TEMPORAL }, 0, 0,
VE,
"direct-pred" },
739 {
"auto", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_AUTO }, 0, 0,
VE,
"direct-pred" },
740 {
"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 },
742 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
744 {
"none", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX,
VE,
"nal-hrd" },
745 {
"vbr", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR}, INT_MIN, INT_MAX,
VE,
"nal-hrd" },
746 {
"cbr", NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR}, INT_MIN, INT_MAX,
VE,
"nal-hrd" },
747 {
"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 },
770 {
"i_qfactor",
"-1" },
778 {
"sc_threshold",
"-1" },
781 {
"me_range",
"-1" },
782 {
"me_method",
"-1" },
784 {
"b_strategy",
"-1" },
785 {
"keyint_min",
"-1" },
789 {
"thread_type",
"0" },
790 {
"flags",
"+cgop" },
791 {
"rc_init_occupancy",
"-1" },
805 .priv_class = &x264_class,
811 .
name =
"libx264rgb",
820 .priv_class = &rgbclass,