[原]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/path
if [ "$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/bash

export NDK=$ANDROID_NDK

if [ "$NDK" = "" ]; then
    echo NDK variable not set, assuming ${HOME}/android-ndk
    export NDK=${HOME}/android-ndk
fi

echo "Fetching Android system headers"
git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_frameworks_base.git ../android-source/frameworks/base
git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_system_core.git ../android-source/system/core

echo "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 ../system
fi


SYSROOT=$NDK/platforms/android-9/arch-arm
# Expand the prebuilt/* path into the correct one
TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64`
export PATH=$TOOLCHAIN/bin:$PATH
ANDROID_SOURCE=../android-source
ANDROID_LIBS=../android-libs
ABI="armeabi-v7a"

rm -rf ../build/stagefright
mkdir -p ../build/stagefright

DEST=../build/stagefright
FLAGS="--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 $DEST

echo $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 1
make clean
make -j4 || exit 1

 

第九步,执行./build_stagefright编译,最终输出如下内容则表示编译成功:

CC    ffprobe.o
CC    ffserver.o
AR    libavfilter/libavfilter.a
AR    libavformat/libavformat.a
AR    libavcodec/libavcodec.a
AR    libswresample/libswresample.a
AR    libswscale/libswscale.a
AR    libavutil/libavutil.a
HOSTLD    doc/print_options
GENTEXI    doc/avoptions_format.texi
GENTEXI    doc/avoptions_codec.texi
POD    doc/ffmpeg.pod
POD    doc/ffprobe.pod
POD    doc/ffserver.pod
POD    doc/ffmpeg-all.pod
POD    doc/ffprobe-all.pod
POD    doc/ffserver-all.pod
POD    doc/ffmpeg-utils.pod
POD    doc/ffmpeg-scaler.pod
POD    doc/ffmpeg-resampler.pod
POD    doc/ffmpeg-codecs.pod
POD    doc/ffmpeg-bitstream-filters.pod
POD    doc/ffmpeg-formats.pod
POD    doc/ffmpeg-protocols.pod
POD    doc/ffmpeg-filters.pod
POD    doc/libavutil.pod
POD    doc/libswscale.pod
POD    doc/libswresample.pod
POD    doc/libavcodec.pod
POD    doc/libavformat.pod
POD    doc/libavfilter.pod
MAN    doc/ffmpeg.1
MAN    doc/ffprobe.1
MAN    doc/ffserver.1
MAN    doc/ffmpeg-all.1
MAN    doc/ffprobe-all.1
MAN    doc/ffserver-all.1
MAN    doc/ffmpeg-utils.1
MAN    doc/ffmpeg-scaler.1
MAN    doc/ffmpeg-resampler.1
MAN    doc/ffmpeg-codecs.1
MAN    doc/ffmpeg-bitstream-filters.1
MAN    doc/ffmpeg-formats.1
MAN    doc/ffmpeg-protocols.1
MAN    doc/ffmpeg-filters.1
MAN    doc/libavutil.3
MAN    doc/libswscale.3
MAN    doc/libswresample.3
MAN    doc/libavcodec.3
MAN    doc/libavformat.3
MAN    doc/libavfilter.3
LD    ffmpeg_g
LD    ffprobe_g
LD    ffserver_g
CP    ffprobe
CP    ffmpeg
STRIP    ffprobe
STRIP    ffmpeg
CP    ffserver
STRIP    ffserver

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。