Skip to content

Instantly share code, notes, and snippets.

@m1entus
Last active June 22, 2024 04:06
Show Gist options
  • Save m1entus/6983547 to your computer and use it in GitHub Desktop.
Save m1entus/6983547 to your computer and use it in GitHub Desktop.
Installing ffmpeg ios libraries armv7, armv7s, i386
#!/bin/bash
###########################################################################
# Choose your ffmpeg version and your currently-installed iOS SDK version:
#
VERSION="2.0.2"
SDKVERSION="7.0"
ARCHS="armv7 armv7s i386"
#
#
###########################################################################
#
# Don't change anything under this line!
#
###########################################################################
DEVELOPER=`xcode-select -print-path`
cd "`dirname \"$0\"`"
REPOROOT=$(pwd)
# Where we'll end up storing things in the end
OUTPUTDIR="${REPOROOT}/dependencies"
mkdir -p ${OUTPUTDIR}/include
mkdir -p ${OUTPUTDIR}/lib
mkdir -p ${OUTPUTDIR}/bin
BUILDDIR="${REPOROOT}/build"
mkdir -p $BUILDDIR
# where we will keep our sources and build from.
SRCDIR="${BUILDDIR}/src"
mkdir -p $SRCDIR
# where we will store intermediary builds
INTERDIR="${BUILDDIR}/built"
mkdir -p $INTERDIR
########################################
cd $SRCDIR
# Exit the script if an error happens
set -e
if [ ! -e "${SRCDIR}/ffmpeg-${VERSION}.tar.bz2" ]; then
echo "Downloading ffmpeg-${VERSION}.tar.bz2"
curl -LO http://ffmpeg.org/releases/ffmpeg-${VERSION}.tar.bz2
else
echo "Using ffmpeg-${VERSION}.tar.bz2"
fi
tar jxf ffmpeg-${VERSION}.tar.bz2 -C $SRCDIR
cd "${SRCDIR}/ffmpeg-${VERSION}"
set +e # don't bail out of bash script if ccache doesn't exist
CCACHE=`which ccache`
if [ $? == "0" ]; then
echo "Building with ccache: $CCACHE"
CCACHE="${CCACHE} "
else
echo "Building without ccache"
CCACHE=""
fi
set -e # back to regular "bail out on error" mode
for ARCH in ${ARCHS}
do
if [ "${ARCH}" == "i386" ];
then
PLATFORM="iPhoneSimulator"
EXTRA_CONFIG="--arch=i386 --disable-asm --enable-cross-compile --target-os=darwin --cpu=i386"
EXTRA_CFLAGS="-arch i386"
EXTRA_LDFLAGS="-I${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk/usr/lib -mfpu=neon"
else
PLATFORM="iPhoneOS"
EXTRA_CONFIG="--arch=arm --target-os=darwin --enable-cross-compile --cpu=cortex-a9 --disable-armv5te"
EXTRA_CFLAGS="-w -arch ${ARCH} -mfpu=neon"
EXTRA_LDFLAGS="-mfpu=neon"
fi
mkdir -p "${INTERDIR}/${ARCH}"
./configure --prefix="${INTERDIR}/${ARCH}" --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-iconv --disable-bzlib --enable-avresample --sysroot="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" --cc="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" --as='/usr/local/bin/gas-preprocessor.pl' --extra-cflags="${EXTRA_CFLAGS} -miphoneos-version-min=${SDKVERSION} -I${OUTPUTDIR}/include" --extra-ldflags="-arch ${ARCH} ${EXTRA_LDFLAGS} -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk -miphoneos-version-min=${SDKVERSION} -L${OUTPUTDIR}/lib" ${EXTRA_CONFIG} --enable-pic --extra-cxxflags="$CPPFLAGS -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk"
make && make install && make clean
done
mkdir -p "${INTERDIR}/universal/lib"
cd "${INTERDIR}/armv7/lib"
for file in *.a
do
cd ${INTERDIR}
xcrun -sdk iphoneos lipo -output universal/lib/$file -create -arch armv7 armv7/lib/$file -arch armv7s armv7s/lib/$file -arch i386 i386/lib/$file
echo "Universal $file created."
done
cp -r ${INTERDIR}/armv7/include ${INTERDIR}/universal/
echo "Done."
@nicpro85
Copy link

nicpro85 commented May 5, 2014

Thanks! But when I compile ffmpeg2.2.2 use your script ,I still encounter the problem "Unable to identify target architecture at /usr/bin/gas-preprocessor.pl line 82" .
I used iPhoneOS7.1.sdk .
I don't where is wrong .Thanks again.

@poholo
Copy link

poholo commented Jun 5, 2014

help me

WARNING: pkg-config not found, library detection may fail.
mktemp -u XXXXXX
3kPfry
check_ld cc
check_cc
BEGIN /var/folders/bq/tz1vgr9j1xv1s8pwlzx6_cg80000gn/T//ffconf.91jLl9Wt.c
1 int main(void){ return 0; }
END /var/folders/bq/tz1vgr9j1xv1s8pwlzx6_cg80000gn/T//ffconf.91jLl9Wt.c
/Applications/XCode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -arch armv7 -mcpu=cortex-a8 -c -o /var/folders/bq/tz1vgr9j1xv1s8pwlzx6_cg80000gn/T//ffconf.8iyA1IKl.o /var/folders/bq/tz1vgr9j1xv1s8pwlzx6_cg80000gn/T//ffconf.91jLl9Wt.c
./configure: line 786: /Applications/XCode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang: No such file or directory
C compiler test failed.

@poholo
Copy link

poholo commented Jul 7, 2014

the libavcodec.a is large than 133.6MB , how can I make a small libavcodec.a

@RenXLin
Copy link

RenXLin commented Oct 27, 2014

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: libavformat/libavformat.a(w64.o) cputype (12) does not match previous archive members cputype (7) (all members must match)
make: *** [libavformat/libavformat.a] Error 1

i do not know why?I use xcode 6.

@Ankish
Copy link

Ankish commented Jan 20, 2015

Update for xcode 6.1 with ios 8 ver above. Recommended changes to the script ?
Moreover in the path I${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk/usr/lib - only 5.0sdk is avaialble even though i user xcode 6.1 with ios 8.0. Is sdks path changed , any changes in script? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment