无法将FFmpeg C库导入到android中 [英] Unable to port FFmpeg C library into android
问题描述
我完全想做的:访问 ffmpeg.c 文件来修改 int main(int argc,char ** argv)函数到 JNI ,并将ffmpeg的命令作为字符串传递。
我已经尝试将ffmpeg C库移植到android(ARM处理器) 。我遵循以下不同的方法来做到这一点。
第一尝试:使用官方的ffmpeg安装文档。步骤如下
a)git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
b)阅读INSTALL文件。
c)使用 build_x264.sh 下载x264库并构建成功。
NDK = / home / nav / Work / android / ndk
PREBUILT = $ NDK / toolchains / arm-linux -androideabi-4.4.3 / prebuilt
PLATFORM = $ NDK / platforms / android-8 / arch-arm
PREFIX = / home / nav / 28ffmpeg / android-ffmpeg
./configure - -prefix = $ PREFIX --enable-static --enable-pic --disable-asm --disable-cli --host = arm-linux --cross-prefix = $ PREBUILT / linux-x86 / bin / arm-linux -androideabi- --sysroot = $ PLATFORM
make
sudo make install
sudo ldconfig
d)然后我从( ffmpeg库 > http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 )使用 build_android.sh
构建它, #!/ bin / bash
NDK = / home / nav / Work / android / ndk
PLATFORM = $ NDK / -8 / arch-arm
PREBUILT = $ NDK / toolchains / arm-linux-androideabi-4.4.3 / prebuilt / linux-x86
PREFIX = / home / nav / 28ffmpeg / android-ffmpeg
函数build_one
{
./configure --target-os = linux --prefix = $ PREFIX \
--enable-cross-compile \
--enable-runtime-cpudetect \
--disable-asm \
--arch = arm \
--cc = $ PREBUILT / bin / arm-linux-androideabi-gcc \
--cross-prefix = $ PREBUILT / bin / arm-linux-androideabi- \
--disable-剥离\
--nm = $ PREBUILT / bin / arm-linux-androideabi-nm \
--sysroot = $ PLATFORM \
--enable-nonfree \
--enable-version3 \
--disable-everything \
--enable-gpl \
--disable-doc \
--enable- avresample \
--enable-demuxer = rtsp \
--enable-muxer = rtsp \
--disable-ffplay \
--disable-ffserver \
--enable-ffmpeg \
- -disable-ffprobe \
--enable-libx264 \
--enable-encoder = libx264 \
--enable-decoder = h264 \
--enable -protocol = rtp \
--enable-hwaccels \
--enable-zlib \
--disable-devices \
--disable-avdevice \
--extra-cflags = - I / home / android-ffmpeg / include -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi = softfp -mfpu = vfpv3-d16 - marm -march = armv7-a\
--extra-ldflags = - L / home / android-ffmpeg / lib
make -j4 install
$ PREBUILT / bin / arm-linux-androideabi-ar d libavcodec / libavcodec.a inverse.o
$ PREBUILT / bin / arm-linux-androideabi-ld -rpath-link = $ PLATFORM / usr / lib -L $ PLATFORM / usr / lib -L $ PREFIX / lib -soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole -archive --no-undefined -o $ PREFIX / libffmpeg.so libavcodec / libavcodec.a libavfilter / libavfilter.a libavresample / libavresample.a libavformat / libavformat.a libavutil / libavutil.a libswscale / libswscale.a -lc -lm - lz -ldl -llog -lx264 - warn-once --dynamic-linker = / system / bin / linker $ PREBUILT / lib / gcc / arm-linux-androideabi / 4.4.3 / libgcc.a
}
build_one
e)最初它的工作原理很好。但是之后错误来了:
libavformat / libavformat.a(log2_tab.o):(。 rodata + 0x0):多个定义`ff_log2_tab'
libavcodec / libavcodec.a(log2_tab.o):(。rodata + 0x0):在这里首先定义
libavutil / libavutil.a(log2_tab.o) :(。rodata + 0x0):多个定义`ff_log2_tab'
libavcodec / libavcodec.a(log2_tab.o):(。rodata + 0x0):这里首先定义
build_android.sh:48:build_one :未找到
结果: libffmpeg.so 没有找到。
第二次尝试:然后我按照 http://dl.dropbox.com/u/22605641/ffmpeg_android/main.html - >构建
a)我从上面的链接下载了Pre-Build libffmpeg.so 。
b)将 libffmpeg.so 添加到 libs / armeabi / 。
c)使 Android.mk
include $(CLEAR_VARS)
LOCAL_MODULE:= ffmpeg
LOCAL_SRC_FILES:= libffmpeg.so
包括$(PREBUILT_SHARED_LIBRARY)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= main
LOCAL_STATIC_LIBRARIES + = ffmpeg
LOCAL_SRC_FILES:= ffmpeg-test.c
include $(BUILD_SHARED_LIBRARY)
d)然后,我通过更改其 int,将所有的ndk设置和all.Copy ffmpeg.c 从库更改为 ffmpeg-test.c 主要功能到我的 JNI 功能,并包含所有必需的包含文件。
错误: p>
控制台:
/ home / nav / Work / android / ndk / ndk-build all
预建:libffmpeg.so< = jni /
安装:libffmpeg.so => libs / armeabi / libffmpeg.so
编译thumb:main< = ffmpeg-test.c
jni / ffmpeg-test.c:在函数'print_report'中:
jni / ffmpeg-test .c:1139:94:warning:内置函数log2的不兼容隐式声明[默认启用]
SharedLibrary:libmain.so
/ home / nav / Work / android / ndk / toolchains /arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/ bin / ld:./obj/local/armeabi/objs/main/ffmpeg-test.o:in function check_keyboard_interaction:jni / ffmpeg-test.c:2496:error:undefined reference to'qp_hist'
和许多其他未定义的引用.....
告诉我我在哪里错了需要紧急.....
https://github.com/guardianproject/android-ffmpeg
在git上查看这个项目,了解更改的线索到'ffmpeg.c.main()'
我相信这个项目的构建将在自述文件中提及的NDK的发行中正常工作。
注意:
您应该花一些时间与NDK发行版中的所有文档文件,以便您了解该作品的作品。
对于android JNI,'main()'函数的退出条件通常需要稍微改变。
What i exactly want to-do : Access the ffmpeg.c file to modify the int main(int argc, char **argv) function to JNI and passing the command of ffmpeg as string.
I have tried to port ffmpeg C library to android(ARM processor). I followed following different ways to do this.
1st Try: using official ffmpeg installation documentation. Steps as follows
a) git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
b) Read the INSTALL file.
c) Download x264 library and build by using build_x264.sh which build successfully.
NDK=/home/nav/Work/android/ndk
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt
PLATFORM=$NDK/platforms/android-8/arch-arm
PREFIX=/home/nav/28ffmpeg/android-ffmpeg
./configure --prefix=$PREFIX --enable-static --enable-pic --disable-asm --disable-cli --host=arm-linux --cross-prefix=$PREBUILT/linux-x86/bin/arm-linux-androideabi- --sysroot=$PLATFORM
make
sudo make install
sudo ldconfig
d) Then i download ffmpeg library from (http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2) build it by using build_android.sh
#!/bin/bash
NDK=/home/nav/Work/android/ndk
PLATFORM=$NDK/platforms/android-8/arch-arm
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
PREFIX=/home/nav/28ffmpeg/android-ffmpeg
function build_one
{
./configure --target-os=linux --prefix=$PREFIX \
--enable-cross-compile \
--enable-runtime-cpudetect \
--disable-asm \
--arch=arm \
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--disable-stripping \
--nm=$PREBUILT/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--enable-nonfree \
--enable-version3 \
--disable-everything \
--enable-gpl \
--disable-doc \
--enable-avresample \
--enable-demuxer=rtsp \
--enable-muxer=rtsp \
--disable-ffplay \
--disable-ffserver \
--enable-ffmpeg \
--disable-ffprobe \
--enable-libx264 \
--enable-encoder=libx264 \
--enable-decoder=h264 \
--enable-protocol=rtp \
--enable-hwaccels \
--enable-zlib \
--disable-devices \
--disable-avdevice \
--extra-cflags="-I/home/android-ffmpeg/include -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a" \
--extra-ldflags="-L/home/android-ffmpeg/lib"
make -j4 install
$PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
$PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -L$PREFIX/lib -soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavfilter/libavfilter.a libavresample/libavresample.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog -lx264 --warn-once --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
}
build_one
e) Initially it works perfectly. But after that error comes:
libavformat/libavformat.a(log2_tab.o):(.rodata+0x0): multiple definition of `ff_log2_tab'
libavcodec/libavcodec.a(log2_tab.o):(.rodata+0x0): first defined here
libavutil/libavutil.a(log2_tab.o):(.rodata+0x0): multiple definition of `ff_log2_tab'
libavcodec/libavcodec.a(log2_tab.o):(.rodata+0x0): first defined here
build_android.sh: 48: build_one: not found
Result: libffmpeg.so not found.
2nd Try: Then I follow steps in http://dl.dropbox.com/u/22605641/ffmpeg_android/main.html-> Builds
a) I downloaded Pre-Build libffmpeg.so from above link.
b) Add libffmpeg.so to libs/armeabi/ .
c) Make Android.mk
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_SRC_FILES := libffmpeg.so
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := main
LOCAL_STATIC_LIBRARIES += ffmpeg
LOCAL_SRC_FILES := ffmpeg-test.c
include $(BUILD_SHARED_LIBRARY)
d) Then I do all ndk set up and all.Copy ffmpeg.c from library to ffmpeg-test.c by changing its int main function to my JNI functin and include all necessary include files.
Error:
Console:
/home/nav/Work/android/ndk/ndk-build all
Prebuilt : libffmpeg.so <= jni/
Install : libffmpeg.so => libs/armeabi/libffmpeg.so
Compile thumb : main <= ffmpeg-test.c
jni/ffmpeg-test.c: In function 'print_report':
jni/ffmpeg-test.c:1139:94: warning: incompatible implicit declaration of built-in function 'log2' [enabled by default]
SharedLibrary : libmain.so
/home/nav/Work/android/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/main/ffmpeg-test.o: in function check_keyboard_interaction:jni/ffmpeg-test.c:2496: error: undefined reference to 'qp_hist'
and many other undefined references.....
Tell me where I am getting wrong. Needed Urgently.....
https://github.com/guardianproject/android-ffmpeg
look at this project on git for clues on making changes to 'ffmpeg.c.main()' I believe that the build for this project will work fine on release of NDK mentioned in the readme.
Note:
you should spend some time with all the doc files in the NDK distro so that u understand how the make works.
The exit condition of the 'main()' function usually needs to be altered slightly for android JNI .
这篇关于无法将FFmpeg C库导入到android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!