tanersener / mobile-ffmpeg

FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.
https://tanersener.github.io/mobile-ffmpeg
GNU General Public License v3.0
3.85k stars 787 forks source link

static build failed #652

Closed juha-h closed 3 years ago

juha-h commented 3 years ago

Description I edited android-ffmpeg.sh ./configure arguments so that only static libs with the features that are need are build:

./configure \
    --cross-prefix="${BUILD_HOST}-" \
    --sysroot="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${TOOLCHAIN}/sysroot" \
    --prefix="${BASEDIR}/prebuilt/android-$(get_target_build)/${LIB_NAME}" \
    --pkg-config="${HOST_PKG_CONFIG_PATH}" \
    --enable-version3 \
    --arch="${TARGET_ARCH}" \
    --cpu="${TARGET_CPU}" \
    --cc="${CC}" \
    --cxx="${CXX}" \
    --extra-libs="$(pkg-config --libs --static cpu-features)" \
    --target-os=android \
    ${ARCH_OPTIONS} \
    --disable-everything \
    --enable-cross-compile \
    --enable-pic \
    --enable-jni \
    --enable-optimizations \
    --enable-static \
    --enable-swscale \
    --enable-libx264 \
    --enable-libx265 \
    --enable-libvpx \
    --enable-encoder=libx264 \
    --enable-decoder=h264 \
    --enable-encoder=libx265 \
    --enable-decoder=hevc \
    --enable-encoder=libvpx_vp8 \
    --enable-decoder=vp8 \
    --enable-encoder=libvpx_vp9 \
    --enable-decoder=vp9 \
    --enable-decoder=rawvideo \
    --enable-indev=android_camera \
    ${SIZE_OPTIONS} \
    ${DEBUG_OPTIONS} \
    --enable-small \
    --enable-gpl \
    --disable-programs \
    --disable-doc \
    --disable-debug \
    ${CONFIGURE_POSTFIX} 1>>${BASEDIR}/build.log 2>&1

Build of the libs went fine, but mobile-ffmpeg (whatever that is) failed:

Building mobile-ffmpeg library for Android

Architectures: arm64-v8a
Libraries: cpu-features, libvpx, x264, x265

Building arm64-v8a platform on API level 24

libvpx: already built
x264: already built
x265: already built
cpu-features: already built

ffmpeg: ok

mobile-ffmpeg: failed

Expected behavior I would expect the build to succeed.

Current behavior See above. According to build.log, failure was due to a missing dynamic lib:

INFO: Completed build for arm64-v8a on API level 24 at Thu 14 Jan 2021 12:05:19 PM EET

Android NDK: ERROR:jni/ffmpeg/Android.mk:avcodec: LOCAL_SRC_FILES points to a missing file    
Android NDK: Check that jni/ffmpeg/../../../prebuilt/android-arm64/ffmpeg/lib/libavcodec.so exists  or that its path is correct  

That, of course, does not exist because I didn't build shared libs. android.sh should check if shared libs have been build before trying to do something with them.

Screenshots If applicable, add screenshots to help explain your problem.

Logs Post logs here or paste them to Ghostbin and insert the link here.

Environment

Other Add any other context about the problem here.

tanersener commented 3 years ago

mobile-ffmpeg build scripts do not support static libraries on Android. If you want use static libraries and modify the scripts to build them then I suggest you modify the files under android/jni as well. We can not support all possible build combinations in top-level build scripts.

juha-h commented 3 years ago

I haven't tested yet, but looks like the static libs were built OK. The only issue seemed to be that android.sh failed AFTER building them. If so, I can just ignore the failure and use the libs that appeared in prebuilt folder. Have I understood this correctly?

juha-h commented 3 years ago

I checked the architecture of the resulting static libraries with objdump. Libs libvpx, x264, and x265 were all OK (elf64-little), but ffmpeg libs were not OK, for example:

$ objdump -f ./src/ffmpeg/libavdevice/libavdevice.a 
In archive ./src/ffmpeg/libavdevice/libavdevice.a:
objdump: alldevices.o: file format not recognized
objdump: android_camera.o: file format not recognized
objdump: avdevice.o: file format not recognized
objdump: utils.o: file format not recognized

Any explanation for that or is it really as you tell that this project cannot be used to build static ffmpeg libraries?

tanersener commented 3 years ago

I can just ignore the failure and use the libs that appeared in prebuilt folder. Have I understood this correctly?

Yeah, you can use ffmpeg libs from prebuilt folder.

Any explanation for that or is it really as you tell that this project cannot be used to build static ffmpeg libraries?

I don't know what is the last architecture built under the src/ffmpeg folder. So, instead of doing that I suggest running objdump on files under the prebuilt folder with objdump provided by NDK.

juha-h commented 3 years ago

Directory prebuilt/android-arm64/ffmpeg/lib has these files after I enabled shared:

libavcodec.a     libavfilter.so*  libpostproc.a      libswscale.so*
libavcodec.so*   libavformat.a    libpostproc.so*    pkgconfig/
libavdevice.a    libavformat.so*  libswresample.a
libavdevice.so*  libavutil.a      libswresample.so*
libavfilter.a    libavutil.so*    libswscale.a

Shared libs are OK, for example:

./toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objdump -f /usr/src/mobile-ffmpeg/prebuilt/android-arm64/ffmpeg/lib/libavdevice.so
/usr/src/mobile-ffmpeg/prebuilt/android-arm64/ffmpeg/lib/libavdevice.so:     file format elf64-little
architecture: UNKNOWN!, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x0000000000000000

but static ones are not, for example:

./toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objdump -f /usr/src/mobile-ffmpeg/prebuilt/android-arm64/ffmpeg/lib/libavdevice.a 
In archive /usr/src/mobile-ffmpeg/prebuilt/android-arm64/ffmpeg/lib/libavdevice.a:
./toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objdump: alldevices.o: File format not recognized
./toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objdump: android_camera.o: File format not recognized
./toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objdump: avdevice.o: File format not recognized
./toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objdump: reverse.o: File format not recognized
./toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objdump: utils.o: File format not recognized
juha-h commented 3 years ago

Looks like I'm able to use shared ffmpeg libs in my project, so this issue can be closed.

tanersener commented 3 years ago

You have a binary built for arm64 but you're using objdump that supports i686 architecture.

/usr/src/mobile-ffmpeg/prebuilt/android-arm64/ffmpeg/lib/libavdevice.a

i686-linux-android-objdump

I don't know whether it will resolve your File format not recognized errors but at least use an objdump variant that supports your binary format, e.g.aarch64-linux-android-objdump for arm64 binaries.

juha-h commented 3 years ago

Same result with aarch64-linux-android-objdump:

/opt/Android/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/objdump -f prebuilt/android-arm64/ffmpeg/lib/libavdevice.a
In archive prebuilt/android-arm64/ffmpeg/lib/libavdevice.a:
/opt/Android/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/objdump: alldevices.o: File format not recognized
...

Also android-studio build gave the same error when I tried to use these static ffmpeg libs.

But as I mentioned, looks like shared libs are also OK for me and I don't need the static ones.