x264 ARM cross compiled not executing in Android

1,476 views
Skip to first unread message

Pavan

unread,
Aug 24, 2010, 7:15:21 AM8/24/10
to android-ndk
Hi,
I want to execute the standalone x264 encoder in android .i.e i want
to encode yuv to *.264 in command line in android shell.
I have taken the ARM X264 code and configured/built the executable by:
#./configure --host=arm-none-linux --cross-prefix=arm-none-linux-
gnueabi-
#make

I got the x264 ARM executable dynamically linked (uses shared
libs).Then I pushed x264 executable using adb to my
beagleboard(target).
In Target (using adb shell) at x264 executable location
# ./x264
./x264: not found

I am unable to execute x264 command in adb shell.

Can't I run executables like x264 directly in android.Please suggest
how to proceed from now.

Thanks
Pavan

Chris Stratton

unread,
Aug 24, 2010, 3:32:20 PM8/24/10
to android-ndk
Things to check:

executable is stored in a filesystem that isn't mounted noexec

executable has execute permission for current user

executable isn't linked against libraries that aren't on the device

executable is actually built for arm (.configure doesn't always do
well at cross compiling)

try it with a simple hello world program

Angus Lees

unread,
Aug 24, 2010, 11:29:23 PM8/24/10
to andro...@googlegroups.com
Also check you specified the correct dynamic linker when building.

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>

Pavan

unread,
Aug 25, 2010, 2:52:04 AM8/25/10
to android-ndk
I tried with simple helloword prog ..i compiled with #arm-none-linux-
gnueabi-gcc -static helloword.c -o helloword and ran fine in board.
I am a root user and has permisions to execute.
I guess ./configure has set correctly the ARM compilers because i get
the following message after./configure --host=arm-none-linux --cross-
prefix=arm-none-linux-gnueabi-

Platform: ARM
System: LINUX
asm: yes
avis input: no
mp4 output: no
pthread: yes
debug: no
gprof: no
PIC: no
shared: no
visualize: no

I need to check if executable is trying to link any libs on the
device and also I 'll try to build the x264 executable as static
lib..but not sure how to make x264 as static because when i tried
giving "make LDFLAGS=-static" i am getting erros like

input/thread.o: In function `close_file':
thread.c:(.text+0x5c): undefined reference to `pthread_join

ratecontrol.c:(.text+0x3cac): undefined reference to `pow'
ratecontrol.c:(.text+0x3cd8): undefined reference to `sqrt'
ratecontrol.c:(.text+0x3d28): undefined reference to `log'
ratecontrol.c:(.text+0x3d50): undefined reference to `log'
ratecontrol.c:(.text+0x3de4): undefined reference to `pow'
ratecontrol.c:(.text+0x3f58): undefined reference to `pow'
ratecontrol.c:(.text+0x3f88): undefined reference to `pow'
ratecontrol.c:(.text+0x404c): undefined reference to `pow'
ratecontrol.c:(.text+0x407c): undefined reference to `pow'

and so on..Please suggest.

alan

unread,
Aug 26, 2010, 4:52:52 AM8/26/10
to android-ndk
you need to build using the android toolchain, just using any gcc arm
compiler is likely to not work

Pavan

unread,
Aug 26, 2010, 7:58:53 AM8/26/10
to android-ndk
Thanks for the reply Alan...I will try and get back.

Pavan

unread,
Aug 26, 2010, 8:11:16 AM8/26/10
to android-ndk
Alan you mean using NDK or something else ..please help me how to
proceed ...I have my Android SDK(with eclipse and ADT) running.

alan

unread,
Aug 26, 2010, 9:29:44 AM8/26/10
to android-ndk
yes using the compiler provided by the ndk, ideally using the
android.mk files too

kiran

unread,
Aug 26, 2010, 8:16:27 AM8/26/10
to andro...@googlegroups.com


There are two ways to build
1)  cross compile using Android Native toolchain (arm-eabi-4.4.0).

2)  Write Android,mk file for your libx264  and include the libx264 package in the external folder of Android, Android will take care of building.

Regards
Kiran

Pavan

unread,
Aug 27, 2010, 6:43:00 AM8/27/10
to android-ndk
Hi All

Thanks for the support ..I used NDK toolchain and compiled.
Its working fine and could even encode the input yuv to *.264.

Please find the below script :Which is working :
*******************************************
#!/bin/sh
export ARM_ROOT=/Android/android-ndk-r4b
export ARM_INC=$ARM_ROOT/build/platforms/android-3/arch-arm/usr/
include/
export ARM_LIB=$ARM_ROOT/build/platforms/android-3/arch-arm/usr/lib/
export ARM_TOOL=$ARM_ROOT/build/prebuilt/linux-x86/arm-eabi-4.4.0
export ARM_LIBO=$ARM_TOOL/lib/gcc/arm-eabi/4.4.0
export PATH=$ARM_TOOL/bin:$PATH
export ARM_PRE=arm-eabi

make distclean

./configure --disable-gpac \
--extra-cflags=" -I$ARM_INC -fPIC -DANDROID -fpic -mthumb-
interwork -ffunction-sections -funwind-tables -fstack-protector -fno-
short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -
D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-
float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-
limit=64 -DANDROID -Wa,--noexecstack -MMD -MP " --extra-ldflags="-
nostdlib -Bdynamic -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-
z,nocopyreloc -Wl,-soname,/system/lib/libz.so -Wl,-rpath-link=
$ARM_LIB,-dynamic-linker=/system/bin/linker -lm -L$ARM_LIB -nostdlib
$ARM_LIB/crtbegin_dynamic.o $ARM_LIB/crtend_android.o -lc -ldl -lgcc "
\
--cross-prefix=${ARM_PRE}- --disable-asm --host=arm-linux

make -j4

***********************
At make time if we get undefined reference to log2f error .It means
there is no log2f and you have to add this to osdep.h:
#define log2f(x) (logf(x)*1.4426950408889634f)

Thanks
Pavan

On Aug 26, 5:16 pm, kiran <kiranbhat2...@gmail.com> wrote:
> There are two ways to build
> 1)  cross compile using Android Native toolchain (arm-eabi-4.4.0).
>
> 2)  Write Android,mk file for your libx264  and include the libx264 package
> in the external folder of Android, Android will take care of building.
>
> Regards
> Kiran
>
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .

Alexandre Ferrieux

unread,
Sep 1, 2010, 4:09:37 PM9/1/10
to android-ndk
Thanks a lot for this summary !
Now doing this, x264 is built without any processor-specific
accelerators.
I've got an HTC Desire, and x264 performs ~0.4fps on a VGA source :(
Now I know from /proc/cpuinfo that it is an ARMv7 with Neon. How do I
tell configure to target that, since we are cross-compiling (hence no
timing tests can be run from the host) ?

-Alex

Dana L

unread,
Sep 20, 2010, 9:39:03 PM9/20/10
to android-ndk
This config is setup for the ARMv5

To get this to build with ARMv7 optimizations, you basically want to
replace the following command line arguments:
-march=armv7-a
-D__ARM_ARCH_7__

If you're using ARM7, you can enable assembler support (because the
armv7-a supports the necessary primitives), which involves getting rid
of the --disable-asm flag

I'm wondering whether anyone has gotten this working with pthread
support on the ndk?

On Sep 1, 1:09 pm, Alexandre Ferrieux <alexandre.ferri...@gmail.com>
wrote:
> Now doing this,x264is built without any processor-specific
> accelerators.
> I've got an HTC Desire, andx264performs ~0.4fps on a VGA source :(

Dana L

unread,
Sep 21, 2010, 11:25:16 AM9/21/10
to android-ndk
To reply to my own question, the reason why you don't get pthread
support is that the configure script does a check for libpthread,
which android lacks. If you override this, and hack the code that
detects the number of processors (since android doesn't seem to have
cpu_set_t), you can get it to compile with pthread support. Sadly,
enabling pthreads didn't seem to affect performance much.

Alexandre Ferrieux

unread,
Sep 21, 2010, 11:32:19 AM9/21/10
to android-ndk


On Sep 21, 5:25 pm, Dana L <dana11...@gmail.com> wrote:
> [...]
> Sadly,
> enabling pthreads didn't seem to affect performance much.

Oh, do you have a multi-core/hyperthreaded Android mobile phone ?

-Alex
Message has been deleted

Alex Cohn

unread,
Oct 13, 2013, 5:54:15 AM10/13/13
to andro...@googlegroups.com, dana...@gmail.com
On Tuesday, September 21, 2010 6:25:16 PM UTC+3, Dana L wrote:
To reply to my own question, the reason why you don't get pthread
support is that the configure script does a check for libpthread,
which android lacks. If you override this, and hack the code that
detects the number of processors (since android doesn't seem to have
cpu_set_t), you can get it to compile with pthread support. Sadly,
enabling pthreads didn't seem to affect performance much.


The easy fix is to create a fake empty library:

/etc/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
q ./libpthread.a
./configure --enable-pic --enable-static
--cross-prefix=/etc/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/arm-linux-androideabi-
--sysroot=/etc/android-ndk-r8d/platforms/android-14/arch-arm
--host=arm-linux --extra-ldflags="-L."

After this, configuration gives us

thread:     posix

This is not enough, though. make will fail, because Android does not
define cpu_set_t and the affinity API to derive number of cores at
runtime. I am using the following patch:

git diff common/cpu.c
diff --git a/common/cpu.c b/common/cpu.c
index 42a1b0e..bbbfcf4 100644
--- a/common/cpu.c
+++ b/common/cpu.c
@@-416,6 +416,9 @@ int x264_cpu_num_processors( void )
 #if !HAVE_THREAD
     return 1;

+#elif ANDROID
+     return android_getCpuCount();
+
 #elif SYS_WINDOWS
    return x264_pthread_num_processors_np( void )

To enable this, use

./configure --enable-pic --enable-static
--cross-prefix=/etc/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86/bin/arm-linux-androideabi-
--sysroot=/etc/android-ndk-r8d/platforms/android-14/arch-arm
--host=arm-linux --extra-ldflags="-L." --extra-cflags="-DANDROID"

android_getCpuCount() is supplied by Android NDK, see
http://www.kandroid.org/ndk/docs/CPU-FEATURES.html.

I hope this helps. On quad-core Android devices, the gain is quite significant (nowhere near 400%, though). We are using the ultafast/zerolatency preset to compress VGA frames in multi-sliced mode.

Alex Cohn
Reply all
Reply to author
Forward
0 new messages