0

Right now, I have a ffmeg build script which recognizes libx264 and compiles succesfully. I have also compiled x264 and obtained libx264.a library. Both ffmpeg and libx264 are built from source. I can build ffmpeg without libx264 succesfully as well. Below you may find my script which tries to build ffmpeg with libx264.

#!/bin/bash
NDK=~/Android_NDK_r7b
PLATFORM=$NDK/platforms/android-8/arch-arm/
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
alitan=~/x264/ndk7_build
function build_one
{
./configure --target-os=linux \
--prefix=$PREFIX \
--enable-cross-compile \
--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=" -I$alitan/include" \
--disable-shared \
--enable-static \
--extra-ldflags=" -L$alitan/lib " \
--enable-version3 \
--enable-gpl \
--disable-doc \
--disable-everything \
--enable-libx264 \
--enable-encoder=libx264 \
$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
}

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

Above script doesn't give me libx264.a in ffmpeg output builds.Several other scenarios are as follows. If I enable x264 encoder, I get undefined reference errors to some variables in x264.c (in libavcodec). If I enable shared in ffmpeg configure, I get an error which says it can't cd to my prefix directory (no permission issues by the way).

I am using latest releases of ffmpeg and x264 (cloned the git today) and ndk 7. Ubuntu runs on VM, installed on Windows 7. For further details about my adventure of ffmpeg/x264 porting to Android, you may refer here.

What should I do to use libx264 with ffmpeg? I kept on trying this script with different configurations, removed all ffmpeg x264 folders and reinstalled them, but to no avail.

Thanks a lot in advance.

EDIT Below is my x264 build script. It builds fine, gives me the static library and the headers.

export ARM_ROOT=/home/mehmet/Android_NDK_r7b
export ARM_INC=$ARM_ROOT/platforms/android-8/arch-arm/usr/include/
export ARM_LIB=$ARM_ROOT/platforms/android-8/arch-arm/usr/lib/
export ARM_TOOL=$ARM_ROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
export ARM_LIBO=$ARM_TOOL/lib/gcc/arm-linux-androideabi/4.4.3
export PATH=$ARM_TOOL/bin:$PATH
export PATH=$ARM_TOOL/arm-linux-androideabi/bin:$PATH
export ARM_PRE=arm-linux-androideabi
#tries to build for 4.4.3 toolchain

./configure --prefix=./ndk7_build \
--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 -L$ARM_LIB -nostdlib $ARM_LIB/crtbegin_dynamic.o $ARM_LIB/crtend_android.o -lc -lm -ldl -lgcc " \
--cross-prefix=${ARM_PRE}- \
--disable-asm \
--enable-static \
--host=arm-linux \

This is what happens on terminal when i enable libx264 encoder.

STRIP   ffmpeg
INSTALL install-progs-yes
INSTALL ffmpeg
INSTALL ffprobe
libavcodec/libavcodec.a(libx264.o): In function `X264_frame':
/home/mehmet/ffmpeg/libavcodec/libx264.c:158: undefined reference to `x264_picture_init'
/home/mehmet/ffmpeg/libavcodec/libx264.c:178: undefined reference to `x264_encoder_reconfig'
/home/mehmet/ffmpeg/libavcodec/libx264.c:189: undefined reference to `x264_encoder_encode'
/home/mehmet/ffmpeg/libavcodec/libx264.c:195: undefined reference to `x264_encoder_delayed_frames'
libavcodec/libavcodec.a(libx264.o): In function `encode_nals':
/home/mehmet/ffmpeg/libavcodec/libx264.c:100: undefined reference to `x264_bit_depth'
libavcodec/libavcodec.a(libx264.o): In function `X264_close':
/home/mehmet/ffmpeg/libavcodec/libx264.c:230: undefined reference to `x264_encoder_close'
libavcodec/libavcodec.a(libx264.o): In function `X264_init':
/home/mehmet/ffmpeg/libavcodec/libx264.c:283: undefined reference to `x264_param_default'
/home/mehmet/ffmpeg/libavcodec/libx264.c:291: undefined reference to `x264_param_default_preset'
/home/mehmet/ffmpeg/libavcodec/libx264.c:313: undefined reference to `x264_param_parse'
/home/mehmet/ffmpeg/libavcodec/libx264.c:448: undefined reference to `x264_param_apply_fastfirstpass'
/home/mehmet/ffmpeg/libavcodec/libx264.c:451: undefined reference to `x264_param_apply_profile'
/home/mehmet/ffmpeg/libavcodec/libx264.c:494: undefined reference to `x264_encoder_open_125'
/home/mehmet/ffmpeg/libavcodec/libx264.c:505: undefined reference to `x264_encoder_headers'
Community
  • 1
  • 1
kerim yucel
  • 127
  • 1
  • 3
  • 13
  • @rogerdpack I edited the question with my x264 build script. – kerim yucel Aug 31 '12 at 21:23
  • I think the issue with getting missing x264 symbols is the right scenario to solve. Can you print the symbols found missing for x264. I ask this because I think you need to use the latest ffmpeg for the latest x264. – av501 Aug 31 '12 at 21:25
  • Also these guys have seemed to face a similar issue and solved it. Take a look: http://stackoverflow.com/questions/8812827/build-ffmpeg-with-x264-for-android?rq=1 – av501 Aug 31 '12 at 21:30
  • Try looking at http://stackoverflow.com/questions/8812827/build-ffmpeg-with-x264-for-android?rq=1 once. They had the same issue. – av501 Aug 31 '12 at 21:30
  • @av501 I thought about this too, that's why I downloaded the last version of ffmpeg just today, along with x264's latest version. I will check config.log with --enable-encoder=libx264 again and try to see what's wrong. – kerim yucel Aug 31 '12 at 21:30
  • These guys had the same issue: http://stackoverflow.com/questions/8812827/build-ffmpeg-with-x264-for-android?rq=1 Try their solution once. – av501 Aug 31 '12 at 21:31
  • @av501 I have already bookmarked this days ago :). Actually I am trying the simplest option that is preferred in that post, namely enabling x264 and nothing else. As I said before, without encoder enabled, it builds fine but it doesn't give the libx264.a in ffmpeg build output. Real trouble starts when encoder is enabled. – kerim yucel Aug 31 '12 at 21:36
  • Question is edited again with encoder enabled scenario's output seen from terminal. – kerim yucel Aug 31 '12 at 22:31
  • @kerimyucel, ffmpeg build will not give you libx264. So I am not sure what you mean by "doesn't give lix264.a in ffmpeg build output". x264 build gives libx264. So your ffmpeg must have a -L to the x264 library path which is where you build x264 and its library is available. I don't see such a path in your ffmpeg build file. Your x264 build will generate a libx264. Find out where it is. Then add that path to your ffmpeg build. That is the problem you have. – av501 Sep 01 '12 at 06:32
  • @av501 ffmpeg including libx264.a was just a misunderstanding on my side, I thought it will include the static library along with others (libavcodec, etc..). I think I have added the path of libx264, both for header and static library itself. (extrald and extracf flags). Should I add something more? – kerim yucel Sep 01 '12 at 13:54
  • @kerimyucel, This should suffice. Is x264/ndk7_build where the libx264.a available? So what does the build command line look like? Look at the command line of the build. Is it proper? – av501 Sep 01 '12 at 14:01
  • @av501 Yes, I have the headers and the static library under this folder, in /include and /lib subfolders respectively. As I have stated earlier, when I run the script without enabling encoder libx264, it builds brilliantly, no problems. I don't understand what might be wrong when I enable encoderlibx264, I get the errors that are posted in my question. – kerim yucel Sep 01 '12 at 14:17
  • It may build fine. Does ffmpeg rum run without libx264? Also x264 build seperately. So can you run x264 by itself, not as part of ffmpeg? – av501 Sep 01 '12 at 17:06
  • FFmpeg without encoderx264 enabled builds fine, no problems with that matter. I might use them seperately (wrapping them with JNI into java) but I am trying to avoid this as much as I can. Meanwhile I have tried something else, I have seen my x264 script optimizes the code for arm5, whereas ffmpeg does it for armv7. I changed the flags of x264 for armv7 optimization, ran the script with encoder enabled but still the same error as original post. – kerim yucel Sep 01 '12 at 17:25
  • I can see some flags in x264 which dont exist for ffmpeg. Ideally both should run with both flags. The thing i am worried about is -lc -lm -lgcc etc. Where does it get the libraries to link from. It should use the ones in file system. The other question is can you build and run x264 executable seperately and run? The thing is since ffmpeg cannot find libx264 there are two possibilities only 1. path is wrong to the library. 2. format of the library is wrong. So my only suspicion now is in the build of x264 since you should have checked if paths are fine. – av501 Sep 01 '12 at 17:56
  • I didn't try to run the executable, actually I am not generating an executable for libx264. I think there might be a problem with the linker flags. We are discussing it under the answer above. – kerim yucel Sep 01 '12 at 18:10

2 Answers2

1

Well, thanks to Robert's git, I have checked it and it worked just fine. I don't know why but using SYSROOT style build and adding armv7 optimization flags worked. I have produced a binary for ffmpeg linked to x264 with encoder x264 support. Thanks for your help.

kerim yucel
  • 127
  • 1
  • 3
  • 13
0

https://github.com/guardianproject/android-ffmpeg/blob/master/configure_ffmpeg.sh

look at above link and how eighthave includes L..X264 in his ./ffmpeg/configure...

if u get the correct libs into the search chain for the config step on ffmpeg , then all those undefined refs go away...

Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
  • If I am not wrong, the flags in configure script you posted just adds some optimizations for NEON when compared to my script, so that shouldn't cause a problem. My bet, regarding my issue, is flags in libx264 script I use. Anyone can spot anything in x264 script I have posted above? (even though it works fine, something should be wrong so that I am getting the error in the original post) – kerim yucel Sep 01 '12 at 17:00
  • --extra-ldflags=" -L$alitan/lib " \ thats your linker lib expression. How does that include -L..X264 for the linker? – Robert Rowntree Sep 01 '12 at 17:13
  • I am trying to search libx264 headers and static lib in a different folder (which is $alitan/include and /lib respectively), whereas the script you have posted looks for them in parentdirectory/x264, isn't that right? I have also make install'd x264 build, so I am looking for it in the output build folder which is x264/alitan. I can't see the difference to be honest. – kerim yucel Sep 01 '12 at 17:35
  • looks to me like your x264 build outputs static lib to ./configure --prefix=./android2 \ .Dont you have to coordinate that target with the subsequent build steps - ie libs that are searched for by the linker in the config_ffmpeg step? – Robert Rowntree Sep 01 '12 at 17:56
  • So I assume you are saying that I need to pass an option to the linker, such as " -wl,-rpath-link=$alitan/lib -L$alitan/lib " should be added to ldflags? Did I understand correctly? – kerim yucel Sep 01 '12 at 18:06
  • step 4 ffmpeg_config ... the linker statement for where the X264 static lib gets picked up should agree with the output ./lib destination from the earlier step ( ie the x264 make/install for the cross toolchain puts its static where) .. i looked at your x264 config and i think the output goes to --prefix... so ffmeg_config needs to be aware of where to pick up the x264 lib. – Robert Rowntree Sep 01 '12 at 18:36
  • I know what you mean, actually x264 and ffmpeg scripts above pointed out different build folders for x264, but I corrected this. The reason I changed the prefix for x264 install is that I was trying to build with different configurations. I edited the x264 script in the build accordingly. It finds the libx264 path, I am sure since when I enablelibx264 in ffmpeg config, it builds. When I add encoderlibx264, it gives me the error shown in original post. – kerim yucel Sep 01 '12 at 18:48
  • sheesh! https://github.com/guardianproject/android-ffmpeg .. So, i have x264 working fine on android... and to get the x264 going .. i used this project.. he doesn't have all the android i needed so, i added my own. But, i know his x264 stuff is solid.. https://github.com/rowntreerob/android-ffmpeg good luck with cross toolchain issues... – Robert Rowntree Sep 01 '12 at 19:21
  • I know this is ridicilous, it can link without encoder, i get libffmpeg.so but with the encoder, i get the errors and can't obtain libffmpeg.so . I will try to do this for a while, if not, I will definitely try the link you posted. Thanks a lot. – kerim yucel Sep 01 '12 at 19:30