android UVC h264 ffmpeg硬解码(RK3288 android5.1)

需求:由于软解码速度跟不上导致解码花屏严重,转用ffmpeg交叉编译android 5.1源码硬解码

 

假设已经编译好RK3288 android5.1系统(主要是硬编码用到的libstagefright库)

系统编译参考:https://blog.csdn.net/pizziars/article/details/83176742

 

修改ffmpeg-2.2/configure文件

如果直接按照未修改的配置进行编译,结果编译出来的so文件类似libavcodec.so.55.39.101,版本号位于so之后,Android上似乎无法加载。因此需要按如下修改:

将该文件中的如下四行:

SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'

LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'

SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'

SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR)$(SLIBNAME)'

替换为:

SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'

LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'

SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'

SLIB_INSTALL_LINKS='$(SLIBNAME)'

 

另外(硬编码相关,否则提示 ERROR: libstagefright_h264 not found):

enabled libstagefright_h264  && require_cpp libstagefright_h264 "binder/ProcessState.h media/stagefright/MetaData.h
    media/stagefright/MediaBufferGroup.h media/stagefright/MediaDebug.h media/stagefright/MediaDefs.h
    media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder -lgnustl_static

修改为

enabled libstagefright  && require_cpp libstagefright_h264 "binder/ProcessState.h media/stagefright/MetaData.h
    media/stagefright/MediaBufferGroup.h media/stagefright/MediaDebug.h media/stagefright/MediaDefs.h
    media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder -lgnustl_static

 

编写config_android.sh脚本文件

config_android.sh的内容如下:

#!/bin/bash
export NDK=/home/username/ffmpeg/android-ndk-r9d
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64

#git clone --depth=1 --branch gingerbread-release https://github.com/CyanogenMod/android_frameworks_base.git ../android-source/frameworks/base
#git clone --depth=1 --branch gingerbread-release https://github.com/CyanogenMod/android_system_core.git ../android-source/system/core

# 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

function build_one
{
./configure \
    --prefix=$PREFIX \
    --enable-shared \
    --disable-static \
    --enable-libstagefright-h264 \
    --disable-doc \
    --disable-ffserver \
    --enable-cross-compile \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --target-os=linux \
    --arch=arm \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic $ADDI_CFLAGS $EXTRA_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS $EXTRA_LDFLAGS" \
    --extra-cxxflags="$EXTRA_CXXFLAGS" \
     $ADDITIONAL_CONFIGURE_FLAG
}

ANDROID_SOURCE=/home/username/rk
ANDROID_LIBS=/home/username/rk/out/target/product/rk3288_box/system/lib
ABI="armeabi-v7a"

EXTRA_CFLAGS="-I$ANDROID_SOURCE/frameworks/base/include -I$ANDROID_SOURCE/system/core/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/native/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/av/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/hardware/libhardware/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/native/include/media/openmax"
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="-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"

EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti"

CPU=armeabi-v7a
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
#make clean
#make -j6 || exit 1


 

给config_android.sh增加可执行权限:

$chmod +x config_android.sh

执行config_android.sh

$./config_android.sh

 

修改刚刚生成的文件config.h

#define HAVE_LOG2 1
#define HAVE_LOG2F 1
#define HAVE_POSIX_MEMALIGN 1

修改为

#define HAVE_LOG2 0
#define HAVE_LOG2F 0
#define HAVE_POSIX_MEMALIGN 0

 

修改文件/libavcodec/libstagefright.cpp(注释掉#include <media/stagefright/MediaDebug.h>):
//#include <media/stagefright/MediaDebug.h>

 

编译:

make -j6

 

至此编译完成

 

参考资料:

https://blog.csdn.net/gobitan/article/details/22750719 

https://blog.csdn.net/lidecoolblue/article/details/17240813

发布了5 篇原创文章 · 获赞 2 · 访问量 3984
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览