NDK编译FFMPEG所遇问题的解决方法(一)

时间:2020-12-28 02:18:42

最近要将FFMPEG v2.1.1移植到我的安卓程序当中去。在NDK编译的过程中遇到了以下的问题:

    $ $NDK/ndk-build NDK_PROJECT_PATH=$NDK/samples/FFMPEG  
Android NDK: WARNING:/cygdrive/d/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/Android.mk:avcodec: LOCAL_LDLIBS is always ignored for static libraries
Android NDK: WARNING:/cygdrive/d/ndk/samples/FFMPEG/jni/ffmpeg/libavformat/Android.mk:avformat: LOCAL_LDLIBS is always ignored for static libraries
[armeabi] SharedLibrary : libffmpeg.so
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(dsputil.o): in function ff_dsputil_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/dsputil.c:2926: error: undefined reference to 'ff_dsputil_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(fmtconvert.o): in function ff_fmt_convert_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/fmtconvert.c:98: error: undefined reference to 'ff_fmt_convert_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(h264chroma.o): in function ff_h264chroma_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/h264chroma.c:50: error: undefined reference to 'ff_h264chroma_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(h264dsp.o): in function ff_h264dsp_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/h264dsp.c:182: error: undefined reference to 'ff_h264dsp_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(h264pred.o): in function ff_h264_pred_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/h264pred.c:593: error: undefined reference to 'ff_h264_pred_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(h264qpel.o): in function ff_h264qpel_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/h264qpel.c:100: error: undefined reference to 'ff_h264qpel_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(hpeldsp.o): in function ff_hpeldsp_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/hpeldsp.c:60: error: undefined reference to 'ff_hpeldsp_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(mpegvideo.o): in function ff_dct_common_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/mpegvideo.c:174: error: undefined reference to 'ff_MPV_common_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavcodec.a(videodsp.o): in function ff_videodsp_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavcodec/videodsp.c:48: error: undefined reference to 'ff_videodsp_init_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavutil.a(cpu.o): in function av_get_cpu_flags:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavutil/cpu.c:57: error: undefined reference to 'ff_get_cpu_flags_arm'
D:/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: D:/ndk/samples/FFMPEG/obj/local/armeabi/libavutil.a(float_dsp.o): in function avpriv_float_dsp_init:D:/ndk/samples/FFMPEG/jni/ffmpeg/libavutil/float_dsp.c:131: error: undefined reference to 'ff_float_dsp_init_arm'
collect2: ld returned 1 exit status
/cygdrive/d/ndk/build/core/build-binary.mk:588: recipe for target '/cygdrive/d/ndk/samples/FFMPEG/obj/local/armeabi/libffmpeg.so' failed
make: *** [/cygdrive/d/ndk/samples/FFMPEG/obj/local/armeabi/libffmpeg.so] Error 1

报错原因分析:出错原因正如错误报告当中所述的,编译器无法识别在那些个C文件中的xxx_init_arm函数,导致编译失败。

解决方法:到对应的C文件当中,将报错的函数删去或者注释掉(建议注释掉,因为即使编译通过之后,可能会因为缺少这些函数而出现运行错误,所以恢复原来的样子也比较方便)。这个办法可以骗过编译器,并且在我的程序当中可以正常运行。如果有出现类似错误的朋友们,或许可以试试这个办法。