├── .gitignore ├── patches └── patch_fix_ffmpeg_lib_name.txt ├── _old_build_openssl.sh ├── _build_openssl.sh ├── README.md ├── _old_build_ffmpeg.sh ├── Setenv-android.sh └── _build_ffmpeg.sh /.gitignore: -------------------------------------------------------------------------------- 1 | /libs 2 | /src 3 | 4 | -------------------------------------------------------------------------------- /patches/patch_fix_ffmpeg_lib_name.txt: -------------------------------------------------------------------------------- 1 | --- ./configure 2017-04-13 04:55:54.000000000 +0300 2 | +++ ./configure_fix 2017-05-02 00:27:55.241807220 +0300 3 | @@ -3302,10 +3302,10 @@ 4 | SLIBSUF=".so" 5 | SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)' 6 | SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)' 7 | -SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)' 8 | +SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' 9 | LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"' 10 | -SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)' 11 | -SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)' 12 | +SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' 13 | +SLIB_INSTALL_LINKS='$(SLIBNAME)' 14 | VERSION_SCRIPT_POSTPROCESS_CMD="cat" 15 | 16 | asflags_filter=echo 17 | -------------------------------------------------------------------------------- /_old_build_openssl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # use extended globbing features 4 | shopt -s extglob 5 | 6 | #-- error function 7 | function die { 8 | code=-1 9 | err="Unknown error!" 10 | test "$1" && err=$1 11 | cd ${top_root} 12 | echo "$err" 13 | echo "Check the build log: ${build_log}" 14 | exit -1 15 | } 16 | 17 | export NDK=/home/davinctor/Android/Sdk/ndk-bundle 18 | 19 | # environment variables 20 | top_root=$PWD 21 | src_root=${top_root}/src 22 | patch_root=${top_root}/patches 23 | dist_root=${top_root}/libs/openssl 24 | dist_bin_root=${dist_root}/bin 25 | dist_include_root=${dist_root}/include 26 | dist_lib_root=${dist_root}/lib 27 | build_log=${top_root}/openssl_build.log 28 | 29 | # create our folder structure 30 | cd ${top_root} 31 | test -d ${src_root} || mkdir -p ${src_root} 32 | test -d ${dist_root} || mkdir -p ${dist_root} 33 | test -d ${dist_bin_root} || mkdir -p ${dist_bin_root} 34 | test -d ${dist_include_root} || mkdir -p ${dist_include_root} 35 | test -d ${dist_lib_root} || mkdir -p ${dist_lib_root} 36 | touch ${build_log} 37 | 38 | rm -f ${build_log} 39 | 40 | echo "Building openssl-android ..." 41 | 42 | test -d ${src_root}/openssl-android || \ 43 | git clone https://github.com/guardianproject/openssl-android.git ${src_root}/openssl-android >> ${build_log} 2>&1 || \ 44 | die "Couldn't clone openssl-android repository!" 45 | cd ${src_root}/openssl-android 46 | 47 | ${NDK}/ndk-build >> ${build_log} 2>&1 || die "Couldn't build openssl-android!" 48 | 49 | # copy the versioned libraries 50 | #cp -r ${src_root}/openssl-android/libs/armeabi/lib*.so --parents ${dist_lib_root}/. 51 | rsync -a --include '*/' --include '*.so' --exclude '*' ${src_root}/openssl-android/libs/ ${dist_lib_root}/ 52 | # copy the executables 53 | #cp -r ${src_root}/openssl-android/libs/armeabi/openssl ${dist_bin_root}/. # work only for one abi folder 54 | rsync -a --include '*/openssl' --exclude '*.so' ${src_root}/openssl-android/libs/ ${dist_bin_root}/ 55 | #cp -r ${src_root}/openssl-android/libs/armeabi/ssltest ${dist_bin_root}/. # work only for one abi folder 56 | rsync -a --include '*/ssltest' --exclude '*.so' ${src_root}/openssl-android/libs/ ${dist_bin_root}/ 57 | # copy the headers 58 | cp -r ${src_root}/openssl-android/include/* ${dist_include_root}/. 59 | 60 | cd ${top_root} 61 | 62 | -------------------------------------------------------------------------------- /_build_openssl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Cross-compile environment for Android on ARMv7 and x86 3 | # 4 | 5 | export WORKING_DIR=`pwd` 6 | 7 | export NDK=~/Android/Sdk/ndk-bundle 8 | 9 | export ANDROID_NDK_ROOT=$NDK 10 | 11 | if [ $# -ne 1 ]; 12 | then echo "illegal number of parameters" 13 | echo "usage: build_openssl.sh TARGET" 14 | exit 1 15 | fi 16 | 17 | export TARGET=$1 18 | 19 | ARM_PLATFORM=$NDK/platforms/android-9/arch-arm/ 20 | ARM_PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 21 | 22 | ARM64_PLATFORM=$NDK/platforms/android-21/arch-arm64/ 23 | ARM64_PREBUILT=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 24 | 25 | X86_PLATFORM=$NDK/platforms/android-9/arch-x86/ 26 | X86_PREBUILT=$NDK/toolchains/x86-4.9/prebuilt/dlinux-x86_64 27 | 28 | X86_64_PLATFORM=$NDK/platforms/android-21/arch-x86_64/ 29 | X86_64_PREBUILT=$NDK/toolchains/x86_64-4.9/prebuilt/linux-x86_64 30 | 31 | MIPS_PLATFORM=$NDK/platforms/android-9/arch-mips/ 32 | MIPS_PREBUILT=$NDK/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86_64 33 | 34 | OPENSSL_VERSION="1.0.2k" #1.0.2j #"1.1.0c" 35 | 36 | TOP_ROOT=`pwd` 37 | BUILD_DIR=${TOP_ROOT}/libs/openssl 38 | SOURCE=${TOP_ROOT}/src 39 | SOURCE_OPENSSL=$SOURCE/openssl-android 40 | mkdir -p ${BUILD_DIR} 41 | mkdir -p ${SOURCE} 42 | mkdir -p ${SOURCE_OPENSSL} 43 | 44 | cd $SOURCE 45 | 46 | if [ ! -e "openssl-${OPENSSL_VERSION}.tar.gz" ]; then 47 | echo "Downloading openssl-${OPENSSL_VERSION}.tar.gz" 48 | curl -LO https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz 49 | tar -xvf openssl-${OPENSSL_VERSION}.tar.gz -C $SOURCE_OPENSSL --strip-components=1 50 | else 51 | echo "Using openssl-${OPENSSL_VERSION}.tar.gz" 52 | fi 53 | 54 | #if [ -d openssl-${OPENSSL_VERSION} ] 55 | #then 56 | # rm -rf openssl-${OPENSSL_VERSION} 57 | #fi 58 | 59 | function build_one 60 | { 61 | 62 | if [ $ARCH == "arm" ] 63 | then 64 | PLATFORM=$ARM_PLATFORM 65 | PREBUILT=$ARM_PREBUILT 66 | HOST=arm-linux-androideabi 67 | #added by alexvas 68 | elif [ $ARCH == "arm64" ] 69 | then 70 | PLATFORM=$ARM64_PLATFORM 71 | PREBUILT=$ARM64_PREBUILT 72 | HOST=aarch64-linux-android 73 | elif [ $ARCH == "mips" ] 74 | then 75 | PLATFORM=$MIPS_PLATFORM 76 | PREBUILT=$MIPS_PREBUILT 77 | HOST=mipsel-linux-android 78 | #alexvas 79 | elif [ $ARCH == "x86_64" ] 80 | then 81 | PLATFORM=$X86_64_PLATFORM 82 | PREBUILT=$X86_64_PREBUILT 83 | HOST=x86_64-linux-android 84 | else 85 | PLATFORM=$X86_PLATFORM 86 | PREBUILT=$X86_PREBUILT 87 | HOST=i686-linux-android 88 | fi 89 | 90 | INSTALL_DIR=$BUILD_DIR/build/$ABI 91 | mkdir -p ${INSTALL_DIR} 92 | 93 | cd $TOP_ROOT 94 | . ./Setenv-android.sh $NDK $ANDROID_EABI $ANDROID_ARCH 95 | cd $SOURCE_OPENSSL 96 | 97 | if [ $TARGET == "mips" ] 98 | then 99 | ./Configure android-mips shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=$INSTALL_DIR --prefix=$INSTALL_DIR 100 | elif [ $TARGET == "x86_64" ] 101 | then 102 | ./Configure linux-x86_64 shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=$INSTALL_DIR --prefix=$INSTALL_DIR 103 | else 104 | ./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=$INSTALL_DIR --prefix=$INSTALL_DIR 105 | fi 106 | 107 | make clean 108 | make depend 109 | make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" MAKE="make -e" all 110 | 111 | echo $ANDROID_TOOLCHAIN 112 | echo $PREBUILT/bin 113 | 114 | mkdir -p $INSTALL_DIR/lib 115 | echo "place-holder make target for avoiding symlinks" >> $INSTALL_DIR/lib/link-shared 116 | make SHLIB_EXT=.so install_sw 117 | #make install CC=$PREBUILT/bin/$HOST-gcc RANLIB=$PREBUILT/bin/$HOST-ranlib 118 | 119 | # copy the binaries 120 | OPENSSL_LIB_DIR=$BUILD_DIR/lib/$ABI 121 | OPENSSL_INCLUDE_DIR=$BUILD_DIR/include/$ABI 122 | mkdir -p ${OPENSSL_LIB_DIR} 123 | mkdir -p ${OPENSSL_INCLUDE_DIR} 124 | cp -r $INSTALL_DIR/lib/*.so ${OPENSSL_LIB_DIR}/. 125 | cp -r $INSTALL_DIR/include/* ${OPENSSL_INCLUDE_DIR}/. 126 | } 127 | 128 | if [ $TARGET == 'arm' ]; then 129 | ABI=armeabi 130 | CPU=arm 131 | ARCH=arm 132 | PREFIX=`pwd`/../jni/openssl-android/armeabi 133 | export ANDROID_EABI=arm-linux-androideabi-4.9 134 | export ANDROID_ARCH=arch-arm 135 | build_one 136 | fi 137 | 138 | if [ $TARGET == 'armv7-a' ]; then 139 | ABI=armeabi-v7a 140 | CPU=armv7-a 141 | ARCH=arm 142 | PREFIX=`pwd`/../jni/openssl-android/armeabi-v7a 143 | export ANDROID_EABI=arm-linux-androideabi-4.9 144 | export ANDROID_ARCH=arch-arm 145 | build_one 146 | fi 147 | 148 | if [ $TARGET == 'i686' ]; then 149 | ABI=x86 150 | CPU=i686 151 | ARCH=i686 152 | PREFIX=`pwd`/../jni/openssl-android/x86 153 | export ANDROID_EABI=x86-4.9 154 | export ANDROID_ARCH=arch-x86 155 | build_one 156 | fi 157 | 158 | if [ $TARGET == 'mips' ]; then 159 | ABI=mips 160 | CPU=mips 161 | ARCH=mips 162 | PREFIX=`pwd`/../jni/openssl-android/mips 163 | export ANDROID_EABI=mipsel-linux-android-4.9 164 | export ANDROID_ARCH=arch-mips 165 | build_one 166 | fi 167 | 168 | if [ $TARGET == 'x86_64' ]; then 169 | ABI=x86_64 170 | CPU=x86_64 171 | ARCH=x86_64 172 | PREFIX=`pwd`/../jni/openssl-android/x86_64 173 | export ANDROID_EABI=x86_64-4.9 174 | export ANDROID_ARCH=arch-x86_64 175 | build_one 176 | fi 177 | 178 | if [ $TARGET == 'arm64-v8a' ]; then 179 | ABI=arm64-v8a 180 | CPU=arm64-v8a 181 | ARCH=arm64 182 | PREFIX=`pwd`/../jni/openssl-android/arm64-v8a 183 | export ANDROID_EABI=aarch64-linux-android-4.9 184 | export ANDROID_ARCH=arch-arm64 185 | build_one 186 | fi 187 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | A bunch of script you can use to compile FFmpeg with OpenSSL 3 | 4 | # Environment 5 | 1. Linux (At that time I used Linux Mint 18.1 Serena MATE 64-bit) 6 | 2. Android NDK r14b 7 | 3. Internet 8 | 9 | # How to run it 10 | 1. Copy the repository 11 | 2. cd into it 12 | 3. Call in console `./build.sh` 13 | 4. Wait for a while 14 | 5. Congratulations! 15 | 16 | # Output folder structure 17 | ``` 18 | ~/AndroidStudioProjects/compile-ffmpeg-and-openssl/ 19 | → build.sh (the main compilation script for both FFmpeg and OpenSSL) 20 | → _build_ffmpeg.sh (FFmpeg compilation script) 21 | → _build_openssl.sh (OpenSSL compilation script) 22 | → _old_build_ffmpeg.sh (FFmpeg compilation script for only armeabi architecture) 23 | → _old_build_openssl.sh (OpenSSL 1.0.0a compilation script) 24 | → Setenv-android.sh (set up environment (variables, etc) for OpenSSL compilation, runs inside _build_openssl.sh) 25 | → patches 26 | → patch_fix_ffmpeg_lib_name.txt (the patch file to fix FFmpeg libs name suffix) 27 | → src 28 | → ffmpeg-android (FFmpeg sources) 29 | → openssl-android (OpenSSL sources) 30 | → ffmpeg-3.3tar.bz2 31 | → openssl-1.0.2j.tar.gz 32 | → libs (folder with compiled libs) 33 | → ffmpeg 34 | → include 35 | → armeabi-v7a 36 | → libavcodec 37 | → libavdevice 38 | → libavfilter 39 | → libavformat 40 | → libavutil 41 | → libswresample 42 | → libswscale 43 | → x86 44 | → (Like inside armeabi-v7a folder) 45 | → armeabi 46 | → (Like inside armeabi-v7a folder) 47 | → arm64-v8a 48 | → (Like inside armeabi-v7a folder) 49 | → binaries 50 | → armeabi-v7a 51 | → libavcodec-57.so 52 | → libavcodec.so -> libavcodec-57.so 53 | → libavdevice-57.so 54 | → libavdevice.so -> libavdevice-57.so 55 | → libavfilter-6.so 56 | → libavfilter.so -> libavfilter-6.so 57 | → libavformat-57.so 58 | → libavformat.so -> libavformat-57.so 59 | → libavutil-55.so 60 | → libavutil.so -> libavutil-55.so 61 | → x86 62 | → (Like inside armeabi-v7a folder) 63 | → armeabi 64 | → (Like inside armeabi-v7a folder) 65 | → arm64-v8a 66 | → (Like inside armeabi-v7a folder) 67 | → lib 68 | → libavcodec 69 | → armeabi-v7a 70 | → libavcodec-57.so 71 | → libavcodec.so -> libavcodec-57.so 72 | → x86 73 | → (Like inside armeabi-v7a folder) 74 | → armeabi 75 | → (Like inside armeabi-v7a folder) 76 | → arm64-v8a 77 | → (Like inside armeabi-v7a folder) 78 | → libavdevice 79 | → armeabi-v7a 80 | → libavdevice-57.so 81 | → libavdevice.so -> libavdevice-57.so 82 | → x86 83 | → (Like inside armeabi-v7a folder) 84 | → armeabi 85 | → (Like inside armeabi-v7a folder) 86 | → arm64-v8a 87 | → (Like inside armeabi-v7a folder) 88 | 89 | → libavfilter 90 | → armeabi-v7a 91 | → libavfilter-6.so 92 | → libavfilter.so -> libavfilter-6.so 93 | → x86 94 | → (Like inside armeabi-v7a folder) 95 | → armeabi 96 | → (Like inside armeabi-v7a folder) 97 | → arm64-v8a 98 | → (Like inside armeabi-v7a folder) 99 | → libavformat 100 | → armeabi-v7a 101 | → libavformat-57.so 102 | → libavformat.so -> libavformat-57.so 103 | → x86 104 | → (Like inside armeabi-v7a folder) 105 | → armeabi 106 | → (Like inside armeabi-v7a folder) 107 | → arm64-v8a 108 | → (Like inside armeabi-v7a folder) 109 | → libavutil 110 | → armeabi-v7a 111 | → libavutil-55.so 112 | → libavutil.so -> libavutil-55.so 113 | → x86 114 | → (Like inside armeabi-v7a folder) 115 | → armeabi 116 | → (Like inside armeabi-v7a folder) 117 | → arm64-v8a 118 | → (Like inside armeabi-v7a folder) 119 | → libswresample 120 | → armeabi-v7a 121 | → libswresample-2.so 122 | → libswresample.so -> libswresample-2.so 123 | → x86 124 | → (Like inside armeabi-v7a folder) 125 | → armeabi 126 | → (Like inside armeabi-v7a folder) 127 | → arm64-v8a 128 | → (Like inside armeabi-v7a folder) 129 | → libswscale 130 | → armeabi-v7a 131 | → libswscale-4.so 132 | → libswscale.so -> libswscale-4.so 133 | → x86 134 | → (Like inside armeabi-v7a folder) 135 | → armeabi 136 | → (Like inside armeabi-v7a folder) 137 | → arm64-v8a 138 | → (Like inside armeabi-v7a folder) 139 | → openssl (libs/openssl) 140 | → build 141 | → armeabi-v7a 142 | → bin 143 | → certs 144 | → include 145 | → openssl 146 | → lib 147 | → engines 148 | → libcrypto.a 149 | → libscrypto.so 150 | → libssl.a 151 | → libssl.so 152 | → link_shared 153 | → pkg-config 154 | → misc 155 | → private 156 | → openssl.cnf 157 | → x86 158 | → (Like inside armeabi-v7a folder) 159 | → armeabi 160 | → (Like inside armeabi-v7a folder) 161 | → arm64-v8a 162 | → (Like inside armeabi-v7a folder) 163 | → include 164 | → armeabi-v7a 165 | → openssl 166 | → x86 167 | → (Like inside armeabi-v7a folder) 168 | → armeabi 169 | → (Like inside armeabi-v7a folder) 170 | → arm64-v8a 171 | → (Like inside armeabi-v7a folder) 172 | → lib 173 | → armeabi-v7a 174 | → libssl.so 175 | → libcrypto.so 176 | → x86 177 | → (Like inside armeabi-v7a folder) 178 | → armeabi 179 | → (Like inside armeabi-v7a folder) 180 | → arm64-v8a 181 | → (Like inside armeabi-v7a folder) 182 | 183 | ``` 184 | 185 | # Resources that I used 186 | 1. https://github.com/wseemann/FFmpegMediaMetadataRetriever (forked from) 187 | 2. https://github.com/wseemann/FFmpegMediaPlayer (old version of 1-st point) 188 | 3. https://github.com/wseemann/ServeStream 189 | 4. https://github.com/cine-io/android-ffmpeg-with-rtmp (It was my first target to compile, but this script compile only to armeabi-v7a) 190 | 5. https://github.com/WritingMinds/ffmpeg-android-java (A wrapper around FFmpeg(.so) and calling FFmpeg through the terminal) 191 | 6. https://github.com/WritingMinds/ffmpeg-android (Another one compilation script for FFmpeg with a lot of additional libs) 192 | 7. https://github.com/OnlyInAmerica/FFmpeg-Android (deprecated, but useful) 193 | 8. https://github.com/appunite/AndroidFFmpeg (a compilation script with sample) 194 | 9. https://github.com/havlenapetr/FFMpeg (A sample FFmpeg for android - wrapper for all FFmpeg classes) 195 | 196 | # P.S. 197 | The status of compilation - at begin of MAY 2017 with using NDK version r14b FFmpeg compilation fails for `x86_64, mips, arm64-v8a`, and OpenSSL fails for `x86_64`. 198 | As we all know for mass production **is enough** to have *armeabi-v7a* (the most polular architecture, other arm-based processors can work with it) and x86 (around 2 percent of all android devices). So I don't stuck with other architectures, and I guess that using older one version of NDK, for example, one of NDK r12 can fix the problem for some architectures. 199 | 200 | **Summary** 201 | 202 | As `build.sh` script I *can*: 203 | - FFmpeg for armeabi, armeabi-v7a, x86; 204 | - OpenSSL for armeabi, armeabi-v7a, arm64-v8a, mips, x86; 205 | 206 | As `build.sh` script I *can't* (but I tried): 207 | - FFmpeg for arm64-v8a, x86_64, mips; 208 | - OpenSSL for x86_64 and other; 209 | 210 | # License FFmpeg 211 | 212 | Check [LICENSE.GPLv3](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html) and make sure to follow the licensing terms and conditions of the project and the software used to build the project. 213 | 214 | # License OpenSSL 215 | 216 | Check [license](https://www.openssl.org/source/license.html) and make sure to follow the licensing terms and conditions of the project and the software used to build the project. 217 | 218 | # License 219 | 220 | ``` 221 | MIT License 222 | 223 | Copyright (c) 2017 Victor Ponomarenko 224 | 225 | Permission is hereby granted, free of charge, to any person obtaining a copy 226 | of this software and associated documentation files (the "Software"), to deal 227 | in the Software without restriction, including without limitation the rights 228 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 229 | copies of the Software, and to permit persons to whom the Software is 230 | furnished to do so, subject to the following conditions: 231 | 232 | The above copyright notice and this permission notice shall be included in all 233 | copies or substantial portions of the Software. 234 | 235 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 236 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 237 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 238 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 239 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 240 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 241 | SOFTWARE. 242 | ``` 243 | 244 | -------------------------------------------------------------------------------- /_old_build_ffmpeg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Set your own NDK here 6 | NDK=~/Android/Sdk/ndk-bundle 7 | 8 | #export NDK=`grep ndk.dir $PROPS | cut -d'=' -f2` 9 | 10 | if [ "$NDK" = "" ] || [ ! -d $NDK ]; then 11 | echo "NDK variable not set or path to NDK is invalid, exiting..." 12 | exit 1 13 | fi 14 | 15 | export TARGET=$1 16 | 17 | ARM_PLATFORM=$NDK/platforms/android-9/arch-arm/ 18 | ARM_PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 19 | 20 | ARM64_PLATFORM=$NDK/platforms/android-21/arch-arm64/ 21 | ARM64_PREBUILT=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 22 | 23 | X86_PLATFORM=$NDK/platforms/android-9/arch-x86/ 24 | X86_PREBUILT=$NDK/toolchains/x86-4.9/prebuilt/linux-x86_64 25 | 26 | X86_64_PLATFORM=$NDK/platforms/android-21/arch-x86_64/ 27 | X86_64_PREBUILT=$NDK/toolchains/x86_64-4.9/prebuilt/linux-x86_64 28 | 29 | MIPS_PLATFORM=$NDK/platforms/android-9/arch-mips/ 30 | MIPS_PREBUILT=$NDK/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86_64 31 | 32 | BUILD_DIR=`pwd`/libs 33 | OPENSSL_BUILD_DIR=${BUILD_DIR}/lib 34 | OPENSSL_SRC_DIR=`pwd`/src/openssl-android 35 | 36 | FFMPEG_VERSION="3.3" 37 | #FFMPEG_VERSION="3.0.1" 38 | 39 | if [ ! -e "ffmpeg-${FFMPEG_VERSION}.tar.bz2" ]; then 40 | echo "Downloading ffmpeg-${FFMPEG_VERSION}.tar.bz2" 41 | curl -LO http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 42 | else 43 | echo "Using ffmpeg-${FFMPEG_VERSION}.tar.bz2" 44 | fi 45 | 46 | tar -xvf ffmpeg-${FFMPEG_VERSION}.tar.bz2 47 | 48 | for i in `find diffs -type f`; do 49 | (cd ffmpeg-${FFMPEG_VERSION} && patch -p1 < ../$i) 50 | done 51 | 52 | ###################################################### 53 | ############### START die ############################ 54 | ###################################################### 55 | 56 | #-- error function 57 | function die { 58 | code=-1 59 | err="Unknown error!" 60 | test "$1" && err=$1 61 | cd ${top_root} 62 | echo "$err" 63 | echo "Check the build log: ${build_log}" 64 | exit -1 65 | } 66 | 67 | ###################################################### 68 | ############### START die ############################ 69 | ###################################################### 70 | 71 | ###################################################### 72 | ############### START build_one ###################### 73 | ###################################################### 74 | 75 | function build_one 76 | { 77 | if [ $ARCH == "arm" ] 78 | then 79 | PLATFORM=$ARM_PLATFORM 80 | PREBUILT=$ARM_PREBUILT 81 | HOST=arm-linux-androideabi 82 | #added by alexvas 83 | elif [ $ARCH == "arm64" ] 84 | then 85 | PLATFORM=$ARM64_PLATFORM 86 | PREBUILT=$ARM64_PREBUILT 87 | HOST=aarch64-linux-android 88 | elif [ $ARCH == "mips" ] 89 | then 90 | PLATFORM=$MIPS_PLATFORM 91 | PREBUILT=$MIPS_PREBUILT 92 | HOST=mipsel-linux-android 93 | #alexvas 94 | elif [ $ARCH == "x86_64" ] 95 | then 96 | PLATFORM=$X86_64_PLATFORM 97 | PREBUILT=$X86_64_PREBUILT 98 | HOST=x86_64-linux-android 99 | else 100 | PLATFORM=$X86_PLATFORM 101 | PREBUILT=$X86_PREBUILT 102 | HOST=i686-linux-android 103 | fi 104 | 105 | top_root=$(pwd) 106 | patch_root=${top_root}/patches 107 | configuration_log=${top_root}/configuration.log 108 | 109 | # patch the configure script to use an Android-friendly versioning scheme 110 | patch -u configure ${patch_root}/ffmpeg-configure.patch || die "Couldn't patch ffmpeg configure script!" 111 | 112 | export PKG_CONFIG_PATH="${OPENSSL_SRC_DIR}" 113 | echo "pkg-config path = ${PKG_CONFIG_PATH}" 114 | 115 | openssl_addi_ldflags="" 116 | 117 | # --prefix=$PREFIX \ 118 | 119 | #--incdir=$BUILD_DIR/include \ 120 | #--libdir=$BUILD_DIR/lib/$CPU \ 121 | 122 | # --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 " \ 123 | # --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \ 124 | 125 | # TODO Adding aac decoder brings "libnative.so has text relocations. This is wasting memory and prevents security hardening. Please fix." message in Android. 126 | pushd ffmpeg-$FFMPEG_VERSION 127 | ./configure \ 128 | --target-os=linux \ 129 | --incdir=$BUILD_DIR/include/$TARGET \ 130 | --libdir=$BUILD_DIR/lib/$TARGET \ 131 | --enable-cross-compile \ 132 | --extra-libs="-lgcc" \ 133 | --arch=$ARCH \ 134 | --cc=$PREBUILT/bin/$HOST-gcc \ 135 | --cross-prefix=$PREBUILT/bin/$HOST- \ 136 | --nm=$PREBUILT/bin/$HOST-nm \ 137 | --sysroot=$PLATFORM \ 138 | --extra-cflags="$OPTIMIZE_CFLAGS " \ 139 | --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog -L${OPENSSL_BUILD_DIR}/${ABI} ${openssl_addi_ldflags}" \ 140 | --disable-static \ 141 | --disable-ffplay \ 142 | --disable-ffmpeg \ 143 | --disable-ffprobe \ 144 | --disable-ffserver \ 145 | --disable-doc \ 146 | --disable-postproc \ 147 | --disable-gpl \ 148 | --disable-encoders \ 149 | --disable-muxers \ 150 | --disable-bsfs \ 151 | --disable-protocols \ 152 | --disable-indevs \ 153 | --disable-outdevs \ 154 | --disable-devices \ 155 | --enable-shared \ 156 | --enable-small \ 157 | --enable-openssl \ 158 | --enable-encoder=png \ 159 | --enable-protocol=file,ftp,http,https,httpproxy,hls,mmsh,mmst,pipe,rtmp,rtmps,rtmpt,rtmpts,rtp,sctp,srtp,tcp,udp \ 160 | --pkg-config=$(which pkg-config) \ 161 | $ADDITIONAL_CONFIGURE_FLAG >> ${configuration_log} 2>&1 || die "Couldn't configure ffmpeg!" 162 | 163 | make clean 164 | make -j8 install V=1 165 | $PREBUILT/bin/$HOST-ar d libavcodec/libavcodec.a inverse.o 166 | #$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 167 | popd 168 | 169 | # copy the binaries 170 | mkdir -p $PREFIX 171 | cp -r $BUILD_DIR/$TARGET/* $PREFIX 172 | } 173 | 174 | ###################################################### 175 | ############### END build_one ######################## 176 | ###################################################### 177 | 178 | if [ $TARGET == 'arm-v5te' ]; then 179 | #arm v5te 180 | ABI=armeabi 181 | CPU=armv5te 182 | ARCH=arm 183 | OPTIMIZE_CFLAGS="-marm -march=$CPU" 184 | PREFIX=$BUILD_DIR/$CPU 185 | ADDITIONAL_CONFIGURE_FLAG= 186 | build_one 187 | fi 188 | 189 | if [ $TARGET == 'arm-v6' ]; then 190 | #arm v6 191 | ABI=armeabi 192 | CPU=armv6 193 | ARCH=arm 194 | OPTIMIZE_CFLAGS="-marm -march=$CPU" 195 | PREFIX=`pwd`/ffmpeg-android/$CPU 196 | ADDITIONAL_CONFIGURE_FLAG= 197 | build_one 198 | fi 199 | 200 | if [ $TARGET == 'arm-v7vfpv3' ]; then 201 | #arm v7vfpv3 202 | ABI=armeabi-v7a 203 | CPU=armv7-a 204 | ARCH=arm 205 | OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU " 206 | PREFIX=$BUILD_DIR/$CPU 207 | ADDITIONAL_CONFIGURE_FLAG= 208 | build_one 209 | fi 210 | 211 | if [ $TARGET == 'arm-v7vfp' ]; then 212 | #arm v7vfp 213 | ABI=armeabi-v7a 214 | CPU=armv7-a 215 | ARCH=arm 216 | OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU " 217 | PREFIX=`pwd`/ffmpeg-android/$CPU-vfp 218 | ADDITIONAL_CONFIGURE_FLAG= 219 | build_one 220 | fi 221 | 222 | if [ $TARGET == 'arm-v7n' ]; then 223 | #arm v7n 224 | ABI=armeabi-v7a 225 | CPU=armv7-a 226 | ARCH=arm 227 | OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8" 228 | PREFIX=`pwd`/ffmpeg-android/$CPU 229 | ADDITIONAL_CONFIGURE_FLAG=--enable-neon 230 | build_one 231 | fi 232 | 233 | if [ $TARGET == 'arm-v6+vfp' ]; then 234 | #arm v6+vfp 235 | ABI=armeabi 236 | CPU=armv6 237 | ARCH=arm 238 | OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU" 239 | PREFIX=`pwd`/ffmpeg-android/${CPU}_vfp 240 | ADDITIONAL_CONFIGURE_FLAG= 241 | build_one 242 | fi 243 | 244 | if [ $TARGET == 'arm64-v8a' ]; then 245 | #arm64-v8a 246 | ABI=arm64-v8a 247 | CPU=arm64-v8a 248 | ARCH=arm64 249 | OPTIMIZE_CFLAGS= 250 | PREFIX=$BUILD_DIR/$CPU 251 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/arm64-v8a 252 | ADDITIONAL_CONFIGURE_FLAG= 253 | build_one 254 | fi 255 | 256 | if [ $TARGET == 'x86_64' ]; then 257 | #x86_64 258 | ABI=x86_64 259 | CPU=x86_64 260 | ARCH=x86_64 261 | OPTIMIZE_CFLAGS="-fomit-frame-pointer" 262 | #PREFIX=$BUILD_DIR/$CPU 263 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/x86_64 264 | ADDITIONAL_CONFIGURE_FLAG= 265 | build_one 266 | fi 267 | 268 | if [ $TARGET == 'i686' ]; then 269 | #x86 270 | ABI=x86 271 | CPU=i686 272 | ARCH=i686 273 | OPTIMIZE_CFLAGS="-fomit-frame-pointer" 274 | #PREFIX=$BUILD_DIR/$CPU 275 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/x86 276 | ADDITIONAL_CONFIGURE_FLAG= 277 | build_one 278 | fi 279 | 280 | if [ $TARGET == 'mips' ]; then 281 | #mips 282 | ABI=mips 283 | CPU=mips 284 | ARCH=mips 285 | OPTIMIZE_CFLAGS="-std=c99 -O3 -Wall -pipe -fpic -fasm \ 286 | -ftree-vectorize -ffunction-sections -funwind-tables -fomit-frame-pointer -funswitch-loops \ 287 | -finline-limit=300 -finline-functions -fpredictive-commoning -fgcse-after-reload -fipa-cp-clone \ 288 | -Wno-psabi -Wa,--noexecstack" 289 | #PREFIX=$BUILD_DIR/$CPU 290 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/mips 291 | ADDITIONAL_CONFIGURE_FLAG= 292 | build_one 293 | fi 294 | 295 | if [ $TARGET == 'armv7-a' ]; then 296 | #arm armv7-a 297 | ABI=armeabi-v7a 298 | CPU=armv7-a 299 | ARCH=arm 300 | OPTIMIZE_CFLAGS="-mfloat-abi=softfp -marm -march=$CPU " 301 | #PREFIX=`pwd`/ffmpeg-android/$CPU 302 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/armeabi-v7a 303 | ADDITIONAL_CONFIGURE_FLAG= 304 | build_one 305 | fi 306 | 307 | if [ $TARGET == 'arm' ]; then 308 | #arm arm 309 | ABI=armeabi 310 | CPU=arm 311 | ARCH=arm 312 | OPTIMIZE_CFLAGS="" 313 | #PREFIX=`pwd`/ffmpeg-android/$CPU 314 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/armeabi 315 | ADDITIONAL_CONFIGURE_FLAG= 316 | build_one 317 | fi 318 | -------------------------------------------------------------------------------- /Setenv-android.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Cross-compile environment for Android on ARMv7 and x86 3 | # 4 | # Contents licensed under the terms of the OpenSSL license 5 | # http://www.openssl.org/source/license.html 6 | # 7 | # See http://wiki.openssl.org/index.php/FIPS_Library_and_Android 8 | # and http://wiki.openssl.org/index.php/Android 9 | 10 | if [ $# -ne 3 ]; 11 | then echo "illegal number of parameters" 12 | echo "usage: Setenv-android.sh ANDROID_NDK_ROOT ANDROID_EABI ANDROID_ARCH" 13 | exit 1 14 | fi 15 | 16 | export ANDROID_NDK_ROOT=$1 17 | export ANDROID_EABI=$2 18 | export ANDROID_ARCH=$3 19 | 20 | ##################################################################### 21 | 22 | # Set ANDROID_NDK_ROOT to you NDK location. For example, 23 | # /opt/android-ndk-r8e or /opt/android-ndk-r9. This can be done in a 24 | # login script. If ANDROID_NDK_ROOT is not specified, the script will 25 | # try to pick it up with the value of _ANDROID_NDK_ROOT below. If 26 | # ANDROID_NDK_ROOT is set, then the value is ignored. 27 | # _ANDROID_NDK="android-ndk-r8e" 28 | _ANDROID_NDK="android-ndk-r9" 29 | # _ANDROID_NDK="android-ndk-r10" 30 | 31 | # Set _ANDROID_EABI to the EABI you want to use. You can find the 32 | # list in $ANDROID_NDK_ROOT/toolchains. This value is always used. 33 | # _ANDROID_EABI="x86-4.6" 34 | # _ANDROID_EABI="arm-linux-androideabi-4.6" 35 | _ANDROID_EABI=$ANDROID_EABI 36 | #"arm-linux-androideabi-4.8" 37 | 38 | # Set _ANDROID_ARCH to the architecture you are building for. 39 | # This value is always used. 40 | # _ANDROID_ARCH=arch-x86 41 | _ANDROID_ARCH=$ANDROID_ARCH 42 | 43 | # Set _ANDROID_API to the API you want to use. You should set it 44 | # to one of: android-14, android-9, android-8, android-14, android-5 45 | # android-4, or android-3. You can't set it to the latest (for 46 | # example, API-17) because the NDK does not supply the platform. At 47 | # Android 5.0, there will likely be another platform added (android-22?). 48 | # This value is always used. 49 | # _ANDROID_API="android-14" 50 | _ANDROID_API="android-9" 51 | # _ANDROID_API="android-19" 52 | 53 | ##################################################################### 54 | 55 | # If the user did not specify the NDK location, try and pick it up. 56 | # We expect something like ANDROID_NDK_ROOT=/opt/android-ndk-r8e 57 | # or ANDROID_NDK_ROOT=/usr/local/android-ndk-r8e. 58 | 59 | if [ -z "$ANDROID_NDK_ROOT" ]; then 60 | 61 | _ANDROID_NDK_ROOT="" 62 | if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/usr/local/$_ANDROID_NDK" ]; then 63 | _ANDROID_NDK_ROOT="/usr/local/$_ANDROID_NDK" 64 | fi 65 | 66 | if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "/opt/$_ANDROID_NDK" ]; then 67 | _ANDROID_NDK_ROOT="/opt/$_ANDROID_NDK" 68 | fi 69 | 70 | if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$HOME/$_ANDROID_NDK" ]; then 71 | _ANDROID_NDK_ROOT="$HOME/$_ANDROID_NDK" 72 | fi 73 | 74 | if [ -z "$_ANDROID_NDK_ROOT" ] && [ -d "$PWD/$_ANDROID_NDK" ]; then 75 | _ANDROID_NDK_ROOT="$PWD/$_ANDROID_NDK" 76 | fi 77 | 78 | # If a path was set, then export it 79 | if [ ! -z "$_ANDROID_NDK_ROOT" ] && [ -d "$_ANDROID_NDK_ROOT" ]; then 80 | export ANDROID_NDK_ROOT="$_ANDROID_NDK_ROOT" 81 | fi 82 | fi 83 | 84 | # Error checking 85 | # ANDROID_NDK_ROOT should always be set by the user (even when not running this script) 86 | # http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77 87 | if [ -z "$ANDROID_NDK_ROOT" ] || [ ! -d "$ANDROID_NDK_ROOT" ]; then 88 | echo "Error: ANDROID_NDK_ROOT is not a valid path. Please edit this script." 89 | # echo "$ANDROID_NDK_ROOT" 90 | # exit 1 91 | fi 92 | 93 | # Error checking 94 | if [ ! -d "$ANDROID_NDK_ROOT/toolchains" ]; then 95 | echo "Error: ANDROID_NDK_ROOT/toolchains is not a valid path. Please edit this script." 96 | # echo "$ANDROID_NDK_ROOT/toolchains" 97 | # exit 1 98 | fi 99 | 100 | # Error checking 101 | if [ ! -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" ]; then 102 | echo "Error: ANDROID_EABI is not a valid path. Please edit this script." 103 | # echo "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI" 104 | # exit 1 105 | fi 106 | 107 | ##################################################################### 108 | 109 | # Based on ANDROID_NDK_ROOT, try and pick up the required toolchain. We expect something like: 110 | # /opt/android-ndk-r83/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin 111 | # Once we locate the toolchain, we add it to the PATH. Note: this is the 'hard way' of 112 | # doing things according to the NDK documentation for Ice Cream Sandwich. 113 | # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html 114 | 115 | ANDROID_TOOLCHAIN="" 116 | for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86" 117 | do 118 | if [ -d "$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" ]; then 119 | ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/$_ANDROID_EABI/prebuilt/$host/bin" 120 | break 121 | fi 122 | done 123 | 124 | # Error checking 125 | if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; then 126 | echo "Error: ANDROID_TOOLCHAIN is not valid. Please edit this script." 127 | # echo "$ANDROID_TOOLCHAIN" 128 | # exit 1 129 | fi 130 | 131 | case $_ANDROID_ARCH in 132 | arch-arm) 133 | ANDROID_TOOLS="arm-linux-androideabi-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld" 134 | _ANDROID_API="android-9" 135 | ;; 136 | arch-x86) 137 | ANDROID_TOOLS="i686-linux-android-gcc i686-linux-android-ranlib i686-linux-android-ld" 138 | _ANDROID_API="android-9" 139 | ;; 140 | arch-mips) 141 | ANDROID_TOOLS="mipsel-linux-android-gcc mipsel-linux-android-ranlib mipsel-linux-android-ld" 142 | _ANDROID_API="android-9" 143 | ;; 144 | arch-x86_64) 145 | ANDROID_TOOLS="x86_64-linux-android-gcc x86_64-linux-android-ranlib x86_64-linux-android-ld" 146 | _ANDROID_API="android-21" 147 | ;; 148 | arch-arm64) 149 | ANDROID_TOOLS="aarch64-linux-android-gcc aarch64-linux-android-ranlib aarch64-linux-android-ld" 150 | _ANDROID_API="android-21" 151 | ;; 152 | *) 153 | echo "ERROR ERROR ERROR" 154 | ;; 155 | esac 156 | 157 | for tool in $ANDROID_TOOLS 158 | do 159 | # Error checking 160 | if [ ! -e "$ANDROID_TOOLCHAIN/$tool" ]; then 161 | echo "Error: Failed to find $tool. Please edit this script." 162 | # echo "$ANDROID_TOOLCHAIN/$tool" 163 | # exit 1 164 | fi 165 | done 166 | 167 | # Only modify/export PATH if ANDROID_TOOLCHAIN good 168 | if [ ! -z "$ANDROID_TOOLCHAIN" ]; then 169 | export ANDROID_TOOLCHAIN="$ANDROID_TOOLCHAIN" 170 | export PATH="$ANDROID_TOOLCHAIN":"$PATH" 171 | fi 172 | 173 | ##################################################################### 174 | 175 | # For the Android SYSROOT. Can be used on the command line with --sysroot 176 | # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html 177 | export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH" 178 | export CROSS_SYSROOT="$ANDROID_SYSROOT" 179 | export NDK_SYSROOT="$ANDROID_SYSROOT" 180 | 181 | # Error checking 182 | if [ -z "$ANDROID_SYSROOT" ] || [ ! -d "$ANDROID_SYSROOT" ]; then 183 | echo "Error: ANDROID_SYSROOT is not valid. Please edit this script." 184 | # echo "$ANDROID_SYSROOT" 185 | # exit 1 186 | fi 187 | 188 | ##################################################################### 189 | 190 | # If the user did not specify the FIPS_SIG location, try and pick it up 191 | # If the user specified a bad location, then try and pick it up too. 192 | if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then 193 | 194 | # Try and locate it 195 | _FIPS_SIG="" 196 | if [ -d "/usr/local/ssl/$_ANDROID_API" ]; then 197 | _FIPS_SIG=`find "/usr/local/ssl/$_ANDROID_API" -name incore` 198 | fi 199 | 200 | if [ ! -e "$_FIPS_SIG" ]; then 201 | _FIPS_SIG=`find $PWD -name incore` 202 | fi 203 | 204 | # If a path was set, then export it 205 | if [ ! -z "$_FIPS_SIG" ] && [ -e "$_FIPS_SIG" ]; then 206 | export FIPS_SIG="$_FIPS_SIG" 207 | fi 208 | fi 209 | 210 | # Error checking. Its OK to ignore this if you are *not* building for FIPS 211 | if [ -z "$FIPS_SIG" ] || [ ! -e "$FIPS_SIG" ]; then 212 | echo "Error: FIPS_SIG does not specify incore module. Please edit this script." 213 | # echo "$FIPS_SIG" 214 | # exit 1 215 | fi 216 | 217 | ##################################################################### 218 | 219 | # Most of these should be OK (MACHINE, SYSTEM, ARCH). RELEASE is ignored. 220 | export MACHINE=armv7 221 | export RELEASE=2.6.37 222 | export SYSTEM=android 223 | export ARCH=arm 224 | export CROSS_COMPILE="arm-linux-androideabi-" 225 | 226 | if [ "$_ANDROID_ARCH" == "arch-x86" ]; then 227 | export MACHINE=i686 228 | export RELEASE=2.6.37 229 | export SYSTEM=android 230 | export ARCH=x86 231 | export CROSS_COMPILE="i686-linux-android-" 232 | fi 233 | 234 | if [ "$_ANDROID_ARCH" == "arch-mips" ]; then 235 | export MACHINE=mips 236 | export RELEASE=2.6.37 237 | export SYSTEM=android 238 | export ARCH=mips 239 | export CROSS_COMPILE="mipsel-linux-android-" 240 | fi 241 | 242 | if [ "$_ANDROID_ARCH" == "arch-x86_64" ]; then 243 | export MACHINE=x86_64 244 | export RELEASE=2.6.37 245 | export SYSTEM=android 246 | export ARCH=x86_64 247 | export CROSS_COMPILE="x86_64-linux-android-" 248 | fi 249 | 250 | if [ "$_ANDROID_ARCH" == "arch-arm64" ]; then 251 | export MACHINE=arm64-v8a 252 | export RELEASE=2.6.37 253 | export SYSTEM=android 254 | export ARCH=arm64 255 | export CROSS_COMPILE="aarch64-linux-android-" 256 | fi 257 | 258 | # For the Android toolchain 259 | # https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html 260 | export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH" 261 | export SYSROOT="$ANDROID_SYSROOT" 262 | export NDK_SYSROOT="$ANDROID_SYSROOT" 263 | export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT" 264 | export ANDROID_API="$_ANDROID_API" 265 | 266 | # CROSS_COMPILE and ANDROID_DEV are DFW (Don't Fiddle With). Its used by OpenSSL build system. 267 | # export CROSS_COMPILE="arm-linux-androideabi-" 268 | export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr" 269 | export HOSTCC=gcc 270 | 271 | VERBOSE=1 272 | if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; then 273 | echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT" 274 | echo "ANDROID_ARCH: $_ANDROID_ARCH" 275 | echo "ANDROID_EABI: $_ANDROID_EABI" 276 | echo "ANDROID_API: $ANDROID_API" 277 | echo "ANDROID_SYSROOT: $ANDROID_SYSROOT" 278 | echo "ANDROID_TOOLCHAIN: $ANDROID_TOOLCHAIN" 279 | echo "FIPS_SIG: $FIPS_SIG" 280 | echo "CROSS_COMPILE: $CROSS_COMPILE" 281 | echo "ANDROID_DEV: $ANDROID_DEV" 282 | fi 283 | -------------------------------------------------------------------------------- /_build_ffmpeg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Set your own NDK here 6 | export NDK=~/Android/Sdk/ndk-bundle 7 | 8 | #export NDK=`grep ndk.dir $PROPS | cut -d'=' -f2` 9 | 10 | if [ "$NDK" = "" ] || [ ! -d $NDK ]; then 11 | echo "NDK variable not set or path to NDK is invalid, exiting..." 12 | exit 1 13 | fi 14 | 15 | export TARGET=$1 16 | 17 | ARM_PLATFORM=$NDK/platforms/android-9/arch-arm/ 18 | ARM_PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 19 | 20 | ARM64_PLATFORM=$NDK/platforms/android-21/arch-arm64/ 21 | ARM64_PREBUILT=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 22 | 23 | X86_PLATFORM=$NDK/platforms/android-9/arch-x86/ 24 | X86_PREBUILT=$NDK/toolchains/x86-4.9/prebuilt/linux-x86_64 25 | 26 | X86_64_PLATFORM=$NDK/platforms/android-21/arch-x86_64/ 27 | X86_64_PREBUILT=$NDK/toolchains/x86_64-4.9/prebuilt/linux-x86_64 28 | 29 | MIPS_PLATFORM=$NDK/platforms/android-9/arch-mips/ 30 | MIPS_PREBUILT=$NDK/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86_64 31 | 32 | FFMPEG_VERSION="3.3" 33 | 34 | TOP_ROOT=$PWD 35 | SOURCE=${TOP_ROOT}/src 36 | FFMPEG_SOURCE=$SOURCE/ffmpeg-android 37 | BUILD_DIR=`pwd`/libs/ffmpeg 38 | mkdir -p ${BUILD_DIR} 39 | mkdir -p ${SOURCE} 40 | mkdir -p ${FFMPEG_SOURCE} 41 | 42 | cd $SOURCE 43 | if [ ! -e "ffmpeg-${FFMPEG_VERSION}.tar.bz2" ]; then 44 | echo "Downloading ffmpeg-${FFMPEG_VERSION}.tar.bz2" 45 | curl -LO http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 46 | tar -xvf ffmpeg-${FFMPEG_VERSION}.tar.bz2 -C $FFMPEG_SOURCE --strip-components=1 47 | cd $FFMPEG_SOURCE 48 | PATCH_ROOT=${TOP_ROOT}/patches 49 | # patch the configure script to use an Android-friendly versioning scheme 50 | patch -u configure ${PATCH_ROOT}/patch_fix_ffmpeg_lib_name.txt 51 | else 52 | echo "Using ffmpeg-${FFMPEG_VERSION}.tar.bz2" 53 | fi 54 | 55 | #for i in `find diffs -type f`; do 56 | # (cd ffmpeg-${FFMPEG_VERSION} && patch -p1 < ../$i) 57 | #done 58 | 59 | ###################################################### 60 | ############### START die ############################ 61 | ###################################################### 62 | 63 | #-- error function 64 | function die { 65 | code=-1 66 | err="Unknown error!" 67 | test "$1" && err=$1 68 | cd ${top_root} 69 | echo "$err" 70 | echo "Check the build log: ${build_log}" 71 | exit -1 72 | } 73 | 74 | ###################################################### 75 | ############### END die ############################ 76 | ###################################################### 77 | 78 | ###################################################### 79 | ############### START build_one ###################### 80 | ###################################################### 81 | 82 | function build_one 83 | { 84 | OPENSSL_DIR=$TOP_ROOT/libs/openssl 85 | OPENSSL_BUILD_DIR=$OPENSSL_DIR/lib/$ABI 86 | OPENSSL_INCLUDE_DIR=$OPENSSL_DIR/include/$ABI 87 | OPENSSL_SRC_DIR=$SOURCE/openssl-android 88 | 89 | SSL_EXTRA_LDFLAGS="-L$OPENSSL_BUILD_DIR" 90 | SSL_EXTRA_CFLAGS="-I$OPENSSL_INCLUDE_DIR" 91 | 92 | echo $SSL_EXTRA_LDFLAGS 93 | echo $SSL_EXTRA_CFLAGS 94 | 95 | if [ $ARCH == "arm" ] 96 | then 97 | PLATFORM=$ARM_PLATFORM 98 | PREBUILT=$ARM_PREBUILT 99 | HOST=arm-linux-androideabi 100 | #added by alexvas 101 | elif [ $ARCH == "arm64" ] 102 | then 103 | PLATFORM=$ARM64_PLATFORM 104 | PREBUILT=$ARM64_PREBUILT 105 | HOST=aarch64-linux-android 106 | elif [ $ARCH == "mips" ] 107 | then 108 | PLATFORM=$MIPS_PLATFORM 109 | PREBUILT=$MIPS_PREBUILT 110 | HOST=mipsel-linux-android 111 | #alexvas 112 | elif [ $ARCH == "x86_64" ] 113 | then 114 | PLATFORM=$X86_64_PLATFORM 115 | PREBUILT=$X86_64_PREBUILT 116 | HOST=x86_64-linux-android 117 | else 118 | PLATFORM=$X86_PLATFORM 119 | PREBUILT=$X86_PREBUILT 120 | HOST=i686-linux-android 121 | fi 122 | 123 | pushd $FFMPEG_SOURCE 124 | 125 | #export PKG_CONFIG_PATH="${TOP_ROOT}/src/openssl-android" 126 | export ABI="${ABI}" 127 | openssl_addi_ldflags="" 128 | #echo "pkg-config path = '${PKG_CONFIG_PATH}'" 129 | #echo "openssl compile ldflag = '${OPENSSL_BUILD_DIR} ${openssl_addi_ldflags}'" 130 | 131 | # --prefix=$PREFIX \ 132 | 133 | #--incdir=$BUILD_DIR/include \ 134 | #--libdir=$BUILD_DIR/lib/$CPU \ 135 | 136 | # --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 " \ 137 | # --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \ 138 | 139 | # TODO Adding aac decoder brings "libnative.so has text relocations. This is wasting memory and prevents security hardening. Please fix." message in Android. 140 | 141 | INCLUDE_DIR=$BUILD_DIR/include/$ABI 142 | BINARIES_DIR=$BUILD_DIR/binaries/$ABI 143 | 144 | ./configure \ 145 | --target-os=linux \ 146 | --incdir=$INCLUDE_DIR \ 147 | --libdir=$BINARIES_DIR \ 148 | --enable-cross-compile \ 149 | --extra-libs="-lgcc" \ 150 | --arch=$ARCH \ 151 | --cc=$PREBUILT/bin/$HOST-gcc \ 152 | --cross-prefix=$PREBUILT/bin/$HOST- \ 153 | --nm=$PREBUILT/bin/$HOST-nm \ 154 | --sysroot=$PLATFORM \ 155 | --extra-cflags="$OPTIMIZE_CFLAGS $SSL_EXTRA_CFLAGS" \ 156 | --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog -lz $SSL_EXTRA_LDFLAGS -DOPENSSL_API_COMPAT=0x00908000L" \ 157 | --disable-static \ 158 | --disable-ffplay \ 159 | --disable-ffmpeg \ 160 | --disable-ffprobe \ 161 | --disable-ffserver \ 162 | --disable-doc \ 163 | --disable-symver \ 164 | --disable-postproc \ 165 | --disable-encoders \ 166 | --disable-muxers \ 167 | --disable-bsfs \ 168 | --disable-indevs \ 169 | --disable-outdevs \ 170 | --disable-devices \ 171 | --disable-asm \ 172 | --enable-shared \ 173 | --enable-small \ 174 | --enable-encoder=png \ 175 | --enable-openssl \ 176 | --enable-protocol=file,ftp,http,https,httpproxy,hls,mmsh,mmst,pipe,rtmp,rtmps,rtmpt,rtmpts,rtp,sctp,srtp,tcp,udp \ 177 | $ADDITIONAL_CONFIGURE_FLAG || die "Couldn't configure ffmpeg!" 178 | 179 | make clean 180 | make -j8 install V=1 181 | $PREBUILT/bin/$HOST-ar d libavcodec/libavcodec.a inverse.o 182 | 183 | #$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 184 | popd 185 | 186 | # copy the binaries 187 | LIB_DIR=$BUILD_DIR/lib 188 | LIBAVCODEC_DIR=$LIB_DIR/libavcodec/$ABI 189 | LIBAVDEVICE_DIR=$LIB_DIR/libavdevice/$ABI 190 | LIBAVFILTER_DIR=$LIB_DIR/libavfilter/$ABI 191 | LIBAVFORMAT_DIR=$LIB_DIR/libavformat/$ABI 192 | LIBAVUTIL_DIR=$LIB_DIR/libavutil/$ABI 193 | LIBSWRESAMPLE_DIR=$LIB_DIR/libswresample/$ABI 194 | LIBSWSCALE_DIR=$LIB_DIR/libswscale/$ABI 195 | mkdir -p ${LIBAVCODEC_DIR} 196 | mkdir -p ${LIBAVDEVICE_DIR} 197 | mkdir -p ${LIBAVFILTER_DIR} 198 | mkdir -p ${LIBAVFORMAT_DIR} 199 | mkdir -p ${LIBAVUTIL_DIR} 200 | mkdir -p ${LIBSWRESAMPLE_DIR} 201 | mkdir -p ${LIBSWSCALE_DIR} 202 | cp -r $BINARIES_DIR/libavcodec* ${LIBAVCODEC_DIR}/. 203 | cp -r $BINARIES_DIR/libavdevice* ${LIBAVDEVICE_DIR}/. 204 | cp -r $BINARIES_DIR/libavfilter* ${LIBAVFILTER_DIR}/. 205 | cp -r $BINARIES_DIR/libavformat* ${LIBAVFORMAT_DIR}/. 206 | cp -r $BINARIES_DIR/libavutil* ${LIBAVUTIL_DIR}/. 207 | cp -r $BINARIES_DIR/libswresample* ${LIBSWRESAMPLE_DIR}/. 208 | cp -r $BINARIES_DIR/libswscale* ${LIBSWSCALE_DIR}/. 209 | #rsync -a --include '*/' --include 'libavcoded' --exclude '*' BUILD_DIR/$ABI/binaries ${dist_lib_root}/ 210 | # copy the executables 211 | #cp -r ${src_root}/openssl-android/libs/armeabi/openssl ${dist_bin_root}/. # work only for one abi folder 212 | #rsync -a --include '*/openssl' --exclude '*.so' ${src_root}/openssl-android/libs/ ${dist_bin_root}/ 213 | #cp -r ${src_root}/openssl-android/libs/armeabi/ssltest ${dist_bin_root}/. # work only for one abi folder 214 | #rsync -a --include '*/ssltest' --exclude '*.so' ${src_root}/openssl-android/libs/ ${dist_bin_root}/ 215 | # copy the headers 216 | #cp -r ${src_root}/openssl-android/include/* ${dist_include_root}/. 217 | } 218 | 219 | ###################################################### 220 | ############### END build_one ######################## 221 | ###################################################### 222 | 223 | if [ $TARGET == 'arm-v5te' ]; then 224 | #arm v5te 225 | ABI=armeabi 226 | CPU=armv5te 227 | ARCH=arm 228 | OPTIMIZE_CFLAGS="-marm -march=$CPU" 229 | PREFIX=$BUILD_DIR/$CPU 230 | ADDITIONAL_CONFIGURE_FLAG= 231 | build_one 232 | fi 233 | 234 | if [ $TARGET == 'arm-v6' ]; then 235 | #arm v6 236 | ABI=armeabi 237 | CPU=armv6 238 | ARCH=arm 239 | OPTIMIZE_CFLAGS="-marm -march=$CPU" 240 | PREFIX=`pwd`/ffmpeg-android/$CPU 241 | ADDITIONAL_CONFIGURE_FLAG= 242 | build_one 243 | fi 244 | 245 | if [ $TARGET == 'arm-v7vfpv3' ]; then 246 | #arm v7vfpv3 247 | ABI=armeabi-v7a 248 | CPU=armv7-a 249 | ARCH=arm 250 | OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU " 251 | PREFIX=$BUILD_DIR/$CPU 252 | ADDITIONAL_CONFIGURE_FLAG= 253 | build_one 254 | fi 255 | 256 | if [ $TARGET == 'arm-v7vfp' ]; then 257 | #arm v7vfp 258 | ABI=armeabi-v7a 259 | CPU=armv7-a 260 | ARCH=arm 261 | OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU " 262 | PREFIX=`pwd`/ffmpeg-android/$CPU-vfp 263 | ADDITIONAL_CONFIGURE_FLAG= 264 | build_one 265 | fi 266 | 267 | if [ $TARGET == 'arm-v7n' ]; then 268 | #arm v7n 269 | ABI=armeabi-v7a 270 | CPU=armv7-a 271 | ARCH=arm 272 | OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8" 273 | PREFIX=`pwd`/ffmpeg-android/$CPU 274 | ADDITIONAL_CONFIGURE_FLAG=--enable-neon 275 | build_one 276 | fi 277 | 278 | if [ $TARGET == 'arm-v6+vfp' ]; then 279 | #arm v6+vfp 280 | ABI=armeabi 281 | CPU=armv6 282 | ARCH=arm 283 | OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU" 284 | PREFIX=`pwd`/ffmpeg-android/${CPU}_vfp 285 | ADDITIONAL_CONFIGURE_FLAG= 286 | build_one 287 | fi 288 | 289 | if [ $TARGET == 'arm64-v8a' ]; then 290 | #arm64-v8a 291 | ABI=arm64-v8a 292 | CPU=arm64-v8a 293 | ARCH=arm64 294 | OPTIMIZE_CFLAGS= 295 | PREFIX=$BUILD_DIR/$CPU 296 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/arm64-v8a 297 | ADDITIONAL_CONFIGURE_FLAG= 298 | build_one 299 | fi 300 | 301 | if [ $TARGET == 'x86_64' ]; then 302 | #x86_64 303 | ABI=x86_64 304 | CPU=x86_64 305 | ARCH=x86_64 306 | OPTIMIZE_CFLAGS="-fomit-frame-pointer" 307 | #PREFIX=$BUILD_DIR/$CPU 308 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/x86_64 309 | ADDITIONAL_CONFIGURE_FLAG= 310 | build_one 311 | fi 312 | 313 | if [ $TARGET == 'i686' ]; then 314 | #x86 315 | ABI=x86 316 | CPU=i686 317 | ARCH=i686 318 | OPTIMIZE_CFLAGS="-fomit-frame-pointer" 319 | #PREFIX=$BUILD_DIR/$CPU 320 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/x86 321 | ADDITIONAL_CONFIGURE_FLAG= 322 | build_one 323 | fi 324 | 325 | if [ $TARGET == 'mips' ]; then 326 | #mips 327 | ABI=mips 328 | CPU=mips 329 | ARCH=mips 330 | OPTIMIZE_CFLAGS="-std=c99 -O3 -Wall -pipe -fpic -fasm \ 331 | -ftree-vectorize -ffunction-sections -funwind-tables -fomit-frame-pointer -funswitch-loops \ 332 | -finline-limit=300 -finline-functions -fpredictive-commoning -fgcse-after-reload -fipa-cp-clone \ 333 | -Wno-psabi -Wa,--noexecstack" 334 | #PREFIX=$BUILD_DIR/$CPU 335 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/mips 336 | ADDITIONAL_CONFIGURE_FLAG= 337 | build_one 338 | fi 339 | 340 | if [ $TARGET == 'armv7-a' ]; then 341 | #arm armv7-a 342 | ABI=armeabi-v7a 343 | CPU=armv7-a 344 | ARCH=arm 345 | OPTIMIZE_CFLAGS="-mfloat-abi=softfp -marm -march=$CPU " 346 | #PREFIX=`pwd`/ffmpeg-android/$CPU 347 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/armeabi-v7a 348 | ADDITIONAL_CONFIGURE_FLAG= 349 | build_one 350 | fi 351 | 352 | if [ $TARGET == 'arm' ]; then 353 | #arm arm 354 | ABI=armeabi 355 | CPU=arm 356 | ARCH=arm 357 | OPTIMIZE_CFLAGS="" 358 | #PREFIX=`pwd`/ffmpeg-android/$CPU 359 | PREFIX=`pwd`/../jni/ffmpeg/ffmpeg/armeabi 360 | ADDITIONAL_CONFIGURE_FLAG= 361 | build_one 362 | fi 363 | --------------------------------------------------------------------------------