Android libX265库的交叉编译及x265编码,解码测试程序

基于x265_2.5(2.5版本),Android-18

0.提取Android交叉编译工具链

运行如下命令:

/home/xxxx/project/test/ndk/android-ndk-r9d/build/tools/make-standalone-toolchain.sh --platform=android-17 --install-dir=/home/xxxx/project/test/ndk/android-ndk-r9d/tmp/android-17-toolchain

make-standalone-toolchain.sh --platform=android-18 --install-dir=/home/yuhao/android-18-toolchain

1.交叉编译

下载libx265源码
下载地址:https://bitbucket.org/multicoreware/x265/downloads/

1.修改文件libx265/x265_2.5/build/arm-linux/crosscompile.cmake
源文件

  5 set(CROSS_COMPILE_ARM 1)
  6 set(CMAKE_SYSTEM_NAME Linux)
  7 set(CMAKE_SYSTEM_PROCESSOR armv6l)
  8 
  9 # specify the cross compiler
 10 set(CMAKE_C_COMPILER arm-linux-androideabi-gcc)
 11 set(CMAKE_CXX_COMPILER arm-linux-androideabi-g++)
 12 
 13 # specify the target environment
 14 SET(CMAKE_FIND_ROOT_PATH  /home/yuhao/android-16-toolchain)
 15 

修改为

  5 set(CROSS_COMPILE_ARM 1)
  6 set(CMAKE_SYSTEM_NAME Linux)
  7 set(CMAKE_SYSTEM_PROCESSOR armv6l)
  8 
  9 # specify the cross compiler
 10 set(CMAKE_C_COMPILER arm-linux-androideabi-gcc)
 11 set(CMAKE_CXX_COMPILER arm-linux-androideabi-g++)
 12 
 13 # specify the target environment
 14 SET(CMAKE_FIND_ROOT_PATH  /home/yuhao/android-18-toolchain)
 15 
 16 set(CMAKE_SYSROOT /home/yuhao/android-18-toolchain/sysroot)

1.2修改libx265/x265_2.5/source/CMakeLists.txt

619 if(X265_LATEST_TAG)
620     # convert lists of link libraries into -lstdc++ -lm etc..
621     fore::ach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
622         if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
623             list(APPEND PLIBLIST "${LIB}")
624         else()
625             list(APPEND PLIBLIST "-l${LIB}")
626         endif()
627     endforeach()
628     if(PLIBLIST)
629         # blacklist of libraries that should not be in Libs.private
630         list(REMOVE_ITEM PLIBLIST "-lc" "-lpthread")  //修改点
631         string(REPLACE ";" " " PRIVATE_LIBS "${PLIBLIST}")
632     else()
633         set(PRIVATE_LIBS "")
634     endif(PLIBLIST)

修改为

619 if(X265_LATEST_TAG)
620     # convert lists of link libraries into -lstdc++ -lm etc..
621     foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
622         if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
623             list(APPEND PLIBLIST "${LIB}")
624         else()
625             list(APPEND PLIBLIST "-l${LIB}")
626         endif()
627     endforeach()
628     if(PLIBLIST)
629         # blacklist of libraries that should not be in Libs.private
630         list(REMOVE_ITEM PLIBLIST "-lc")  //修改点
631         string(REPLACE ";" " " PRIVATE_LIBS "${PLIBLIST}")
632     else()
633         set(PRIVATE_LIBS "")
634     endif(PLIBLIST)

当前文件libx265/x265_2.5/source/CMakeLists.txt

 81 if(UNIX)
 82     list(APPEND PLATFORM_LIBS pthread)  //修改点
 83     find_library(LIBRT rt)
 84     if(LIBRT)
 85         list(APPEND PLATFORM_LIBS rt)
 86     endif()

修改为

 81 if(UNIX)
 82 #    list(APPEND PLATFORM_LIBS pthread)  //修改点
 83     find_library(LIBRT rt)
 84     if(LIBRT)
 85         list(APPEND PLATFORM_LIBS rt)
 86     endif()

2.安装编译所需要的软件
执行如下命令

sudo apt-get install cmake-curses-gui

3.配置编译信息
执行配置命令

cmake -DCMAKE_TOOLCHAIN_FILE=crosscompile.cmake -G "Unix Makefiles" ../../source && ccmake ../../source

执行如上命令会出现下图信息

 CHECKED_BUILD                    OFF        
 CMAKE_BUILD_TYPE                 Release    
 CMAKE_INSTALL_PREFIX             /home/yuhao/ytxPlayer/android/contrib/jni/jniLibs/x265
 DETAILED_CU_STATS                OFF  
 ENABLE_AGGRESSIVE_CHECKS         OFF  
 ENABLE_ASSEMBLY                  OFF   //关闭汇编
 ENABLE_CLI                       ON   
 ENABLE_HDR10_PLUS                OFF  
 ENABLE_LIBNUMA                   ON   
 ENABLE_PIC                       ON  //打开PIC 位置无关
 ENABLE_PPA                       OFF  
 ENABLE_SHARED                    ON   
 ENABLE_TESTS                     OFF   
 ENABLE_VTUNE                     OFF   
 FSANITIZE                              
 HIGH_BIT_DEPTH                   OFF   
 LIBDL                            /home/yuhao/android-18-toolchain/sysroot/usr/lib/libdl.so
 LIB_INSTALL_DIR                  lib    
 NO_ATOMICS                       OFF    
 NUMA_ROOT_DIR                    /usr   
 STATIC_LINK_CRT                  OFF  
 WARNINGS_AS_ERRORS               OFF    
 YASM_EXECUTABLE                  /home/yuhao/android-18-toolchain/bin/yasm                     

输入c
然后输入g

修改文件CMakeFiles/x265-shared.dir/link.txt

arm-linux-androideabi-g++  -fPIC -O3 -DNDEBUG -Wl,-Bsymbolic,-znoexecstack -shared -Wl,-soname,libx265.so.130 -o libx265.so.130

修改为

arm-linux-androideabi-g++  -fPIC -O3 -DNDEBUG -Wl,-Bsymbolic,-znoexecstack -shared -o libx265.so

修改文件CMakeFiles/cli.dir/link.txt

-o x265 -rdynamic libx265.so.130

修改为

-o x265 -rdynamic libx265.so

修改文件./CMakeFiles/x265-shared.dir/build.make

187 libx265.so: encoder/CMakeFiles/encoder.dir/__/x265-extras.cpp.o
188 libx265.so: common/CMakeFiles/common.dir/arm/asm-primitives.cpp.o //修改点
189 libx265.so: common/CMakeFiles/common.dir/primitives.cpp.o
190 libx265.so: common/CMakeFiles/common.dir/pixel.cpp.o
191 libx265.so: common/CMakeFiles/common.dir/dct.cpp.o
192 libx265.so: common/CMakeFiles/common.dir/ipfilter.cpp.o
193 libx265.so: common/CMakeFiles/common.dir/intrapred.cpp.o
194 libx265.so: common/CMakeFiles/common.dir/loopfilter.cpp.o
195 libx265.so: common/CMakeFiles/common.dir/constants.cpp.o
196 libx265.so.130: common/CMakeFiles/common.dir/cpu.cpp.o
197 libx265.so.130: common/CMakeFiles/common.dir/version.cpp.o
198 libx265.so.130: common/CMakeFiles/common.dir/threading.cpp.o
199 libx265.so.130: common/CMakeFiles/common.dir/threadpool.cpp.o
200 libx265.so.130: common/CMakeFiles/common.dir/wavefront.cpp.o
201 libx265.so.130: common/CMakeFiles/common.dir/md5.cpp.o
202 libx265.so.130: common/CMakeFiles/common.dir/bitstream.cpp.o
203 libx265.so.130: common/CMakeFiles/common.dir/yuv.cpp.o
204 libx265.so.130: common/CMakeFiles/common.dir/shortyuv.cpp.o
205 libx265.so.130: common/CMakeFiles/common.dir/picyuv.cpp.o
206 libx265.so.130: common/CMakeFiles/common.dir/common.cpp.o
207 libx265.so.130: common/CMakeFiles/common.dir/param.cpp.o
208 libx265.so.130: common/CMakeFiles/common.dir/frame.cpp.o
209 libx265.so.130: common/CMakeFiles/common.dir/framedata.cpp.o
210 libx265.so.130: common/CMakeFiles/common.dir/cudata.cpp.o
211 libx265.so.130: common/CMakeFiles/common.dir/slice.cpp.o
212 libx265.so.130: common/CMakeFiles/common.dir/lowres.cpp.o
213 libx265.so.130: common/CMakeFiles/common.dir/piclist.cpp.o
214 libx265.so.130: common/CMakeFiles/common.dir/predict.cpp.o
215 libx265.so.130: common/CMakeFiles/common.dir/scalinglist.cpp.o
216 libx265.so.130: common/CMakeFiles/common.dir/quant.cpp.o
217 libx265.so.130: common/CMakeFiles/common.dir/deblock.cpp.o
218 libx265.so.130: CMakeFiles/x265-shared.dir/build.make
219 libx265.so.130: x265.def
220 libx265.so.130: CMakeFiles/x265-shared.dir/link.txt
221         @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/yuhao/ytxPlayer/android/contrib/libx265/tmp/x265_2.5/build/arm-lin
    ux/CMakeFiles --progress-num=$(CMAKE_PROGRESS_10) "Linking CXX shared library libx265.so"
222         $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/x265-shared.dir/link.txt --verbose=$(VERBOSE)
223         $(CMAKE_COMMAND) -E cmake_symlink_library libx265.so.130 libx265.so.130 libx265.so
224 
225 libx265.so: libx265.so.130
226         @$(CMAKE_COMMAND) -E touch_nocreate libx265.so

改为

187 libx265.so: encoder/CMakeFiles/encoder.dir/__/x265-extras.cpp.o
188 #libx265.so: common/CMakeFiles/common.dir/arm/asm-primitives.cpp.o //修改点
189 libx265.so: common/CMakeFiles/common.dir/primitives.cpp.o
190 libx265.so: common/CMakeFiles/common.dir/pixel.cpp.o
191 libx265.so: common/CMakeFiles/common.dir/dct.cpp.o
192 libx265.so: common/CMakeFiles/common.dir/ipfilter.cpp.o //将libx265.so.130改为libx265.so
193 libx265.so: common/CMakeFiles/common.dir/intrapred.cpp.o
194 libx265.so: common/CMakeFiles/common.dir/loopfilter.cpp.o
195 libx265.so: common/CMakeFiles/common.dir/constants.cpp.o
196 libx265.so: common/CMakeFiles/common.dir/cpu.cpp.o
197 libx265.so: common/CMakeFiles/common.dir/version.cpp.o
198 libx265.so: common/CMakeFiles/common.dir/threading.cpp.o
199 libx265.so: common/CMakeFiles/common.dir/threadpool.cpp.o
200 libx265.so: common/CMakeFiles/common.dir/wavefront.cpp.o
201 libx265.so: common/CMakeFiles/common.dir/md5.cpp.o
202 libx265.so: common/CMakeFiles/common.dir/bitstream.cpp.o
203 libx265.so: common/CMakeFiles/common.dir/yuv.cpp.o
204 libx265.so: common/CMakeFiles/common.dir/shortyuv.cpp.o
205 libx265.so: common/CMakeFiles/common.dir/picyuv.cpp.o
206 libx265.so: common/CMakeFiles/common.dir/common.cpp.o
207 libx265.so: common/CMakeFiles/common.dir/param.cpp.o
208 libx265.so: common/CMakeFiles/common.dir/frame.cpp.o
209 libx265.so: common/CMakeFiles/common.dir/framedata.cpp.o
210 libx265.so: common/CMakeFiles/common.dir/cudata.cpp.o
211 libx265.so: common/CMakeFiles/common.dir/slice.cpp.o
212 libx265.so: common/CMakeFiles/common.dir/lowres.cpp.o
213 libx265.so: common/CMakeFiles/common.dir/piclist.cpp.o
214 libx265.so: common/CMakeFiles/common.dir/predict.cpp.o
215 libx265.so: common/CMakeFiles/common.dir/scalinglist.cpp.o
216 libx265.so: common/CMakeFiles/common.dir/quant.cpp.o
217 libx265.so: common/CMakeFiles/common.dir/deblock.cpp.o
218 libx265.so: CMakeFiles/x265-shared.dir/build.make
219 libx265.so: x265.def
220 libx265.so: CMakeFiles/x265-shared.dir/link.txt
221         @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/yuhao/ytxPlayer/android/contrib/libx265/x265_2.5/build/arm-linux/C
    MakeFiles --progress-num=$(CMAKE_PROGRESS_10) "Linking CXX shared library libx265.so"
222         $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/x265-shared.dir/link.txt --verbose=$(VERBOSE)
223         $(CMAKE_COMMAND) -E cmake_symlink_library libx265.so libx265.so libx265.so.130 //修改点
224 
225 libx265.so.130: libx265.so
226         @$(CMAKE_COMMAND) -E touch_nocreate libx265.so.130 //修改点

libx265.so.130改为libx265.so

修改文件source/common/cpu.cpp

331 uint32_t cpu_detect(void)
332 {   
333     int flags = 0;
334 
335 #if HAVE_ARMV6
336     flags |= X265_CPU_ARMV6;
337 
338     // don't do this hack if compiled with -mfpu=neon
339 #if !HAVE_NEON
340     static void (* oldsig)(int);
341     oldsig = signal(SIGILL, sigill_handler);
342     if (sigsetjmp(jmpbuf, 1))
343     {
344         signal(SIGILL, oldsig);
345         return flags;
346     }
347 
348     canjump = 1;
349     PFX(cpu_neon_test)();
350     canjump = 0;
351     signal(SIGILL, oldsig);
352 #endif // if !HAVE_NEON
353 
354     flags |= X265_CPU_NEON;
355 
356     // fast neon -> arm (Cortex-A9) detection relies on user access to the
357     // cycle counter; this assumes ARMv7 performance counters.
358     // NEON requires at least ARMv7, ARMv8 may require changes here, but
359     // hopefully this hacky detection method will have been replaced by then.
360     // Note that there is potential for a race condition if another program or
361     // x264 instance disables or reinits the counters while x264 is using them,
362     // which may result in incorrect detection and the counters stuck enabled.
363     // right now Apple does not seem to support performance counters for this test
364 #ifndef __MACH__
365     flags |= PFX(cpu_fast_neon_mrc_test)() ? X265_CPU_FAST_NEON_MRC : 0;
366 #endif
367     // TODO: write dual issue test? currently it's A8 (dual issue) vs. A9 (fast mrc)
368 #endif // if HAVE_ARMV6
369  
370     return flags;
371 } 

修改为

uint32_t cpu_detect(void)
{   
     int flags = 0;  
     return flags;
}

执行make命令

编译结束

下面给出一个H265编码和解码的测试程序

点击H265ENCODE按钮开始进行编码,通过log输出等待编码完成。完成后点击H265DECODE进行解码,生成YUV数据。

在测试时注意替换输入输出文件的路径

测试源码下载地址:https://github.com/ytxhao/androidH265Codec

device.jpg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,547评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,399评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,428评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,599评论 1 274
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,612评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,577评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,941评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,603评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,852评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,605评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,693评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,375评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,955评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,936评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,172评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,970评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,414评论 2 342

推荐阅读更多精彩内容