当前位置:网站首页>X264性能优化

X264性能优化

2022-08-09 13:05:00 zhouyongku

一、X264性能分析

测试环境

测试环境:Intel Pentium4 3.00GHz  (双核cpu),开启超线程
内存:    DDR 1.00G
操作系统: Windows sever 2003 Enterprise Edition
分析软件: Intel(R) VTune(TM) Performance Analyzer 8.0(评估版lic)
编译软件: VC71+nasm0.98
Bus Speed: 800MHz
测试程序: X264 20060506 编码器

1、Debug版本
编码参数:
X264 -fps -o foreman.264 forman.cif 352x288
编码400frames,编码效率:23fps左右(libx264 debug版本),35fps(libx264 release版本),提高了10fps以上,比较可观

2、
编码参数:
X264 -fps --no-asm -o foreman.264 forman.cif 352x288
--no-asm,Disable all CPU optimizations即未使用mmx,mmxext, sse,sse2,3dNow,3dnow ext,altivec等汇编指令优化。
编码400frames,编码效率2.67fps(libx264 debug版本),12.67fps(libx264 release版本),提高了10fps


Clockticks per Instructions Retired (CPI)表示该程序段的平均执行一条指令所需的时钟周期数,CPI越大表示该程序段调用的浮点数操作,乘法,除法,I/O处理,系统调用或文

件访问等代价昂贵的操作较多。
Instructions Retired events, 表示执行的指令数,越大表示该模块调用的较多.
Clockticks events 则表示该模块所消耗的时钟周期数,一般Clockticks events = Instructions Retired events * Clockticks per Instructions Retired (CPI),越大表示该模块消耗的时间越多,后面的Clockticks %则表示该模块的在所有程序中的时耗百分比.

这里有一点需要注意:(还是举例吧),例如要分析视频编码中去块滤波器算法/程序的时耗,并不是一个 x264_frame_deblocking_filter函数的时间消耗就是所有x264编解码过程中的时间消耗,由于 x264_frame_deblocking_filter调用deblck_edge,x264_clip3(该函数也被其他函数所调用)函数,而 deblock_edge下又调用x264_deblock_v8_luma_mmxext, x264_deblock_h_luma_mmxext,x_264_deblock_h_chroma_mmxext, deblock_luma_intra_c, x264_deblock_v_chroma_mmxext(这些函数通过指针重定义的方式以适应于不同的硬件平台,比如Intel,AMD的CPU采用 不同的指令系统,其实Mplayer,FFMPEG,T264等软件都采用类似的重定义方式,已达到一个软件使用与不同构架/平台,如 arm,powerpc,x86等)等函数。那么这里如果统计去块滤波器的算法的时间消耗百分比,就需要将该函数及其所有调用的子函数的时间消耗都计算在 内,x264_deblock_****都是唯一被deblock_edge调用,但对于x264_clip3,并不仅仅是去块滤波器部分调用,那么就只 能部分计算在去块滤波器之内,至于部分是多少要根据个函数的调用次数,这里不确定。

相关x264时耗分析数据后面的表格。deblock占4.3%左右,quant+dequant占3.3%左右,DCT+IDCT占1.1%左 右,主要是运动估计和运动补偿,ME中大量的sad/satd的计算,MC中的六阶滤波器tap_filter是主要时耗,具体我没有太细统计将近20% 左右,x264中由于采用了算法优化,程序优化及mmx,sse,sse2等指令优化,将原本消耗较大的去块滤波器等都有了较大程度地优化。

这里再讨论一下程序性能优化技术,程序性能优化可以大致从3个部分考虑。
1、算法结构优化,实现同样的应用功能可采用多种不同的算法和方 法,比如H.264种的运动估计全搜索和快速运动估计算法,实现的编码效率基本一致,但是处理时间可以节省10~20倍,所以需要选择高效的算法。还有递 归算法非递归化,递归算法使得程序结构清晰,可读性高,但却需要执行大量的过程调用,堆栈保存等,运行效率低下。

2、编译优化,现在很多编译器都实现了较强的代码优化功能,多数编译器都基于数据流分析以实现别名分析(通过变量重命名来消除数据相关,提高流水线 的执行效率),常数折叠,公共子表达式消除、冗余代码删除,循环逆转和循环展开等与体系结构无关的优化,例如GNU gcc就是个很好的编译工具。还有借用并行程序设计技术,进行相关性分析,并通过相应技术是程序具有更好的局部性以提高Cashe命中率。对于GCC中采 用-O -O2 -O3 -O4等选项选择针对速度/面积等性能优化,另外debug版本由于程序中加入较多的debug参数,影响程序效率,上面x264的debug和 release运行效率的对比可见一斑.编译优化属于静态优化,由编译器自动完成,但是编译器很难得到程序的语义信息,算法流程等信息。所以需要我们手工 编程优化以最大程度提高程序运行效率

3、程序优化,包括a)使用inline函数,很多编译器支持inline关键字,减少函数调用开销却增加了代码量。b)针对程序运行平台,如 x86(Intel),Xscale,ARM,DSP等不同构架,可采用相应的汇编优化,将主要时耗部分/循环调用等,进行汇编指令优化 MMX,SSE,WiMMX,ARM/Thumb指令,DSP汇编等,或者采用专用的库函数,如针对Intel CPU/Xscale构架的嵌入式系统(PXA255,PXA270等)可使用IPP/GPP库,提高程序效率。c)对于DSP系统,由于有多个并行处理 单元,编译器会并行优化,所以需要尽量减少频繁小循环跳转,将循环展开,同时减少循环或内层循环也可以提高CPU的流线效率,尽量不断流。d)在 Switch语句中根据发生频率排序case语句,编译器对于switch语句将生成if-else-if的嵌套代码,按概率排序可提高效率 (FPGA/CPLD等逻辑器件中,采用VHDL语言描述的switch是生成多个逻辑器件,并且完全并行的)。e)减少函数调用参数. f)减少耗时的浮点数操作,除法操作等降低CPI。

SizeFunctionClockticks per Instructions Retired (CPI)Instructions Retired eventsClockticks eventsClockticks %Source File
4917refine_subpel3.050938338111900000034140000006.582219909f:\x264-060506\x264-060506\encoder\me.c
176x264_mc_chroma_mmxext1.463709677223200000032670000006.298802707 
21502x264_me_search_ref2.51592356794200000023700000004.569379374f:\x264-060506\x264-060506\encoder\me.c
880x264_pixel_satd_8x8_sse21.43551797141900000020370000003.927352652 
99RTC_CheckStackVars3.56315789557000000020310000003.915784603 
3296x264_pixel_satd_16x16_sse21.54047619126000000019410000003.742263867 
237get_ref_mmx1.72592592681000000013980000002.695355428f:\x264-060506\x264-060506\common\i386\mc-c.c
1183block_residual_write_cabac3.1586206943500000013740000002.649083232f:\x264-060506\x264-060506\encoder\cabac.c
6480x264_macroblock_analyse24.055555565400000012990000002.504482619f:\x264-060506\x264-060506\encoder\analyse.c
272x264_pixel_satd_4x4_mmxext1.229850746100500000012360000002.383018104 
80x264_pixel_avg_w16_mmxext2.09604519853100000011130000002.145873099 
232x264_mb_decimate_score1.35408560377100000010440000002.012840534f:\x264-060506\x264-060506\encoder\macroblock.c
64x264_pixel_avg_w8_mmxext1.7569060775430000009540000001.839319799 
2413x264_frame_deblocking_filter1.7039106155370000009150000001.76412748f:\x264-060506\x264-060506\common\frame.c
2491x264_macroblock_cache_save2.1521739134140000008910000001.717855284f:\x264-060506\x264-060506\common\macroblock.c
656x264_center_filter_mmxext1.2118644077080000008580000001.654231014 
146quant_4x42.9892473122790000008340000001.607958818f:\x264-060506\x264-060506\encoder\macroblock.c
5930x264_macroblock_cache_load2.0902255643990000008340000001.607958818f:\x264-060506\x264-060506\common\macroblock.c
206x264_cabac_encode_renorm2.1259842523810000008100000001.561686622f:\x264-060506\x264-060506\common\cabac.c
83array_non_zero_count1.1919642866720000008010000001.544334548f:\x264-060506\x264-060506\encoder\macroblock.h
96memset9.464285714840000007950000001.532766499F:\VS70Builds\3077\vc\crtbld\crt\src\intel\memset.asm
363predict_16x16_p1.0954356857230000007920000001.526982474f:\x264-060506\x264-060506\common\predict.c
184x264_cabac_encode_decision2.3714285713150000007470000001.440222107f:\x264-060506\x264-060506\common\cabac.c
37_RTC_CheckEsp1.7071428574200000007170000001.382381861 
3693x264_macroblock_encode2.8902439022460000007110000001.370813812f:\x264-060506\x264-060506\encoder\macroblock.c
47x264_clip_uint81.3173652695010000006600000001.272485395f:\x264-060506\x264-060506\common\clip1.h
304x264_quant_4x4_core15_mmx1.6747967483690000006180000001.191509052 
2091x264_mb_analyse_intra1.8440366973270000006030000001.162588929f:\x264-060506\x264-060506\encoder\analyse.c
1680x264_pixel_satd_8x16_sse21.1445086715190000005940000001.145236856 
1696x264_pixel_satd_16x8_sse21.4496124033870000005610000001.081612586 
164motion_compensation_chroma_mmxext1.4596774193720000005430000001.046908439f:\x264-060506\x264-060506\common\mc.c
328deblock_edge1.5940594063030000004830000000.931227948f:\x264-060506\x264-060506\common\frame.c
363predict_8x8c_p1.4537037043240000004710000000.90809185f:\x264-060506\x264-060506\common\predict.c
176x264_macroblock_cache_mv1.6626506022490000004140000000.798195384f:\x264-060506\x264-060506\common\macroblock.h
71x264_clip31.6666666672160000003600000000.694082943f:\x264-060506\x264-060506\common\common.h
121x264_macroblock_cache_ref2.3333333331530000003570000000.688298918f:\x264-060506\x264-060506\common\macroblock.h
272x264_horizontal_filter_mmxext1.2164948452910000003540000000.682514894 
1104x264_pixel_sad_x4_16x16_sse24.423076923780000003450000000.66516282 
480x264_pixel_satd_8x4_sse21.4303797472370000003390000000.653594771 
496x264_deblock_v8_luma_mmxext1.0666666673150000003360000000.647810747 
432x264_pixel_sad_x4_8x8_mmxext1.6716417912010000003360000000.647810747 
288x264_pixel_sad_16x16_sse24.608695652690000003180000000.6131066 
910x264_mb_predict_mv2.3636363641320000003120000000.601538551f:\x264-060506\x264-060506\common\macroblock.c
106bs_write12.6666666671170000003120000000.601538551f:\x264-060506\x264-060506\common\bs.h
224x264_sub4x4_dct_mmx1.160919542610000003030000000.584186477 
211scan_zigzag_4x4full1.6727272731650000002760000000.532130256f:\x264-060506\x264-060506\encoder\macroblock.c
656x264_deblock_h_luma_mmxext3.214285714840000002700000000.520562207 
227predict_16x16_dc2.3783783781110000002640000000.508994158f:\x264-060506\x264-060506\common\predict.c
496x264_pixel_satd_4x8_mmxext1.2428571432100000002610000000.503210134 
960x264_pixel_ssd_16x16_sse24.315789474570000002460000000.474290011 
33abs1.8604651161290000002400000000.462721962f:\vs70builds\3077\vc\crtbld\crt\src\abs.c
864x264_pixel_sad_x3_16x16_sse23.391304348690000002340000000.451153913 
962x264_mb_analyse_inter_p8x81.9487179491170000002280000000.439585864f:\x264-060506\x264-060506\encoder\analyse.c
3064x264_macroblock_write_cabac2.62962963810000002130000000.410665741f:\x264-060506\x264-060506\encoder\cabac.c
1209x264_mb_encode_8x8_chroma2.379310345870000002070000000.399097692f:\x264-060506\x264-060506\encoder\macroblock.c
829memcpy11180000001980000000.381745619F:\VS70Builds\3077\vc\crtbld\crt\src\intel\memcpy.asm
386predict_8x8c_dc2.52750000001890000000.364393545f:\x264-060506\x264-060506\common\predict.c
202bs_write1.909090909990000001890000000.364393545f:\x264-060506\x264-060506\common\bs.h
352x264_pixel_sad_x3_8x8_mmxext2.172413793870000001890000000.364393545 
144x264_pixel_sad_8x8_mmxext2.384615385780000001860000000.358609521 
156predict_16x16_h2900000001800000000.347041471f:\x264-060506\x264-060506\common\predict.c
178predict_16x16_v2.52173913690000001740000000.335473422f:\x264-060506\x264-060506\common\predict.c
128x264_mc_copy_w16_mmx9.666666667180000001740000000.335473422 
405x264_cabac_mb_mvd_cpn2.192307692780000001710000000.329689398f:\x264-060506\x264-060506\encoder\cabac.c
161x264_cabac_putbit1.41200000001680000000.323905373f:\x264-060506\x264-060506\common\cabac.c
304x264_dequant_4x4_mmx2.545454545660000001680000000.323905373 
592x264_pixel_sad_x4_16x8_sse22.291666667720000001650000000.318121349 
103x264_median2.6600000001560000000.300769275f:\x264-060506\x264-060506\common\common.h
398predict_4x4_ddl1.5625960000001500000000.289201226f:\x264-060506\x264-060506\common\predict.c
272x264_add4x4_idct_mmx1.1395348841290000001470000000.283417202 
418x264_cabac_mb_cbp_luma2.666666667540000001440000000.277633177f:\x264-060506\x264-060506\encoder\cabac.c
414predict_4x4_ddr2.285714286630000001440000000.277633177f:\x264-060506\x264-060506\common\predict.c
405predict_4x4_vl1.777777778810000001440000000.277633177f:\x264-060506\x264-060506\common\predict.c
1455x264_mb_predict_mv_ref16x163.692307692390000001440000000.277633177f:\x264-060506\x264-060506\common\macroblock.c
1181x264_mb_analyse_inter_p16x164.6300000001380000000.266065128f:\x264-060506\x264-060506\encoder\analyse.c
176x264_macroblock_cache_mvd1.769230769780000001380000000.266065128f:\x264-060506\x264-060506\common\macroblock.h
816x264_pixel_sad_x4_8x16_mmxext1.769230769780000001380000000.266065128 
199scan_zigzag_4x42.045454545660000001350000000.260281104f:\x264-060506\x264-060506\encoder\macroblock.c
446predict_4x4_mode_available2.25600000001350000000.260281104f:\x264-060506\x264-060506\encoder\analyse.c
1148x264_mb_analyse_inter_p16x83.142857143420000001320000000.254497079f:\x264-060506\x264-060506\encoder\analyse.c
1746x264_mb_analyse_init8.2150000001230000000.237145005f:\x264-060506\x264-060506\encoder\analyse.c
511x264_mb_analyse_intra_chroma2.733333333450000001230000000.237145005f:\x264-060506\x264-060506\encoder\analyse.c
425predict_4x4_hd1.28125960000001230000000.237145005f:\x264-060506\x264-060506\common\predict.c
425predict_4x4_vr1.413793103870000001230000000.237145005f:\x264-060506\x264-060506\common\predict.c
122predict_8x8c_h1.952380952630000001230000000.237145005f:\x264-060506\x264-060506\common\predict.c
425x264_mb_encode_i4x42.105263158570000001200000000.231360981f:\x264-060506\x264-060506\encoder\macroblock.c
464x264_pixel_sad_x3_16x8_sse25240000001200000000.231360981 
672x264_pixel_sad_x3_8x16_mmxext2.666666667450000001200000000.231360981 
297predict_4x4_hu1.772727273660000001170000000.225576956f:\x264-060506\x264-060506\common\predict.c
120predict_8x8c_v3.083333333360000001110000000.214008907f:\x264-060506\x264-060506\common\predict.c
464x264_deblock_h_chroma_mmxext1.166666667900000001050000000.202440858 
240x264_pixel_sad_8x16_mmxext1.888888889540000001020000000.196656834 
1104x264_mb_analyse_inter_p8x16333000000990000000.190872809f:\x264-060506\x264-060506\encoder\analyse.c
176x264_pixel_sad_16x8_sse23.66666666727000000990000000.190872809 
194x264_cabac_encode_bypass1.19230769278000000930000000.17930476f:\x264-060506\x264-060506\common\cabac.c
836x264_cabac_mb_cbf_ctxidxinc1.87548000000900000000.173520736f:\x264-060506\x264-060506\encoder\cabac.c
80x264_mc_copy_w8_mmx330000000900000000.173520736 
1385x264_slice_write4.83333333318000000870000000.167736711f:\x264-060506\x264-060506\encoder\encoder.c
680deblock_luma_intra_c2.15384615439000000840000000.161952687f:\x264-060506\x264-060506\common\frame.c
503x264_mb_mc_0xywh1.85714285742000000780000000.150384638f:\x264-060506\x264-060506\common\macroblock.c
134predict_4x4_dc515000000750000000.144600613f:\x264-060506\x264-060506\common\predict.c
577x264_mb_predict_mv_16x162.530000000750000000.144600613f:\x264-060506\x264-060506\common\macroblock.c
324plane_expand_border6.2512000000750000000.144600613f:\x264-060506\x264-060506\common\frame.c
272x264_deblock_v_chroma_mmxext1.64285714342000000690000000.133032564 
123x264_sub8x8_dct_mmx1.11111111154000000600000000.11568049f:\x264-060506\x264-060506\common\i386\dct-c.c
1359x264_macroblock_probe_skip2.71428571421000000570000000.109896466f:\x264-060506\x264-060506\encoder\macroblock.c
305x264_cabac_mb_mvd3.415000000510000000.098328417f:\x264-060506\x264-060506\encoder\cabac.c
1880x264_analyse_update_cache412000000480000000.092544392f:\x264-060506\x264-060506\encoder\analyse.c
64array_non_zero4.6666666679000000420000000.080976343f:\x264-060506\x264-060506\encoder\macroblock.h
271x264_mb_dequant_2x2_dc3.512000000420000000.080976343f:\x264-060506\x264-060506\common\quant.c
266mc_luma_mmx2.16666666718000000390000000.075192319f:\x264-060506\x264-060506\common\i386\mc-c.c
199dct2x2dc3.2512000000390000000.075192319f:\x264-060506\x264-060506\common\dct.c
149quant_2x2_dc133000000330000000.06362427f:\x264-060506\x264-060506\encoder\macroblock.c
320x264_cabac_mb_cbp_chroma2.7512000000330000000.06362427f:\x264-060506\x264-060506\encoder\cabac.c
61_alloca_probe 0330000000.06362427F:\VS70Builds\3077\vc\crtbld\crt\src\intel\chkstk.asm
38x264_me_search2.512000000300000000.057840245f:\x264-060506\x264-060506\encoder\analyse.c
145x264_mb_predict_intra4x4_mode130000000300000000.057840245f:\x264-060506\x264-060506\common\macroblock.c
194x264_mb_predict_mv_pskip 0300000000.057840245f:\x264-060506\x264-060506\common\macroblock.c
279x264_nal_encode215000000300000000.057840245f:\x264-060506\x264-060506\common\common.c
172x264_cabac_mb_skip39000000270000000.052056221f:\x264-060506\x264-060506\encoder\cabac.c
59predict_4x4_v4.56000000270000000.052056221f:\x264-060506\x264-060506\common\predict.c
1253x264_mb_mc39000000270000000.052056221f:\x264-060506\x264-060506\common\macroblock.c
74x264_deblock_v_luma_mmxext1.12524000000270000000.052056221f:\x264-060506\x264-060506\common\frame.c
227predict_8x8chroma_mode_available46000000240000000.046272196f:\x264-060506\x264-060506\encoder\analyse.c
47bs_size_te 0240000000.046272196f:\x264-060506\x264-060506\common\bs.h
1131x264_cabac_mb_type121000000210000000.040488172f:\x264-060506\x264-060506\encoder\cabac.c
80predict_4x4_h3.56000000210000000.040488172f:\x264-060506\x264-060506\common\predict.c
17x264_ratecontrol_qp 0180000000.034704147f:\x264-060506\x264-060506\encoder\ratecontrol.c
55scan_zigzag_2x2_dc29000000180000000.034704147f:\x264-060506\x264-060506\encoder\macroblock.c
115x264_macroblock_encode_skip29000000180000000.034704147f:\x264-060506\x264-060506\encoder\macroblock.c
279x264_mb_analyse_transform63000000180000000.034704147f:\x264-060506\x264-060506\encoder\analyse.c
138x264_sub16x16_dct_mmx1.512000000180000000.034704147f:\x264-060506\x264-060506\common\i386\dct-c.c
125bs_size_ue118000000180000000.034704147f:\x264-060506\x264-060506\common\bs.h
142x264_me_refine_qpel2.56000000150000000.028920123f:\x264-060506\x264-060506\encoder\me.c
233x264_mb_analyse_load_costs1.6666666679000000150000000.028920123f:\x264-060506\x264-060506\encoder\analyse.c
14_security_check_cookie2.56000000150000000.028920123f:\vs70builds\3077\vc\crtbld\crt\src\secchk.c
444x264_cabac_mb8x8_mvd43000000120000000.023136098f:\x264-060506\x264-060506\encoder\cabac.c
312x264_cabac_mb_qp_delta43000000120000000.023136098f:\x264-060506\x264-060506\encoder\cabac.c
207predict_16x16_dc_top26000000120000000.023136098f:\x264-060506\x264-060506\common\predict.c
213predict_8x8c_dc_top 0120000000.023136098f:\x264-060506\x264-060506\common\predict.c
39x264_cabac_pos43000000120000000.023136098f:\x264-060506\x264-060506\common\cabac.h
368x264_deblock_h_chroma_intra_mmxext1.3333333339000000120000000.023136098 
5058x264_encoder_encode 090000000.017352074f:\x264-060506\x264-060506\encoder\encoder.c
768x264_mb_cache_mv_p8x8 090000000.017352074f:\x264-060506\x264-060506\encoder\analyse.c
211predict_16x16_dc_left1.5600000090000000.017352074f:\x264-060506\x264-060506\common\predict.c
299predict_8x8c_dc_left0.751200000090000000.017352074f:\x264-060506\x264-060506\common\predict.c
91x264_cabac_encode_terminal 090000000.017352074f:\x264-060506\x264-060506\common\cabac.c
104_aulldiv3300000090000000.017352074F:\VS70Builds\3077\vc\crtbld\crt\src\intel\ulldiv.asm
341x264_macroblock_encode_pskip 060000000.011568049f:\x264-060506\x264-060506\encoder\macroblock.c
130x264_psnr 060000000.011568049f:\x264-060506\x264-060506\encoder\encoder.c
950x264_slice_header_write 060000000.011568049f:\x264-060506\x264-060506\encoder\encoder.c
161x264_cabac_encode_ue_bypass1600000060000000.011568049f:\x264-060506\x264-060506\encoder\cabac.c
100x264_add8x8_idct_mmx0.3333333331800000060000000.011568049f:\x264-060506\x264-060506\common\i386\dct-c.c
69plane_copy 060000000.011568049f:\x264-060506\x264-060506\common\csp.c
142x264_cabac_context_init2300000060000000.011568049f:\x264-060506\x264-060506\common\cabac.c
3526_output 060000000.011568049f:\vs70builds\3077\vc\crtbld\crt\src\output.c
52_allmul2300000060000000.011568049F:\VS70Builds\3077\vc\crtbld\crt\src\intel\llmul.asm
173__add_12 060000000.011568049 
600_log_pentium4 060000000.011568049 
96x264_quant_2x2_dc_core16_mmxext 060000000.011568049 
802x264_ratecontrol_start 030000000.005784025f:\x264-060506\x264-060506\encoder\ratecontrol.c
1051x264_mb_encode_i16x161300000030000000.005784025f:\x264-060506\x264-060506\encoder\macroblock.c
139x264_nal_end 030000000.005784025f:\x264-060506\x264-060506\encoder\encoder.c
426x264_slice_init 030000000.005784025f:\x264-060506\x264-060506\encoder\encoder.c
227predict_16x16_mode_available1300000030000000.005784025f:\x264-060506\x264-060506\encoder\analyse.c
1625x264_cqm_init 030000000.005784025f:\x264-060506\x264-060506\common\set.c
430x264_mb_dequant_4x4_dc 030000000.005784025f:\x264-060506\x264-060506\common\quant.c
137predict_16x16_dc_128 030000000.005784025f:\x264-060506\x264-060506\common\predict.c
101predict_8x8c_dc_128 030000000.005784025f:\x264-060506\x264-060506\common\predict.c
575x264_macroblock_slice_init 030000000.005784025f:\x264-060506\x264-060506\common\macroblock.c
929x264_mb_mc_8x8 030000000.005784025f:\x264-060506\x264-060506\common\macroblock.c
338i420_to_i420 030000000.005784025f:\x264-060506\x264-060506\common\csp.c
29bs_pos1300000030000000.005784025f:\x264-060506\x264-060506\common\bs.h
172bs_write_ue 030000000.005784025f:\x264-060506\x264-060506\common\bs.h
1100_read 030000000.005784025f:\vs70builds\3077\vc\crtbld\crt\src\read.c
1242I10_OUTPUT1300000030000000.005784025 
62__addl 030000000.005784025 
332__dtold 030000000.005784025 
1007__ld12mul0.5600000030000000.005784025 
389_cftof 030000000.005784025 
675x264_pixel_ssd_wxh0600000000f:\x264-060506\x264-060506\common\pixel.c
108write_string0300000000f:\vs70builds\3077\vc\crtbld\crt\src\output.c
467_filbuf0300000000f:\vs70builds\3077\vc\crtbld\crt\src\_filbuf.c

3、设置set.c中的sps->b_vui = 0;表示vui信息不出现在码流中 sps->b_frame_mbs_only = 1;表示采用所有图像均帧编码

4、屏蔽掉:cavlc.c中的else if( i_mb_type == B_8x8 ),else if( i_mb_type!= B_DIRECT ), else if( i_mb_type == B_DIRECT ),else if( i_mb_type == B_8x8 )等相关内容,编码级别为baseline没有B帧。

5、去掉common.h中的CHECKED_MALLOC中的if(!var)...(即检查分配内存成功与否) 

6、屏蔽掉ratecontrol_en.c中的x264_ratecontrol_new中的if( h->param.rc.i_rc_method == X264_RC_CRF)..和if( h->param.rc.b_stat_read )...等相关内容,因为已经设置i_rc_method == X264_RC_NONE,参数i_rc_method表示码率控制,CQP

x264优化(二)

1、去掉assert()语句

2、去掉common.c中的x264_param_parse()函数,及其相关定义和调用,这个主要是用来检查参数赋值对不对。 并将i_rc_method直接赋值为X264_RC_CQP。

3、去掉analyse.c中的static const int i_mb_b_cost_table[19]类似的数组(B帧用到的),以及以if( h->sh.i_type == SLICE_TYPE_B )...开头的语句。

4、去掉analyse.c中的x264_mb_analyse_inter_direct(),x264_mb_analyse_inter_b16x16(),x264_mb_analyse_inter_b8x8,x264_mb_analyse_inter_b16x8,x264_mb_analyse_inter_b8x16()等五个函数,这五个函数是用来进行B帧帧间预测的,不需要用到。

5、去掉有h->sh.i_type == SLICE_TYPE_B的语句。

6、将以for(i_list = 0;i_list<(h->sh.i_type == SLICE_TYPE_B ? 2 : 1 );i_list++ )的循环去掉,因为不使用B帧只执行一次,不需循环,但需加入i_list = 0;置初值。

7、analyse.c中的x264_mb_analyse_b_rd(),和x264_refine_bidir()函数去掉。

8、去掉cavlc_en.c中的uint8_t mb_type_b_to_golomb[3][9]和sub_mb_type_b_to_golomb[13]数组

9、去掉common.c中的parse_enum

x264优化(三)

1、去掉ratecontrol.c中的parse_zones相关的三处代码

2、去掉encoder.c中的x264_encoder_close()函数中的x264_ratecontrol_summary()函数及在ratecontrol.c中的相应代码(因为在这个函数中调用了if(rc->b_abr)...;

3、去掉rate_estimate_qscale()函数,clip_qscale()函数。

4、int x264_me_refine_bidir( x264_t *h, x264_me_t *m0, x264_me_t *m1,int i_weight ) 函数(me_en.c中)及其相关函数去掉,在程序中未能调用,且有内联,占用了大量的空间。

5、bs.h中int型数据改为short型,函数返回int的除外。

6、去掉 if( analysis.i_mbrd >= 2 && h->mb.i_type != I_PCM )的内容。

7、删除me.c中的COST_MV_RD宏。

8、删除analyse.c中的x264_intra_rd_refine函数,x264_intra_rd函数,x264_mb_analyse_p_rd()x264_mb_analyse_transform_rd() (可以考虑删除所有以_rd结尾的函数或变量)

9、删除x264_rd_cost_mb,x264_rd_cost_subpart,x264_rd_cost_part,uint64_t x264_rd_cost_i8x8,x264_rd_cost_i4x4,x264_rd_cost_i8x8_chroma

10、删除me.c中COST_BIMV_SATD宏里面if(rd)的内

x264优化(四)

1、删除x264_macroblock_encode_p8x8,x264_mb_analyse_inter_p8x8_mixed_ref,x264_mb_cache_mv_b8x8,sub16x16_dct8,sub8x8_dct8,x264_psy_trellis_init。

2、删除x264_mb_predict_mv_direct16x16,static int x264_mb_predict_mv_direct16x16_spatial。

3、删除x264_mb_mc_01xywh(可能是对后向参考帧计算的,或者和B帧有关),x264_macroblock_bipred_init, x264_mb_load_mv_direct8x8,x264_mb_mc_1xywh。

4、删除x264_ratecontrol_mb,predict_row_size和predict_size函数

5、删除x264_predict_8x8_filter,scaling_list_write,transpose函数

6、删除quant_8x8,dequant_8x8。set.c中的x264_cqm_parse_file,x264_cqm_parse_jmlist,common.c中的x264_encoder_headers,x264_encoder_reconfig。

7、 frame.c中删除x264_frame_expand_border_mod16(),macroblock_en.c中删除x264_denoise_dct()

8、删除x264_mb_transform_8x8_allowed,x264_mb_analyse_transform,x264_cabac_mb_transform_size,x264_psy_trellis_init,x264_mb_cache_fenc_satd(和rd有关的函数),去掉和b_transform_8x8相关的东西。i_mb_c

x264优化(五)

1、删除和dequant8_mf有关的一个循环。h->mb.pic.p_integral,h->sh.i_num_ref_idx_l1_active,去掉(m)->integral = &h->mb.pic.p_integral[list][ref][(xoff)+(yoff)*(m)->i_stride[0]]和common.h中的uint16_t *p_integral[2][16];

2、删除void x264_rdo_init,static ALWAYS_INLINE int quant_trellis_cabac(),删除trellis_node_t结构体,x264_cabac_size_decision_noup2。

3、删除 cabac.c,cabac1.c和cabac.h文件。

4、删除x264_macroblock_cache_skip

5、去掉和cpu相关的代码。

6、去掉rdo率失真优化相关东西。

7、去掉ssim相关的代码。SSIM(structural similarity index) 一种衡量两幅图像相似度的新指标,其值越大越好,最大为1,经常用到图像处理中,特别在图像去噪处理中在图像相似度评价上全面超越SNR(signal to noise ratio)和PSNR(peak signal to noise ratio)。

x264优化(六)

1、删除get_diff_limited_q,get_qscale,parse_zone函数

2、去掉和zones相关的结构体,代码。

3、去掉类似于b_have_lowres这样的变量,这样的变量赋了初始值之后,以后if(该变量)的语句是可以预测到的,若始终为0,那么这样的if判断是可以去掉的。去掉i_aq_mode相关的一些if判断语句。 

4、2pass 多次压缩码率控制 int b_stat_write; Enable stat writing in psz_stat_out char *psz_stat_out; int 

x264优化(七)

1、去掉有关信噪比的计算PSNR

2、去掉x264_rc_analyse_slice,x264_lowres_context_init,函数。

3、由于DIA菱形搜索算法是最快的,这里只保留菱形搜索法,将其他算法删去。

4、i_rd16x16bi,i_rd16x16direct,i_rd16x16,i_rd16x8bi,int i_rd8x16bi,i_rd8x8bi。

5、删除x264_slicetype_mb_cost,x264_slicetype_frame_cost,x264_slicetype_path,x264_slicetype_path_search函数。

6、删除ssd_mb,ssd_plane,sum_sa8d,sum_satd。

7、删除matroska.h和matroska.c文件。

8、删除gcd函数,删除muxer.h和muxer.c文件中有关y4m,mkv,thread相关的一些内容,因为这里输入只有YUV的原始数据额格式,最后编码出来的数据也是.264的原始编码数据。

9、bs.h文件,bs_write32,bs_align_0,bs_align_1。 common.h文件,x264_predictor_difference。

10、去掉和SLICE_TYPE_B,B_SKIP,B_BI_BI,B_BI_L1,B_BI_LO,B_L1_BI,B_L1_L1,B_L1_L0,B_L0_L1,B_L0_L0,B_DIRECT有关的条件,赋值等语句。

x264优化(八)

1、 D_L1_4x4 = 4, D_L1_8x4 = 5, D_L1_4x8 = 6, D_L1_8x8 = 7, D_BI_4x4 = 8, D_BI_8x4 = 9, D_BI_4x8 = 10, D_BI_8x8 = 11, D_DIRECT = 12, 可删除。

2、x264_mb_partition_count_table[]删除,x264_pixel_ssd_wxh()删除。

3、去掉x264_mb_analysis_t里的i_mbrd变

 x264优化(九)1、analyse.c文件中去掉WEIGHTED_AVG宏,删除scenecut()函数,x264_zigzag_scan2数组。2、去掉b_bframe_pyramid,i_bframe,X264_TYPE_B,X264_TYPE_BREF变量和相关代码。3、去掉Encode函数,for( i_frame = 0, i_file = 0;(i_frame < i_frame_total || i_frame_total == 0); )循环中的parse_qpfile()函数。4、去掉encode.c文件中x264_thread_sync_context()函数。5、stdint.h文件中将不必要的宏去掉。6、common.h文件中dist_scale_factor,bipred_weight,map_col_to_list0_buf,map_col_to_list0数组去掉,b_direct_auto_read,b_direct_auto_write,b_direct_spatial_mv_pred,b_sp_for_swidth,i_qs_delta,i_delay,fenc_dct8,fenc_dct4,fenc_satd,fenc_satd_sum,fenc_sa8d,fenc_sa8d_sum,i_neighbour_transform_size,i_neighbour_interlaced,i_cbp_top,i_cbp_left,i_last_dqp,i_misc_bits,i_direct_score,i_ssd_global,i_ssd,f_slice_qp,i_consecutive_bframes,i_direct_frames删除。if( h->frames.i_input <= h->frames.i_delay )循环去掉。 在Encodex264优化(十) 1、去掉局部变量未使用的变量。2、根据CCS的调试结果,去掉i_update_interval,opterr,print_errors变量。i_yuv_size,lambda2_tab[2][52],LAMBDA_BITS变量,i_left_type,i_top_type。def_dequant8,def_quant8数组。square1,hex2,mod6m1数组,quant8_scale,dequant8_scale,quant8_scan。x264_mb_cache_mv_b8x16()函数,x264_mb_cache_mv_b8x16()函数。predict_8x8_vl(),predict_8x8_hd(),predict_8x8_vr()munge_cavlc_nnz(),restore_cavlc_nnz_row(),munge_cavlc_nnz_row(),x264_atoi(),x264_atof(),3、去掉ratecontrol.c文件的expected_bits_sum,wanted_bits_window,short_term_cplxsum,short_term_cplxsum,short_term_cplxcount,rate_factor_constant,last_satd,last_rceq,cplxr_sum,cbr_decay变量,qscale2bits()函数,qscale2qp()函数。4、去掉x264_frame_t *last_nonb;5、删除slicetype.c文件。

原文地址: X264性能优化_liuchen1206的专栏-CSDN博客

原网站

版权声明
本文为[zhouyongku]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zhouyongku/article/details/121001860