6

I needed to install ffmpeg with libx264 support for enabling H.264 encoding . I installed libx264 successfully using the below script with toolchains available in android-ndk-r9d .

 #!/bin/bash
 NDK=~/android-ndk-r9d
 SYSROOT=$NDK/platforms/android-8/arch-arm/
 TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64
 function build_one
 {
 ./configure \
 --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
 --sysroot="$SYSROOT" \
 --host=arm-linux \
 --enable-pic \
 --enable-shared \
 --disable-cli
 make clean
 make
 make install
 }
 build_one 

Now I wanted to build ffmpeg with libx264 support . I used the below script with --enable-libx264 , --enable-nonfree , --enable-gpl options as in the below script .

#!/bin/bash
NDK=~/android-ndk-r9d
SYSROOT=$NDK/platforms/android-8/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--enable-nonfree \
--enable-gpl \
--enable-libx264 \
--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

But when I run the script I'm getting error "ERROR: libx264 not found" .

I suppose ffmpeg is not able to figure out the installed location of libx264 . After libx264 installation I have libx264.so file in /usr/local/lib executable at /usr/local/bin and header files at /usr/local/include directories .

What all changes do I need to make to the ffmpeg build script in-order to make it detect libx264?

Note : I am using Ubuntu 12.04(64 bit) for cross compiling .

davidvarghese
  • 637
  • 2
  • 10
  • 18

4 Answers4

9

On newer versions of libx264 you must configure with --disable-opencl for ffmpeg to find the library correctly.

./configure --enable-static --disable-opencl

i.e.

wget http://download.videolan.org/pub/x264/snapshots/x264-snapshot-20191217-2245-stable.tar.bz2
tar xjvf x264-snapshot-20191217-2245-stable.tar.bz2
cd x264-snapshot*
./configure --enable-static --disable-opencl
make install
Meekohi
  • 10,390
  • 6
  • 49
  • 58
  • Thanks. Finally, I solved the problem using the option (--disable-opencl) – Hyunho Jo May 09 '16 at 23:54
  • Thanks, it's still helpful after 2 years! – lucky1928 Dec 21 '17 at 18:12
  • That link is now dead – dǝɥɔS ʇoıןןƎ Jan 12 '22 at 03:40
  • According to http://download.videolan.org/pub/x264/snapshots/x264-snapshot-20191218-README.txt you should now download the files directly from the repository at https://code.videolan.org/videolan/x264, but someone would need to verify that it works. Otherwise I've updated the above with the last snapshot they took. – Meekohi Jan 13 '22 at 04:26
8

Make sure your $ADDI_CFLAGS variable (which you pass in --extra-cflags) includes -I /usr/local/include

George Y.
  • 11,307
  • 3
  • 24
  • 25
  • Thanks . I modified -cflags and -ldflags accordingly and its working . – davidvarghese Aug 04 '14 at 12:39
  • 1
    can you tell me which path you are including in flags?? i Mean to say what is /usr/local/include where I get this path ? – Ahmad Arslan Mar 05 '15 at 11:09
  • Can you answer me ?? http://stackoverflow.com/questions/28876811/compile-ffmpeg-with-libx264-for-android – Ahmad Arslan Mar 05 '15 at 12:47
  • 3
    Where are your x264 headers located? You need to add this path as -I /path/to/headers to your compiler command-line option. You also need to add the -L /path/to/x264libraries to your linker command-line flags. – George Y. Mar 06 '15 at 00:04
2

you need to cross-compile libx264 for Android as well, don't use the one from your linux distribution.

Once it's cross-compiled, add the path to libx264.a by adding -I/path/to/x264 inside $ADDI_CFLAGS var.

To do all this, you can directly try this build script: https://github.com/ph0b/FFmpeg-Android

ph0b
  • 14,353
  • 4
  • 43
  • 41
1

I have tried this and it worked for me.

cd /opt

git clone git://git.videolan.org/x264.git

cd x264

./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static 

make

make install
Prasad Revanaki
  • 783
  • 4
  • 10
  • 23