How to build ffmpeg for Android in Windows/Cygwin

Post date: Jan 01, 2015 8:28:50 PM

The following tutorial shows how to build ffmpeg for Android in Windows. It is based on the tutorial in [1], which is meant for unix system, and adjusts approriately for the Windows/Cygwin build platform.

1. Download ffmpeg, edit the configure file as follows

SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'

LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'

SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'

SLIB_INSTALL_LINKS='$(SLIBNAME)'

#: ${TMPDIR:=$TEMPDIR}

#: ${TMPDIR:=$TMP}

: ${TMPDIR:=C:/cygwin64/tmp}

2. Remove ^M in version.sh using the following command

cp configure version.sh.bak

tr -cd '\11\12\40-\176' <version.sh.bak >version.sh

3. Create an build_android.sh with the following content.

#!/bin/bash

NDK=C:/NVPACK/android-ndk-r9d/

SYSROOT=$NDK/platforms/android-9/arch-arm/

TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows

function build_one

{

./configure \

    --prefix=C:/NVPACK/android-ndk-r9d/sources/ffmpeg/android/arm \

    --enable-shared \

    --disable-static \

    --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

cp config.h config.h.bak

tr -cd '\11\12\40-\176' <config.h.bak >config.h

make clean

make

make install

}

CPU=arm

PREFIX=$(pwd)/android/$CPU

ADDI_CFLAGS="-marm"

build_one

4. Execute build_android.sh (after making it executable). The build will fail at various linking stages due to no support for Cygwin's symbolic link. This is fixed by removing the symbolic link, e.g. libavutil/libavutil.so and make a copy of the actual library, e.g. libavutil/libavutil-52.so, with the symlink name. Then type make to continue.

[1] http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/