31 #define X264_API_IMPORTS 1 92 static const int level_map[] = {
99 if (level < 0 || level > X264_LOG_DEBUG)
102 av_vlog(p, level_map[level], fmt, args);
107 x264_nal_t *nals,
int nnal)
116 for (i = 0; i < nnal; i++)
117 size += nals[i].i_payload;
131 for (i = 0; i < nnal; i++){
132 memcpy(p, nals[i].p_payload, nals[i].i_payload);
133 p += nals[i].i_payload;
147 x264_encoder_reconfig(x4->
enc, &x4->
params);
153 x264_encoder_reconfig(x4->
enc, &x4->
params);
160 x264_encoder_reconfig(x4->
enc, &x4->
params);
163 if (x4->
params.rc.i_rc_method == X264_RC_ABR &&
166 x264_encoder_reconfig(x4->
enc, &x4->
params);
170 x4->
params.rc.i_rc_method == X264_RC_CRF &&
171 x4->
params.rc.f_rf_constant != x4->
crf) {
173 x264_encoder_reconfig(x4->
enc, &x4->
params);
176 if (x4->
params.rc.i_rc_method == X264_RC_CQP &&
177 x4->
params.rc.i_qp_constant != x4->
cqp) {
179 x264_encoder_reconfig(x4->
enc, &x4->
params);
185 x264_encoder_reconfig(x4->
enc, &x4->
params);
193 switch (stereo->
type) {
212 #if X264_BUILD >= 145 225 "Ignoring unsupported inverted stereo value %d\n", fpa_type);
229 if (fpa_type != x4->
params.i_frame_packing) {
230 x4->
params.i_frame_packing = fpa_type;
231 x264_encoder_reconfig(x4->
enc, &x4->
params);
242 x264_picture_t pic_out;
244 x264_picture_init( &x4->
pic );
246 if (x264_bit_depth > 8)
247 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
248 x4->
pic.img.i_plane = 3;
251 for (i = 0; i < 3; i++) {
252 x4->
pic.img.plane[i] = frame->
data[i];
256 x4->
pic.i_pts = frame->
pts;
261 : X264_TYPE_KEYFRAME;
264 x4->
pic.i_type = X264_TYPE_P;
267 x4->
pic.i_type = X264_TYPE_B;
270 x4->
pic.i_type = X264_TYPE_AUTO;
276 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic:
NULL, &pic_out) < 0)
282 }
while (!ret && !frame && x264_encoder_delayed_frames(x4->
enc));
284 pkt->
pts = pic_out.i_pts;
285 pkt->
dts = pic_out.i_dts;
287 #if FF_API_CODED_FRAME 289 switch (pic_out.i_type) {
313 #if FF_API_CODED_FRAME 332 x264_encoder_close(x4->
enc);
363 #define PARSE_X264_OPT(name, var)\ 364 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\ 365 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\ 366 return AVERROR(EINVAL);\ 374 #if CONFIG_LIBX262_ENCODER 377 x264_param_default_mpeg2(&x4->
params);
380 x264_param_default(&x4->
params);
391 if (avctx->
level > 0)
395 x4->
params.p_log_private = avctx;
396 x4->
params.i_log_level = X264_LOG_DEBUG;
401 x4->
params.rc.i_rc_method = X264_RC_ABR;
407 x4->
params.rc.b_stat_read = 1;
410 x4->
params.rc.i_rc_method = X264_RC_CRF;
412 }
else if (x4->
cqp >= 0) {
413 x4->
params.rc.i_rc_method = X264_RC_CQP;
423 x4->
params.rc.f_vbv_buffer_init =
431 #if FF_API_PRIVATE_OPT 445 #if FF_API_PRIVATE_OPT 454 if (avctx->
qmin >= 0)
456 if (avctx->
qmax >= 0)
460 if (avctx->
qblur >= 0)
464 if (avctx->
refs >= 0)
470 #if FF_API_PRIVATE_OPT 480 #if FF_API_PRIVATE_OPT 488 #if FF_API_CODER_TYPE 522 x4->
params.b_vfr_input = 0;
524 if (x4->
b_bias != INT_MIN)
545 x264_param_apply_fastfirstpass(&x4->
params);
552 #if FF_API_MOTION_EST 556 x4->
params.analyse.i_me_method = X264_ME_DIA;
558 x4->
params.analyse.i_me_method = X264_ME_HEX;
560 x4->
params.analyse.i_me_method = X264_ME_UMH;
562 x4->
params.analyse.i_me_method = X264_ME_ESA;
564 x4->
params.analyse.i_me_method = X264_ME_TESA;
576 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
611 x4->
params.b_repeat_headers = 0;
621 "Error parsing option '%s = %s'.\n",
631 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
637 x4->
enc = x264_encoder_open(&x4->
params);
646 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
651 for (i = 0; i < nnal; i++) {
653 if (nal[i].i_type == NAL_SEI) {
659 memcpy(x4->
sei, nal[i].p_payload, nal[i].i_payload);
662 memcpy(p, nal[i].p_payload, nal[i].i_payload);
663 p += nal[i].i_payload;
707 if (x264_bit_depth == 8)
709 else if (x264_bit_depth == 9)
711 else if (x264_bit_depth == 10)
715 #define OFFSET(x) offsetof(X264Context, x) 716 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM 723 {
"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 },
724 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(
cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE },
727 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
728 {
"autovariance",
"Auto-variance AQ (experimental)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
744 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
745 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
746 {
"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 },
753 {
"partitions",
"A comma-separated list of partitions to consider. " 754 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(
partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE},
762 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; " 791 {
"i_qfactor",
"-1" },
798 #if FF_API_PRIVATE_OPT 799 {
"sc_threshold",
"-1" },
802 #if FF_API_PRIVATE_OPT 805 {
"me_range",
"-1" },
806 #if FF_API_MOTION_EST 807 {
"me_method",
"-1" },
810 #if FF_API_PRIVATE_OPT 811 {
"b_strategy",
"-1" },
813 {
"keyint_min",
"-1" },
814 #if FF_API_CODER_TYPE 819 {
"thread_type",
"0" },
820 {
"flags",
"+cgop" },
821 {
"rc_init_occupancy",
"-1" },
825 #if CONFIG_LIBX264_ENCODER 843 .priv_class = &
class,
851 #if CONFIG_LIBX262_ENCODER 852 static const AVClass X262_class = {
869 .priv_class = &X262_class,
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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 ...
Views are packed per line, as if interlaced.
This structure describes decoded (raw) audio or video data.
Views are alternated temporally.
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#define AV_CODEC_FLAG_LOOP_FILTER
loop filter.
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)
#define AV_LOG_WARNING
Something somehow does not look correct.
memory handling functions
int max_bitrate
Maximum bitrate of the stream, in bits per second.
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.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
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.
static void X264_log(void *p, int level, const char *fmt, va_list args)
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
static av_cold int X264_init(AVCodecContext *avctx)
attribute_deprecated int me_method
This option does nothing.
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 ...
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
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 AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
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).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int me_cmp
motion estimation comparison function
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static enum AVPixelFormat pix_fmts_10bit[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
int flags
Additional information about the frame packing.
int qmax
maximum quantizer
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
int flags
AV_CODEC_FLAG_*.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
int rc_max_rate
maximum bitrate
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_...
#define AV_PIX_FMT_YUV444P10
Video is not stereoscopic (and metadata has to be there).
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
common internal API header
as above, but U and V bytes are swapped
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.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
int width
picture width / height.
attribute_deprecated int noise_reduction
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
int scenechange_threshold
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
static const AVCodecDefault defaults[]
int max_qdiff
maximum quantizer difference between frames
enum AVPixelFormat pix_fmt
#define AV_PIX_FMT_YUV444P9
attribute_deprecated int coder_type
preferred ID for MPEG-1/2 video decoding
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
the normal 2^n-1 "JPEG" YUV ranges
static enum AVPixelFormat pix_fmts_8bit[]
static const AVCodecDefault x264_defaults[]
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add to a dictionary.
This structure describes the bitrate properties of an encoded bitstream.
enum AVStereo3DType type
How views are packed within the video.
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
static av_cold int X264_close(AVCodecContext *avctx)
attribute_deprecated int scenechange_threshold
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
attribute_deprecated int b_frame_strategy
main external API structure.
static const AVOption options[]
int qmin
minimum quantizer
#define AV_PIX_FMT_YUV420P10
Describe the class of an AVClass context structure.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
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 AV_PIX_FMT_YUV420P9
attribute_deprecated int chromaoffset
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
static void reconfig_encoder(AVCodecContext *ctx, const AVFrame *frame)
static enum AVPixelFormat pix_fmts[]
Views are on top of each other.
This side data contains an integer value representing the quality factor of the compressed frame...
#define AV_PIX_FMT_YUV422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Views are next to each other.
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)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static av_cold int init(AVCodecParserContext *s)
int trellis
trellis RD quantization
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
int slices
Number of slices.
#define FF_ENABLE_DEPRECATION_WARNINGS
int top_field_first
If the content is interlaced, is top field displayed first.
uneven multi-hexagon search
int avg_bitrate
Average bitrate of the stream, in bits per second.
Views are packed in a checkerboard-like structure per pixel.
Views are packed per column.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define AV_DICT_IGNORE_SUFFIX
static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
#define AV_CODEC_FLAG_CLOSED_GOP
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Stereoscopic 3d metadata.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int me_subpel_quality
subpel ME quality
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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)