注:问号以及未注释部分 会在x265-1.9版本内更新
/*****************************************************************************
* Copyright (C) 2013 x265 project
*
* Authors: Steve Borho
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*
* This program is also available under a commercial proprietary license.
* For more information, contact us at license @ x265.com.
*****************************************************************************/
#ifndef X265_H
#define X265_H
#include
#include "x265_config.h"
#ifdef __cplusplus
extern "C" {
#endif
/* x265_encoder:
* opaque handler for encoder */
typedef struct x265_encoder x265_encoder;
/* Application developers planning to link against a shared library version of
* libx265 from a Microsoft Visual Studio or similar development environment
* will need to define X265_API_IMPORTS before including this header.
* This clause does not apply to MinGW, similar development environments, or non
* Windows platforms. */
#ifdef X265_API_IMPORTS
#define X265_API __declspec(dllimport)
#else
#define X265_API
#endif
//IRAP(Intra Random Access Point) 参考IRAP且在前面的称为前置图像 参考IRAP且在后面的称为后置图像
//前置图像: RADL(Random Access Decodable Leading)(不依赖IRAP前的帧) RASL(Random Access Skipped Leading)(依赖IRAP前的帧)
//三种IRAP IDR(Instantaneous Decoding Refresh) CRA(Clean Random Access) BLA(Broken Link Access)
//IDR 要求前置图像必须是RADL 即 IDR后续帧不依赖IDR前向帧
//CRA 允许前置图像是RASL(编码效率高) 直接从CRA进入,则其前置图像RASL的不能解码
//BLA 如果直接从CRA介入,其前置RASL不能解码,则此图像被称为BLA
//时域号:关键帧号为0 底层不参考高层 最高为6
//下切换:从任何图像开始,可以丢弃其后(码率顺序)具有更高时域层标识号的图像
//上切换:从某一图像开始,可以发送具有该图像时域层标示号的图像,而该图像之前发送的图像的时域标示号小于该图像的时域标识号。 要求:从这个图像开始,其所在时域层内的所有图像不依赖该图像之前(码流顺序)相同时域层中的图像
//TSA(Temporal Sub-layer Access)和 STSA(Step-wise Temporal Sub-layer Access),用于标识时域子层切换点,即从这些图像开始可以进行时域子层上切换
//STSA:从该图像可以切换到该图像所属的时域层,要求:同一层中后续帧不依赖该图像之前的图像
//TSA:可以切换到大于或等于该图像时域层的图像
typedef enum
{
NAL_UNIT_CODED_SLICE_TRAIL_N = 0,//未被参考的后置图像,且非TSA、非STSA的视频片段
NAL_UNIT_CODED_SLICE_TRAIL_R, //被参考的后置图像,且非TSA、非STSA的视频片段
NAL_UNIT_CODED_SLICE_TSA_N,//未被参考的TSA图像 在时域子层打开的时候有
NAL_UNIT_CODED_SLICE_TLA_R, //被参考的TSA图像 不应该是TLA??? x265中未使用
NAL_UNIT_CODED_SLICE_STSA_N,//不被参考的STSA图像 x265中未使用
NAL_UNIT_CODED_SLICE_STSA_R,//被参考的STSA图像 x265中未使用
NAL_UNIT_CODED_SLICE_RADL_N,//RADL 前置图像(不依赖IRAP前的帧) 不被参考的前置图像 只在openGOP关闭才会有此类型
NAL_UNIT_CODED_SLICE_RADL_R,//RADL 前置图像(不依赖IRAP前的帧) 被参考的前置图像 只在openGOP关闭才会有此类型
NAL_UNIT_CODED_SLICE_RASL_N,//RASL 前置图像(依赖IRAP前的帧) 不被参考的前置图像 只在openGOP打开才会有此类型
NAL_UNIT_CODED_SLICE_RASL_R,//RASL 前置图像(依赖IRAP前的帧) 被参考的前置图像 只在openGOP打开才会有此类型
NAL_UNIT_CODED_SLICE_BLA_W_LP = 16,//BLA x265中未使用 未完成
NAL_UNIT_CODED_SLICE_BLA_W_RADL,//RADL BLA 前置图像(不依赖IRAP前的帧) x265中未使用 未完成
NAL_UNIT_CODED_SLICE_BLA_N_LP, //BLA x265中未使用 未完成
NAL_UNIT_CODED_SLICE_IDR_W_RADL,//RADL IDR 前置图像(不依赖IRAP前的帧) 可能有RADL图像的SS(视频片段)编码数据
NAL_UNIT_CODED_SLICE_IDR_N_LP,//IDR 未完成
NAL_UNIT_CODED_SLICE_CRA,//CRA 关键帧 在openGOP时使用
NAL_UNIT_VPS = 32,
NAL_UNIT_SPS,
NAL_UNIT_PPS,
NAL_UNIT_ACCESS_UNIT_DELIMITER,
NAL_UNIT_EOS,
NAL_UNIT_EOB,
NAL_UNIT_FILLER_DATA,
NAL_UNIT_PREFIX_SEI,
NAL_UNIT_SUFFIX_SEI,
NAL_UNIT_INVALID = 64,
} NalUnitType;
/* The data within the payload is already NAL-encapsulated; the type is merely
* in the struct for easy access by the calling application. All data returned
* in an x265_nal, including the data in payload, is no longer valid after the
* next call to x265_encoder_encode. Thus it must be used or copied before
* calling x265_encoder_encode again. */
typedef struct x265_nal
{
uint32_t type; /* NalUnitType */
uint32_t sizeBytes; /* size in bytes */
uint8_t* payload;
} x265_nal;
/* Stores all analysis data for a single frame */
typedef struct x265_analysis_data
{
void* interData;
void* intraData;
uint32_t frameRecordSize;
uint32_t poc;
uint32_t sliceType;
uint32_t numCUsInFrame;
uint32_t numPartitions;
} x265_analysis_data;
/* cu statistics */
typedef struct x265_cu_stats
{
double percentSkipCu[4]; // Percentage of skip cu in all depths
double percentMergeCu[4]; // Percentage of merge cu in all depths
double percentIntraDistribution[4][3]; // Percentage of DC, Planar, Angular intra modes in all depths
double percentInterDistribution[4][3]; // Percentage of 2Nx2N inter, rect and amp in all depths
double percentIntraNxN; // Percentage of 4x4 cu
/* All the above values will add up to 100%. */
} x265_cu_stats;
/* Frame level statistics */
typedef struct x265_frame_stats
{
double qp;
double rateFactor;
double psnrY;
double psnrU;
double psnrV;
double psnr;
double ssim;
double decideWaitTime;
double row0WaitTime;
double wallTime;
double refWaitWallTime;
double totalCTUTime;
double stallTime;
double avgWPP;
double avgLumaDistortion;
double avgChromaDistortion;
double avgPsyEnergy;
double avgLumaLevel;
uint64_t bits;
int encoderOrder;
int poc;
int countRowBlocks;
int list0POC[16];
int list1POC[16];
uint16_t maxLumaLevel;
char sliceType;
x265_cu_stats cuStats;
} x265_frame_stats;
/* Used to pass pictures into the encoder, and to get picture data back out of
* the encoder. The input and output semantics are different */
typedef struct x265_picture
{
/* presentation time stamp: user-specified, returned on output */
int64_t pts;//显示时间戳,在编码器内环里一般就是poc的值,用于标记显示的顺序?
/* display time stamp: ignored on input, copied from reordered pts. Returned
* on output */
int64_t dts;
/* force quantizer for != X265_QP_AUTO */
/* The value provided on input is returned with the same picture (POC) on
* output */
void* userData;
/* Must be specified on input pictures, the number of planes is determined
* by the colorSpace value */
void* planes[3];
/* Stride is the number of bytes between row starts */
int stride[3];
/* Must be specified on input pictures. x265_picture_init() will set it to
* the encoder's internal bit depth, but this field must describe the depth
* of the input pictures. Must be between 8 and 16. Values larger than 8
* imply 16bits per input sample. If input bit depth is larger than the
* internal bit depth, the encoder will down-shift pixels. Input samples
* larger than 8bits will be masked to internal bit depth. On output the
* bitDepth will be the internal encoder bit depth */
int bitDepth;
/* Must be specified on input pictures: X265_TYPE_AUTO or other.
* x265_picture_init() sets this to auto, returned on output */
int sliceType;
/* Ignored on input, set to picture count, returned on output */
int poc;
/* Must be specified on input pictures: X265_CSP_I420 or other. It must
* match the internal color space of the encoder. x265_picture_init() will
* initialize this value to the internal color space */
int colorSpace;
/* Force the slice base QP for this picture within the encoder. Set to 0
* to allow the encoder to determine base QP */
int forceqp;
/* If param.analysisMode is X265_ANALYSIS_OFF this field is ignored on input
* and output. Else the user must call x265_alloc_analysis_data() to
* allocate analysis buffers for every picture passed to the encoder.
*
* On input when param.analysisMode is X265_ANALYSIS_LOAD and analysisData
* member pointers are valid, the encoder will use the data stored here to
* reduce encoder work.
*
* On output when param.analysisMode is X265_ANALYSIS_SAVE and analysisData
* member pointers are valid, the encoder will write output analysis into
* this data structure */
x265_analysis_data analysisData;
/* Frame level statistics */
x265_frame_stats frameData;
} x265_picture;
typedef enum
{
X265_DIA_SEARCH, // 菱形搜索
X265_HEX_SEARCH, // 六边形搜索
X265_UMH_SEARCH, // UMH搜索
X265_STAR_SEARCH,// 星型搜索,与HM中的TZ很像,但是有一些区别
X265_FULL_SEARCH // 全搜索
} X265_ME_METHODS;
/* CPU flags */
/* x86 */
#define X265_CPU_CMOV 0x0000001
#define X265_CPU_MMX 0x0000002
#define X265_CPU_MMX2 0x0000004 /* MMX2 aka MMXEXT aka ISSE */
#define X265_CPU_MMXEXT X265_CPU_MMX2
#define X265_CPU_SSE 0x0000008
#define X265_CPU_SSE2 0x0000010
#define X265_CPU_SSE3 0x0000020
#define X265_CPU_SSSE3 0x0000040
#define X265_CPU_SSE4 0x0000080 /* SSE4.1 */
#define X265_CPU_SSE42 0x0000100 /* SSE4.2 */
#define X265_CPU_LZCNT 0x0000200 /* Phenom support for "leading zero count" instruction. */
#define X265_CPU_AVX 0x0000400 /* AVX support: requires OS support even if YMM registers aren't used. */
#define X265_CPU_XOP 0x0000800 /* AMD XOP */
#define X265_CPU_FMA4 0x0001000 /* AMD FMA4 */
#define X265_CPU_AVX2 0x0002000 /* AVX2 */
#define X265_CPU_FMA3 0x0004000 /* Intel FMA3 */
#define X265_CPU_BMI1 0x0008000 /* BMI1 */
#define X265_CPU_BMI2 0x0010000 /* BMI2 */
/* x86 modifiers */
#define X265_CPU_CACHELINE_32 0x0020000 /* avoid memory loads that span the border between two cachelines */
#define X265_CPU_CACHELINE_64 0x0040000 /* 32/64 is the size of a cacheline in bytes */
#define X265_CPU_SSE2_IS_SLOW 0x0080000 /* avoid most SSE2 functions on Athlon64 */
#define X265_CPU_SSE2_IS_FAST 0x0100000 /* a few functions are only faster on Core2 and Phenom */
#define X265_CPU_SLOW_SHUFFLE 0x0200000 /* The Conroe has a slow shuffle unit (relative to overall SSE performance) */
#define X265_CPU_STACK_MOD4 0x0400000 /* if stack is only mod4 and not mod16 */
#define X265_CPU_SLOW_CTZ 0x0800000 /* BSR/BSF x86 instructions are really slow on some CPUs */
#define X265_CPU_SLOW_ATOM 0x1000000 /* The Atom is terrible: slow SSE unaligned loads, slow
* SIMD multiplies, slow SIMD variable shifts, slow pshufb,
* cacheline split penalties -- gather everything here that
* isn't shared by other CPUs to avoid making half a dozen
* new SLOW flags. */
#define X265_CPU_SLOW_PSHUFB 0x2000000 /* such as on the Intel Atom */
#define X265_CPU_SLOW_PALIGNR 0x4000000 /* such as on the AMD Bobcat */
/* ARM */
#define X265_CPU_ARMV6 0x0000001
#define X265_CPU_NEON 0x0000002 /* ARM NEON */
#define X265_CPU_FAST_NEON_MRC 0x0000004 /* Transfer from NEON to ARM register is fast (Cortex-A9) */
#define X265_MAX_SUBPEL_LEVEL 7
/* Log level */
#define X265_LOG_NONE (-1)
#define X265_LOG_ERROR 0
#define X265_LOG_WARNING 1
#define X265_LOG_INFO 2
#define X265_LOG_DEBUG 3
#define X265_LOG_FULL 4
#define X265_B_ADAPT_NONE 0
#define X265_B_ADAPT_FAST 1
#define X265_B_ADAPT_TRELLIS 2
#define X265_REF_LIMIT_DEPTH 1
#define X265_REF_LIMIT_CU 2
#define X265_BFRAME_MAX 16
#define X265_MAX_FRAME_THREADS 16
#define X265_TYPE_AUTO 0x0000 /* Let x265 choose the right type */
#define X265_TYPE_IDR 0x0001
#define X265_TYPE_I 0x0002
#define X265_TYPE_P 0x0003
#define X265_TYPE_BREF 0x0004 /* Non-disposable B-frame */
#define X265_TYPE_B 0x0005
#define IS_X265_TYPE_I(x) ((x) == X265_TYPE_I || (x) == X265_TYPE_IDR)
#define IS_X265_TYPE_B(x) ((x) == X265_TYPE_B || (x) == X265_TYPE_BREF)
#define X265_QP_AUTO 0
#define X265_AQ_NONE 0
#define X265_AQ_VARIANCE 1
#define X265_AQ_AUTO_VARIANCE 2
#define X265_AQ_AUTO_VARIANCE_BIASED 3
/* NOTE! For this release only X265_CSP_I420 and X265_CSP_I444 are supported */
/* Supported internal color space types (according to semantics of chroma_format_idc) */
#define X265_CSP_I400 0 /* yuv 4:0:0 planar */
#define X265_CSP_I420 1 /* yuv 4:2:0 planar */
#define X265_CSP_I422 2 /* yuv 4:2:2 planar */
#define X265_CSP_I444 3 /* yuv 4:4:4 planar */
#define X265_CSP_COUNT 4 /* Number of supported internal color spaces */
/* These color spaces will eventually be supported as input pictures. The pictures will
* be converted to the appropriate planar color spaces at ingest */
#define X265_CSP_NV12 4 /* yuv 4:2:0, with one y plane and one packed u+v */
#define X265_CSP_NV16 5 /* yuv 4:2:2, with one y plane and one packed u+v */
/* Interleaved color-spaces may eventually be supported as input pictures */
#define X265_CSP_BGR 6 /* packed bgr 24bits */
#define X265_CSP_BGRA 7 /* packed bgr 32bits */
#define X265_CSP_RGB 8 /* packed rgb 24bits */
#define X265_CSP_MAX 9 /* end of list */
#define X265_EXTENDED_SAR 255 /* aspect ratio explicitly specified as width:height */
/* Analysis options */
#define X265_ANALYSIS_OFF 0
#define X265_ANALYSIS_SAVE 1
#define X265_ANALYSIS_LOAD 2
typedef struct x265_cli_csp
{
int planes;
int width[3];
int height[3];
} x265_cli_csp;
static const x265_cli_csp x265_cli_csps[] =
{
{ 1, { 0, 0, 0 }, { 0, 0, 0 } }, /* i400 */
{ 3, { 0, 1, 1 }, { 0, 1, 1 } }, /* i420 */
{ 3, { 0, 1, 1 }, { 0, 0, 0 } }, /* i422 */
{ 3, { 0, 0, 0 }, { 0, 0, 0 } }, /* i444 */
{ 2, { 0, 0 }, { 0, 1 } }, /* nv12 */
{ 2, { 0, 0 }, { 0, 0 } }, /* nv16 */
};
/* rate tolerance method */
typedef enum
{
X265_RC_ABR,//可用比特率(ABR: available bit-rate) 固定码率
X265_RC_CQP,//固定QP模式
X265_RC_CRF //CRF就是constant ratefactor,就是保证“一定质量”,智能分配码率。
// 智能分配码率包含两个意思:
// (1)同一帧内分配码率。就是在细节的地方分配更多的字节(bits)。实际效果举例:前景细节保留完整,背景压缩得很厉害。
// (2)帧间分配码率。CRF会智能分析哪些是重要帧,哪些是次要帧。重要帧会得到更多的字节。实际效果举例:帧排列:清晰-模糊-模糊-清晰。但是给人的感觉会是比较清晰的,因为看电影的时候一般注意焦点,不会去辨认背景。次要帧一般都一闪而过,也不容易注意到。
// main里面的CRF调节是对上面提到的“一定质量”的调节。值18基本为无损,19-21.5为高质量,22-26为中等质量。
} X265_RC_METHODS;
/*
ABR 也可以理解为:Average Bitrate 平均码率
CBR 也可以理解为:Constant BitRate 固定码率
VBR 也可以理解为:Variable BitRate 可变速率 简单部分低码率 复杂部分高码率
CBR(Constant bitrate)即固定码率,就是静态(恒定)比特率的意思,CBR是一种固定采样率的压缩方式。,效果不十分理想,现已逐步被VBR的方式取代。
固定码率是一个用来形容通信服务质量(QoS,Quality of Service)的术语。一般来说,音视频质量越好,记录音视频的数据量就越多,要求的编码码率就会越高。和该词相对应的词是可变码率或可变比特率(英文Variable Bitrate,缩写VBR)。CBR和VBR都是控制编码器输出码率大小的方法,即码率控制模式。
对于视频编码来说,CBR编码指的是编码器每秒钟的输出码数据量(或者解码器的输入码率)应该是固定制(常数)。编码器检测每一帧图像的复杂程度,然后计算出码率。如果码率过小,就填充无用数据,使之与指定码率保持一致;如果码率过大,就适当降低码率,也使之与指定码率保持一致。因此,固定码率模式的编码效率比较低。在快速运动画面部分,画面细节较多,一般需要更多的比特来描述,但由于强行降低码率,因此会丢失部分画面的细节信息,而出现画面模糊、不清晰现象。对于音频压缩来说,比如MP3,比特率是最重要的因素,它用来表示每秒钟的音频数据占用了多少个比特,这个值越高,音质就越好。CBR使用固定比特率编码音频,一首MP3从头至尾为某固定值,如128 kbps进行编码。
总之,无论对于音频编码还是视频编码,CBR方式编码的优点是压缩快,能被大多数软件和设备支持;而且当在一个带宽受限的信道中进行多媒体通讯的时候,CBR是非常有用的,因为这时候受限的是最高码率,CBR可以更好的易用这样的信道。但是缺点是占用空间相对大,不适合进行存储,因为CBR将导致没有足够的码率对复杂的内容部分进行编码,从而导致质量下降,同时在简单的内容部分会浪费一些码率。
大部分编码方案的输出都是可变长的码字,例如霍夫曼编码或者游程编码(run-length coding),这使得编码器很难做到完美的CBR。编码器可以通过调整量化(进而调整编码质量)来部分的解决这个问题,如果同时使用填充码来完美的达到CBR。(有时候,CBR也指一种非常简单的编码方案,比如将一个16位精度的音频数据流通过抽样得到一个8位精度的数据流)。
**/
/* slice type statistics */
typedef struct x265_sliceType_stats
{
double avgQp;
double bitrate;
double psnrY;
double psnrU;
double psnrV;
double ssim;
uint32_t numPics;
} x265_sliceType_stats;
/* Output statistics from encoder */
typedef struct x265_stats
{
double globalPsnrY;
double globalPsnrU;
double globalPsnrV;
double globalPsnr;
double globalSsim;
double elapsedEncodeTime; /* wall time since encoder was opened */
double elapsedVideoTime; /* encoded picture count / frame rate */
double bitrate; /* accBits / elapsed video time */
uint64_t accBits; /* total bits output thus far */
uint32_t encodedPictureCount; /* number of output pictures thus far */
uint32_t totalWPFrames; /* number of uni-directional weighted frames used */
x265_sliceType_stats statsI; /* statistics of I slice */
x265_sliceType_stats statsP; /* statistics of P slice */
x265_sliceType_stats statsB; /* statistics of B slice */
} x265_stats;
/* String values accepted by x265_param_parse() (and CLI) for various parameters */
static const char * const x265_motion_est_names[] = { "dia", "hex", "umh", "star", "full", 0 };
static const char * const x265_source_csp_names[] = { "i400", "i420", "i422", "i444", "nv12", "nv16", 0 };
static const char * const x265_video_format_names[] = { "component", "pal", "ntsc", "secam", "mac", "undef", 0 };
static const char * const x265_fullrange_names[] = { "limited", "full", 0 };
static const char * const x265_colorprim_names[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "film", "bt2020", 0 };
static const char * const x265_transfer_names[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "linear", "log100",
"log316", "iec61966-2-4", "bt1361e", "iec61966-2-1", "bt2020-10", "bt2020-12",
"smpte-st-2084", "smpte-st-428", "arib-std-b67", 0 };
static const char * const x265_colmatrix_names[] = { "GBR", "bt709", "undef", "", "fcc", "bt470bg", "smpte170m", "smpte240m",
"YCgCo", "bt2020nc", "bt2020c", 0 };
static const char * const x265_sar_names[] = { "undef", "1:1", "12:11", "10:11", "16:11", "40:33", "24:11", "20:11",
"32:11", "80:33", "18:11", "15:11", "64:33", "160:99", "4:3", "3:2", "2:1", 0 };
static const char * const x265_interlace_names[] = { "prog", "tff", "bff", 0 };
static const char * const x265_analysis_names[] = { "off", "save", "load", 0 };
/* Zones: override ratecontrol for specific sections of the video.
* If zones overlap, whichever comes later in the list takes precedence. */
typedef struct x265_zone //存储空间在param类中
{
int startFrame, endFrame;//起始与最后帧(标号只当前在RC中的帧数从1开始计数) /* range of frame numbers */
int bForceQp; //是否用固定qp 1用固定qp 2不用 /* whether to use qp vs bitrate factor */
int qp; //配置qp 用途:当前qp
float bitrateFactor; //配置码率因子 用途:当前qscale 除以 bitrateFactor
} x265_zone;
/* x265 input parameters
*
* For version safety you may use x265_param_alloc/free() to manage the
* allocation of x265_param instances, and x265_param_parse() to assign values
* by name. By never dereferencing param fields in your own code you can treat
* x265_param as an opaque data structure */
typedef struct x265_param
{
/* x265_param_default() will auto-detect this cpu capability bitmap. it is
* recommended to not change this value unless you know the cpu detection is
* somehow flawed on your target hardware. The asm function tables are
* process global, the first encoder configures them for all encoders */
int cpuid;
/*== Parallelism Features ==*/
/* Number of concurrently encoded frames between 1 and X265_MAX_FRAME_THREADS
* or 0 for auto-detection. By default x265 will use a number of frame
* threads empirically determined to be optimal for your CPU core count,
* between 2 and 6. Using more than one frame thread causes motion search
* in the down direction to be clamped but otherwise encode behavior is
* unaffected. With CQP rate control the output bitstream is deterministic
* for all values of frameNumThreads greater than 1. All other forms of
* rate-control can be negatively impacted by increases to the number of
* frame threads because the extra concurrency adds uncertainty to the
* bitrate estimations. Frame parallelism is generally limited by the the
* is generally limited by the the number of CU rows
*
* When thread pools are used, each frame thread is assigned to a single
* pool and the frame thread itself is given the node affinity of its pool.
* But when no thread pools are used no node affinity is assigned. */
int frameNumThreads;//同时几个frame编码,0:自动检测(根据内核数) 1 ~ X265_MAX_FRAME_THREADS 表示有几个同时编码 ,默认为内核数
/* Comma seperated list of threads per NUMA node. If "none", then no worker
* pools are created and only frame parallelism is possible. If NULL or ""
* (default) x265 will use all available threads on each NUMA node.
*
* '+' is a special value indicating all cores detected on the node
* '*' is a special value indicating all cores detected on the node and all
* remaining nodes.
* '-' is a special value indicating no cores on the node, same as '0'
*
* example strings for a 4-node system:
* "" - default, unspecified, all numa nodes are used for thread pools
* "*" - same as default
* "none" - no thread pools are created, only frame parallelism possible
* "-" - same as "none"
* "10" - allocate one pool, using up to 10 cores on node 0
* "-,+" - allocate one pool, using all cores on node 1
* "+,-,+" - allocate two pools, using all cores on nodes 0 and 2
* "+,-,+,-" - allocate two pools, using all cores on nodes 0 and 2
* "-,*" - allocate three pools, using all cores on nodes 1, 2 and 3
* "8,8,8,8" - allocate four pools with up to 8 threads in each pool
*
* The total number of threads will be determined by the number of threads
* assigned to all nodes. The worker threads will each be given affinity for
* their node, they will not be allowed to migrate between nodes, but they
* will be allowed to move between CPU cores within their node.
*
* If the three pool features: bEnableWavefront, bDistributeModeAnalysis and
* bDistributeMotionEstimation are all disabled, then numaPools is ignored
* and no thread pools are created.
*
* If "none" is specified, then all three of the thread pool features are
* implicitly disabled.
*
* Multiple thread pools will be allocated for any NUMA node with more than
* 64 logical CPU cores. But any given thread pool will always use at most
* one NUMA node.
*
* Frame encoders are distributed between the available thread pools, and
* the encoder will never generate more thread pools than frameNumThreads */
const char* numaPools;
/* Enable wavefront parallel processing, greatly increases parallelism for
* less than 1% compression efficiency loss. Requires a thread pool, enabled
* by default */
int bEnableWavefront; // 波前并行处理 (Wavefront Parallel Processing,WPP) 默认打开(行并行)
/* Use multiple threads to measure CU mode costs. Recommended for many core
* CPUs. On RD levels less than 5, it may not offload enough work to warrant
* the overhead. It is useful with the slow preset since it has the
* rectangular predictions enabled. At RD level 5 and 6 (preset slower and
* below), this feature should be an unambiguous win if you have CPU
* cores available for work. Default disabled */
int bDistributeModeAnalysis;
/* Use multiple threads to perform motion estimation to (ME to one reference
* per thread). Recommended for many core CPUs. The more references the more
* motion searches there will be to distribute. This option is often not a
* win, particularly in video sequences with low motion. Default disabled */
int bDistributeMotionEstimation;
/*== Logging Features ==*/
/* Enable analysis and logging distribution of CUs. Now deprecated */
int bLogCuStats;
/* Enable the measurement and reporting of PSNR. Default is enabled */
int bEnablePsnr;
/* Enable the measurement and reporting of SSIM. Default is disabled */
int bEnableSsim;
/* The level of logging detail emitted by the encoder. X265_LOG_NONE to
* X265_LOG_FULL, default is X265_LOG_INFO */
int logLevel;
/* Filename of CSV log. Now deprecated */
const char* csvfn;
/*== Internal Picture Specification ==*/
/* Internal encoder bit depth. If x265 was compiled to use 8bit pixels
* (HIGH_BIT_DEPTH=0), this field must be 8, else this field must be 10.
* Future builds may support 12bit pixels. */
int internalBitDepth;//像素位宽 8 10 12 默认值为8
/* Color space of internal pictures, must match color space of input
* pictures */
int internalCsp;//图像格式 默认为420
/* Numerator and denominator of frame rate */
uint32_t fpsNum; //配置的fps信息 必须配置 值一般等于fps*1000
uint32_t fpsDenom;//用于fps精度控制 一般等于1000
/* Width (in pixels) of the source pictures. If this width is not an even
* multiple of 4, the encoder will pad the pictures internally to meet this
* minimum requirement. All valid HEVC widths are supported */
int sourceWidth; //源图像的宽度
/* Height (in pixels) of the source pictures. If this height is not an even
* multiple of 4, the encoder will pad the pictures internally to meet this
* minimum requirement. All valid HEVC heights are supported */
int sourceHeight;//源图像的高度
/* Interlace type of source pictures. 0 - progressive pictures (default).
* 1 - top field first, 2 - bottom field first. HEVC encodes interlaced
* content as fields, they must be provided to the encoder in the correct
* temporal order */
int interlaceMode;//场编码: 默认为0 (非场编码) 1顶场 2底场
/* Total Number of frames to be encoded, calculated from the user input
* (--frames) and (--seek). In case, the input is read from a pipe, this can
* remain as 0. It is later used in 2 pass RateControl, hence storing the
* value in param */
int totalFrames;//编码的总帧数 配置方式 --total-frames 或者 -f
/*== Profile / Tier / Level ==*/
/* Note: the profile is specified by x265_param_apply_profile() */
/* Minimum decoder requirement level. Defaults to 0, which implies auto-
* detection by the encoder. If specified, the encoder will attempt to bring
* the encode specifications within that specified level. If the encoder is
* unable to reach the level it issues a warning and emits the actual
* decoder requirement. If the requested requirement level is higher than
* the actual level, the actual requirement level is signaled. The value is
* an specified as an integer with the level times 10, for example level
* "5.1" is specified as 51, and level "5.0" is specified as 50. */
int levelIdc;
/* if levelIdc is specified (non-zero) this flag will differentiate between
* Main (0) and High (1) tier. Default is Main tier (0) */
int bHighTier;//是否采用HIGH层次 默认为MAIN层次
/* The maximum number of L0 references a P or B slice may use. This
* influences the size of the decoded picture buffer. The higher this
* number, the more reference frames there will be available for motion
* search, improving compression efficiency of most video at a cost of
* performance. Value must be between 1 and 16, default is 3 */
int maxNumReferences; //L0可以取的最大参考帧个数 取值范围(1~16,默认为3)
/* Allow libx265 to emit HEVC bitstreams which do not meet strict level
* requirements. Defaults to false */
int bAllowNonConformance;
/*== Bitstream Options ==*/
/* Flag indicating whether VPS, SPS and PPS headers should be output with
* each keyframe. Default false */
int bRepeatHeaders;//是否将VPS SPS PPS 在每一个关键帧中都写入 默认为false
/* Flag indicating whether the encoder should generate start codes (Annex B
* format) or length (file format) before NAL units. Default true, Annex B.
* Muxers should set this to the correct value */
int bAnnexB;
/* Flag indicating whether the encoder should emit an Access Unit Delimiter
* NAL at the start of every access unit. Default false */
int bEnableAccessUnitDelimiters;//分解符???????
/* Enables the buffering period SEI and picture timing SEI to signal the HRD
* parameters. Default is disabled */
int bEmitHRDSEI;
/* Enables the emission of a user data SEI with the stream headers which
* describes the encoder version, build info, and parameters. This is
* very helpful for debugging, but may interfere with regression tests.
* Default enabled */
int bEmitInfoSEI;
/* Enable the generation of SEI messages for each encoded frame containing
* the hashes of the three reconstructed picture planes. Most decoders will
* validate those hashes against the reconstructed images it generates and
* report any mismatches. This is essentially a debugging feature. Hash
* types are MD5(1), CRC(2), Checksum(3). Default is 0, none */
int decodedPictureHashSEI;
/* Enable Temporal Sub Layers while encoding, signals NAL units of coded
* slices with their temporalId. Output bitstreams can be extracted either
* at the base temporal layer (layer 0) with roughly half the frame rate or
* at a higher temporal layer (layer 1) that decodes all the frames in the
* sequence. */
int bEnableTemporalSubLayers;//是否应用时域子层????
/*== GOP structure and slice type decisions (lookahead) ==*/
/* Enable open GOP - meaning I slices are not necessarily IDR and thus frames
* encoded after an I slice may reference frames encoded prior to the I
* frame which have remained in the decoded picture buffer. Open GOP
* generally has better compression efficiency and negligible encoder
* performance impact, but the use case may preclude it. Default true */
int bOpenGOP; //打开表示,除第一帧为 X265_TYPE_IDR外,其它I帧为 X265_TYPE_I,打开可以提高压缩率,但是要保留前一个I帧,目的是可以获取当前I帧(IDR无须参考任何帧,I帧可能参考其它I帧)
//关闭表示,全部I帧都为IDR帧 默认为打开,但是打开不适用随机访问
//打开即其关键帧为CAR 不同CVS(GOP)可以相互参考 关闭为IDR(不同GOP不相互参考)
//打开情况:编码顺序。I帧后可能有小于I帧号的帧(RDSL) 关闭情况:I帧后的帧号一定大于I帧
/* Scene cuts closer together than this are coded as I, not IDR. */
int keyframeMin;//默认为fps长度(如果keyframeMax/10 小于fps 则等于keyframeMax/10)
//功能一:最小IDR帧间隔,如果当前判断为I帧并且距离上一IDR帧大于此值,则将其置为IDR帧
//功能二:场景切换判断,值越小越容易判断为场景切换,编码I帧的概率越大
/* Maximum keyframe distance or intra period in number of frames. If 0 or 1,
* all frames are I frames. A negative value is casted to MAX_INT internally
* which effectively makes frame 0 the only I frame. Default is 250 */
int keyframeMax; //标记相邻两个关键帧(IDR帧)的最大间隔
/* Maximum consecutive B frames that can be emitted by the lookahead. When
* b-adapt is 0 and keyframMax is greater than bframes, the lookahead emits
* a fixed pattern of `bframes` B frames between each P. With b-adapt 1 the
* lookahead ignores the value of bframes for the most part. With b-adapt 2
* the value of bframes determines the search (POC) distance performed in
* both directions, quadratically increasing the compute load of the
* lookahead. The higher the value, the more B frames the lookahead may
* possibly use consecutively, usually improving compression. Default is 3,
* maximum is 16 */
int bframes; //一个GOP中的连续B帧的最大个数,默认为3,最大为16
/* Sets the operating mode of the lookahead. With b-adapt 0, the GOP
* structure is fixed based on the values of keyframeMax and bframes.
* With b-adapt 1 a light lookahead is used to chose B frame placement.
* With b-adapt 2 (trellis) a viterbi B path selection is performed */
int bFrameAdaptive; //B帧决策 默认为2。如果为0,固定B帧位置,如果为1快速决定B帧位置, 如果为2比较精细的决定B帧位置
/* When enabled, the encoder will use the B frame in the middle of each
* mini-GOP larger than 2 B frames as a motion reference for the surrounding
* B frames. This improves compression efficiency for a small performance
* penalty. Referenced B frames are treated somewhere between a B and a P
* frame by rate control. Default is enabled. */
int bBPyramid; //是否有B帧参考 开:有B 关:无B ,默认打开.注意 B:表示可以参考的B帧, b表示不可以参考的b帧, 关闭此开关,只拥有b
/* A value which is added to the cost estimate of B frames in the lookahead.
* It may be a positive value (making B frames appear more expensive, which
* causes the lookahead to chose more P frames) or negative, which makes the
* lookahead chose more B frames. Default is 0, there are no limits */
int bFrameBias; //设置B帧权重 默认值为0 取值范围(-90,100) 值越大B帧权重越高 score = score * 100 / (130 + param->bFrameBias) CostEstimateGroup::estimateFrameCost
/* The number of frames that must be queued in the lookahead before it may
* make slice decisions. Increasing this value directly increases the encode
* latency. The longer the queue the more optimally the lookahead may make
* slice decisions, particularly with b-adapt 2. When cu-tree is enabled,
* the length of the queue linearly increases the effectiveness of the
* cu-tree analysis. Default is 40 frames, maximum is 250 */
int lookaheadDepth;
/* Use multiple worker threads to measure the estimated cost of each frame
* within the lookahead. When bFrameAdaptive is 2, most frame cost estimates
* will be performed in batch mode, many cost estimates at the same time,
* and lookaheadSlices is ignored for batched estimates. The effect on
* performance can be quite small. The higher this parameter, the less
* accurate the frame costs will be (since context is lost across slice
* boundaries) which will result in less accurate B-frame and scene-cut
* decisions. Default is 0 - disabled. 1 is the same as 0. Max 16 */
int lookaheadSlices; //配置在lookachead可以多条slice并行操作,默认为0, 并行可能引起性能损失
/* An arbitrary threshold which determines how aggressively the lookahead
* should detect scene cuts. The default (40) is recommended. */
int scenecutThreshold; //场景切换的阈值: 值越大越容易判断为场景切换,编码I帧的概率越大
/*== Coding Unit (CU) definitions ==*/
/* Maximum CU width and height in pixels. The size must be 64, 32, or 16.
* The higher the size, the more efficiently x265 can encode areas of low
* complexity, greatly improving compression efficiency at large
* resolutions. The smaller the size, the more effective wavefront and
* frame parallelism will become because of the increase in rows. default 64
* All encoders within the same process must use the same maxCUSize, until
* all encoders are closed and x265_cleanup() is called to reset the value. */
uint32_t maxCUSize;//最大的CU大小
/* Minimum CU width and height in pixels. The size must be 64, 32, 16, or
* 8. Default 8. All encoders within the same process must use the same
* minCUSize. */
uint32_t minCUSize;
/* Enable rectangular motion prediction partitions (vertical and
* horizontal), available at all CU depths from 64x64 to 8x8. Default is
* disabled */
int bEnableRectInter;
/* Enable asymmetrical motion predictions. At CU depths 64, 32, and 16, it
* is possible to use 25%/75% split partitions in the up, down, right, left
* directions. For some material this can improve compression efficiency at
* the cost of extra analysis. bEnableRectInter must be enabled for this
* feature to be used. Default disabled */
int bEnableAMP;
/*== Residual Quadtree Transform Unit (TU) definitions ==*/
/* Maximum TU width and height in pixels. The size must be 32, 16, 8 or 4.
* The larger the size the more efficiently the residual can be compressed
* by the DCT transforms, at the expense of more computation */
uint32_t maxTUSize;
/* The additional depth the residual quad-tree is allowed to recurse beyond
* the coding quad-tree, for inter coded blocks. This must be between 1 and
* 4. The higher the value the more efficiently the residual can be
* compressed by the DCT transforms, at the expense of much more compute */
uint32_t tuQTMaxInterDepth;
/* The additional depth the residual quad-tree is allowed to recurse beyond
* the coding quad-tree, for intra coded blocks. This must be between 1 and
* 4. The higher the value the more efficiently the residual can be
* compressed by the DCT transforms, at the expense of much more compute */
uint32_t tuQTMaxIntraDepth;
/* Set the amount of rate-distortion analysis to use within quant. 0 implies
* no rate-distortion optimization. At level 1 rate-distortion cost is used to
* find optimal rounding values for each level (and allows psy-rdoq to be
* enabled). At level 2 rate-distortion cost is used to make decimate decisions
* on each 4x4 coding group (including the cost of signaling the group within
* the group bitmap). Psy-rdoq is less effective at preserving energy when
* RDOQ is at level 2 */
int rdoqLevel;
/* Enable the implicit signaling of the sign bit of the last coefficient of
* each transform unit. This saves one bit per TU at the expense of figuring
* out which coefficient can be toggled with the least distortion.
* Default is enabled */
int bEnableSignHiding;
/* Allow intra coded blocks to be encoded directly as residual without the
* DCT transform, when this improves efficiency. Checking whether the block
* will benefit from this option incurs a performance penalty. Default is
* disabled */
int bEnableTransformSkip;
/* An integer value in range of 0 to 2000, which denotes strength of noise
* reduction in intra CUs. 0 means disabled */
int noiseReductionIntra;//intra变换域去噪强度 值越大 去噪强度越大 0 不去噪 取值范围:0~2000 默认为0 --nr-intra xxx配置
/* An integer value in range of 0 to 2000, which denotes strength of noise
* reduction in inter CUs. 0 means disabled */
int noiseReductionInter;//inter变换域去噪强度 值越大 去噪强度越大 0 不去噪 取值范围:0~2000 默认为0 --nr-inter xxx配置
/* Quantization scaling lists. HEVC supports 6 quantization scaling lists to
* be defined; one each for Y, Cb, Cr for intra prediction and one each for
* inter prediction.
*
* - NULL and "off" will disable quant scaling (default)
* - "default" will enable the HEVC default scaling lists, which
* do not need to be signaled since they are specified
* - all other strings indicate a filename containing custom scaling lists
* in the HM format. The encode will fail if the file is not parsed
* correctly. Custom lists must be signaled in the SPS. */
const char *scalingLists;// 是否使用量化矩阵, 默认不使用 通过--scaling-list xxx配置, xxx可以为空或者"off" 表示不适用量化矩阵 "default" 为模式使用HEVC设置的量化矩阵 其它给出一个文件名,来解析量化矩阵
/*== Intra Coding Tools ==*/
/* Enable constrained intra prediction. This causes intra prediction to
* input samples that were inter predicted. For some use cases this is
* believed to me more robust to stream errors, but it has a compression
* penalty on P and (particularly) B slices. Defaults to disabled */
int bEnableConstrainedIntra;//表示帧内预测是否受限,即是否允许使用采用帧间预测模式的邻近块信息进行帧内预测 默认否(不受限制)
/* Enable strong intra smoothing for 32x32 blocks where the reference
* samples are flat. It may or may not improve compression efficiency,
* depending on your source material. Defaults to disabled */
int bEnableStrongIntraSmoothing;//当前intra参考像素是否需要强滤波
/*== Inter Coding Tools ==*/
/* The maximum number of merge candidates that are considered during inter
* analysis. This number (between 1 and 5) is signaled in the stream
* headers and determines the number of bits required to signal a merge so
* it can have significant trade-offs. The smaller this number the higher
* the performance but the less compression efficiency. Default is 3 */
uint32_t maxNumMergeCand;//Merge选择的候选个数,默认值为3
/* Limit the motion references used for each search based on the results of
* previous motion searches already performed for the same CU: If 0 all
* references are always searched. If X265_REF_LIMIT_CU all motion searches
* will restrict themselves to the references selected by the 2Nx2N search
* at the same depth. If X265_REF_LIMIT_DEPTH the 2Nx2N motion search will
* only use references that were selected by the best motion searches of the
* 4 split CUs at the next lower CU depth. The two flags may be combined */
uint32_t limitReferences;
/* ME search method (DIA, HEX, UMH, STAR, FULL). The search patterns
* (methods) are sorted in increasing complexity, with diamond being the
* simplest and fastest and full being the slowest. DIA, HEX, and UMH were
* adapted from x264 directly. STAR is an adaption of the HEVC reference
* encoder's three step search, while full is a naive exhaustive search. The
* default is the star search, it has a good balance of performance and
* compression efficiency */
int searchMethod;
/* A value between 0 and X265_MAX_SUBPEL_LEVEL which adjusts the amount of
* effort performed during sub-pel refine. Default is 5 */
int subpelRefine;
/* The maximum distance from the motion prediction that the full pel motion
* search is allowed to progress before terminating. This value can have an
* effect on frame parallelism, as referenced frames must be at least this
* many rows of reconstructed pixels ahead of the referencee at all times.
* (When considering reference lag, the motion prediction must be ignored
* because it cannot be known ahead of time). Default is 60, which is the
* default max CU size (64) minus the luma HPEL half-filter length (4). If a
* smaller CU size is used, the search range should be similarly reduced */
int searchRange;
/* Enable availability of temporal motion vector for AMVP, default is enabled */
int bEnableTemporalMvp;
/* Enable weighted prediction in P slices. This enables weighting analysis
* in the lookahead, which influences slice decisions, and enables weighting
* analysis in the main encoder which allows P reference samples to have a
* weight function applied to them prior to using them for motion
* compensation. In video which has lighting changes, it can give a large
* improvement in compression efficiency. Default is enabled */
int bEnableWeightedPred; //是否应用加权P帧 (默认打开) 在亮度渐变场景中有帮助
/* Enable weighted prediction in B slices. Default is disabled */
int bEnableWeightedBiPred; //是否应用加权B帧 默认关闭
/*== Loop Filters ==*/
/* Enable the deblocking loop filter, which improves visual quality by
* reducing blocking effects at block edges, particularly at lower bitrates
* or higher QP. When enabled it adds another CU row of reference lag,
* reducing frame parallelism effectiveness. Default is enabled */
int bEnableLoopFilter;
/* deblocking filter tC offset [-6, 6] -6 light filter, 6 strong.
* This is the coded div2 value, actual offset is doubled at use */
int deblockingFilterTCOffset;
/* deblocking filter Beta offset [-6, 6] -6 light filter, 6 strong
* This is the coded div2 value, actual offset is doubled at use */
int deblockingFilterBetaOffset;
/* Enable the Sample Adaptive Offset loop filter, which reduces distortion
* effects by adjusting reconstructed sample values based on histogram
* analysis to better approximate the original samples. When enabled it adds
* a CU row of reference lag, reducing frame parallelism effectiveness.
* Default is enabled */
int bEnableSAO;//是否开启SAO --sao
/* Note: when deblocking and SAO are both enabled, the loop filter CU lag is
* only one row, as they operate in series on the same row. */
/* Select the method in which SAO deals with deblocking boundary pixels. If
* disabled the right and bottom boundary areas are skipped. If enabled,
* non-deblocked pixels are used entirely. Default is disabled */
int bSaoNonDeblocked;//????
/*== Analysis tools ==*/
/* A value between X265_NO_RDO_NO_RDOQ and X265_RDO_LEVEL which determines
* the level of rate distortion optimizations to perform during mode
* decisions and quantization. The more RDO the better the compression
* efficiency at a major cost of performance. Default is no RDO (0) */
int rdLevel;
/* Enable early skip decisions to avoid intra and inter analysis in likely
* skip blocks. Default is disabled */
int bEnableEarlySkip;
/* Use a faster search method to find the best intra mode. Default is 0 */
int bEnableFastIntra;
/* Enable a faster determination of whether skipping the DCT transform will
* be beneficial. Slight performance gain for some compression loss. Default
* is enabled */
int bEnableTSkipFast;
/* The CU Lossless flag, when enabled, compares the rate-distortion costs
* for normal and lossless encoding, and chooses the best mode for each CU.
* If lossless mode is chosen, the cu-transquant-bypass flag is set for that
* CU */
int bCULossless;//是否对CU尝试无损压缩模式 默认关闭 如果选择无损压缩模式 则当前CU cu-transquant-bypass 会标记为true
/* Specify whether to attempt to encode intra modes in B frames. By default
* enabled, but only applicable for the presets which use rdLevel 5 or 6
* (veryslow and placebo). All other presets will not try intra in B frames
* regardless of this setting */
int bIntraInBFrames;
/* Apply an optional penalty to the estimated cost of 32x32 intra blocks in
* non-intra slices. 0 is disabled, 1 enables a small penalty, and 2 enables
* a full penalty. This favors inter-coding and its low bitrate over
* potential increases in distortion, but usually improves performance.
* Default is 0 */
int rdPenalty;
/* Psycho-visual rate-distortion strength. Only has an effect in presets
* which use RDO. It makes mode decision favor options which preserve the
* energy of the source, at the cost of lost compression. The value must
* be between 0 and 2.0, 1.0 is typical. Default 0.3 */
double psyRd;//??? 默认值为0.3
/* Strength of psycho-visual optimizations in quantization. Only has an
* effect in presets which use RDOQ (rd-levels 4 and 5). The value must be
* between 0 and 50, 1.0 is typical. Default 1.0 */
double psyRdoq;//??? 默认为0.0 slow到placebo档次 为1.0 tune psnr ssim 为0.0 --psy-rdoq xx配置 tune grain 为10.0
/* If X265_ANALYSIS_SAVE, write per-frame analysis information into analysis
* buffers. if X265_ANALYSIS_LOAD, read analysis information into analysis
* buffer and use this analysis information to reduce the amount of work
* the encoder must perform. Default X265_ANALYSIS_OFF */
int analysisMode;
/* Filename for analysisMode save/load. Default name is "x265_analysis.dat" */
const char* analysisFileName;
/*== Rate Control ==*/
/* The lossless flag enables true lossless coding, bypassing scaling,
* transform, quantization and in-loop filter processes. This is used for
* ultra-high bitrates with zero loss of quality. It implies no rate control */
int bLossless; //无损压缩 量化参数固定为4 没有码率控制(有PB帧) 默认关闭 配置:--[no-]lossless
/* Generally a small signed integer which offsets the QP used to quantize
* the Cb chroma residual (delta from luma QP specified by rate-control).
* Default is 0, which is recommended */
int cbQpOffset;//cb量化参数相对于亮度量化参数的偏移 默认为0
/* Generally a small signed integer which offsets the QP used to quantize
* the Cr chroma residual (delta from luma QP specified by rate-control).
* Default is 0, which is recommended */
int crQpOffset;//cr量化参数相对于亮度量化参数的偏移 默认为0
struct
{
/* Explicit mode of rate-control, necessary for API users. It must
* be one of the X265_RC_METHODS enum values. */
int rateControlMode;//码流控制方式:CRF ABR QP --crf <> 配置crf --bitrate <> 配置ABR --qp <> 配置固定QP格式 默认为CRF
/* Base QP to use for Constant QP rate control. Adaptive QP may alter
* the QP used for each block. If a QP is specified on the command line
* CQP rate control is implied. Default: 32 */
int qp;//配置的固定QP 默认值为32 -q 配置 (P帧的QP) Pqp = qp Iqp = Pqp - ipoffset bqp = Pqp + pboffset Bqp(可参考B帧)= (bqp + pqp)/2
/* target bitrate for Average BitRate (ABR) rate control. If a non- zero
* bitrate is specified on the command line, ABR is implied. Default 0 */
int bitrate;
/* qComp sets the quantizer curve compression factor. It weights the frame
* quantizer based on the complexity of residual (measured by lookahead).
* Default value is 0.6. Increasing it to 1 will effectively generate CQP */
double qCompress; //强度系数:如果为1.0 则 qpCuTreeOffset = qpAqOffset qCompress越大 qpCuTreeOffset越大 默认值:0.6
/* QP offset between I/P and P/B frames. Default ipfactor: 1.4
* Default pbFactor: 1.3 */
double ipFactor;//用途:I帧与P帧的qscale关系 P = Iqscale * m_param->rc.ipFactor 默认 1.4
double pbFactor;//用途: B帧与P帧的qscale关系 B = Pqscale * m_param->rc.pbFactor 默认 1.3
/* Ratefactor constant: targets a certain constant "quality".
* Acceptable values between 0 and 51. Default value: 28 */
double rfConstant;//???在CRF模式中应用 一种统一质量的等级 范围在(0~51) 值越小 质量越好 默认为28 --crf <>
/* Max QP difference between frames. Default: 4 */
int qpStep;//两帧见最大的QP差 --qpstep 配置 默认值为4
/* Enable adaptive quantization. This mode distributes available bits between all
* CTUs of a frame, assigning more bits to low complexity areas. Turning
* this ON will usually affect PSNR negatively, however SSIM and visual quality
* generally improves. Default: X265_AQ_VARIANCE */
int aqMode; //自适应量化 默认打开,一般打开对psnr有损失,但是对ssim和主观质量优增益,选择一下几个值,默认为1
//#define X265_AQ_NONE 0
//#define X265_AQ_VARIANCE 1
//#define X265_AQ_AUTO_VARIANCE 2
//X265_AQ_AUTO_VARIANCE_BIASED 3
/* Sets the strength of AQ bias towards low detail CTUs. Valid only if
* AQ is enabled. Default value: 1.0. Acceptable values between 0.0 and 3.0 */
double aqStrength;//自适应量化的强度 取值范围(0.0~3.0) 默认为1.0
//固定QP X265_RC_CQP 、aqMode关闭、tune psnr 都会使其关闭
/* Sets the maximum rate the VBV buffer should be assumed to refill at
* Default is zero */
int vbvMaxBitrate;//最大的bits值,默认值为0 CBR规定encoder的输出码率为恒定,但是各帧编码后的大小不是固定的(I,B,P帧的存在),因此需要在encoder后面加入VBV buffer。
// Video Buffer Verifier (VBV)是一个当输入码流遵从MPEG标准时,既不会上溢出,也不会下溢出的理论上的解码缓冲器模型。
/* Sets the size of the VBV buffer in kilobits. Default is zero */
int vbvBufferSize;// 默认值为0 Video Buffering Verifier 视频缓存检验器
/* Sets how full the VBV buffer must be before playback starts. If it is less than
* 1, then the initial fill is vbv-init * vbvBufferSize. Otherwise, it is
* interpreted as the initial fill in kbits. Default is 0.9 */
double vbvBufferInit;//???
/* Enable CUTree rate-control. This keeps track of the CUs that propagate temporally
* across frames and assigns more bits to these CUs. Improves encode efficiency.
* Default: enabled */
int cuTree;//如果当前可参考帧中的块的传播cost比较大,分配其更多的bits 默认:打开
/* In CRF mode, maximum CRF as caused by VBV. 0 implies no limit */
double rfConstantMax; //CRF 模式下配置的最大 crf值 默认为0
/* In CRF mode, minimum CRF as caused by VBV */
double rfConstantMin;//CRF 模式下配置的最小 crf值 默认为0 --crf-min
/* Multi-pass encoding */
/* Enable writing the stats in a multi-pass encode to the stat output file */
int bStatWrite;
/* Enable loading data from the stat input file in a multi pass encode */
int bStatRead;
/* Filename of the 2pass output/input stats file, if unspecified the
* encoder will default to using x265_2pass.log */
const char* statFileName;
/* temporally blur quants */
double qblur;
/* temporally blur complexity */
double complexityBlur;
/* Enable slow and a more detailed first pass encode in multi pass rate control */
int bEnableSlowFirstPass;
/* rate-control overrides */
int zoneCount;//配置zones的个数 自动识别
x265_zone* zones;//用途????zones存储 配置关系如: --zones 2,4,q=4/10,12,b=3.2 分别为,,