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,
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
static int X264_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data)
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static int convert_pix_fmt(enum PixelFormat pix_fmt)
AVCodec ff_libx264_encoder
float qblur
amount of qscale smoothing over time (0.0-1.0)
AVFrame * coded_frame
the picture in the bitstream
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...
#define AV_LOG_WARNING
Something somehow does not look correct.
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
static void X264_log(void *p, int level, const char *fmt, va_list args)
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
static av_cold int X264_init(AVCodecContext *avctx)
int scenechange_threshold
scene change detection threshold 0 is default, larger means fewer detected scene changes.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define PIX_FMT_YUV420P10
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
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...
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int me_cmp
motion estimation comparison function
enhanced predictive zonal search
static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size, x264_nal_t *nals, int nnal, int skip_sei)
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
static int init(AVCodecParserContext *s)
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
int chromaoffset
chroma qp offset from luma
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
static enum PixelFormat pix_fmts_9bit[]
int qmax
maximum quantizer
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int rc_max_rate
maximum bitrate
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
float i_quant_factor
qscale factor between P and I-frames If > 0 then the last p frame quantizer will be used (q= lastp_q*...
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static enum PixelFormat pix_fmts_10bit[]
int rc_buffer_size
decoder bitstream buffer size
int refs
number of reference frames
#define PARSE_X264_OPT(name, var)
int bit_rate
the average bitrate
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
int width
picture width / height.
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
#define CODEC_FLAG_LOOP_FILTER
loop filter
int max_qdiff
maximum quantizer difference between frames
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
static const AVCodecDefault x264_defaults[]
static av_cold int X264_close(AVCodecContext *avctx)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
#define PIX_FMT_YUV422P10
main external API structure.
static void close(AVCodecParserContext *s)
static const AVOption options[]
int qmin
minimum quantizer
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
transformed exhaustive search algorithm
struct X264Context X264Context
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
enum PixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
int noise_reduction
noise reduction strength
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
#define CODEC_FLAG_CLOSED_GOP
static av_cold void X264_init_static(AVCodec *codec)
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uneven multi-hexagon search
int trellis
trellis RD quantization
int slices
Number of slices.
#define PIX_FMT_YUV444P10
int top_field_first
If the content is interlaced, is top field displayed first.
int key_frame
1 -> keyframe, 0-> not
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int me_method
Motion estimation algorithm used for video coding.
int me_subpel_quality
subpel ME quality
int keyint_min
minimum GOP size
static enum PixelFormat pix_fmts_8bit[]