| 1 | #!/bin/bash
|
|---|
| 2 |
|
|---|
| 3 | set -e
|
|---|
| 4 |
|
|---|
| 5 | # Set your own NDK here
|
|---|
| 6 | NDK=~/android-ndk-r10e
|
|---|
| 7 |
|
|---|
| 8 | ARM_PLATFORM=$NDK/platforms/android-9/arch-arm/
|
|---|
| 9 | ARM_PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64
|
|---|
| 10 |
|
|---|
| 11 | ARM64_PLATFORM=$NDK/platforms/android-21/arch-arm64/
|
|---|
| 12 | ARM64_PREBUILT=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64
|
|---|
| 13 |
|
|---|
| 14 | X86_PLATFORM=$NDK/platforms/android-9/arch-x86/
|
|---|
| 15 | X86_PREBUILT=$NDK/toolchains/x86-4.9/prebuilt/darwin-x86_64
|
|---|
| 16 |
|
|---|
| 17 | X86_64_PLATFORM=$NDK/platforms/android-21/arch-x86_64/
|
|---|
| 18 | X86_64_PREBUILT=$NDK/toolchains/x86_64-4.9/prebuilt/darwin-x86_64
|
|---|
| 19 |
|
|---|
| 20 | MIPS_PLATFORM=$NDK/platforms/android-9/arch-mips/
|
|---|
| 21 | MIPS_PREBUILT=$NDK/toolchains/mipsel-linux-android-4.8/prebuilt/darwin-x86_64
|
|---|
| 22 |
|
|---|
| 23 | BUILD_DIR=`pwd`/ffmpeg-android
|
|---|
| 24 |
|
|---|
| 25 | FFMPEG_VERSION="2.8.1"
|
|---|
| 26 |
|
|---|
| 27 | if [ ! -e "ffmpeg-${FFMPEG_VERSION}.tar.bz2" ]; then
|
|---|
| 28 | echo "Downloading ffmpeg-${FFMPEG_VERSION}.tar.bz2"
|
|---|
| 29 | curl -LO http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2
|
|---|
| 30 | else
|
|---|
| 31 | echo "Using ffmpeg-${FFMPEG_VERSION}.tar.bz2"
|
|---|
| 32 | fi
|
|---|
| 33 |
|
|---|
| 34 | tar -xvf ffmpeg-${FFMPEG_VERSION}.tar.bz2
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | function build_one
|
|---|
| 38 | {
|
|---|
| 39 | if [ $ARCH == "arm" ]
|
|---|
| 40 | then
|
|---|
| 41 | PLATFORM=$ARM_PLATFORM
|
|---|
| 42 | PREBUILT=$ARM_PREBUILT
|
|---|
| 43 | HOST=arm-linux-androideabi
|
|---|
| 44 | #added by alexvas
|
|---|
| 45 | elif [ $ARCH == "arm64" ]
|
|---|
| 46 | then
|
|---|
| 47 | PLATFORM=$ARM64_PLATFORM
|
|---|
| 48 | PREBUILT=$ARM64_PREBUILT
|
|---|
| 49 | HOST=aarch64-linux-android
|
|---|
| 50 | elif [ $ARCH == "mips" ]
|
|---|
| 51 | then
|
|---|
| 52 | PLATFORM=$MIPS_PLATFORM
|
|---|
| 53 | PREBUILT=$MIPS_PREBUILT
|
|---|
| 54 | HOST=mipsel-linux-android
|
|---|
| 55 | #alexvas
|
|---|
| 56 | elif [ $ARCH == "x86_64" ]
|
|---|
| 57 | then
|
|---|
| 58 | PLATFORM=$X86_64_PLATFORM
|
|---|
| 59 | PREBUILT=$X86_64_PREBUILT
|
|---|
| 60 | HOST=x86_64-linux-android
|
|---|
| 61 | else
|
|---|
| 62 | PLATFORM=$X86_PLATFORM
|
|---|
| 63 | PREBUILT=$X86_PREBUILT
|
|---|
| 64 | HOST=i686-linux-android
|
|---|
| 65 | fi
|
|---|
| 66 |
|
|---|
| 67 | # --prefix=$PREFIX \
|
|---|
| 68 |
|
|---|
| 69 | # TODO Adding aac decoder brings "libnative.so has text relocations. This is wasting memory and prevents security hardening. Please fix." message in Android.
|
|---|
| 70 | pushd ffmpeg-$FFMPEG_VERSION
|
|---|
| 71 | ./configure --target-os=linux \
|
|---|
| 72 | --incdir=$BUILD_DIR/include \
|
|---|
| 73 | --libdir=$BUILD_DIR/lib/$CPU \
|
|---|
| 74 | --enable-cross-compile \
|
|---|
| 75 | --extra-libs="-lgcc" \
|
|---|
| 76 | --arch=$ARCH \
|
|---|
| 77 | --cc=$PREBUILT/bin/$HOST-gcc \
|
|---|
| 78 | --cross-prefix=$PREBUILT/bin/$HOST- \
|
|---|
| 79 | --nm=$PREBUILT/bin/$HOST-nm \
|
|---|
| 80 | --sysroot=$PLATFORM \
|
|---|
| 81 | --extra-cflags="-fvisibility=hidden -fdata-sections -ffunction-sections -Os -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 " \
|
|---|
| 82 | --enable-shared \
|
|---|
| 83 | --enable-small \
|
|---|
| 84 | --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \
|
|---|
| 85 | --disable-everything \
|
|---|
| 86 | --disable-ffplay \
|
|---|
| 87 | --disable-ffmpeg \
|
|---|
| 88 | --disable-ffprobe \
|
|---|
| 89 | --disable-avfilter \
|
|---|
| 90 | --disable-avdevice \
|
|---|
| 91 | --disable-ffserver \
|
|---|
| 92 | $ADDITIONAL_CONFIGURE_FLAG
|
|---|
| 93 |
|
|---|
| 94 | make clean
|
|---|
| 95 | make -j8 install V=1
|
|---|
| 96 | $PREBUILT/bin/$HOST-ar d libavcodec/libavcodec.a inverse.o
|
|---|
| 97 | #$PREBUILT/bin/$HOST-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/$HOST/4.6/libgcc.a
|
|---|
| 98 | popd
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | #arm v5te
|
|---|
| 102 | #CPU=armv5te
|
|---|
| 103 | #ARCH=arm
|
|---|
| 104 | #OPTIMIZE_CFLAGS="-marm -march=$CPU"
|
|---|
| 105 | #PREFIX=$BUILD_DIR/$CPU
|
|---|
| 106 | #ADDITIONAL_CONFIGURE_FLAG=
|
|---|
| 107 | #build_one
|
|---|
| 108 |
|
|---|
| 109 | #arm v6
|
|---|
| 110 | #CPU=armv6
|
|---|
| 111 | #ARCH=arm
|
|---|
| 112 | #OPTIMIZE_CFLAGS="-marm -march=$CPU"
|
|---|
| 113 | #PREFIX=`pwd`/ffmpeg-android/$CPU
|
|---|
| 114 | #ADDITIONAL_CONFIGURE_FLAG=
|
|---|
| 115 | #build_one
|
|---|
| 116 |
|
|---|
| 117 | #arm v7vfpv3
|
|---|
| 118 | #CPU=armv7-a
|
|---|
| 119 | #ARCH=arm
|
|---|
| 120 | #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
|
|---|
| 121 | #PREFIX=$BUILD_DIR/$CPU
|
|---|
| 122 | #ADDITIONAL_CONFIGURE_FLAG=
|
|---|
| 123 | #build_one
|
|---|
| 124 |
|
|---|
| 125 | #arm v7vfp
|
|---|
| 126 | #CPU=armv7-a
|
|---|
| 127 | #ARCH=arm
|
|---|
| 128 | #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
|
|---|
| 129 | #PREFIX=`pwd`/ffmpeg-android/$CPU-vfp
|
|---|
| 130 | #ADDITIONAL_CONFIGURE_FLAG=
|
|---|
| 131 | #build_one
|
|---|
| 132 |
|
|---|
| 133 | #arm v7n
|
|---|
| 134 | #CPU=armv7-a
|
|---|
| 135 | #ARCH=arm
|
|---|
| 136 | #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"
|
|---|
| 137 | #PREFIX=`pwd`/ffmpeg-android/$CPU
|
|---|
| 138 | #ADDITIONAL_CONFIGURE_FLAG=--enable-neon
|
|---|
| 139 | #build_one
|
|---|
| 140 |
|
|---|
| 141 | #arm v6+vfp
|
|---|
| 142 | #CPU=armv6
|
|---|
| 143 | #ARCH=arm
|
|---|
| 144 | #OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
|
|---|
| 145 | #PREFIX=`pwd`/ffmpeg-android/${CPU}_vfp
|
|---|
| 146 | #ADDITIONAL_CONFIGURE_FLAG=
|
|---|
| 147 | #build_one
|
|---|
| 148 |
|
|---|
| 149 | #arm64-v8a
|
|---|
| 150 | #CPU=arm64-v8a
|
|---|
| 151 | #ARCH=arm64
|
|---|
| 152 | #OPTIMIZE_CFLAGS=
|
|---|
| 153 | #PREFIX=$BUILD_DIR/$CPU
|
|---|
| 154 | #ADDITIONAL_CONFIGURE_FLAG=
|
|---|
| 155 | #build_one
|
|---|
| 156 |
|
|---|
| 157 | #x86_64
|
|---|
| 158 | #CPU=x86_64
|
|---|
| 159 | #ARCH=x86_64
|
|---|
| 160 | #OPTIMIZE_CFLAGS="-fomit-frame-pointer"
|
|---|
| 161 | #PREFIX=$BUILD_DIR/$CPU
|
|---|
| 162 | #ADDITIONAL_CONFIGURE_FLAG=
|
|---|
| 163 | #build_one
|
|---|
| 164 |
|
|---|
| 165 | #x86
|
|---|
| 166 | CPU=i686
|
|---|
| 167 | ARCH=i686
|
|---|
| 168 | OPTIMIZE_CFLAGS="-fomit-frame-pointer"
|
|---|
| 169 | PREFIX=$BUILD_DIR/$CPU
|
|---|
| 170 | ADDITIONAL_CONFIGURE_FLAG=
|
|---|
| 171 | build_one
|
|---|