32 #define X264_API_IMPORTS 1
89 static const int level_map[] = {
96 if (level < 0 || level > X264_LOG_DEBUG)
99 av_vlog(p, level_map[level], fmt, args);
104 const x264_nal_t *nals,
int nnal)
113 for (i = 0; i < nnal; i++)
114 size += nals[i].i_payload;
133 for (i = 0; i < nnal; i++){
134 memcpy(p, nals[i].p_payload, nals[i].i_payload);
135 p += nals[i].i_payload;
167 x264_picture_t pic_out = {0};
170 x264_picture_init( &x4->
pic );
172 if (x264_bit_depth > 8)
173 x4->
pic.img.i_csp |= X264_CSP_HIGH_DEPTH;
177 for (i = 0; i < x4->
pic.img.i_plane; i++) {
178 x4->
pic.img.plane[i] = frame->
data[i];
182 x4->
pic.i_pts = frame->
pts;
192 x264_encoder_reconfig(x4->
enc, &x4->
params);
198 x264_encoder_reconfig(x4->
enc, &x4->
params);
205 x264_encoder_reconfig(x4->
enc, &x4->
params);
208 if (x4->
params.rc.i_rc_method == X264_RC_ABR &&
211 x264_encoder_reconfig(x4->
enc, &x4->
params);
215 x4->
params.rc.i_rc_method == X264_RC_CRF &&
216 x4->
params.rc.f_rf_constant != x4->
crf) {
218 x264_encoder_reconfig(x4->
enc, &x4->
params);
221 if (x4->
params.rc.i_rc_method == X264_RC_CQP &&
223 x4->
params.rc.i_qp_constant != x4->
cqp) {
225 x264_encoder_reconfig(x4->
enc, &x4->
params);
231 x264_encoder_reconfig(x4->
enc, &x4->
params);
240 switch (stereo->
type) {
264 if (fpa_type != x4->
params.i_frame_packing) {
265 x4->
params.i_frame_packing = fpa_type;
266 x264_encoder_reconfig(x4->
enc, &x4->
params);
271 if (x264_encoder_encode(x4->
enc, &nal, &nnal, frame? &x4->
pic:
NULL, &pic_out) < 0)
277 }
while (!ret && !frame && x264_encoder_delayed_frames(x4->
enc));
279 pkt->
pts = pic_out.i_pts;
280 pkt->
dts = pic_out.i_dts;
282 switch (pic_out.i_type) {
312 x264_encoder_close(x4->
enc);
321 #define OPT_STR(opt, param) \
324 if (param && (ret = x264_param_parse(&x4->params, opt, param)) < 0) { \
325 if(ret == X264_PARAM_BAD_NAME) \
326 av_log(avctx, AV_LOG_ERROR, \
327 "bad option '%s': '%s'\n", opt, param); \
329 av_log(avctx, AV_LOG_ERROR, \
330 "bad value for '%s': '%s'\n", opt, param); \
351 return X264_CSP_BGRA;
365 #define PARSE_X264_OPT(name, var)\
366 if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
367 av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
368 return AVERROR(EINVAL);\
379 x264_param_default(&x4->
params);
388 for (i = 0; x264_preset_names[i]; i++)
392 for (i = 0; x264_tune_names[i]; i++)
398 if (avctx->
level > 0)
402 x4->
params.p_log_private = avctx;
403 x4->
params.i_log_level = X264_LOG_DEBUG;
410 x4->
params.rc.i_rc_method = X264_RC_ABR;
416 x4->
params.rc.b_stat_read = 1;
419 x4->
params.rc.i_rc_method = X264_RC_CRF;
421 }
else if (x4->
cqp >= 0) {
422 x4->
params.rc.i_rc_method = X264_RC_CQP;
432 x4->
params.rc.f_vbv_buffer_init =
446 x4->
params.analyse.i_me_method = X264_ME_DIA;
448 x4->
params.analyse.i_me_method = X264_ME_HEX;
450 x4->
params.analyse.i_me_method = X264_ME_UMH;
452 x4->
params.analyse.i_me_method = X264_ME_ESA;
454 x4->
params.analyse.i_me_method = X264_ME_TESA;
462 if (avctx->
qmin >= 0)
464 if (avctx->
qmax >= 0)
468 if (avctx->
qblur >= 0)
472 if (avctx->
refs >= 0)
474 else if (x4->
level) {
479 int scale = X264_BUILD < 129 ? 384 : 1;
481 if (!strcmp(x4->
level,
"1b")) {
483 }
else if (strlen(x4->
level) <= 3){
491 for (i = 0; i<x264_levels[i].level_idc; i++)
492 if (x264_levels[i].level_idc == level_id)
493 x4->
params.i_frame_reference = av_clip(x264_levels[i].dpb / mbn / scale, 1, x4->
params.i_frame_reference);
538 x4->
params.b_vfr_input = 0;
541 #if X264_BUILD >= 142
545 "x264 too old for AVC Intra, at least version 142 needed\n");
547 if (x4->
b_bias != INT_MIN)
578 x264_param_apply_fastfirstpass(&x4->
params);
609 if (x264_param_apply_profile(&x4->
params, x4->
profile) < 0) {
613 for (i = 0; x264_profile_names[i]; i++)
622 x4->
params.vui.i_sar_width = sw;
623 x4->
params.vui.i_sar_height = sh;
654 x4->
params.b_repeat_headers = 0;
659 char param[256]={0},
val[256]={0};
660 if(sscanf(p,
"%255[^:=]=%255[^:]", param,
val) == 1){
677 "Error parsing option '%s = %s'.\n",
687 x4->
params.i_bframe_pyramid ? 2 : 1 : 0;
693 x4->
enc = x264_encoder_open(&x4->
params);
706 s = x264_encoder_headers(x4->
enc, &nal, &nnal);
711 for (i = 0; i < nnal; i++) {
713 if (nal[i].i_type ==
NAL_SEI) {
719 memcpy(x4->
sei, nal[i].p_payload, nal[i].i_payload);
722 memcpy(p, nal[i].p_payload, nal[i].i_payload);
723 p += nal[i].i_payload;
765 if (x264_bit_depth == 8)
767 else if (x264_bit_depth == 9)
769 else if (x264_bit_depth == 10)
773 #define OFFSET(x) offsetof(X264Context, x)
774 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
779 {
"fastfirstpass",
"Use fast settings when encoding first pass",
OFFSET(fastfirstpass),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE},
784 {
"crf",
"Select the quality for constant quality mode",
OFFSET(crf),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE },
785 {
"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 },
786 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE },
789 {
"variance",
"Variance AQ (complexity mask)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
790 {
"autovariance",
"Auto-variance AQ", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX,
VE,
"aq_mode" },
791 #if X264_BUILD >= 144
792 {
"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,
"aq_mode" },
794 {
"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},
796 {
"psy-rd",
"Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.",
OFFSET(psy_rd),
AV_OPT_TYPE_STRING, {0 }, 0, 0,
VE},
797 {
"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 },
798 {
"weightb",
"Weighted prediction for B-frames.",
OFFSET(weightb),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
799 {
"weightp",
"Weighted prediction analysis method.",
OFFSET(weightp),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"weightp" },
804 {
"intra-refresh",
"Use Periodic Intra Refresh instead of IDR frames.",
OFFSET(intra_refresh),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
805 {
"bluray-compat",
"Bluray compatibility workarounds.",
OFFSET(bluray_compat) ,
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
806 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, { .i64 = INT_MIN}, INT_MIN, INT_MAX,
VE },
807 {
"b-pyramid",
"Keep some B-frames as references.",
OFFSET(b_pyramid),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"b_pyramid" },
809 {
"strict",
"Strictly hierarchical pyramid", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
810 {
"normal",
"Non-strict (not Blu-ray compatible)", 0,
AV_OPT_TYPE_CONST, {.i64 = X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX,
VE,
"b_pyramid" },
811 {
"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 },
817 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX,
VE},
818 {
"partitions",
"A comma-separated list of partitions to consider. "
819 "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all",
OFFSET(partitions),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE},
820 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX,
VE,
"direct-pred" },
825 {
"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 },
827 {
"nal-hrd",
"Signal HRD information (requires vbv-bufsize; "
832 {
"avcintra-class",
"AVC-Intra class 50/100/200",
OFFSET(avcintra_class),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 200 ,
VE},
833 {
"x264-params",
"Override the x264 configuration using a :-separated list of key=value parameters",
OFFSET(x264_params),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE },
856 {
"i_qfactor",
"-1" },
857 {
"b_qfactor",
"-1" },
865 {
"sc_threshold",
"-1" },
868 {
"me_range",
"-1" },
869 {
"me_method",
"-1" },
871 {
"b_strategy",
"-1" },
872 {
"keyint_min",
"-1" },
876 {
"thread_type",
"0" },
877 {
"flags",
"+cgop" },
878 {
"rc_init_occupancy",
"-1" },
892 .priv_class = &x264_class,
900 .
name =
"libx264rgb",
909 .priv_class = &rgbclass,
#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)
#define FF_PROFILE_H264_HIGH_10
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
const char const char void * val
static enum AVPixelFormat pix_fmt
Views are packed per line, as if interlaced.
static int avfmt2_num_planes(int avfmt)
This structure describes decoded (raw) audio or video data.
Views are alternated temporally.
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define FF_PROFILE_H264_HIGH_444
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)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
memory handling functions
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
AVFrame * coded_frame
the picture in the bitstream
static av_cold int init(AVCodecContext *avctx)
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.
static enum AVPixelFormat pix_fmts_8bit_rgb[]
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 FF_PROFILE_H264_MAIN
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...
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
#define CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
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 FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
static const AVClass rgbclass
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
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.
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
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
static av_cold void init_static_data(void)
Structure to hold side data for an AVFrame.
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...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int chromaoffset
chroma qp offset from luma
#define CODEC_FLAG_LOOP_FILTER
loop filter
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.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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.
static const AVClass x264_class
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
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_q*...
#define AV_PIX_FMT_YUV444P10
transformed exhaustive search algorithm
Libavcodec external API header.
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
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
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.
#define OPT_STR(opt, param)
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.
#define FF_CEIL_RSHIFT(a, b)
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
packed RGB 8:8:8, 24bpp, BGRBGR...
int max_qdiff
maximum quantizer difference between frames
#define AV_PIX_FMT_YUV444P9
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[]
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
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 the parsed entries to a dictionary.
enum AVStereo3DType type
How views are packed within the video.
#define AV_LOG_INFO
Standard information.
static av_cold int X264_close(AVCodecContext *avctx)
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
char * av_strdup(const char *s)
Duplicate the string s.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
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...
static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, const x264_nal_t *nals, int nnal)
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
#define AV_PIX_FMT_YUV420P9
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
#define CODEC_FLAG_CLOSED_GOP
Views are on top of each other.
int global_quality
Global quality for codecs which cannot change it per frame.
#define AV_PIX_FMT_YUV422P10
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int noise_reduction
noise reduction strength
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)
#define FF_PROFILE_H264_HIGH
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
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
AVCodec ff_libx264rgb_encoder
#define FF_PROFILE_H264_BASELINE
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
#define FF_PROFILE_H264_HIGH_422
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static const AVCodecDefault defaults[]
int me_method
Motion estimation algorithm used for video coding.
Stereoscopic 3d metadata.
#define AVERROR_EXTERNAL
Generic error in an external library.
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.
simple arithmetic expression evaluator
int keyint_min
minimum GOP size