最经一直在搞andoid下ffmpeg视频优化 ,前文已经说了neon优化的方法 ,性能大大提升。 不过再快终究是软解码 ,和硬解码还是不能比,我们的目标是更快更快更快!那么要让ffmpeg支持硬解码就必须用android的媒体库
libstagefright
下载libstagefright的花就要到ffmpeg 目录的tools 目录下面, 这里有个 build-libstagefright.sh , 其内容如下:
#!/bin/bash
#在这里添加你的NDK目录
if [ "$NDK" = "" ]; then
fi
echo "Fetching Android system headers"
git clone --depth=1 --branchgingerbread-releasegit://github.com/CyanogenMod/android_frameworks_base.git../android-source/frameworks/base
git clone --depth=1 --branchgingerbread-releasegit://github.com/CyanogenMod/android_system_core.git../android-source/system/core
echo "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
fi
SYSROOT=$NDK/platforms/android-9/arch-arm
# Expand the prebuilt/* path into the correct one
TOOLCHAIN=`echo$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86`
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++/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 $DEST
echo $FLAGS --extra-cflags="$EXTRA_CFLAGS"--extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS"> $DEST/info.txt
#注意看这里是./configure,说明这个脚本要移动到上级目录去执行,也就是ffmpeg目录下。而不是仅仅把 ./configure 修改为../configure ,不然找不到头文件什么的,我之前说错了sorry
./configure
[ $PIPESTATUS == 0 ] || exit 1
make clean
make -j4 || exit 1
你会发现这里面绿色的两行是要用git工具的。 git是啥? github 专用的下载工具,功能和svn类似。
但是接下来遇到一个问题: 我们公司是有代理网关的, 通过网关要用户密码。 而git始终没有办法通过代理网关。
git://github.com/CyanogenMod/...修改为 https://github.com/CyanogenMod/ 就能下载了! !
脚本最后执行了make。是会编译的,而且在编译之前会先执行configure配置(原先的配置项会保留,同时会追加编译stagefright 需要的参数)
不过我现在在预编译时候出错:configure 执行报错,
END /tmp/ffconf.rwJcAHAu.cpp
arm-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_XOP
EN_SOURCE=600 -DPIC-I../android-source/frameworks/base/include-I../android-source/system/core/include-I../android-source/frameworks/base/media/libstagefright-I../android-sou
rce/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/arme
abi-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.cpp
cc1plus: 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()'
。。。
怀疑是有些库没有链接进去导致的。尚未看