X264
JahnLiang
-
x264参数配置-tune
x264中tune等级有8个,表示应用的场景。相比preset,tune主要调节环路滤波强度、psy强度、adaptive qp强度等画质相关因素。const char * const x264_tune_names[] = { "film", "animation", "grain", "stillimage", "psnr", "ssim", "fastdecode", "zerol...原创 2020-03-25 21:27:22 · 957 阅读 · 0 评论 -
x264参数配置-preset
x264中preset等级有10个,表示编码速度的快慢。static const char * const x264_preset_names[] = { "ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo", 0 ...原创 2020-03-25 15:52:12 · 2053 阅读 · 0 评论 -
x264参数配置
默认参数配置 //帧率25fps param->i_fps_num = 25; param->i_fps_den = 1; /* Encoder parameters * 帧类型决策相关 */ param->i_frame_reference = 3; //参考帧列表3帧 param->i_keyint_...原创 2020-03-25 15:10:54 · 701 阅读 · 0 评论 -
码控-macroblock_tree_finish()
/* 将frame的propagate_cost变现为f_qp_offset*/static void macroblock_tree_finish( x264_t *h, x264_frame_t *frame, float average_duration, int ref0_distance )原创 2020-03-14 17:55:43 · 208 阅读 · 0 评论 -
码控-mbtree_propagate_list()
/* 根据宏块之间的参考信息 将宏块的propagate_amount瓜分到其参考帧中 ref_costs[2] 表示两个参考帧的propagate_amount (*mvs)[2]表示参考向量 propagate_amount表示将要被瓜分宏块的propagate_amount lowres_costs 帧间预测satd bipred_weigtht 帧间预测权重 mb_y...原创 2020-03-14 17:53:26 · 250 阅读 · 0 评论 -
码控-mbtree_propagate_cost()
/* Estimate the total amount of influence on future quality that could be had if we * were to improve the reference samples used to inter predict any given macroblock. * * 若我们提升宏块的质量,则会对未来的质量照成多大...原创 2020-03-14 17:43:34 · 262 阅读 · 0 评论 -
码控-macroblock_tree_propagate()
/* 计算帧b的propagate_cost,并瓜分到其参考帧中 average_duration 当前这一组用于mb tree计算的帧的平均帧时间(s) p0,p1,b 前向参考帧、后向参考帧、当前帧 referenced 是否是参考帧 过程: 1.取帧b前向参考帧和后向参考帧的propagate_cost 2.计算参考的距离因子dist_scale_factor...原创 2020-03-14 17:42:49 · 321 阅读 · 0 评论 -
x264-码控
x264提供三级码控基本单位:帧级,行级,宏块级帧级定位:帧类型决策之后,帧实际编码之前主控函数:x264_ratecontrol_start()关键函数1:rate_estimate_qscale()用于根据当前实际使用的比特开销来确定当前帧的qscale关键函数2:clip_qscale()用于对得到的qscale进行clip,并进行vbv检验辅助函数1:qp2qscale()...原创 2020-03-14 17:36:48 · 844 阅读 · 0 评论 -
码控-macroblock_tree()
mbtree_propagate_cost()/* Estimate the total amount of influence on future quality that could be had if we * were to improve the reference samples used to inter predict any given macroblock. * *...原创 2020-03-13 18:11:51 · 347 阅读 · 0 评论 -
码控-x264_ratecontrol_mb_qp()
/* 得到当前待编码宏块的qp 过程: 1.取之前帧级码控决定的qp 2.计算当前宏块的qp,若使用adaptive qp ·若是参考帧,则 宏块qp = 帧级qp + qp_offset[mb_index] ·若非参考帧,则 宏块qp = 帧级qp + qp_offset_aq[mb_index] 3.clip宏块级qp*/int x264_ratecontro...原创 2020-03-12 10:35:17 · 570 阅读 · 0 评论 -
队列流程
x264中有几个队列unused queue :相当于内存池,当需要存储帧时取一个x264_frame_t,编码完成后释放回去lookahead-ifbuff queue:作为unused queue到lookahead-next queue之间的中间缓存,用于多线程并发lookahead-next queue:实际进行帧类型决策的队列lookahead-ofbuff queue:作为l...原创 2020-03-10 10:42:35 · 698 阅读 · 0 评论 -
码控-qp2qscale()/qscale2qp()
x264中是通过qscale来进行码率控制,而非qp。qscale是qp线性化计算的产物,qp线性化成qscale后可与bits存在对应关系:若 qscale *= A,则 qp /= A若 qscale /= A,则 qp *= A/* Terminology: * qp = h.264's quantizer * qscale = linearized quantizer = La...原创 2020-03-10 10:06:07 · 922 阅读 · 0 评论 -
码控-predict_size()/predict_row_size() / update_predictor()
predict_size()/* 根据帧的satd和qscale来估计帧的bits开销 p:一组用于satd=>bits的参数 q:qscale var:satd 过程: bits = (coeff * satd +offset) / (qscale * count)*/static float predict_size( predictor_t *p, float q,...原创 2020-03-07 16:47:58 · 464 阅读 · 0 评论 -
码控-clip_qscale()
// apply VBV constraints and clip qscale to between lmin and lmax/* 对qscale进行VBV检验,然后clip到lmin和lmax中 过程: 1.根据帧类型得到qscale的lmin和lmax 2.若使用vbv,则进行vbv检查 1.两个算法择一进行约束 ·lookahead vbv 1.计...原创 2020-03-06 17:56:21 · 564 阅读 · 0 评论 -
码控-rate_estimate_qscale()
// update qscale for 1 frame based on actual bits used so far/* 基于当前实际使用的比特开销来确定当前帧的qscale 过程: 1.计算total_bits,即目前为止编码所有帧所耗费的比特开销总和 2.计算qscale ·B帧 1.根据相邻的两个参考帧来推算当前帧的QP 2.qp to qscal...原创 2020-03-05 20:50:35 · 629 阅读 · 0 评论 -
码控-x264_ratecontrol_start()
/* Before encoding a frame, choose a QP for it 在一帧编码之前,进行帧级码率控制 过程: 1.若使用vbv 1. 2.根据profile和level得到最小压缩比MinCR 3.根据MinCR计算当前帧的最大体积限制 4.计算QP ·ABR QP = rate_estimate_qscale()...原创 2020-02-27 21:39:53 · 482 阅读 · 0 评论 -
帧类型决策-x264_slicetype_decide()
/* lookahead队列中的帧类型确定 过程: 1.计算每一帧的时长duration 2.对lookahead里的每一帧进行帧类型分析 ·x264_ratecontrol_slice_type() ·x264_slicetpye_analyse() 3.对一段BBB...BBB(IDR/I/P) 1.检查BREF是否合规 2.检查Keyframe,设置...原创 2020-02-24 21:55:27 · 917 阅读 · 0 评论 -
帧类型决策-x264_slicetype_analyse()
/* 对lookahead队列中的帧分析,确定他们的帧类型 过程: 1. 若第一帧是AUTO/I,检查其相对于上一个非B帧是否场景切换,若场景切换则将当前帧设置为I,return 2. 遍历,将所有的关键帧根据openGOP设置成I/IDR 3. 将所有IDR帧前的AUTO/B帧改为P帧 4. 若允许使用B帧 · 使用X264_B_ADAPT_TRELLIS方法自适应设...原创 2020-02-20 21:38:30 · 807 阅读 · 0 评论 -
帧类型决策-slicetype_frame/slice/mb_cost()
/* 计算并返回帧b的开销,其中p0表示b的前向参考帧,p1表示b的后向参考帧 若p0 = p1 = b,则表示没有参考帧,即I帧 若p1 = b,则表示只有前向参考帧,即P帧 其中每一个帧都带有开销矩阵i_cost_est[b-p0][p1-b] 表示帧b以p0为前向参考,p1为后向参考时的帧cost*/static int x264_slicetype_frame_cost( ...原创 2020-02-19 20:42:43 · 938 阅读 · 0 评论 -
帧类型决策-scenecut()
static int scenecut_internal( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, int p0, int p1, int real_scenecut ){ x264_frame_t *frame = frames[p1]; //取p1帧 /* Don't do scenecuts on ...原创 2020-02-19 16:48:06 · 920 阅读 · 0 评论 -
帧类型决策-slicetype_path_cost()
/*计算一个路径的cost总和,若超过了阈值则立马结束返回*/static uint64_t slicetype_path_cost( x264_t *h, x264_mb_analysis_t *a, x264_frame_t **frames, char *path, uint64_t threshold ){ uint64_t cost = 0; int loc = ...原创 2020-02-19 15:27:44 · 415 阅读 · 0 评论