简体   繁体   English

在 Mac 上为 android 编译 ffmpeg

[英]Compiling ffmpeg for android on Mac

I tried to compile ffmpeg for android on Mac, but it does not work for me.我试图在 Mac 上为 android 编译 ffmpeg,但它对我不起作用。

#!/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我还通过chmod +x build_script.sh授予执行权限

I tried ffmpeg 4.1 and 4.0.3 but both are not work and same error reason.我尝试了 ffmpeg 4.14.0.3但两者都不起作用并且错误原因相同。

I also tried on android-21 and android-18我也试过android-21android-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) Mac OS X High Sierra (10.13.6)
  • Android NDK (18.1.5063045)安卓 NDK (18.1.5063045)
  • Android SDK Tools and SDK Build-Tools Android SDK 工具和 SDK 构建工具
  • CMake制作

EDIT I also tried ffmpeg version 3.3.9 but it does not work either.编辑我也试过 ffmpeg 3.3.9版,但它也不起作用。

You can use wrappers https://github.com/WritingMinds/ffmpeg-android if you want to use most of the command.如果您想使用大部分命令,您可以使用包装器https://github.com/WritingMinds/ffmpeg-android It will increase the size of apk.它会增加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.但我只是想告诉,如果您不考虑 apk 的大小,请使用 FFmpeg 包装器。 There is not the considerable gain of performance in own compiled FFmpeg.在自己编译的 FFmpeg 中没有显着的性能提升。 Use above mentioned wrapper u want.使用上面提到的你想要的包装器。 It works well.它运作良好。 If u more enthusiastic about compile and integrate your own FFmpeg, try above tutorials.如果您更热衷于编译和集成您自己的 FFmpeg,请尝试上面的教程。

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.我是通过Android Studio安装 NDK 的,我认为这是问题所在,所以我手动下载了 Android NDK,现在我可以配置和运行 makefile。

Wait!等待! Not done yet.还没做完。 When I ran makefile with latest stable NDK (r16b), it says:当我使用最新的稳定 NDK (r16b) 运行 makefile 时,它​​说:
./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.根据这个文档,所以我尝试使用 NDK r15c ,它终于对我r15c

To summarize how I solve this problem : Manually install NDK r15c and DON'T FORGET update your shell script file!总结一下我是如何解决这个问题的:手动安装 NDK r15c并且不要忘记更新你的 shell 脚本文件!

Hope this help!!希望这有帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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