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) {
284 "Ignoring unsupported inverted stereo value %d\n", fpa_type);
288 if (fpa_type != x4->
params.i_frame_packing) {
289 x4->
params.i_frame_packing = fpa_type;
290 x264_encoder_reconfig(x4->
enc, &x4->
params);
297 for (
int i = 0;
i < pic->extra_sei.num_payloads;
i++)
298 av_free(pic->extra_sei.payloads[
i].payload);
302 pic->extra_sei.num_payloads = 0;
363 nb_rects =
info->nb_rects;
365 mbinfo =
av_calloc(mb_width * mb_height,
sizeof(*mbinfo));
369 #define COMPUTE_MBINFO(mbinfo_filler_, mbinfo_marker_, compute_coords_fn_) \
370 memset(mbinfo, mbinfo_filler_, sizeof(*mbinfo) * mb_width * mb_height); \
372 for (int i = 0; i < nb_rects; i++) { \
373 int min_x, max_x, min_y, max_y; \
375 compute_coords_fn_(mbinfo_rects, &min_x, &max_x, &min_y, &max_y); \
376 for (int mb_y = min_y; mb_y < max_y; ++mb_y) { \
377 memset(mbinfo + mb_y * mb_width + min_x, mbinfo_marker_, max_x - min_x); \
389 pic->prop.mb_info = mbinfo;
390 pic->prop.mb_info_free =
av_free;
402 int qp_range = 51 + 6 * (x4->
params.i_bitdepth - 8);
408 if (x4->
params.rc.i_aq_mode == X264_AQ_NONE) {
424 if (!roi_size ||
size % roi_size != 0) {
428 nb_rois =
size / roi_size;
430 qoffsets =
av_calloc(mbx * mby,
sizeof(*qoffsets));
436 for (
int i = nb_rois - 1;
i >= 0;
i--) {
437 int startx, endx, starty, endy;
453 qoffset =
av_clipf(qoffset * qp_range, -qp_range, +qp_range);
455 for (
int y = starty; y < endy; y++) {
456 for (
int x = startx; x < endx; x++) {
457 qoffsets[x + y*mbx] = qoffset;
462 pic->prop.quant_offsets = qoffsets;
463 pic->prop.quant_offsets_free =
av_free;
469 x264_picture_t **ppic)
473 x264_picture_t *pic = &x4->
pic;
474 x264_sei_t *
sei = &pic->extra_sei;
475 unsigned int sei_data_size = 0;
485 x264_picture_init(pic);
486 pic->img.i_csp = x4->
params.i_csp;
487 if (x4->
params.i_bitdepth > 8)
488 pic->img.i_csp |= X264_CSP_HIGH_DEPTH;
491 for (
int i = 0;
i < pic->img.i_plane;
i++) {
492 pic->img.plane[
i] =
frame->data[
i];
493 pic->img.i_stride[
i] =
frame->linesize[
i];
496 pic->i_pts =
frame->pts;
512 pic->opaque = opaque;
517 switch (
frame->pict_type) {
519 pic->i_type = x4->
forced_idr > 0 ? X264_TYPE_IDR : X264_TYPE_KEYFRAME;
522 pic->i_type = X264_TYPE_P;
525 pic->i_type = X264_TYPE_B;
528 pic->i_type = X264_TYPE_AUTO;
543 if (!
sei->payloads) {
551 sei->payloads[0].payload_size = sei_size;
552 sei->payloads[0].payload = sei_data;
554 sei->num_payloads = 1;
577 for (
int j = 0; j <
frame->nb_side_data; j++) {
580 x264_sei_payload_t *sei_payload;
590 sei_payload = &
sei->payloads[
sei->num_payloads];
592 if (!sei_payload->payload) {
596 sei_payload->payload_size = side_data->
size;
617 x264_picture_t pic_out = {0}, *pic_in;
627 if (x264_encoder_encode(x4->
enc, &nal, &nnal, pic_in, &pic_out) < 0)
638 "Unhandled reconstructed frame colorspace: %d\n",
645 for (
int i = 0;
i < pic_out.img.i_plane;
i++) {
660 }
while (!
ret && !
frame && x264_encoder_delayed_frames(x4->
enc));
668 out_opaque = pic_out.opaque;
684 "this is a bug, please report it.\n");
687 switch (pic_out.i_type) {
712 double scale[3] = { 1,
724 double mse = (max_value * max_value) / pow(10, pic_out.prop.f_psnr[
i] / 10.0);
734 errors, error_count, pict_type);
749 x264_picture_t pic_out = {0};
752 ret = x264_encoder_encode(x4->
enc, &nal, &nnal,
NULL, &pic_out);
753 }
while (
ret > 0 && x264_encoder_delayed_frames(x4->
enc));
772 #if X264_BUILD >= 161
773 x264_param_cleanup(&x4->
params);
777 x264_encoder_close(x4->
enc);
789 if ((
ret = x264_param_parse(&x4->
params, opt, param)) < 0) {
790 if (
ret == X264_PARAM_BAD_NAME) {
792 "bad option '%s': '%s'\n", opt, param);
794 #if X264_BUILD >= 161
795 }
else if (
ret == X264_PARAM_ALLOC_FAILED) {
797 "out of memory parsing option '%s': '%s'\n", opt, param);
802 "bad value for '%s': '%s'\n", opt, param);
825 return X264_CSP_BGRA;
855 memcpy(x4->
sei, nal->p_payload, nal->i_payload);
860 #if CONFIG_LIBX264_ENCODER
861 static int set_avcc_extradata(
AVCodecContext *avctx, x264_nal_t *nal,
int nnal)
863 x264_nal_t *sps_nal =
NULL;
864 x264_nal_t *pps_nal =
NULL;
871 for (
int i = 0;
i < nnal;
i++) {
872 switch (nal[
i].i_type) {
886 if (!sps_nal || !pps_nal)
889 avctx->
extradata_size = sps_nal->i_payload + pps_nal->i_payload + 7;
897 sps = sps_nal->p_payload + 4;
904 memcpy(p, sps_nal->p_payload + 2, sps_nal->i_payload - 2);
908 p += sps_nal->i_payload - 2;
910 memcpy(p, pps_nal->p_payload + 2, pps_nal->i_payload - 2);
911 p += pps_nal->i_payload - 2;
913 if (
sps[3] != 66 &&
sps[3] != 77 &&
sps[3] != 88) {
915 int chroma_format_idc;
916 int bit_depth_luma_minus8, bit_depth_chroma_minus8;
931 if (chroma_format_idc == 3)
936 *p++ = 0xFC | chroma_format_idc;
937 *p++ = 0xF8 | bit_depth_luma_minus8;
938 *p++ = 0xF8 | bit_depth_chroma_minus8;
955 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
959 #if CONFIG_LIBX264_ENCODER
961 return set_avcc_extradata(avctx, nal, nnal);
968 for (
int i = 0;
i < nnal;
i++) {
970 if (nal[
i].i_type == NAL_SEI) {
976 memcpy(p, nal[
i].p_payload, nal[
i].i_payload);
977 p += nal[
i].i_payload;
984 #define PARSE_X264_OPT(name, var)\
985 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
986 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
987 return AVERROR(EINVAL);\
990 #if CONFIG_LIBX264_HDR10
997 params->mastering_display.b_mastering_display = 1;
1000 int *
const points[][2] = {
1002 ¶ms->mastering_display.i_red_x,
1003 ¶ms->mastering_display.i_red_y
1006 ¶ms->mastering_display.i_green_x,
1007 ¶ms->mastering_display.i_green_y
1010 ¶ms->mastering_display.i_blue_x,
1011 ¶ms->mastering_display.i_blue_y
1015 for (
int i = 0;
i < 3;
i++) {
1017 int *
dst[2] = { points[
i][0], points[
i][1] };
1023 params->mastering_display.i_white_x =
1025 params->mastering_display.i_white_y =
1030 params->mastering_display.i_display_max =
1032 params->mastering_display.i_display_min =
1036 #endif // CONFIG_LIBX264_HDR10
1040 #if CONFIG_LIBX264_HDR10
1053 params->content_light_level.i_max_cll = cll->
MaxCLL;
1054 params->content_light_level.i_max_fall = cll->
MaxFALL;
1056 params->content_light_level.b_cll = 1;
1062 #endif // CONFIG_LIBX264_HDR10
1075 #if CONFIG_LIBX262_ENCODER
1078 x264_param_default_mpeg2(&x4->
params);
1081 x264_param_default(&x4->
params);
1090 for (
i = 0; x264_preset_names[
i];
i++)
1094 for (
i = 0; x264_tune_names[
i];
i++)
1100 if (avctx->
level > 0)
1104 x4->
params.p_log_private = avctx;
1105 x4->
params.i_log_level = X264_LOG_DEBUG;
1113 av_log(avctx,
AV_LOG_ERROR,
"bit_rate and rc_max_rate > %d000 not supported by libx264\n", INT_MAX);
1117 x4->
params.rc.i_rc_method = X264_RC_ABR;
1123 x4->
params.rc.b_stat_read = 1;
1126 x4->
params.rc.i_rc_method = X264_RC_CRF;
1128 }
else if (x4->
cqp >= 0) {
1129 x4->
params.rc.i_rc_method = X264_RC_CQP;
1139 x4->
params.rc.f_vbv_buffer_init =
1161 if (avctx->
qmin >= 0)
1163 if (avctx->
qmax >= 0)
1167 if (avctx->
qblur >= 0)
1171 if (avctx->
refs >= 0)
1173 else if (x4->
params.i_level_idc > 0) {
1177 for (
i = 0;
i<x264_levels[
i].level_idc;
i++)
1179 x4->
params.i_frame_reference =
av_clip(x264_levels[
i].dpb / mbn, 1, x4->
params.i_frame_reference);
1220 x4->
params.b_vfr_input = 0;
1226 #if X264_BUILD < 164
1228 "x264 too old for AVC Intra 300/480, at least version 164 needed\n");
1232 x4->
params.i_avcintra_flavor = X264_AVCINTRA_FLAVOR_SONY;
1236 if (x4->
b_bias != INT_MIN)
1257 x264_param_apply_fastfirstpass(&x4->
params);
1298 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
1302 for (
i = 0; x264_profile_names[
i];
i++)
1311 x4->
params.vui.i_sar_width = sw;
1312 x4->
params.vui.i_sar_height = sh;
1322 #if FF_API_TICKS_PER_FRAME
1346 x4->
params.vui.b_fullrange = 1;
1360 x4->
params.b_repeat_headers = 0;
1363 x4->
params.b_full_recon = 1;
1368 char param[4096]={0},
val[4096]={0};
1369 if(sscanf(p,
"%4095[^:=]=%4095[^:]", param,
val) == 1){
1387 x4->
params.b_repeat_headers = 1;
1394 "Error parsing option '%s = %s'.\n",
1396 #if X264_BUILD >= 161
1397 if (
ret == X264_PARAM_ALLOC_FAILED)
1408 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
1414 x4->
enc = x264_encoder_open(&x4->
params);
1453 #ifdef X264_CSP_NV21
1479 #ifdef X264_CSP_NV21
1486 #ifdef X264_CSP_I400
1492 #if CONFIG_LIBX264RGB_ENCODER
1501 #define OFFSET(x) offsetof(X264Context, x)
1502 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1507 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
VE},
1513 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
1514 {
"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 },
1515 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
1516 {
"aq-mode",
"AQ method",
OFFSET(aq_mode),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"aq_mode"},
1518 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE, .unit =
"aq_mode" },
1519 {
"autovariance",
"Auto-variance AQ", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE, .unit =
"aq_mode" },
1520 {
"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" },
1521 {
"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},
1523 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
1524 {
"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 },
1526 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"weightp" },
1528 {
"simple",
NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX,
VE, .unit =
"weightp" },
1529 {
"smart",
NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_WEIGHTP_SMART}, INT_MIN, INT_MAX,
VE, .unit =
"weightp" },
1531 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
VE },
1532 {
"bluray-compat",
"Bluray compatibility workarounds.",
OFFSET(bluray_compat) ,
AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1,
VE },
1533 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
1534 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"b_pyramid" },
1535 {
"none",
NULL, 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX,
VE, .unit =
"b_pyramid" },
1536 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE, .unit =
"b_pyramid" },
1537 {
"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" },
1538 {
"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 },
1544 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
1545 {
"partitions",
"A comma-separated list of partitions to consider. "
1546 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
1547 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"direct-pred" },
1549 {
"spatial",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_SPATIAL }, 0, 0,
VE, .unit =
"direct-pred" },
1550 {
"temporal",
NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = X264_DIRECT_PRED_TEMPORAL }, 0, 0,
VE, .unit =
"direct-pred" },
1552 {
"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 },
1554 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
1555 "cbr not allowed in .mp4)",
OFFSET(nal_hrd),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE, .unit =
"nal-hrd" },
1559 {
"avcintra-class",
"AVC-Intra class 50/100/200/300/480",
OFFSET(avcintra_class),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 480 ,
VE},
1560 {
"me_method",
"Set motion estimation method",
OFFSET(motion_est),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA,
VE, .unit =
"motion-est"},
1561 {
"motion-est",
"Set motion estimation method",
OFFSET(motion_est),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, X264_ME_TESA,
VE, .unit =
"motion-est"},
1567 {
"forced-idr",
"If forcing keyframes, force them as IDR frames.",
OFFSET(forced_idr),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, -1, 1,
VE },
1574 {
"b_strategy",
"Strategy to choose between I/P/B-frames",
OFFSET(b_frame_strategy),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2,
VE },
1575 {
"chromaoffset",
"QP difference between chroma and luma",
OFFSET(chroma_offset),
AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX,
VE },
1576 {
"sc_threshold",
"Scene change threshold",
OFFSET(scenechange_threshold),
AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX,
VE },
1577 {
"noise_reduction",
"Noise reduction",
OFFSET(noise_reduction),
AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX,
VE },
1578 {
"udu_sei",
"Use user data unregistered SEI if available",
OFFSET(udu_sei),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
VE },
1579 {
"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 },
1589 {
"i_qfactor",
"-1" },
1590 {
"b_qfactor",
"-1" },
1598 {
"trellis",
"-1" },
1599 {
"me_range",
"-1" },
1601 {
"keyint_min",
"-1" },
1604 {
"thread_type",
"0" },
1605 {
"flags",
"+cgop" },
1606 {
"rc_init_occupancy",
"-1" },
1610 #if CONFIG_LIBX264_ENCODER
1611 static const AVClass x264_class = {
1619 .
p.
name =
"libx264",
1628 .p.priv_class = &x264_class,
1629 .p.wrapper_name =
"libx264",
1639 #if X264_BUILD < 158
1646 #if CONFIG_LIBX264RGB_ENCODER
1647 static const AVClass rgbclass = {
1655 .
p.
name =
"libx264rgb",
1656 CODEC_LONG_NAME(
"libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
1662 .p.pix_fmts = pix_fmts_8bit_rgb,
1663 .p.priv_class = &rgbclass,
1664 .p.wrapper_name =
"libx264",
1671 #if X264_BUILD < 158
1678 #if CONFIG_LIBX262_ENCODER
1679 static const AVClass X262_class = {
1687 .
p.
name =
"libx262",
1696 .p.priv_class = &X262_class,
1697 .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)
static void deblock(const RV60Context *s, AVFrame *frame, int xpos, int ypos, int size, int dpos)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PROFILE_H264_MAIN
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
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.
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 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.
#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
const FFCodec ff_libx264_encoder
int qmax
maximum quantizer
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().
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.
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 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.
@ 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, 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
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
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)
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.
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)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#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...
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#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
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.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
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...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
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
@ AV_OPT_TYPE_INT
Underlying C type is int.
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...
int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp)
@ 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)
static void scale(int *out, const int *in, const int w, const int h, const int shift)
int slices
Number of slices.
unsigned MaxFALL
Max average light level per frame (cd/m^2).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
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)
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
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,...
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#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.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
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.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
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.