简体   繁体   中英

Compiling ffmpeg for android on Mac

I tried to compile ffmpeg for android on Mac, but it does not work for me.

#!/bin/bash
NDK=/Users/user/Library/Android/sdk/ndk-bundle
SYSROOT=$NDK/platforms/android-18/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64

function build_one
{
    ./configure \
    --prefix=$PREFIX \
    --enable-shared \
    --disable-static \
    --disable-doc \
    --disable-ffmpeg \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-network \
    --disable-filters \
    --disable-avdevice \
    --disable-doc \
    --disable-symver \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --target-os=linux \
    --arch=arm \
    --enable-cross-compile \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic $ADDI_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS" \
    $ADDITIONAL_CONFIGURE_FLAG

    make clean all
    make
    make install
}

CPU=arm
PREFIX=$(pwd)/android/$CPU 
ADDI_CFLAGS="-marm"

build_one

I also give execute permission via chmod +x build_script.sh

I tried ffmpeg 4.1 and 4.0.3 but both are not work and same error reason.

I also tried on android-21 and android-18

test_cpp_condition stddef.h defined __ARM_ARCH_4__ || defined __TARGET_ARCH_4
test_cpp
BEGIN /tmp/ffconf.bgSdFwkD/test.c
    1   #include <stddef.h>
    2   #if !(defined __ARM_ARCH_4__ || defined __TARGET_ARCH_4)
    3   #error "unsatisfied condition: defined __ARM_ARCH_4__ || defined __TARGET_ARCH_4"
    4   #endif
END /tmp/ffconf.bgSdFwkD/test.c
/Users/user/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/Users/user/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/ -Os -fpic -marm -E -o /tmp/ffconf.bgSdFwkD/test.o /tmp/ffconf.bgSdFwkD/test.c
/tmp/ffconf.bgSdFwkD/test.c:3:2: error: "unsatisfied condition: defined __ARM_ARCH_4__ || defined __TARGET_ARCH_4"
#error "unsatisfied condition: defined __ARM_ARCH_4__ || defined __TARGET_ARCH_4"
 ^
1 error generated.
test_cpp_condition stddef.h defined __ARM_ARCH_4T__ || defined __TARGET_ARCH_4T
test_cpp
BEGIN /tmp/ffconf.bgSdFwkD/test.c
    1   #include <stddef.h>
    2   #if !(defined __ARM_ARCH_4T__ || defined __TARGET_ARCH_4T)
    3   #error "unsatisfied condition: defined __ARM_ARCH_4T__ || defined __TARGET_ARCH_4T"
    4   #endif
END /tmp/ffconf.bgSdFwkD/test.c
/Users/user/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/Users/user/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/ -Os -fpic -marm -E -o /tmp/ffconf.bgSdFwkD/test.o /tmp/ffconf.bgSdFwkD/test.c
test_ld cc
test_cc
BEGIN /tmp/ffconf.bgSdFwkD/test.c
    1   int main(void){ return 0; }
END /tmp/ffconf.bgSdFwkD/test.c
/Users/user/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/Users/user/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/ -Os -fpic -marm -march=armv4t -c -o /tmp/ffconf.bgSdFwkD/test.o /tmp/ffconf.bgSdFwkD/test.c
/Users/user/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/Users/user/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/ -march=armv4t -o /tmp/ffconf.bgSdFwkD/test /tmp/ffconf.bgSdFwkD/test.o
ld: unknown option: --sysroot=/Users/user/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-arm/
clang: error: linker command failed with exit code 1 (use -v to see invocation)
C compiler test failed.

Is there any tools/Applications or libraries I have to additionally install for compiling? I'm confused.... (THIS QUESTION IS MAY DUPLICATE BUT NONE OF SOLUTION WAS WORKED FOR ME)

EDIT To clarify my system environment.

  • Mac OS X High Sierra (10.13.6)
  • Android NDK (18.1.5063045)
  • Android SDK Tools and SDK Build-Tools
  • CMake

EDIT I also tried ffmpeg version 3.3.9 but it does not work either.

You can use wrappers https://github.com/WritingMinds/ffmpeg-android if you want to use most of the command. It will increase the size of apk.

I also tried to compile it and after several attempts, I compiled my own one. But it is hard to integrate as well. I used below tutorials to compile it.

But I just wanted to tell, use FFmpeg wrapper for it if u don't consider the size of apk. There is not the considerable gain of performance in own compiled FFmpeg. Use above mentioned wrapper u want. It works well. If u more enthusiastic about compile and integrate your own FFmpeg, try above tutorials.

I was installed NDK through Android Studio and I think it was the problem, so I downloaded Android NDK manually and now I can configure and run the makefile.

Wait! Not done yet. When I ran makefile with latest stable NDK (r16b), it says:
./libavutil/common.h:33:19: fatal error: errno.h: No such file or directory

According to this document , so I tried using NDK r15c and it finally works for me.

To summarize how I solve this problem : Manually install NDK r15c and DON'T FORGET update your shell script file!

Hope this help!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM