77 static const int level_map[] = {
84 if (level < 0 || level > X264_LOG_DEBUG)
87 av_vlog(p, level_map[level], fmt, args);
92 x264_nal_t *nals,
int nnal)
101 for (i = 0; i < nnal; i++)
102 size += nals[i].i_payload;
116 for (i = 0; i < nnal; i++){
117 memcpy(p, nals[i].p_payload, nals[i].i_payload);
118 p += nals[i].i_payload;
130 x264_picture_t pic_out;
132 x264_picture_init( &x4->
pic );
134 if (x264_bit_depth > 8)
135 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
136 x4->
pic.img.i_plane = 3;
139 for (i = 0; i < 3; i++) {
140 x4->
pic.img.plane[i] = frame->
data[i];
144 x4->
pic.i_pts = frame->
pts;
152 x264_encoder_reconfig(x4->
enc, &x4->
params);
158 x264_encoder_reconfig(x4->
enc, &x4->
params);
163 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic:
NULL, &pic_out) < 0)
169 }
while (!ret && !frame && x264_encoder_delayed_frames(x4->
enc));
171 pkt->
pts = pic_out.i_pts;
172 pkt->
dts = pic_out.i_dts;
174 switch (pic_out.i_type) {
204 x264_encoder_close(x4->
enc);
225 #define PARSE_X264_OPT(name, var)\
226 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
227 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
228 return AVERROR(EINVAL);\
235 x264_param_default(&x4->
params);
245 if (avctx->
level > 0)
249 x4->
params.p_log_private = avctx;
250 x4->
params.i_log_level = X264_LOG_DEBUG;
255 x4->
params.rc.i_rc_method = X264_RC_ABR;
261 x4->
params.rc.b_stat_read = 1;
264 x4->
params.rc.i_rc_method = X264_RC_CRF;
266 }
else if (x4->
cqp >= 0) {
267 x4->
params.rc.i_rc_method = X264_RC_CQP;
277 x4->
params.rc.f_vbv_buffer_init =
286 x4->
params.analyse.i_me_method = X264_ME_DIA;
288 x4->
params.analyse.i_me_method = X264_ME_HEX;
290 x4->
params.analyse.i_me_method = X264_ME_UMH;
292 x4->
params.analyse.i_me_method = X264_ME_ESA;
294 x4->
params.analyse.i_me_method = X264_ME_TESA;
302 if (avctx->
qmin >= 0)
304 if (avctx->
qmax >= 0)
308 if (avctx->
qblur >= 0)
312 if (avctx->
refs >= 0)
354 if (x4->
b_bias != INT_MIN)
375 x264_param_apply_fastfirstpass(&x4->
params);
381 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
408 x4->
params.b_repeat_headers = 0;
412 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
418 x4->
enc = x264_encoder_open(&x4->
params);
429 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
432 for (i = 0; i < nnal; i++) {
434 if (nal[i].i_type ==
NAL_SEI) {
438 memcpy(x4->
sei, nal[i].p_payload, nal[i].i_payload);
441 memcpy(p, nal[i].p_payload, nal[i].i_payload);
442 p += nal[i].i_payload;
471 if (x264_bit_depth == 8)
473 else if (x264_bit_depth == 9)
475 else if (x264_bit_depth == 10)
479 #define OFFSET(x) offsetof(X264Context, x)
480 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
482 {
"preset",
"Set the encoding preset (cf. x264 --fullhelp)",
OFFSET(preset),
AV_OPT_TYPE_STRING, { .str =
"medium" }, 0, 0,
VE},
485 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE},
486 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
487 {
"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 },
488 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
491 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
492 {
"autovariance",
"Auto-variance AQ (experimental)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
493 {
"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},
495 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
496 {
"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 },
497 {
"weightb",
"Weighted prediction for B-frames.",
OFFSET(weightb),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
498 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"weightp" },
503 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
504 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
505 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"b_pyramid" },
507 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
508 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
509 {
"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 },
515 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
516 {
"partitions",
"A comma-separated list of partitions to consider. "
517 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
518 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"direct-pred" },
523 {
"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 },
525 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
550 {
"sc_threshold",
"-1" },
553 {
"me_range",
"-1" },
554 {
"me_method",
"-1" },
556 {
"b_strategy",
"-1" },
557 {
"keyint_min",
"-1" },
561 {
"thread_type",
"0" },
562 {
"flags",
"+cgop" },
563 {
"rc_init_occupancy",
"-1" },
577 .priv_class = &
class,
#define CODEC_FLAG_INTERLACED_DCT
static int convert_pix_fmt(enum AVPixelFormat pix_fmt)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define CODEC_FLAG_CLOSED_GOP
This structure describes decoded (raw) audio or video data.
AVCodec ff_libx264_encoder
float qblur
amount of qscale smoothing over time (0.0-1.0)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
memory handling functions
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...
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
enhanced predictive zonal search
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define CODEC_FLAG_LOOP_FILTER
static void X264_log(void *p, int level, const char *fmt, va_list args)
#define AV_PIX_FMT_YUV444P10
static av_cold int X264_init(AVCodecContext *avctx)
#define AV_PIX_FMT_YUV420P9
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...
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.
#define AV_PIX_FMT_YUV420P10
int me_cmp
motion estimation comparison function
#define AV_PIX_FMT_YUV444P9
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
static enum AVPixelFormat pix_fmts_10bit[]
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(). ...
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*...
transformed exhaustive search algorithm
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int rc_buffer_size
decoder bitstream buffer size
#define CODEC_CAP_AUTO_THREADS
common internal API header
int refs
number of reference frames
static enum AVPixelFormat pix_fmts_9bit[]
#define PARSE_X264_OPT(name, var)
int bit_rate
the average bitrate
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
int width
picture width / height.
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
int max_qdiff
maximum quantizer difference between frames
enum AVPixelFormat pix_fmt
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
static enum AVPixelFormat pix_fmts_8bit[]
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.
main external API structure.
static void close(AVCodecParserContext *s)
static const AVOption options[]
int qmin
minimum quantizer
Describe the class of an AVClass context structure.
struct X264Context X264Context
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
#define CODEC_FLAG_GLOBAL_HEADER
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int noise_reduction
noise reduction strength
#define AV_PIX_FMT_YUV422P10
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
static av_cold void X264_init_static(AVCodec *codec)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
int trellis
trellis RD quantization
int slices
Number of slices.
int top_field_first
If the content is interlaced, is top field displayed first.
uneven multi-hexagon search
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
int me_method
Motion estimation algorithm used for video coding.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int me_subpel_quality
subpel ME quality
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int thread_type
Which multithreading methods to use.
int keyint_min
minimum GOP size
static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, x264_nal_t *nals, int nnal)