当前位置: 首页 > 知识库问答 >
问题:

对libstagefright硬件解码的FFmpeg支持

张丰
2023-03-14

大家:我是FFMPEG的新手。最近我正在做一个项目,把ffmpeg移植到android设备上。在开始的时候,我按照网上的一些指南,以一种非常正常的方式将ffmpeg编译成共享库(.so文件),加载到我的android应用程序中。它工作得很好。

现在我想让ffmpeg使用libstagefright来完成硬件解码。问题是,我可以编译.so库,但当我启动应用程序并加载这些.so库时,总是会出现java.lang.UnsatisfiedLinkError:无法加载库:reloc_library[1314]:114无法定位'_zn7Android11MediabufferC1EJ'

我在那里呆了几天。之前有没有人遇到过类似的问题?如果有人能给我一些关于这个错误的提示,那就太好了。

我的步骤:1。将FFMPEG-2.1.4源代码编译为.so共享库。我使用了build_libstagefright脚本来完成此操作,并根据Internet上的一些指南进行了一些修改。

#!/bin/bash
#export NDK=/home/mingzhang/android/android-ndk-r9c
export NDK=/home/mingzhang/android/android-ndk-r7
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_frameworks_av.git ../android-source/frameworks/av
git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_frameworks_native.git ../android-source/frameworks/native
git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_hardware_libhardware.git ../android-source/hardware/libhardware
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=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64
TOOLCHAIN=/home/mingzhang/android/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
export PATH=$TOOLCHAIN/bin:$PATH
ANDROID_SOURCE=../android-source
ANDROID_LIBS=../android-libs
ABI="armeabi-v7a"
CC=$TOOLCHAIN/bin/arm-linux-androideabi-gcc
#CC=$TOOLCHAIN/bin/arm-eabi-gcc-4.4.3
NM=$TOOLCHAIN/bin/arm-linux-androideabi-nm
#NM=$TOOLCHAIN/bin/arm-eabi-nm

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

ADDI_CFLAGS="-marm"
DEST=../build/stagefright
DEST="$DEST/$ABI"

FLAGS="--target-os=linux --arch=arm --cpu=armv7-a --cross-prefix=arm-linux-androideabi- --cc=$CC --nm=$NM"
#FLAGS="--target-os=linux --arch=arm --cpu=armv7-a --cross-prefix=arm-eabi- --cc=$CC --nm=$NM"
FLAGS="$FLAGS --sysroot=$SYSROOT"
#FLAGS="$FLAGS --disable-avdevice --disable-decoder=h264 --disable-decoder=h264_vdpau --enable-libstagefright-h264"
FLAGS="$FLAGS --enable-shared --disable-demuxers --disable-muxers --disable-parsers --disable-avdevice --disable-filters --disable-programs --disable-encoders --disable-decoders --disable-decoder=h264 --disable-decoder=h264_vdpau --enable-decoder=libstagefright_h264 --enable-libstagefright-h264 \
    --enable-asm \
    --enable-neon \
    --enable-cross-compile \
    --enable-gpl \
    --disable-static \
    --enable-memalign-hack"

EXTRA_CFLAGS="-I$DEST/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/native/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/native/include/media/openmax"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/av/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/include -I$ANDROID_SOURCE/system/core/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/hardware/libhardware/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.6/include -I$NDK/sources/cxx-stl/gnu-libstdc++/4.6/libs/$ABI/include"
EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/stlport/stlport"
EXTRA_CFLAGS="$EXTRA_CFLAGS -march=armv7-a -mfloat-abi=softfp -mfpu=neon -marm -mtune=cortex-a8"
EXTRA_CFLAGS="$EXTRA_CFLAGS -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -D_STLP_USE_NEWALLOC"

EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS -L$NDK/sources/cxx-stl/gnu-libstdc++/4.6/libs/$ABI -static-libstdc++"
EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti"
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
#make -j4
make install || exit 1

将编译好的include和lib目录复制到我的android-ndk-r7/sources/ffmpeg-2.1.4/android/arm目录。这个目录下的android.mk文件是。

local_path:=$(调用my-dir)

include$(CLEAR_VARS)local_module:=libavcodec local_src_files:=lib/libavcodec-55。so local_export_c_include:=$(LOCAL_PATH)/include include$(PREBUILT_SHARED_LIBRARY)

include$(CLEAR_VARS)local_module:=libavformat local_src_files:=lib/libavformat-55。so local_export_c_include:=$(LOCAL_PATH)/include include$(PREBUILT_SHARED_LIBRARY)

include$(CLEAR_VARS)local_module:=libswscale local_src_files:=lib/libswscale-2.so local_export_c_include:=$(LOCAL_PATH)/include include$(PREBUILT_SHARED_LIBRARY)

include$(CLEAR_VARS)local_module:=libavutil local_src_files:=lib/libavutil-52.so LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include include$(PREBUILT_SHARED_LIBRARY)

include$(CLEAR_VARS)local_module:=libavfilter local_src_files:=lib/libavfilter-3。so local_export_c_include:=$(LOCAL_PATH)/include include$(PREBUILT_SHARED_LIBRARY)

include$(CLEAR_VARS)local_module:=libwsresample local_src_files:=lib/libswresample-0。so LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include include$(PREBUILT_SHARED_LIBRARY)

在我的android应用程序的jni目录下,android.mk是。

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE    := libripple
#LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := entrypoint.cpp scene.cpp
LOCAL_LDLIBS    := -llog -lGLESv2 -lm

include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := myfflib
LOCAL_SRC_FILES := fflib.c
LOCAL_LDLIBS := -L/home/mingzhang/ffmpeg_android/android-libs -llog -ljnigraphics -lz -landroid -ldl -lm -llog -lgcc -lc -lstagefright -lmedia -lutils -lbinder #-lstdc++
LOCAL_SHARED_LIBRARIES := libavformat libavcodec libswscale libavutil libutils libstagefright libbinder libmedia libstdc++-6

include $(BUILD_SHARED_LIBRARY)
$(call import-module,ffmpeg-2.1.4/android/arm)

而application.mk是:

APP_ABI=armeabi-v7a
#APP_STL=gnustl_static
APP_STL=stlport_static

我不确定你还需要什么材料,如果有什么东西缺失了,请让我知道,我会上传的。非常感谢你们!!!

共有1个答案

狄鸿禧
2023-03-14

FFmpeg已删除对https://github.com/FFmpeg/FFmpeg/commit/72673AD7EAE2D4F685F3C0A895558502BFE07C8E的libstagefright的支持(包含在N3.0中)。提交消息:

avcodec: Remove libstagefright

It serves absolutely no purpose other than to confuse potentional
Android developers about how to use hardware acceleration properly
on the the platform. The stagefright "API" is not public, and the
MediaCodec API is the proper way to do this.

Furthermore, stagefright support in avcodec needs a series of
magic incantations and version-specific stuff, such that
using it actually provides downsides compared just using the actual
Android frameworks properly, in that it is a lot more work and confusion
to get it even running. It also leads to a lot of misinformation, like
these sorts of comments (in [1]) that are absolutely incorrect.

[1] http://stackoverflow.com/a/29362353/3115956

所以也许再也不可能了。

使用amediacodec和OpenMax可能会有更好的机会。

 类似资料:
  • Debian 不会超出 Linux 内核与 GNU tool-sets 支持的硬件范围之外。 因此,任何 Linux 内核,libc, gcc,等移植过的体系或平台, 对 Debian 移植过的平台,都可以运行 Debian。请参考移植页面 http://www.debian.org/ports/i386/ 了解更多已被 Debian 测试过的 Intel x86 体系。 本章包含一些通用的信息与

  • Debian 不会超出 Linux 内核与 GNU 工具集所支持的硬件范围之外。 因此,任何被移植了 Linux 内核,libc, gcc等,并拥有对应的 Debian 移植版的硬件体系或平台都可以运行 Debian。请参考移植页面 http://www.debian.org/ports/ia64/ 以了解更多已被 Debian 测试过的 IA-64 体系。 本章仅包含一些通用的信息以及在何处可以

  • Debian 不会超出 Linux 内核与 GNU 工具集所支持的硬件范围之外。 因此,任何被移植了 Linux 内核,libc, gcc等,并拥有对应的 Debian 移植版的硬件体系或平台都可以运行 Debian。请参考移植页面 http://www.debian.org/ports/powerpc/ 以了解更多已被 Debian 测试过的 PowerPC 体系。 本章仅包含一些通用的信息以及

  • 我正在尝试解码ADTS容器中的AAC音频流,该音频流来自外部硬件H264编码器。 我分析了ADT,它告诉我我有一个2通道,44100 AAC主配置文件框架。我为ffmpeg解码器设置了额外的数据字节,并成功解码了帧?详情如下: (伪c代码) 设置解码器: 设置额外的数据字节: 然后解码帧: 解码帧: 现在,据我所知,32位原始格式的每个帧每个采样将有4个字节,每个通道将被交错(因此每4个字节是交替

  • 问题内容: 好吧,这实际上是两部分的… 首先我需要 读取文件内容 加密成一个 byte[] 将写入byte[]文件或其他任何内容… 然后,来自#2或#3的结果将进入另一个项目。我正在尝试保护我们的PEM / DER密钥。 对于解密,我需要 读取加密文件的内容为 byte[] 解密成一个 byte[] 将解密的数据写入文件或使用它代替文件 现在,我有一些基本的加密代码 并解密一个 问题是: 给定一个

  • 该页面主要反馈项目运行过程中硬件设备相关参数的具体使用情况。目前,UWA所提供的重要性能参数主要有: 设备温度 移动设备的温度是研发团队非常关注的一项指标。对此,我们将项目检测过程中,硬件设备的真实温度反馈出来,让您对自己的项目在特定设备上的温度变化情况有详细的了解。如果您现在正在研发一款移动设备的VR项目(类似Gear VR设备),那么建议您重点关注项目运行时的温度变化。目前,该项参数仅支持An