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."
@bezigon
Copy link

bezigon commented Nov 7, 2013

I have a broken version of the script to build FLAC library.
https://gist.github.com/bezigon/7352289

Need help!

@ngocdaothanh
Copy link

Thanks! I could build ffmpeg 2.1.1 with your script.
http://stackoverflow.com/a/20064462/827310

@m1entus
Copy link
Author

m1entus commented Dec 16, 2013

This script is working for all ffmpeg versions since 1.0.

@wumingyun
Copy link

is there any possibility that ffmpeg before 1.0 can be compiled by xcode5?
Have you ever try that?
thanks!!!

@marlin2023
Copy link

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

@d370urn3ur
Copy link

i had to change line 56: tar zxf ffmpeg-${VERSION}.tar.bz2 -C $SRCDIR to
tar jxf ffmpeg-${VERSION}.tar.bz2 -C $SRCDIR

the z option is for gzip archives and the script downloads bzip2 archive. tar failed every time unless I changed the "z" to "j". now it works fine

@yungoo
Copy link

yungoo commented Jan 8, 2014

On my building environment XCode5/ios7, the "--cross-prefix="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/" MUST be added to the configure script, if not the ranlib should be failed when compile armv7/armv7s.

@m1entus
Copy link
Author

m1entus commented Jan 9, 2014

@wumingyun No i didn't. I built only >1.0.
@d370urn3ur Thanks, i will fix it.

@Reve
Copy link

Reve commented Jan 14, 2014

Thnx for the script! It saved me a lot of time. Can you also make it compile for x86_64? I want to use ffmpeg on Mac app and i've tried changing the arch to x86_64 but for some reason the library is not working as intended...

@renlifeng
Copy link

wonderful! I just need to use ffmpeg

@kimjj81
Copy link

kimjj81 commented Jan 23, 2014

Thanks very much. This is very useful for me.

@jtiulentino
Copy link

This is awesome. Thank you!

@kimjj81
Copy link

kimjj81 commented Feb 6, 2014

Thanks so much. I love you.

@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