Go to the documentation of this file.
22 #include "config_components.h"
55 #define MB_FLOOR(x) ((x) >> (MB_LSIZE))
56 #define MB_CEIL(x) MB_FLOOR((x) + (MB_SIZE - 1))
135 static const int level_map[] = {
142 if (level < 0 || level > X264_LOG_DEBUG)
151 memset(o, 0,
sizeof(*o));
155 const x264_nal_t *nals,
int nnal)
165 for (
int i = 0;
i < nnal;
i++) {
166 size += nals[
i].i_payload;
170 #if INT_MAX > INT64_MAX / INT_MAX - 1
192 memcpy(p, nals[0].p_payload,
size);
207 x264_encoder_reconfig(x4->
enc, &x4->
params);
209 if (x4->
params.vui.i_sar_height*
ctx->sample_aspect_ratio.num !=
ctx->sample_aspect_ratio.den * x4->
params.vui.i_sar_width) {
210 x4->
params.vui.i_sar_height =
ctx->sample_aspect_ratio.den;
211 x4->
params.vui.i_sar_width =
ctx->sample_aspect_ratio.num;
212 x264_encoder_reconfig(x4->
enc, &x4->
params);
215 if (x4->
params.rc.i_vbv_buffer_size !=
ctx->rc_buffer_size / 1000 ||
216 x4->
params.rc.i_vbv_max_bitrate !=
ctx->rc_max_rate / 1000) {
217 x4->
params.rc.i_vbv_buffer_size =
ctx->rc_buffer_size / 1000;
218 x4->
params.rc.i_vbv_max_bitrate =
ctx->rc_max_rate / 1000;
219 x264_encoder_reconfig(x4->
enc, &x4->
params);
222 if (x4->
params.rc.i_rc_method == X264_RC_ABR &&
225 x264_encoder_reconfig(x4->
enc, &x4->
params);
229 x4->
params.rc.i_rc_method == X264_RC_CRF &&
230 x4->
params.rc.f_rf_constant != x4->
crf) {
232 x264_encoder_reconfig(x4->
enc, &x4->
params);
235 if (x4->
params.rc.i_rc_method == X264_RC_CQP &&
237 x4->
params.rc.i_qp_constant != x4->
cqp) {
239 x264_encoder_reconfig(x4->
enc, &x4->
params);
245 x264_encoder_reconfig(x4->
enc, &x4->
params);
254 switch (stereo->
type) {
273 #if X264_BUILD >= 145
286 "Ignoring unsupported inverted stereo value %d\n", fpa_type);
290 if (fpa_type != x4->
params.i_frame_packing) {
291 x4->
params.i_frame_packing = fpa_type;
292 x264_encoder_reconfig(x4->
enc, &x4->
params);
299 for (
int i = 0;
i < pic->extra_sei.num_payloads;
i++)
300 av_free(pic->extra_sei.payloads[
i].payload);
304 pic->extra_sei.num_payloads = 0;
365 nb_rects =
info->nb_rects;
367 mbinfo =
av_calloc(mb_width * mb_height,
sizeof(*mbinfo));
371 #define COMPUTE_MBINFO(mbinfo_filler_, mbinfo_marker_, compute_coords_fn_) \
372 memset(mbinfo, mbinfo_filler_, sizeof(*mbinfo) * mb_width * mb_height); \
374 for (int i = 0; i < nb_rects; i++) { \
375 int min_x, max_x, min_y, max_y; \
377 compute_coords_fn_(mbinfo_rects, &min_x, &max_x, &min_y, &max_y); \
378 for (int mb_y = min_y; mb_y < max_y; ++mb_y) { \
379 memset(mbinfo + mb_y * mb_width + min_x, mbinfo_marker_, max_x - min_x); \
391 pic->prop.mb_info = mbinfo;
392 pic->prop.mb_info_free =
av_free;
410 if (x4->
params.rc.i_aq_mode == X264_AQ_NONE) {
426 if (!roi_size ||
size % roi_size != 0) {
430 nb_rois =
size / roi_size;
432 qoffsets =
av_calloc(mbx * mby,
sizeof(*qoffsets));
438 for (
int i = nb_rois - 1;
i >= 0;
i--) {
439 int startx, endx, starty, endy;
455 qoffset =
av_clipf(qoffset * qp_range, -qp_range, +qp_range);
457 for (
int y = starty; y < endy; y++) {
458 for (
int x = startx; x < endx; x++) {
459 qoffsets[x + y*mbx] = qoffset;
464 pic->prop.quant_offsets = qoffsets;
465 pic->prop.quant_offsets_free =
av_free;
471 x264_picture_t **ppic)
475 x264_picture_t *pic = &x4->
pic;
476 x264_sei_t *
sei = &pic->extra_sei;
477 unsigned int sei_data_size = 0;
487 x264_picture_init(pic);
488 pic->img.i_csp = x4->
params.i_csp;
489 #if X264_BUILD >= 153
495 pic->img.i_csp |= X264_CSP_HIGH_DEPTH;
498 for (
int i = 0;
i < pic->img.i_plane;
i++) {
519 pic->opaque = opaque;
526 pic->i_type = x4->
forced_idr > 0 ? X264_TYPE_IDR : X264_TYPE_KEYFRAME;
529 pic->i_type = X264_TYPE_P;
532 pic->i_type = X264_TYPE_B;
535 pic->i_type = X264_TYPE_AUTO;
550 if (!
sei->payloads) {
558 sei->payloads[0].payload_size = sei_size;
559 sei->payloads[0].payload = sei_data;
561 sei->num_payloads = 1;
587 x264_sei_payload_t *sei_payload;
597 sei_payload = &
sei->payloads[
sei->num_payloads];
599 if (!sei_payload->payload) {
603 sei_payload->payload_size = side_data->
size;
624 x264_picture_t pic_out = {0}, *pic_in;
634 if (x264_encoder_encode(x4->
enc, &nal, &nnal, pic_in, &pic_out) < 0)
645 "Unhandled reconstructed frame colorspace: %d\n",
652 for (
int i = 0;
i < pic_out.img.i_plane;
i++) {
667 }
while (!
ret && !
frame && x264_encoder_delayed_frames(x4->
enc));
675 out_opaque = pic_out.opaque;
691 "this is a bug, please report it.\n");
694 switch (pic_out.i_type) {
719 double scale[3] = { 1,
731 double mse = (max_value * max_value) / pow(10, pic_out.prop.f_psnr[
i] / 10.0);
741 errors, error_count, pict_type);
756 x264_picture_t pic_out = {0};
759 ret = x264_encoder_encode(x4->
enc, &nal, &nnal,
NULL, &pic_out);
760 }
while (
ret > 0 && x264_encoder_delayed_frames(x4->
enc));
779 #if X264_BUILD >= 161
780 x264_param_cleanup(&x4->
params);
784 x264_encoder_close(x4->
enc);
796 if ((
ret = x264_param_parse(&x4->
params, opt, param)) < 0) {
797 if (
ret == X264_PARAM_BAD_NAME) {
799 "bad option '%s': '%s'\n", opt, param);
801 #if X264_BUILD >= 161
802 }
else if (
ret == X264_PARAM_ALLOC_FAILED) {
804 "out of memory parsing option '%s': '%s'\n", opt, param);
809 "bad value for '%s': '%s'\n", opt, param);
832 return X264_CSP_BGRA;
862 memcpy(x4->
sei, nal->p_payload, nal->i_payload);
867 #if CONFIG_LIBX264_ENCODER
868 static int set_avcc_extradata(
AVCodecContext *avctx, x264_nal_t *nal,
int nnal)
870 x264_nal_t *sps_nal =
NULL;
871 x264_nal_t *pps_nal =
NULL;
878 for (
int i = 0;
i < nnal;
i++) {
879 switch (nal[
i].i_type) {
893 if (!sps_nal || !pps_nal)
896 avctx->
extradata_size = sps_nal->i_payload + pps_nal->i_payload + 7;
904 sps = sps_nal->p_payload + 4;
911 memcpy(p, sps_nal->p_payload + 2, sps_nal->i_payload - 2);
915 p += sps_nal->i_payload - 2;
917 memcpy(p, pps_nal->p_payload + 2, pps_nal->i_payload - 2);
918 p += pps_nal->i_payload - 2;
920 if (
sps[3] != 66 &&
sps[3] != 77 &&
sps[3] != 88) {
922 int chroma_format_idc;
923 int bit_depth_luma_minus8, bit_depth_chroma_minus8;
938 if (chroma_format_idc == 3)
943 *p++ = 0xFC | chroma_format_idc;
944 *p++ = 0xF8 | bit_depth_luma_minus8;
945 *p++ = 0xF8 | bit_depth_chroma_minus8;
962 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
966 #if CONFIG_LIBX264_ENCODER
968 return set_avcc_extradata(avctx, nal, nnal);
975 for (
int i = 0;
i < nnal;
i++) {
977 if (nal[
i].i_type == NAL_SEI) {
983 memcpy(p, nal[
i].p_payload, nal[
i].i_payload);
984 p += nal[
i].i_payload;
991 #define PARSE_X264_OPT(name, var)\
992 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
993 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
994 return AVERROR(EINVAL);\
997 #if CONFIG_LIBX264_HDR10
1004 params->mastering_display.b_mastering_display = 1;
1007 int *
const points[][2] = {
1009 ¶ms->mastering_display.i_red_x,
1010 ¶ms->mastering_display.i_red_y
1013 ¶ms->mastering_display.i_green_x,
1014 ¶ms->mastering_display.i_green_y
1017 ¶ms->mastering_display.i_blue_x,
1018 ¶ms->mastering_display.i_blue_y
1022 for (
int i = 0;
i < 3;
i++) {
1024 int *dst[2] = { points[
i][0], points[
i][1] };
1030 params->mastering_display.i_white_x =
1032 params->mastering_display.i_white_y =
1037 params->mastering_display.i_display_max =
1039 params->mastering_display.i_display_min =
1043 #endif // CONFIG_LIBX264_HDR10
1047 #if CONFIG_LIBX264_HDR10
1060 params->content_light_level.i_max_cll = cll->
MaxCLL;
1061 params->content_light_level.i_max_fall = cll->
MaxFALL;
1063 params->content_light_level.b_cll = 1;
1069 #endif // CONFIG_LIBX264_HDR10
1082 #if CONFIG_LIBX262_ENCODER
1085 x264_param_default_mpeg2(&x4->
params);
1088 x264_param_default(&x4->
params);
1097 for (
i = 0; x264_preset_names[
i];
i++)
1101 for (
i = 0; x264_tune_names[
i];
i++)
1107 if (avctx->
level > 0)
1111 x4->
params.p_log_private = avctx;
1112 x4->
params.i_log_level = X264_LOG_DEBUG;
1114 #if X264_BUILD >= 153
1122 av_log(avctx,
AV_LOG_ERROR,
"bit_rate and rc_max_rate > %d000 not supported by libx264\n", INT_MAX);
1126 x4->
params.rc.i_rc_method = X264_RC_ABR;
1132 x4->
params.rc.b_stat_read = 1;
1135 x4->
params.rc.i_rc_method = X264_RC_CRF;
1137 }
else if (x4->
cqp >= 0) {
1138 x4->
params.rc.i_rc_method = X264_RC_CQP;
1148 x4->
params.rc.f_vbv_buffer_init =
1170 if (avctx->
qmin >= 0)
1172 if (avctx->
qmax >= 0)
1176 if (avctx->
qblur >= 0)
1180 if (avctx->
refs >= 0)
1182 else if (x4->
params.i_level_idc > 0) {
1185 int scale = X264_BUILD < 129 ? 384 : 1;
1187 for (
i = 0;
i<x264_levels[
i].level_idc;
i++)
1230 x4->
params.b_vfr_input = 0;
1233 #if X264_BUILD >= 142
1237 "x264 too old for AVC Intra, at least version 142 needed\n");
1241 #if X264_BUILD < 164
1243 "x264 too old for AVC Intra 300/480, at least version 164 needed\n");
1247 x4->
params.i_avcintra_flavor = X264_AVCINTRA_FLAVOR_SONY;
1251 if (x4->
b_bias != INT_MIN)
1272 x264_param_apply_fastfirstpass(&x4->
params);
1313 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
1317 for (
i = 0; x264_profile_names[
i];
i++)
1326 x4->
params.vui.i_sar_width = sw;
1327 x4->
params.vui.i_sar_height = sh;
1337 #if FF_API_TICKS_PER_FRAME
1361 x4->
params.vui.b_fullrange = 1;
1375 x4->
params.b_repeat_headers = 0;
1378 x4->
params.b_full_recon = 1;
1383 char param[4096]={0},
val[4096]={0};
1384 if(sscanf(p,
"%4095[^:=]=%4095[^:]", param,
val) == 1){
1400 #if X264_BUILD >= 142
1403 x4->
params.b_repeat_headers = 1;
1411 "Error parsing option '%s = %s'.\n",
1413 #if X264_BUILD >= 161
1414 if (
ret == X264_PARAM_ALLOC_FAILED)
1425 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
1431 x4->
enc = x264_encoder_open(&x4->
params);
1470 #ifdef X264_CSP_NV21
1496 #ifdef X264_CSP_NV21
1503 #ifdef X264_CSP_I400
1509 #if CONFIG_LIBX264RGB_ENCODER
1518 #if X264_BUILD < 153
1521 if (x264_bit_depth == 8)
1523 else if (x264_bit_depth == 9)
1525 else if (x264_bit_depth == 10)
1530 #define OFFSET(x) offsetof(X264Context, x)
1531 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1536 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
VE},
1542 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
1543 {
"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 },
1544 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
1545 {
"aq-mode",
"AQ method",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"aq_mode"},
1547 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE, .unit =
"aq_mode" },
1548 {
"autovariance",
"Auto-variance AQ", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE, .unit =
"aq_mode" },
1549 #if X264_BUILD >= 144
1550 {
"autovariance-biased",
"Auto-variance AQ with bias to dark scenes", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE_BIASED}, INT_MIN, INT_MAX,
VE, .unit =
"aq_mode" },
1552 {
"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},
1554 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
1555 {
"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 },
1557 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"weightp" },
1559 {
"simple",
NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX,
VE, .unit =
"weightp" },
1560 {
"smart",
NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SMART}, INT_MIN, INT_MAX,
VE, .unit =
"weightp" },
1562 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
VE },
1563 {
"bluray-compat",
"Bluray compatibility workarounds.",
OFFSET(bluray_compat) ,
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
VE },
1564 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
1565 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"b_pyramid" },
1566 {
"none",
NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX,
VE, .unit =
"b_pyramid" },
1567 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE, .unit =
"b_pyramid" },
1568 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE, .unit =
"b_pyramid" },
1569 {
"mixed-refs",
"One reference per partition, as opposed to one reference per macroblock",
OFFSET(mixed_refs),
AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1,
VE },
1575 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
1576 {
"partitions",
"A comma-separated list of partitions to consider. "
1577 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
1578 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"direct-pred" },
1580 {
"spatial",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_SPATIAL }, 0, 0,
VE, .unit =
"direct-pred" },
1581 {
"temporal",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_TEMPORAL }, 0, 0,
VE, .unit =
"direct-pred" },
1583 {
"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 },
1585 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
1586 "cbr not allowed in .mp4)",
OFFSET(nal_hrd),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"nal-hrd" },
1590 {
"avcintra-class",
"AVC-Intra class 50/100/200/300/480",
OFFSET(avcintra_class),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 480 ,
VE},
1591 {
"me_method",
"Set motion estimation method",
OFFSET(motion_est),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA,
VE, .unit =
"motion-est"},
1592 {
"motion-est",
"Set motion estimation method",
OFFSET(motion_est),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA,
VE, .unit =
"motion-est"},
1598 {
"forced-idr",
"If forcing keyframes, force them as IDR frames.",
OFFSET(forced_idr),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, -1, 1,
VE },
1605 {
"b_strategy",
"Strategy to choose between I/P/B-frames",
OFFSET(b_frame_strategy),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2,
VE },
1606 {
"chromaoffset",
"QP difference between chroma and luma",
OFFSET(chroma_offset),
AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX,
VE },
1607 {
"sc_threshold",
"Scene change threshold",
OFFSET(scenechange_threshold),
AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX,
VE },
1608 {
"noise_reduction",
"Noise reduction",
OFFSET(noise_reduction),
AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX,
VE },
1609 {
"udu_sei",
"Use user data unregistered SEI if available",
OFFSET(udu_sei),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VE },
1610 {
"x264-params",
"Override the x264 configuration using a :-separated list of key=value parameters",
OFFSET(x264_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
1620 {
"i_qfactor",
"-1" },
1621 {
"b_qfactor",
"-1" },
1629 {
"trellis",
"-1" },
1630 {
"me_range",
"-1" },
1632 {
"keyint_min",
"-1" },
1635 {
"thread_type",
"0" },
1636 {
"flags",
"+cgop" },
1637 {
"rc_init_occupancy",
"-1" },
1641 #if CONFIG_LIBX264_ENCODER
1642 static const AVClass x264_class = {
1649 #if X264_BUILD >= 153
1652 FFCodec ff_libx264_encoder = {
1653 .
p.
name =
"libx264",
1662 .p.priv_class = &x264_class,
1663 .p.wrapper_name =
"libx264",
1670 #if X264_BUILD < 153
1676 #if X264_BUILD < 158
1683 #if CONFIG_LIBX264RGB_ENCODER
1684 static const AVClass rgbclass = {
1692 .
p.
name =
"libx264rgb",
1693 CODEC_LONG_NAME(
"libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
1699 .p.pix_fmts = pix_fmts_8bit_rgb,
1700 .p.priv_class = &rgbclass,
1701 .p.wrapper_name =
"libx264",
1708 #if X264_BUILD < 158
1715 #if CONFIG_LIBX262_ENCODER
1716 static const AVClass X262_class = {
1724 .
p.
name =
"libx262",
1732 .p.priv_class = &X262_class,
1733 .p.wrapper_name =
"libx264",
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level.
#define FF_ENABLE_DEPRECATION_WARNINGS
int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size)
Check AVFrame for A53 side data and allocate and fill SEI message with A53 info.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int keyint_min
minimum GOP size
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
FFmpeg currently uses a custom build this text attempts to document some of its obscure features and options Makefile the full command issued by make and its output will be shown on the screen DBG Preprocess x86 external assembler files to a dbg asm file in the object which then gets compiled Helps in developing those assembler files DESTDIR Destination directory for the install useful to prepare packages or install FFmpeg in cross environments GEN Set to ‘1’ to generate the missing or mismatched references Makefile builds all the libraries and the executables fate Run the fate test note that you must have installed it fate list List all fate regression test targets install Install libraries and programs examples Build all examples located in doc examples checkheaders Check headers dependencies alltools Build all tools in tools directory config Reconfigure the project with the current configuration tools target_dec_< decoder > _fuzzer Build fuzzer to fuzz the specified decoder tools target_bsf_< filter > _fuzzer Build fuzzer to fuzz the specified bitstream filter Useful standard make this is useful to reduce unneeded rebuilding when changing but note that you must force rebuilds of files that actually need it by hand then make j< num > Rebuild with multiple jobs at the same time Faster on multi processor systems make k Continue build in case of errors
enum AVColorSpace colorspace
YUV colorspace type.
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
int64_t duration
Duration of the frame, in the same units as pts.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
#define AV_PROFILE_H264_MAIN
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
void * opaque
Frame owner's private data.
unsigned MaxCLL
Max content light level (cd/m^2).
static void X264_log(void *p, int level, const char *fmt, va_list args)
This structure describes decoded (raw) audio or video data.
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
@ AVCOL_RANGE_JPEG
Full range content.
const FFCodec ff_libx264rgb_encoder
Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
int depth
Number of bits in the component.
#define AV_PIX_FMT_YUV420P10
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
static void X264_flush(AVCodecContext *avctx)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
static void av_always_inline mbinfo_compute_changed_coords(const AVVideoRect *rect, int *min_x, int *max_x, int *min_y, int *max_y)
@ AV_VIDEO_HINT_TYPE_CHANGED
int qmax
maximum quantizer
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
int me_subpel_quality
subpel ME quality
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int roi_warned
If the encoder does not support ROI then warn the first time we encounter a frame with ROI side data.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
static av_cold int X264_init(AVCodecContext *avctx)
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
AVBufferRef * opaque_ref
Frame owner's private data.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
static int save_sei(AVCodecContext *avctx, x264_nal_t *nal)
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
static av_cold void X264_init_static(FFCodec *codec)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define AV_CODEC_FLAG_COPY_OPAQUE
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
AVCodec p
The public AVCodec.
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
int refs
number of reference frames
int flags
AV_CODEC_FLAG_*.
static double val(void *priv, double ch)
static av_always_inline AVVideoRect * av_video_hint_rects(const AVVideoHint *hints)
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
#define FF_CODEC_ENCODE_CB(func)
#define AV_CODEC_FLAG_LOOP_FILTER
loop filter.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#define AV_PIX_FMT_YUV444P10
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static enum AVPixelFormat pix_fmts_10bit[]
Structure describing a single Region Of Interest.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
int has_b_frames
Size of the frame reordering buffer in the decoder.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
@ AV_STEREO3D_LINES
Views are packed per line, as if interlaced.
int global_quality
Global quality for codecs which cannot change it per frame.
#define AV_CEIL_RSHIFT(a, b)
int flags
Flags modifying the (de)muxer behaviour.
static __device__ float floor(float a)
static enum AVPixelFormat pix_fmt
#define AV_CODEC_EXPORT_DATA_PRFT
Export encoder Producer Reference Time through packet side data.
static enum AVPixelFormat pix_fmts_all[]
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_PROFILE_H264_HIGH_10
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
int thread_type
Which multithreading methods to use.
#define AV_PIX_FMT_YUV420P9
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define COMPUTE_MBINFO(mbinfo_filler_, mbinfo_marker_, compute_coords_fn_)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int64_t rc_max_rate
maximum bitrate
void * opaque
for some private data of the user
This structure describes the bitrate properties of an encoded bitstream.
#define CODEC_LONG_NAME(str)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define AV_PROFILE_H264_HIGH_422
static int setup_roi(AVCodecContext *ctx, x264_picture_t *pic, int bit_depth, const AVFrame *frame, const uint8_t *data, size_t size)
int flags
Additional information about the frame packing.
#define AV_PIX_FMT_GRAY10
int rc_buffer_size
decoder bitstream buffer size
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
static enum AVPixelFormat pix_fmts_9bit[]
enum AVColorRange color_range
MPEG vs JPEG YUV range.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
uint8_t nb_components
The number of components each pixel has, (1-4)
Rational number (pair of numerator and denominator).
float qblur
amount of qscale smoothing over time (0.0-1.0)
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
int64_t bit_rate
the average bitrate
uint32_t self_size
Must be set to the size of this data structure (that is, sizeof(AVRegionOfInterest)).
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
int me_cmp
motion estimation comparison function
#define AV_PIX_FMT_YUV422P10
int trellis
trellis RD quantization
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
int level
Encoding level descriptor.
static void free_picture(x264_picture_t *pic)
static void stats(AVPacket *const *in, int n_in, unsigned *_max, unsigned *_sum)
@ AVCOL_RANGE_UNSPECIFIED
@ AV_FRAME_DATA_SEI_UNREGISTERED
User data unregistered metadata associated with a video frame.
static void dct8x8(int16_t *coef, int bit_depth)
AVDictionary * x264_params
#define PARSE_X264_OPT(name, var)
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
static void av_always_inline mbinfo_compute_constant_coords(const AVVideoRect *rect, int *min_x, int *max_x, int *min_y, int *max_y)
enum AVPictureType pict_type
Picture type of the frame.
int(* init)(AVBSFContext *ctx)
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
static enum AVPixelFormat pix_fmts_8bit[]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AV_STEREO3D_CHECKERBOARD
Views are packed in a checkerboard-like structure per pixel.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
static av_cold int X264_close(AVCodecContext *avctx)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, const x264_nal_t *nals, int nnal)
static int set_extradata(AVCodecContext *avctx)
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
@ AVCHROMA_LOC_UNSPECIFIED
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
static void opaque_uninit(X264Opaque *o)
#define AVERROR_EXTERNAL
Generic error in an external library.
int flags
A combination of AV_PKT_FLAG values.
static void skip_bits1(GetBitContext *s)
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
#define AV_LOG_INFO
Standard information.
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
AVBufferRef * frame_opaque_ref
#define AV_CODEC_FLAG_RECON_FRAME
Request the encoder to output reconstructed frames, i.e. frames that would be produced by decoding th...
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int top
Distance in pixels from the top edge of the frame to the top and bottom edges and from the left edge ...
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
static int setup_mb_info(AVCodecContext *ctx, x264_picture_t *pic, const AVFrame *frame, const AVVideoHint *info)
static const FFCodecDefault x264_defaults[]
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
AVFrameSideData ** side_data
static enum AVPixelFormat csp_to_pixfmt(int csp)
static const AVOption options[]
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
void * av_calloc(size_t nmemb, size_t size)
#define AV_PIX_FMT_YUV444P9
#define AV_CODEC_FLAG_CLOSED_GOP
X264Opaque * reordered_opaque
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
@ AV_STEREO3D_COLUMNS
Views are packed per column.
enum AVStereo3DType type
How views are packed within the video.
#define AV_PROFILE_H264_BASELINE
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
@ AV_FRAME_DATA_VIDEO_HINT
Provide encoder-specific hinting information about changed/unchanged portions of a frame.
const FFCodec ff_libx262_encoder
int next_reordered_opaque
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
int scenechange_threshold
#define AV_INPUT_BUFFER_PADDING_SIZE
int max_qdiff
maximum quantizer difference between frames
main external API structure.
static void reconfig_encoder(AVCodecContext *ctx, const AVFrame *frame)
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
#define AV_PROFILE_H264_HIGH
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
@ SEI_TYPE_USER_DATA_UNREGISTERED
int qmin
minimum quantizer
enum AVFrameSideDataType type
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int64_t av_gettime(void)
Get the current time in microseconds.
#define FF_DISABLE_DEPRECATION_WARNINGS
@ AV_PICTURE_TYPE_P
Predicted.
#define AV_PROFILE_H264_HIGH_444
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
A reference to a data buffer.
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
static int setup_frame(AVCodecContext *ctx, const AVFrame *frame, x264_picture_t **ppic)
Structure to hold side data for an AVFrame.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int parse_opts(AVCodecContext *avctx, const char *opt, const char *param)
int slices
Number of slices.
unsigned MaxFALL
Max average light level per frame (cd/m^2).
This structure stores compressed data.
static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst, const AVMasteringDisplayMetadata *mdcv)
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
int width
picture width / height.
@ AV_FRAME_DATA_REGIONS_OF_INTEREST
Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of array element is ...
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static int sse(MpegEncContext *s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
AVRational qoffset
Quantisation offset.
void * priv_data
Format private data.
static int convert_pix_fmt(enum AVPixelFormat pix_fmt)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static void handle_side_data(AVCodecContext *avctx, x264_param_t *params)
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.