首页 > 代码库 > [原]ffmpeg编译android 硬解码支持库 libstagefright
[原]ffmpeg编译android 硬解码支持库 libstagefright
最近花了一天时间将ffmpeg/tools/build_stagefright执行成功,主要是交叉编译所需要的各种动态库的支持没链接上,导致各种报错,基本上网络上问到的问题我都碰到了,特此记录下来。
编译环境:Ubuntu 14.04 + Android NDK + FFmpeg源码。
第一步:将ffmpeg/tools/build_stagefright移动到ffmpeg下面,修改执行权限。
chmod u+x build_stagefright
第二步:打开build_stagefright文件,配置Android NDK路径。
#!/bin/bash export NDK=/to/your/ndk/pathif [ "$NDK" = "" ]; then echo NDK variable not set, assuming ${HOME}/android-ndk-r8d export NDK=${HOME}/android-ndk-r8d fi
第三步:build_stagefright中的下载地址http://download.cyanogenmod.com/get/update-cm-7.0.3-N1-signed.zip失效了,所以得手动下载update-cm-7.0.3-N1-signed.zip,附一个可以下载的地址http://sourceforge.net/projects/nexusoneandroid/files/update-cm-7.0.3-N1-signed.zip/stats/timeline
第四步:修改TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.3.3/prebuilt/*-x86 ` 为 TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 ` ,否则会出现arm-linux-androideabi-gcc is unable to create an executable file. C compiler test failed.这样的错误
第五步:vim configure 将enabled libstagefright_h264 && require_cpp libstagefright_h264 改为 enabled libstagefright && require_cpp libstagefright_h264,否则会出现ERROR: libstagefright_h264 not found
第六步:将build_stagefright中的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 -I$NDK/sources/cxx-stl/gnu-libstdc++/4.8/include -I$NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/$ABI/include"
第七步:将build_stagefright中的EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/libs/$ABI"更改为EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/$ABI"
第八步:将build_stagefright中的EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/libs/$ABI"继续修改添加交叉编译所需要的外部库。最终修改为:
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/4.8/libs/$ABI -lstagefright -lstdc++ -lutils -lbinder -lgnustl_static -lgnustl_shared"
第八步能解决大多数交叉编译没有链接相应的库导致的问题。
最终修改完成的build_stagefright内容如下:
#!/bin/bashexport NDK=$ANDROID_NDKif [ "$NDK" = "" ]; then echo NDK variable not set, assuming ${HOME}/android-ndk export NDK=${HOME}/android-ndkfiecho "Fetching Android system headers"git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_frameworks_base.git ../android-source/frameworks/basegit clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_system_core.git ../android-source/system/coreecho "Fetching Android libraries for linking"# Libraries from any froyo/gingerbread device/emulator should work# fine, since the symbols used should be available on most of them.if [ ! -d "../android-libs" ]; then if [ ! -f "../update-cm-7.0.3-N1-signed.zip" ]; then wget http://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.8/prebuilt/linux-x86_64`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++/4.8/include -I$NDK/sources/cxx-stl/gnu-libstdc++/4.8/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++/4.8/libs/$ABI -lstagefright -lstdc++ -lutils -lbinder -lgnustl_static -lgnustl_shared"#EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lcutils -ldl -lstlport -lc -lm -lz -ldl -llog -lstdc++ -lstagefright -lbinder -lstlport -lstdc++ -lstl"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 $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
第九步,执行./build_stagefright编译,最终输出如下内容则表示编译成功:
CC ffprobe.oCC ffserver.oAR libavfilter/libavfilter.aAR libavformat/libavformat.aAR libavcodec/libavcodec.aAR libswresample/libswresample.aAR libswscale/libswscale.aAR libavutil/libavutil.aHOSTLD doc/print_optionsGENTEXI doc/avoptions_format.texiGENTEXI doc/avoptions_codec.texiPOD doc/ffmpeg.podPOD doc/ffprobe.podPOD doc/ffserver.podPOD doc/ffmpeg-all.podPOD doc/ffprobe-all.podPOD doc/ffserver-all.podPOD doc/ffmpeg-utils.podPOD doc/ffmpeg-scaler.podPOD doc/ffmpeg-resampler.podPOD doc/ffmpeg-codecs.podPOD doc/ffmpeg-bitstream-filters.podPOD doc/ffmpeg-formats.podPOD doc/ffmpeg-protocols.podPOD doc/ffmpeg-filters.podPOD doc/libavutil.podPOD doc/libswscale.podPOD doc/libswresample.podPOD doc/libavcodec.podPOD doc/libavformat.podPOD doc/libavfilter.podMAN doc/ffmpeg.1MAN doc/ffprobe.1MAN doc/ffserver.1MAN doc/ffmpeg-all.1MAN doc/ffprobe-all.1MAN doc/ffserver-all.1MAN doc/ffmpeg-utils.1MAN doc/ffmpeg-scaler.1MAN doc/ffmpeg-resampler.1MAN doc/ffmpeg-codecs.1MAN doc/ffmpeg-bitstream-filters.1MAN doc/ffmpeg-formats.1MAN doc/ffmpeg-protocols.1MAN doc/ffmpeg-filters.1MAN doc/libavutil.3MAN doc/libswscale.3MAN doc/libswresample.3MAN doc/libavcodec.3MAN doc/libavformat.3MAN doc/libavfilter.3LD ffmpeg_gLD ffprobe_gLD ffserver_gCP ffprobeCP ffmpegSTRIP ffprobeSTRIP ffmpegCP ffserverSTRIP ffserver
[原]ffmpeg编译android 硬解码支持库 libstagefright