I'm trying to compile ffmpeg for Android, on OSX 10.12.4 .
Here are the steps I followed:
1°) Compile pkg-config
Download the sources from here . Extract && cd in the pkg-config folder.
export DST=/a/path/on/my/computer
./configure --with-internal-glib --prefix=$DST --exec-prefix=$DST
make -j2
make install
export PATH=$PATH:$DST/bin
2°) Compile ffmpeg
Download the sources from here. Extract && cd in the ffmpeg folder.
export NDK=/path/to/android-ndk-r15c
export PLATFORM_VERSION=android-26
export ARCH=arm
export PLATFORM=$NDK/platforms/$PLATFORM_VERSION/arch-$ARCH
export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
export PREFIX=$(pwd)/android/$ARCH
export ADDI_CFLAGS="-Os -fpic -marm"
export ADDI_CONFIGURE_FLAG=""
export ADDI_LDFLAGS=""
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-symver \
--disable-avdevice \
\
--pkg-config=pkg-config \
\
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=$ARCH \
--enable-cross-compile \
--sysroot=$PLATFORM \
--extra-cflags="$ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
\
$ADDI_CONFIGURE_FLAG
make -j2
Make fails with the following error:
AR libavfilter/libavfilter.a
AR libavformat/libavformat.a
CC libavcodec/aaccoder.o
In file included from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/asm/termbits.h:19:0,
from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/asm-generic/termios.h:21,
from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/asm/termios.h:19,
from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/linux/termios.h:22,
from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/sys/ioctl.h:37,
from ./libavutil/timer.h:36,
from ./libavutil/internal.h:42,
from ./libavutil/common.h:467,
from libavcodec/mathops.h:27,
from libavcodec/aaccoder.c:38:
libavcodec/aaccoder.c: In function 'search_for_ms':
libavcodec/aaccoder.c:803:25: error: expected identifier or '(' before numeric constant
int B0 = 0, B1 = 0;
^
libavcodec/aaccoder.c:865:28: error: lvalue required as left operand of assignment
B0 += b1+b2;
^
libavcodec/aaccoder.c:866:25: error: 'B1' undeclared (first use in this function)
B1 += b3+b4;
^
libavcodec/aaccoder.c:866:25: note: each undeclared identifier is reported only once for each function it appears in
make: *** [libavcodec/aaccoder.o] Error 1
make: *** Waiting for unfinished jobs....
I'm able to fix that error by renaming B0 & B1 variables in the source to A0 & A1 (don't know why it fixes the problem), but then it fails somewhere else. I guess something is wrong in my config, and I'd prefer to avoid having to patch the source.
So the questions are:
does someone know what's wrong here? Do I need to give some args to gcc?
is the --target-os=linux correct, or should it be --target-os=darwin? Is target-os the OS where the compilation is done, or where ffmpeg will be executed? By using darwin, I can compile using --enable-static, but not --enable-shared (which I want).
Note: I need to compile it myself as I want only an arm version, with HTTPS support. Thus I can't use the existing built versions.
I also met this problem when I tried to build the ffmpeg 3.4 the latest version.I wish you could try the 3.3 version.I built it successfully.
I doubt that latest version is unstable and with some bug.
By the way,You can take some answer By this article:
http://alientechlab.com/how-to-build-ffmpeg-for-android/
Issue closed by FFmpeg team
--target-os=android solves it
./configure \
...
--target-os=android
Related
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.
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!!
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.
https://syllogismobile.wordpress.com/2017/02/19/building-ffmpeg-for-android/
https://enoent.fr/blog/2014/06/20/compile-ffmpeg-for-android/
https://yesimroy.gitbooks.io/android-note/content/compile_ffmpeg_for_android.html
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.
When i build the x264 ndk library , i face a problem .
I've compiled both in window and liunx environment.i got the same mistakes...
like this:
In file included
from c:\users\xxx\appdata\local\android\sdk\ndk-bundle\toolchains\
aarch64-linux-android-4.9\prebuilt\windows-x86_64\lib\gcc\aarch64-linux-android\4.9.x\include-fixed\syslimits.h:7:0,
from c:\users\xxx\appdata\local\android\sdk\ndk-bundle\toolchains\
aarch64-linux-android-4.9\prebuilt\windows-x86_64\lib\gcc\aarch64-linux-android\4.9.x\include-fixed\limits.h:34,
from ./common/common.h:123,
from ./x264cli.h:30,
from ./input/input.h:31,
from ./filters/video/video.h:29,
from ./filters/video/depth.c:26:
c:\users\xxx\appdata\local\android\sdk\ndk-bundle\toolchains\aarch64-linux-android-4.9\
prebuilt\windows-x86_64\lib\gcc\aarch64-linux-android\4.9.x\include-fixed\limits.h:168:61:
error: no include path in which to search for limits.h
#include_next <limits.h> /* recurse down to the real one */
make: *** [.depend] Error 1
Here is my script:
SYSROOT=$NDK/platforms/android-21/arch-arm64
TOOLCHAIN=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64
CC=$TOOLCHAIN/bin/aarch64-linux-android-gcc-4.9.x
#CXX=$TOOLCHAIN/bin/aarch64-linux-android-g++
CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
EXTRA_CFLAGS="-march=armv8-a -D__ANDROID__"
EXTRA_LDFLAGS="-nostdlib"
./configure --prefix=$PREFIX \
--host=arm-linux \
--sysroot=$SYSROOT \
--cross-prefix=$CROSS_PREFIX \
--extra-cflags="$EXTRA_CFLAGS" \
--extra-ldflags="$EXTRA_LDFLAGS" \
--enable-pic \
--enable-static \
--enable-strip \
--disable-cli \
--disable-win32thread \
--disable-avs \
--disable-swscale \
--disable-lavf \
--disable-ffms \
--disable-gpac \
--disable-lsmash \
--disable-asm \
--disable-opencl
does anyone know how to solve it? thanks every much.
To build with latest NDK You need to use --deprecated-headers while creating standalone toolchain.
Some additional info: NDK unified headers
This problem occurs when you use recent versions of android ndk. Please, use older versions like android ndk r13b. I have successfully built on my mac machine using android ndk r13b.
Link given below:
https://dl.google.com/android/repository/android-ndk-r13b-darwin-x86_64.zip
Please, use one specific to your platform.
You can also follow this link https://osburneblog.wordpress.com/2017/06/01/cross-compiling-ffmpeg-and-libx264-for-android/ know more about build process.
I would like to run a Qt Console Application written in C++ that includes the use of protobuf on a android phone.
Therefore, I need to crosscompile protobuf for a arm architecture. I have been following this script.
https://gist.github.com/helayzhang/9034454
This is my configure command:
sudo ./configure --prefix=/home/staff/Desktop/proto_arm --build=armv7- android-linux-android --host=armv7-android-linux-android --target=armv7-android-linux-android --enable-cross-compile --with-protoc=/home/staff/Desktop/proto_arm/protoc CXXFLAGS="$(pkg-config --cflags protobuf)" LIBS="$(pkg-config --libs protobuf)"
My problems are cross-compilation option is ignored
checking whether we are cross compiling... no
and I am not sure whether I am building for the right architecture. My phone supports ABIs arm64-v8a, armeabi-v7a and armeabi, the OS is android 6 marshmallow
I am grateful for every advice!
Here is a link to my config.log file
enter link description here
I was able to compile protobuf with this scipt:
#!/bin/bash
export NDK=/media/qt5-qwt6/ndk10/android-ndk-r10e
export SYSROOT=$NDK/platforms/android-21/arch-arm
export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
export PATH=$PATH:$TOOLCHAIN/bin
export CC="$TOOLCHAIN/bin/arm-linux-androideabi-gcc --sysroot $SYSROOT"
export CXX="$TOOLCHAIN/bin/arm-linux-androideabi-g++ --sysroot $SYSROOT"
export CXXSTL=$NDK/sources/cxx-stl/gnu-libstdc++/4.9
function build_one
{
mkdir build
./configure --prefix=$(pwd)/build \
--host=arm-linux-androideabi \
--with-sysroot=$SYSROOT \
--enable-static \
--disable-shared \
--enable-cross-compile \
--with-protoc=protoc \
CFLAGS="-march=armv7-a" \
CXXFLAGS="-march=armv7-a -I$CXXSTL/include -I$CXXSTL/libs/armeabi-v7a/include -L$CXXSTL/libs/armeabi-v7a/ -lgnustl_static"
make clean
make
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
# Inspect the library architecture specific information
# arm-linux-androideabi-readelf -A build/lib/libprotobuf-lite.a
I'm trying to compile Protobuf 2.6.0 for Android on Windows.
I have to say that I need a staic Protobuf library for using with Qt 5 on Android.
In Cygwin bash I run the next command:
./configure --prefix=c:/Thirdparty/Android/protobuf/build \
--host=arm-linux-androideabi \
--disable-shared \
--enable-cross-compile \
--with-protoc=c:/Thirdparty/bin/protoc \
CC=c:/Thirdparty/Android/NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc.exe \
CXX=c:/Thirdparty/Android/NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++.exe \
LDFLAGS=-Lc:/Thirdparty/Android/NDK/platforms/android-5/arch-arm/usr/lib \
CPPFLAGS=-Ic:/Thirdparty/Android/NDK/platforms/android-5/arch-arm/usr/include
But I got the next error:
configure:3474: checking whether the C compiler works
configure:3496: c:/Thirdparty/Android/NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc.exe \
-Ic:/Thirdparty/Android/NDK/platforms/android-5/arch-arm/usr/include \
-Lc:/Thirdparty/Android/NDK/platforms/android-5/arch-arm/usr/lib conftest.c >&5
c:/thirdparty/android/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld.exe:
error: cannot open crtbegin_dynamic.o: No such file or directory
c:/thirdparty/android/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld.exe:
error: cannot open crtend_android.o: No such file or directory
collect2.exe: error: ld returned 1 exit status
What should I do else? Thank you.
I found the solution. I had to define --sysroot="", like this:
LDFLAGS="-Lc:/Thirdparty/Android/NDK/platforms/android-5/arch-arm/usr/lib \
--sysroot=c:/Thirdparty/Android/NDK/platforms/android-5/arch-arm"
did someone successfully compile
ffmpeg-2.2.2 on windows with cygwin and android ndkr9c ?
Or can point me to an up to date tutorial ?
(http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/ isn't working for me
i get Makefile:2: config.mak: No such file...
cygwin admin devel gnome is completely installed and make -v ok )
I need to convert a video to images(for live-wallpaper)... do you know a better
method or is ffmpeg the best ?
thx
Start with Roman's tutorial.
Following changes apply to Windows: you should use the NDK make.exe, not the one from cygwin. So, I simply wrote d:/dev/Android/ndk/prebuilt/windows-x86_64/bin/make.exe in my build_android.sh. For some weird reason, I could not run make clean - but I simply chose to ignore this problem for now.
Following the tutorial, don't forget to set
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64
Also, use mixed-style paths, i.e. d:/dev/whatever and not cygwin style /cygdrive/d/dev/whatever. Be careful not to use paths with spaces - neither for ndk installation, nor for ffmpeg git clone.
With ffmpeg 2.2, you can use --target-os=android for ./configure, instead of mangling ./configure file as described in step 2.
On my machine, I did not have pr and od commands. I chose simply to fake them, writing
echo 'cat $3' > ./pr
echo 'echo od' > ./od
These do not spoil the build.
So, my build process is as follows:
git clean -d -f -x
./configure --enable-shared --disable-static --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-doc --disable-symver --cross-prefix=d:/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi- --target-os=android --arch=arm --enable-cross-compile --sysroot=d:/android-ndk-r9c/platforms/android-9/arch-arm/ --extra-cflags="-Os -fpic"
Compilation does display some warnings, but the .so files are all produced.
To enable NEON, I used
--extra-cflags="-Os -fpic -marm -march=armv7-a -mfloat-abi=softfp -mfpu=neon"
--extra-ldflags="-Wl,--fix-cortex-a8"
Now, libavcodec.so could not be built anymore: too many files on the linker list. So, after it crashed, I launched the linker manually:
$ d:/Dev/Android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64//bin/arm-linux-androideabi-gcc -shared -Wl,-Bsymbolic -Wl,--version-script,libavcodec/libavcodec.ver -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -Wl,--fix-cortex-a8 --sysroot=d:/Dev/Android/ndk/platforms/android-9/arch-arm/ -isysroot d:/Dev/Android/ndk/platforms/android-9/arch-arm/ -Wl,--as-needed -Wl,--warn-common -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample #libavcodec/libavcodec.list -lswresample -lavutil -lm -lz -pthread -o libavcodec/libavcodec.so.55
I patch the library.mak file as follows: for $(SUBDIR)$(SLIBNAME_WITH_MAJOR), replace
$$(LD) $(SHFLAGS) $(LDFLAGS) $$(LD_O) $$(filter %.o,$$^) $(FFEXTRALIBS)
with
$(Q)echo >$(SUBDIR)lib$(NAME).list $(wordlist 1,400,$(filter %.o,$$<))
$(Q)echo >>$(SUBDIR)lib$(NAME).list $(wordlist 401,999,$(filter %.o,$$<))
$$(LD) $(SHFLAGS) $(LDFLAGS) $$(LD_O) #$(SUBDIR)lib$(NAME).list $(FFEXTRALIBS)
.. and from there, make proceeded smoothly.
PS: I used make -n libavcodec/libavcodec.so.55 to prepare the response file libavcodec/libavcodec.list.
PPS: Here is another article that helps to build and use ffmpeg for Android.
You can use this as build_android.sh i tested it and it worked with me
#!/bin/bash
NDK=D:/android/ndk/android-ndk-r10d
SYSROOT=$NDK/platforms/android-8/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows
function build_one
{
./configure \
--prefix=$PREFIX \
--disable-shared \
--enable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--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
make
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
you need also to run this commands :
dos2unix build_android.sh
chmod +x build_android.sh
./build_android.sh
Use this Tutorial as reference
Build it on Ubuntu(Guest) and copy lib's(sub folder in /andoid-ndk/sources/ffmpeg/android) folder to Windows(Host).I tried it for Window but ended with lot of bugs, finally installed Ubuntu (Free) on virtualbox. also you willl have to download Andoid (SDK, Ndk) and JDK. This may sound weird but it worked for me.