15

Has anyone been able to compile ffmpeg libraries using the iOS5 sdk? I have found scripts that use the 4.3 sdk but nothing for iOS5. I would assume that libraries built with the old sdk and armv7 will still be compatible for iOS 5.

Here is the command I am trying to use:

./configure \ --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \ --as='gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \ --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk \ --extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system \ --target-os=darwin \ --arch=arm \ --cpu=cortex-a8 \ --extra-cflags='-arch armv7' \ --extra-ldflags='-arch armv7' \ --prefix=compiled/armv7 \ --enable-pic \ --enable-cross-compile \ --disable-armv5te \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffserver \ --disable-ffprobe \ --disable-doc

I have also tried using a script like this one:

#!/bin/tcsh -f

if (! -d armv7) mkdir armv7
if (! -d lib) mkdir lib

rm armv7/*.a

make clean

./configure --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --enable-cross-compile --arch=arm --target-os=darwin --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk --cpu=cortex-a8 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7' --enable-pic

make

mv libavcodec/libavcodec.a armv7/
mv libavdevice/libavdevice.a armv7/
mv libavformat/libavformat.a armv7/
mv libavutil/libavutil.a armv7/
mv libswscale/libswscale.a armv7/

rm lib/*.a

cp armv7/*.a lib/

I have also tried to switch to the gcc-4.2 as well as the llvm-gcc-4.2. However I get an "Unknown option" error shown below in the comments.

Any info will be great and thanks.

brad_roush
  • 235
  • 1
  • 3
  • 10
  • 1
    It should compile absolutely fine AFAIK. Are you seeing any specific errors when compiling using the iOS 5 toolchain? – mattjgalloway Nov 30 '11 at 09:29
  • Unknown option "--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc". The gcc compiler looks like it is in there. Any suggestions? – brad_roush Nov 30 '11 at 17:52
  • 2
    That's right, you'll need to use `llvm-gcc` or `clang` rather than `gcc`. Do you understand how to do that or are you trying to use a script or something similar to compile it? – mattjgalloway Nov 30 '11 at 18:38
  • I have tried using scripts and just running the command from terminal – brad_roush Nov 30 '11 at 18:51
  • What script exactly? I can try fixing it for you - I've been compiling ffmpeg for ios for a while so should be able to sort it out! – mattjgalloway Nov 30 '11 at 22:45
  • I put the script in the question above – brad_roush Dec 01 '11 at 00:31
  • try changing gcc to llvm-gcc for option -CC. Also you could try llvm-gcc-4.2 – chris838 Aug 04 '12 at 23:29
  • See this answer for link talking about legal issues WRT including ffmpeg in an iOS app: http://stackoverflow.com/questions/15832754/trying-to-compile-the-ffmpeg-libraries-for-iphoneos-platform-with-armv6-and-arv7/17202184#17202184 – MoDJ Jul 20 '13 at 19:27

3 Answers3

17

UPDATED: Completely changed the answer to use the script that I use.

You will also need to download gas-preprocessor.pl from https://github.com/yuvi/gas-preprocessor, put it in your path and make it executable.

Then create a script (say make_for_iphone.sh) and put this in it:

export PLATFORM="iPhoneOS"
export MIN_VERSION="4.0"
export MAX_VERSION="5.0"
export DEVROOT=/Developer/Platforms/${PLATFORM}.platform/Developer
export SDKROOT=$DEVROOT/SDKs/${PLATFORM}${MAX_VERSION}.sdk
export CC=$DEVROOT/usr/bin/llvm-gcc
export LD=$DEVROOT/usr/bin/ld
export CPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/llvm-g++
export AR=$DEVROOT/usr/bin/ar
export LIBTOOL=$DEVROOT/usr/bin/libtool
export NM=$DEVROOT/usr/bin/nm
export CXXCPP=$DEVROOT/usr/bin/cpp
export RANLIB=$DEVROOT/usr/bin/ranlib

COMMONFLAGS="-pipe -gdwarf-2 -no-cpp-precomp -isysroot ${SDKROOT} -marm -fPIC"
export LDFLAGS="${COMMONFLAGS} -fPIC"
export CFLAGS="${COMMONFLAGS} -fvisibility=hidden"
export CXXFLAGS="${COMMONFLAGS} -fvisibility=hidden -fvisibility-inlines-hidden"

FFMPEG_LIBS="libavcodec libavdevice libavformat libavutil libswscale"

echo "Building armv6..."

make clean
./configure \
    --cpu=arm1176jzf-s \
    --extra-cflags='-arch armv6 -miphoneos-version-min=${MIN_VERSION} -mthumb' \
    --extra-ldflags='-arch armv6 -miphoneos-version-min=${MIN_VERSION}' \
    --enable-cross-compile \
    --arch=arm \
    --target-os=darwin \
    --cc=${CC} \
    --sysroot=${SDKROOT} \
    --prefix=installed \
    --disable-network \
    --disable-decoders \
    --disable-muxers \
    --disable-demuxers \
    --disable-devices \
    --disable-parsers \
    --disable-encoders \
    --disable-protocols \
    --disable-filters \
    --disable-bsfs \
    --enable-decoder=h264 \
    --enable-decoder=svq3 \
    --enable-gpl \
    --enable-pic \
    --disable-doc
perl -pi -e 's/HAVE_INLINE_ASM 1/HAVE_INLINE_ASM 0/' config.h
make -j3

mkdir -p build.armv6
for i in ${FFMPEG_LIBS}; do cp ./$i/$i.a ./build.armv6/; done

echo "Building armv7..."

make clean
./configure \
    --cpu=cortex-a8 \
    --extra-cflags='-arch armv7 -miphoneos-version-min=${MIN_VERSION} -mthumb' \
    --extra-ldflags='-arch armv7 -miphoneos-version-min=${MIN_VERSION}' \
    --enable-cross-compile \
    --arch=arm \
    --target-os=darwin \
    --cc=${CC} \
    --sysroot=${SDKROOT} \
    --prefix=installed \
    --disable-network \
    --disable-decoders \
    --disable-muxers \
    --disable-demuxers \
    --disable-devices \
    --disable-parsers \
    --disable-encoders \
    --disable-protocols \
    --disable-filters \
    --disable-bsfs \
    --enable-decoder=h264 \
    --enable-decoder=svq3 \
    --enable-gpl \
    --enable-pic \
    --disable-doc
perl -pi -e 's/HAVE_INLINE_ASM 1/HAVE_INLINE_ASM 0/' config.h
make -j3

mkdir -p build.armv7
for i in ${FFMPEG_LIBS}; do cp ./$i/$i.a ./build.armv7/; done

mkdir -p build.universal
for i in ${FFMPEG_LIBS}; do lipo -create ./build.armv7/$i.a ./build.armv6/$i.a -output ./build.universal/$i.a; done

for i in ${FFMPEG_LIBS}; do cp ./build.universal/$i.a ./$i/$i.a; done

make install

This compiles both armv6 and armv7 versions and puts them into a fat library using lipo. It installs to a folder underneath where you run the script from called installed.

Note that at the moment I've had to turn off inline assembly using a perl inline replace to change HAVE_INLINE_ASM from 1 to 0. This is because of this problem with gas-preprocessor.pl - https://github.com/yuvi/gas-preprocessor/issues/16.

Also note that this has turned off all encoders, decoders, muxers, demuxers, etc except for the H264 decoder. Just change the configure lines to compile what you want for your use case.

Please remember also that this has enabled GPL code - so you should be aware about what that means for iPhone apps. If you're not aware then you should do some reading about that.

mattjgalloway
  • 34,792
  • 12
  • 100
  • 110
  • error:Unknown option "--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc". – brad_roush Dec 01 '11 at 02:13
  • When I run the script I get: make: *** No rule to make target `clean'. Stop. ./configure: Command not found. make: *** No targets specified and no makefile found. Stop. – brad_roush Dec 01 '11 at 02:14
  • Matt, I've compiled ffmpeg using your script and it works great. However, when dragging the .a files into Xcode and compiling I'm getting 'Undefined symbols for architecture armv7: "_avcodec_init", referenced from:....' Any thoughts ? – AndyDunn Apr 25 '12 at 00:05
  • Sounds like it's not got the armv7 part. Any errors when you compile? – mattjgalloway Apr 25 '12 at 09:32
  • don't you need the file protocol enabled? – marchinram Oct 22 '12 at 23:43
3

Here is my working Configure for cross-compiling FFmpeg on iOS 6 the arch is ARMv7

NOTE: You must have to have gas-preprocessor.pl inside /usr/local/bin/ please do not continue until you have gas-preprocessor.pl on your bin directory

  • Download FFmpeg 1.0 "Angel" from here

  • Unzip it and place it somewhere i.e. your Desktop folder

  • Open terminal and browse to unzipped FFmpeg folder

  • Copy and paste the following command, (be patient will take a while)

./configure --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --enable-cross-compile --arch=arm --target-os=darwin --cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as='gas-preprocessor/gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk --cpu=cortex-a8 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk' --enable-pic --enable-decoder=rawvideo --disable-asm

  • Now type the following command on terminal make (wait a little more)

  • Once it has finished now type on terminal sudo make install (wait again)

  • Go to /usr/local/lib to find your freshly baked armv7 libs

  • Enjoy!

Alex

dalexsoto
  • 3,412
  • 1
  • 27
  • 43
1

I've created an "ffmpeg4ios" project at https://github.com/ciphor/ffmpeg4ios, which is successfully compiled on iOS 5.0. You can check it.

ciphor
  • 8,018
  • 11
  • 53
  • 70