標籤:

ffmpeg編譯android 硬解碼支持庫 libstagefright(1)——  git

最經一直在搞andoid下ffmpeg視頻優化 ,前文已經說了neon優化的方法 ,性能大大提升。 不過再快終究是軟解碼 ,和硬解碼還是不能比,我們的目標是更快更快更快!那麼要讓ffmpeg支持硬解碼就必須用android的媒體庫libstagefright 下載libstagefright的花就要到ffmpeg 目錄的tools 目錄下面, 這裡有個build-libstagefright.sh , 其內容如下: #!/bin/bash#在這裡添加你的NDK目錄if [ "$NDK" = "" ]; then echo NDK variable notset, assuming ${HOME}/android-ndk exportNDK=${HOME}/android-ndkfiecho "Fetching Android system headers"git clone --depth=1 --branchgingerbread-releasegit://github.com/CyanogenMod/android_frameworks_base.git../android-source/frameworks/basegit clone --depth=1 --branchgingerbread-releasegit://github.com/CyanogenMod/android_system_core.git../android-source/system/coreecho "Fetching Android libraries for linking"# Libraries from any froyo/gingerbread device/emulator shouldwork# fine, since the symbols used should be available on most ofthem.if [ ! -d "../android-libs" ]; then if [ ! -f"../update-cm-7.0.3-N1-signed.zip" ]; then wgethttp://download.cyanogenmod.com/get/update-cm-7.0.3-N1-signed.zip-P../ fi unzip../update-cm-7.0.3-N1-signed.zip system/lib/* -d../ mv ../system/lib../android-libs rmdir ../systemfiSYSROOT=$NDK/platforms/android-9/arch-arm# Expand the prebuilt/* path into the correct oneTOOLCHAIN=`echo$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86`export PATH=$TOOLCHAIN/bin:$PATHANDROID_SOURCE=../android-sourceANDROID_LIBS=../android-libsABI="armeabi-v7a"rm -rf ../build/stagefrightmkdir -p ../build/stagefrightDEST=../build/stagefrightFLAGS="--target-os=linux --cross-prefix=arm-linux-androideabi---arch=arm --cpu=armv7-a"FLAGS="$FLAGS --sysroot=$SYSROOT"FLAGS="$FLAGS --disable-avdevice --disable-decoder=h264--disable-decoder=h264_vdpau --enable-libstagefright-h264"EXTRA_CFLAGS="-I$ANDROID_SOURCE/frameworks/base/include-I$ANDROID_SOURCE/system/core/include"EXTRA_CFLAGS="$EXTRA_CFLAGS-I$ANDROID_SOURCE/frameworks/base/media/libstagefright"EXTRA_CFLAGS="$EXTRA_CFLAGS-I$ANDROID_SOURCE/frameworks/base/include/media/stagefright/openmax"EXTRA_CFLAGS="$EXTRA_CFLAGS-I$NDK/sources/cxx-stl/gnu-libstdc /include-I$NDK/sources/cxx-stl/gnu-libstdc /libs/$ABI/include"EXTRA_CFLAGS="$EXTRA_CFLAGS -march=armv7-a -mfloat-abi=softfp-mfpu=neon"EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS-Wl,-rpath-link,$ANDROID_LIBS-L$NDK/sources/cxx-stl/gnu-libstdc /libs/$ABI"EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions-fno-rtti"DEST="$DEST/$ABI"FLAGS="$FLAGS --prefix=$DEST"mkdir -p $DESTecho $FLAGS --extra-cflags="$EXTRA_CFLAGS"--extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS"> $DEST/info.txt#注意看這裡是./configure,說明這個腳本要移動到上級目錄去執行,也就是ffmpeg目錄下。而不是僅僅把./configure 修改為../configure ,不然找不到頭文件什麼的,我之前說錯了sorry./configure $FLAGS--extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS"--extra-cxxflags="$EXTRA_CXXFLAGS" | tee$DEST/configuration.txt[ $PIPESTATUS == 0 ] || exit 1make cleanmake -j4 || exit 1你會發現這裡面綠色的兩行是要用git工具的。 git是啥? github 專用的下載工具,功能和svn類似。這個東西用apt-get install 的方法居然裝不上,後來用新立德軟體管理器安裝成功了,oh-yeah!但是接下來遇到一個問題: 我們公司是有代理網關的, 通過網關要用戶密碼。 而git始終沒有辦法通過代理網關。網上提供的方法多半是裝一個connect 工具, 進行埠轉換。我覺得太麻煩了。經過一番折騰之後驚奇的發現,把git://github.com/CyanogenMod/...修改為https://github.com/CyanogenMod/就能下載了! !還在被代理困擾的孩紙們可以試試腳本最後執行了make。是會編譯的,而且在編譯之前會先執行configure配置(原先的配置項會保留,同時會追加編譯stagefright 需要的參數)不過我現在在預編譯時候出錯:configure執行報錯,END /tmp/ffconf.rwJcAHAu.cpparm-linux-androideabi-g --sysroot=/opt/android-ndk-r8c/platforms/android-9/arch-arm-D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE-D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DPIC-I../android-source/frameworks/base/include-I../android-source/system/core/include-I../android-source/frameworks/base/media/libstagefright-I../android-source/frameworks/base/include/media/stagefright/openmax-I/opt/android-ndk-r8c/sources/cxx-stl/gnu-libstdc /include-I/opt/android-ndk-r8c/sources/cxx-stl/gnu-libstdc /libs/armeabi-v7a/include -march=armv7-a -mfloat-abi=softfp -mfpu=neon-march=armv7-a -std=c99 -fomit-frame-pointer -fPIC -marm-Wno-multichar -fno-exceptions -fno-rtti -D__STDC_CONSTANT_MACROS -c -o /tmp/ffconf.VAwd3um2.o/tmp/ffconf.rwJcAHAu.cppcc1plus: warning: command line option "-std=c99" is valid forC/ObjC but not for C In file included from../android-source/frameworks/base/include/binder/IBinder.h:23, from../android-source/frameworks/base/include/binder/ProcessState.h:20, from/tmp/ffconf.rwJcAHAu.cpp:1:../android-source/frameworks/base/include/utils/Vector.h:20:15:error: new: No such file or directory出錯的這個文件引用的是這個頭:#ifndef ANDROID_VECTOR_H#define ANDROID_VECTOR_H#include<new>#include <stdint.h>#include <sys/types.h>#include <utils/Log.h>#include<utils/VectorImpl.h>#include<utils/TypeHelpers.h>今天又看了一下: 找到原因了:注意看一下之前的build腳本中,有這樣一段:-I/opt/android-ndk-r8c/sources/cxx-stl/gnu-libstdc /libs/armeabi-v7a/include而實際上,你會發現頭文件所在的實際路徑是這樣的:/opt/android-ndk-r8c/sources/cxx-stl/gnu-libstdc /4.4.3/include所以要把所有這些路徑修正一下,成功編譯出.a 文件了。不過在鏈接這些.a文件的時,又出現這樣的報錯:。。。/opt/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:jni/libavcodec.a(libstagefright.o): in functionStagefright_decode_frame(AVCodecContext*, void*, int*,AVPacket*):/opt/android-ndk-r8c/sources/cxx-stl/gnu-libstdc /4.4.3/include/bits/stl_tree.h:274:error: undefined reference to"std::_Rb_tree_decrement(std::_Rb_tree_node_base const*)"/opt/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:jni/libavcodec.a(libstagefright.o): in functionStagefright_decode_frame(AVCodecContext*, void*, int*,AVPacket*):/opt/android-ndk-r8c/sources/cxx-stl/gnu-libstdc /4.4.3/include/bits/stl_tree.h:923:error: undefined reference to"std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*,std::_Rb_tree_node_base*,std::_Rb_tree_node_base&)"/opt/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:jni/libavcodec.a(libstagefright.o): in functionStagefright_decode_frame(AVCodecContext*, void*, int*,AVPacket*):/opt/android-ndk-r8c/sources/cxx-stl/gnu-libstdc /4.4.3/include/bits/stl_tree.h:274:error: undefined reference to"std::_Rb_tree_decrement(std::_Rb_tree_node_base const*)"。。。/opt/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:jni/libavcodec.a(libstagefright.o): in functiondecode_thread(void*):libavcodec/libstagefright.cpp:180: error:undefined reference to "android::MetaData::findInt32(unsigned int,int*)"/opt/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:jni/libavcodec.a(libstagefright.o): in functiondecode_thread(void*):libavcodec/libstagefright.cpp:215: error:undefined reference to "android::MediaBuffer::data() const"/opt/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:jni/libavcodec.a(libstagefright.o): in functiondecode_thread(void*):libavcodec/libstagefright.cpp:222: error:undefined reference to "android::MediaBuffer::meta_data()"。。。懷疑是有些庫沒有鏈接進去導致的。尚未看
推薦閱讀:

任建英:支持長期吃素——吃素可以預防「三高」
「你也被4G了嗎?」請注意以下手機不支持4G
一位美國中產選民的真實自述:我為什麼支持特朗普?
唯一支持劉備伐吳的人為何死得這麼慘
中國新生兒營養支持臨床應用指南

TAG:編譯 | 支持 |