14

I am trying to build FFMPEG with libx264 for Android.

I can successfully build and use FFMPEG for Android but I realized that I need the ability to encode, therefore I am trying to build FFMPEG with x264.

I am using this tutorial to build FFmpeg for Android http://www.roman10.net/how-to-build-ffmpeg-for-android/

When trying to build FFMPEG I get an error:

"ERROR: libx264 not found"

And in my log it says:

"/usr/local/lib/libx264.a: could not read symbols: Archive has no index; run ranlib to add one..."

I have the latest versions of both FFMPEG and x264. I understand that FFMPEG looks for the header and libraries in usr/lib and usr/include, so in order to make it find x264 I use the cflags and ldflags:

  • --extra-cflags = " -I/usr/local/include "
  • --extra-ldflags = " -L/usr/local/lib "

I have tried building x264 with many different options that other people on the internet have said that i need. eg. --enable-shared, --enable-static, --disable-pthreads etc. Some forums say enable this, others say no disable that.

Any help would be much appreciated, Thanks

EDIT:

If I build FFmpeg with the simplest commands to include libx264 then it works. ie.

./configure --enable-gpl --enable-libx264 --extra-cflags="-I/usr/local/include" --extra-ldflags="-L/usr/local/lib" --enable-static --enable-shared

However I need it to work for Android. The script I am using is:

NDK=~/Desktop/android-ndk-r7
PLATFORM=$NDK/platforms/android-8/arch-arm/
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86
function build_one
{
./configure --target-os=linux \
    --prefix=$PREFIX \
    --enable-cross-compile \
    --enable-shared \
    --enable-static \
    --extra-libs="-lgcc" \
    --arch=arm \
    --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
    --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
    --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
    --sysroot=$PLATFORM \
    --extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS -I/usr/local/include" \
    --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L $PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog -L/usr/local/lib " \
    --enable-gpl \
    --enable-libx264 \
    --disable-everything \
    --enable-demuxer=mov \
    --enable-demuxer=h264 \
    --disable-ffplay \
    --enable-protocol=file \
    --enable-avformat \
    --enable-avcodec \
    --enable-decoder=rawvideo \
    --enable-decoder=mjpeg \
    --enable-decoder=h263 \
    --enable-decoder=mpeg4 \
    --enable-decoder=h264 \
    --enable-encoder=mjpeg \
    --enable-encoder=h263 \
    --enable-encoder=mpeg4 \
    --enable-encoder=h264 \
    --enable-parser=h264 \
    --disable-network \
    --enable-zlib \
    --disable-avfilter \
    --disable-avdevice \
    $ADDITIONAL_CONFIGURE_FLAG

make clean
make  -j4 install
$PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
$PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -soname libffmpeg.so -shared -nostdlib  -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-once  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
}

CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
PREFIX=./android/$CPU
ADDITIONAL_CONFIGURE_FLAG=
build_one

I am guessing that some option in my configure command is conflicting with enabling libx264

NOTE: If I remove --enable-libx264 then it works

8
  • If i build both x264 and FFmpeg with --disable-static and --enable-shared, then I still get the same error, but this time in my log it no longer says "...could not read symbols..." but instead it says "cannot find -lx264..."
    – Kage
    Jan 11, 2012 at 1:05
  • How did you install x264? Did you install it by downloading the source and doing './configure', 'make', 'make install', or did you do something else? Also, what is your build system - *nix or Windows (with cygwin/msys)?
    – sashoalm
    Jan 11, 2012 at 14:43
  • I downloaded the source and used .configure, make, make install Im on a mac (10.7)
    – Kage
    Jan 11, 2012 at 20:06
  • Have you tried the simplest options possible - like only './configure --enable-libx264 && make', just to see if it would work then. The problem might be because some other customization/flags in the ./configure line interfere. You can also look at ffmpegx, which is a mac app, and it should come with an already compiled version of ffmpeg which you can use instead of compiling on your own.
    – sashoalm
    Jan 12, 2012 at 8:30
  • The simplest options do work, I have updated the question accordingly thanks
    – Kage
    Jan 12, 2012 at 20:54

7 Answers 7

3

I had the same problem. But after downgrading NDK to version 5c it works as described by halfninja. (ubuntu 64bit). there seem to be some changes in the toolchain from 5 to 7.

timo@serverplusplus:/tmp/android-ffmpeg-x264/Project/jni$ ndk-build 
Compile thumb  : ffmpeg <= ffmpeg.c
Compile thumb  : ffmpeg <= cmdutils.c
Executable     : ffmpeg
Install        : ffmpeg => libs/armeabi/ffmpeg
Compile thumb  : videokit <= uk_co_halfninja_videokit_Videokit.c
Compile thumb  : videokit <= ffmpeg.c
Compile thumb  : videokit <= cmdutils.c
SharedLibrary  : libvideokit.so
Install        : libvideokit.so => libs/armeabi/libvideokit.so
1
  • How can i use this to run ffmpeg commands in android? Do i have to go for "add native support" option in eclipse to use these libraries? Sep 16, 2012 at 6:53
3

The ffmpeg source code seems to be updated, and I could compile ffmpeg with x264 for Android NDK as the following.

1 Download the halfninja's android-ffmpeg-x264 git file from https://github.com/halfninja/android-ffmpeg-x264

2 At "halfninja-android-ffmpeg-x264-fe12be0/Project/jni" directory, modify "configure_ffmpeg.sh" to link "libgcc.a" for solving a problem that can not resolve "__aeabi_f2uiz".

./configure $DEBUG_FLAG --enable-cross-compile \
--arch=arm5te \
--enable-armv5te \
--target-os=linux \
--disable-stripping \
--prefix=../output \
--disable-neon \
--enable-version3 \
--disable-shared \
--enable-static \
--enable-gpl \
--enable-memalign-hack \
--cc=arm-linux-androideabi-gcc \
--ld=arm-linux-androideabi-ld \
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -I../x264 -Ivideokit" \
 $featureflags \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-network \
--enable-filter=buffer \
--enable-filter=buffersink \
--disable-demuxer=v4l \
--disable-demuxer=v4l2 \
--disable-indev=v4l \
--disable-indev=v4l2 \
--extra-ldflags="-L../x264 -L../toolchain/lib/gcc/arm-linux-androideabi/4.4.3" \
--extra-libs="-lgcc"

3 Modify "Android.mk" to link new library "libswresample.a".

FFMPEG_LIBS := $(addprefix ffmpeg/, \
 libavdevice/libavdevice.a \
 libavformat/libavformat.a \
 libavcodec/libavcodec.a \
 libavfilter/libavfilter.a \
 libswscale/libswscale.a \
 libavutil/libavutil.a \
 libswresample/libswresample.a \
 libpostproc/libpostproc.a )

4 Replace ffmpeg.c and cmdutils.c in videokit directory with ones in ffmpeg directory.

5 Follow a procedure described in README.textile.

1
  • How can i use this to run ffmpeg commands in android? Do i have to go for "add native support" option in eclipse to use these libraries? Sep 16, 2012 at 6:54
2

These are my working flags:

x264 (a recent stable):

./configure --cross-prefix=arm-linux-androideabi- \
--enable-pic \
--enable-static \
--disable-cli \
--disable-asm \
--host=arm-linux

ffmpeg (release/0.10):

./configure --enable-cross-compile \
--arch=arm5te \
--enable-armv5te \
--target-os=linux \
--disable-stripping \
--prefix=../output \
--disable-neon \
--enable-version3 \
--disable-shared \
--enable-static \
--enable-gpl \
--enable-memalign-hack \
--cc=arm-linux-androideabi-gcc \
--ld=arm-linux-androideabi-gcc \
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated" \
--disable-everything \
--enable-decoder=h264 \
--enable-demuxer=mov \
--enable-muxer=mp4 \
--enable-encoder=libx264 \
--enable-libx264 \
--enable-protocol=file \
--enable-decoder=aac \
--enable-encoder=aac \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-network \
--enable-filter=buffer \
--enable-filter=buffersink \
--enable-filter=scale \
--disable-demuxer=v4l \
--disable-demuxer=v4l2 \
--disable-indev=v4l \
--disable-indev=v4l2 \
--extra-cflags="-I../x264" \
--extra-ldflags="-L../x264" \
--extra-libs="-lgcc"

Obviously you will have to adjust the paths.

2

I've put together a Android build system for ffmpeg+x264 here: https://github.com/guardianproject/android-ffmpeg

We're working on some wrapper Java too for running it, but that's not really usable yet.

4
  • too bad that it's only to Debian/Ubuntu, how about mac?
    – shem
    Feb 19, 2013 at 10:16
  • Building on Mac OS X and others should be possible, patches welcome :) we just find it vastly easier to run Android native builds on Debian/Ubuntu than any other platform, including other GNU/Linux distros. Feb 22, 2013 at 19:23
  • Failed to compile it on mac, probably because the lib init you should do before.
    – shem
    Feb 24, 2013 at 11:42
  • To use it : stackoverflow.com/questions/19355423/…
    – Taiko
    Feb 4, 2014 at 13:10
1

I've discovered the --enable-static option does not have any effect on ffmpeg linking behaviour for libx264. I managed to build a copy of ffmpeg with libx264 included statically by editing the config.mak after I'd run ./configure

  • Build x264 from source in another directory
  • Add libx264.a to EXTRALIBS line in config.mak
  • Remove -lx264 from EXTRALIBS line in config.mak

Before

EXTRALIBS=-ldl -lX11 -lx264 etc.

After

EXTRALIBS=/home/adam/x264sourcebuild/libx264.a -ldl -lX11  etc.
1

I have met the same issue before, and I tried several times to find out the reason:

You must make sure the x264 and the ffmpeg are using same way to compile. like: using Android NDK. Using the same gcc compiler.

So you can not compile ffmpeg with this command:"--cross-prefix=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi-", but compile the x264 without that. Here is my x264 compile script:

./configure --prefix=$PREFIX \
--enable-static \
--enable-pic \
--disable-asm \
--disable-cli \
--host=arm-linux \
--cross-prefix=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM

make
sudo make install
sudo ldconfig
0

FFMPEG with x264 works only with version

implementation 'com.arthenica:mobile-ffmpeg-full-gpl:4.2.2.LTS'

Please check you library version. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.