fail building ffmpeg for armv6-7 - iphone

I've been trying to build ffmpeg in every possible way I can think of. I'm trying with the latest revision from their git repository and with a build script which I have confirmation that it works, it's from this question: iPhone SDK 4.3 libav compiling problem. The script was updated yesterday and apparently works for the guy in the question.
my problem is that it doesn't generate the .a files (or actually any files) for armv6 anc armv7. and therefor the lipo commands, to concat into universal libs, fail. I've also tried using the build scripts from iFrameExtractor without any success it also fails with the lipo-commands in the end, i get the following:
lipo: can't open input file: ./compiled/armv6/lib/libavcodec.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libavdevice.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libavfilter.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libavformat.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libavutil.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libpostproc.a (No such file or directory)
lipo: can't open input file: ./compiled/armv6/lib/libswscale.a (No such file or directory)
and i have also posted the entire output here if anyone has any idea what to look for there (because i don't know where to start, it almost 5000 lines of output.)
i should also mention that i'm compiling it for armv6, armv7 and i386. I want to import it in XCode to get H.264 frames from video feed.
when i try to build for armv6 i use the following configure:
./configure \
--enable-cross-compile \
--arch=arm \
--extra-cflags='-arch armv6' \
--extra-ldflags='-arch armv6' \
--target-os=darwin \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk \
--cpu=arm1176jzf-s \
--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/system \
--prefix=compiled/armv6
and get the following output:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc is unable to create an executable file.
C compiler test failed.
If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user#ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solving the problem.
so the question, what c compiler should I use? i've tried different:
arm-apple-darwin10-gcc-4.2.1
arm-apple-darwin10-llvm-gcc-4.2
gcc
but with the same result. gcc works for both i386 and armv7 so i guess it should work for armv6 aswell

i used the following to compile only for armv6 and armv7. I couldn't get it working for i386, i receive errors that the cputype and subcputype are wrong. apparently the cputype is supposed to be x86 and subcputype should be intel.
anyhow i used the following build scripts to compile (i ended up using gcc and it worked, it was the configure flags that were wrong from the beginning i guess) for the arm architectures:
build script:
#!/bin/sh
set -e
SCRIPT_DIR=$( (cd -P $(dirname $0) && pwd) )
DIST_DIR_BASE=${DIST_DIR_BASE:="$SCRIPT_DIR/dist"}
if [ -d ffmpeg ]
then
echo "Found ffmpeg source directory, no need to fetch from git..."
else
echo "Fetching ffmpeg from git://git.videolan.org/ffmpeg.git..."
git clone git://git.videolan.org/ffmpeg.git
fi
ARCHS=${ARCHS:-"armv6 armv7"}
for ARCH in $ARCHS
do
FFMPEG_DIR=ffmpeg-$ARCH
if [ -d $FFMPEG_DIR ]
then
echo "Removing old directory $FFMPEG_DIR"
rm -rf $FFMPEG_DIR
fi
echo "Copying source for $ARCH to directory $FFMPEG_DIR"
cp -a ffmpeg $FFMPEG_DIR
cd $FFMPEG_DIR
DIST_DIR=$DIST_DIR_BASE-$ARCH
mkdir -p $DIST_DIR
case $ARCH in
armv6)
EXTRA_FLAGS="--enable-cross-compile --target-os=darwin --arch=arm --cpu=arm1176jzf-s"
EXTRA_CFLAGS="-arch $ARCH"
EXTRA_LDFLAGS="-arch $ARCH"
;;
armv7)
EXTRA_FLAGS="--enable-cross-compile --target-os=darwin --arch=arm --cpu=cortex-a8 --enable-pic"
EXTRA_CFLAGS="-arch $ARCH"
EXTRA_LDFLAGS="-arch $ARCH"
;;
x86_64)
EXTRA_CC_FLAGS="-mdynamic-no-pic"
;;
esac
echo "Configuring ffmpeg for $ARCH..."
./configure \
--prefix=$DIST_DIR \
--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system \
--disable-bzlib \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk \
--extra-ldflags="$EXTRA_LDFLAGS" \
--extra-cflags="$EXTRA_CFLAGS" \
$EXTRA_FLAGS
echo "Installing ffmpeg for $ARCH..."
make && make install
cd $SCRIPT_DIR
if [ -d $DIST_DIR/bin ]
then
rm -rf $DIST_DIR/bin
fi
if [ -d $DIST_DIR/share ]
then
rm -rf $DIST_DIR/share
fi
done
and combine libs script:
#!/bin/bash
set -e
ARCHS="armv6 armv7"
for ARCH in $ARCHS
do
if [ -d dist-$ARCH ]
then
MAIN_ARCH=$ARCH
fi
done
if [ -z "$MAIN_ARCH" ]
then
echo "Please compile an architecture"
exit 1
fi
OUTPUT_DIR="dist-uarch"
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR/lib $OUTPUT_DIR/include
for LIB in dist-$MAIN_ARCH/lib/*.a
do
LIB=`basename $LIB`
LIPO_CREATE=""
for ARCH in $ARCHS
do
if [ -d dist-$ARCH ]
then
LIPO_CREATE="$LIPO_CREATE-arch $ARCH dist-$ARCH/lib/$LIB "
fi
done
OUTPUT="$OUTPUT_DIR/lib/$LIB"
echo "Creating: $OUTPUT"
lipo -create $LIPO_CREATE -output $OUTPUT
lipo -info $OUTPUT
done
echo "Copying headers from dist-$MAIN_ARCH..."
cp -R dist-$MAIN_ARCH/include/* $OUTPUT_DIR/include
then i import the .a files from BUILD-FOLDER/dist-uarch and it builds in xcode like a charm!

Related

Building postgres from source throws "'utils/errcodes.h' file not found" when called from other makefile

I am currently constructing a Makefile and one of the things it will be doing is downloading and building postgres from source. Before starting to write the makefile file I always used the following set of commands to do this:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3
./configure --prefix "`pwd`" --without-readline --without-zlib
make
make install
Executing the above listed commands in the terminal results in the successful installation of postgres. Then I translated these into a makefile which looks as follows:
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install
Running this Makefile results in the error:
../../src/include/utils/elog.h:71:10: fatal error: 'utils/errcodes.h' file not found
It seems that something about calling the make from another Makefile causes a referencing issue with the files during the build process, but I just can figure out for the life of me what I have to change to fix this.
It appears to be the influence of Makefile enviromental variables. I didn't discover the exact mechanism, but unsetting them helps.
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
unset MAKELEVEL && unset MAKEFLAGS && unset MFLAGS && cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install

Unsupported Architectures .frameworks

I'm using commoncrypto. I added this using carthage. I added the run script. I embed & sign Framework. I also added code to the run script. When I try to install the app in the apple store, I get the error in the photo below. I added framework to input and output. What is the problem?
if [ "${CONFIGURATION}" = "Release" ]; then
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[#]}"
rm "${EXTRACTED_ARCHS[#]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
fi
Where did you put the script to eliminate i386?
Did you try to download the CommonCrypto.framework.zip file then drag and drop directly to your project?

ffmpeg on iOS 5.1 Undefined Symbols Error

So I've spent several hours now working through the scant amount of information available online about building ffmpeg for iOS. The building process seems to work well and I end up with fat files for armv6 and armv7 which I drag over into my project.
However, whenever I try to use the "avcodec_init()" command I get the following error:
Undefined symbols for architecture armv7:
"_avcodec_init", referenced from:
-[FirstViewController viewDidLoad] in FirstViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The library files are included in the 'Link Binary with Libraries' of the project settings, so they are definitely compiled into the app. I just can't for the life of me work out why I'm getting an error on this.
I've tried several different projects, and downloaded some existing project files from the web and get the same error.
This is the build script I used:
export PLATFORM="iPhoneOS" export MIN_VERSION="4.0" export
MAX_VERSION="5.1" export
DEVROOT=/Volumes/Lion/Applications/Xcode.app/Contents/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
I haven't used ffmpeg yet (even though a number of my bosses have had me thinking about using it), but lemme suggest a couple things that could be happening here.
1)
Let's see if the symbol really exists in your compiled library.
Go to Terminal and "cd" to the directory where your .a library lives.
Then type in "nm -arch armv7 ffmpeg.a | egrep avcodec_init" (where you can replace ffmpeg.a in my sample command with the actual name of the .a library) all on one line. That dumps out the symbols in the library for the armv7 architecture and pipes it into grep, which should show you if avcodec_init really does exist in your library.
If it doesn't appear, then it didn't get compiled into your library.
2)
If the symbol does exist in your library, then make sure the path to your .a file is correct in your project. You may be accidentally only including a simulator-only (i386 architecture) version of ffmpeg.

iOS DOxygen adding docSet to Xcode Documents

Hey Everyone just having a problem with DOxygen, Ive generated my documentation and its allthere, but i find i am unable to add it to Xcode.
I currently have a script which takes the HTML directory containing all the files, and generates the .docset file.
# Run the makefile. The --silent parameter stops it from spamming us with too much output.
#/Applications/Xcode.app/Contents/Developer/usr/bin/docsetutil
make --silent -C "$DOCSET_OUTPUT/html" install
# Load docset
osascript "$[location of personal library]/Scripts/XcodeLoadDocSet.scpt"
"~/Library/Developer/Shared/Documentation/DocSets/$DOXYGEN_ID.docset"
This should also add the item to xcode, but running it manually reveals a problem..
/Developer/usr/bin/docsetutil index com.[my app].docset
make: /Developer/usr/bin/docsetutil: No such file or directory
make: *** [docset] Error 1
This is what i have atm for the makefile,
DOCSET_NAME=com.[my app].docset
DOCSET_CONTENTS=$(DOCSET_NAME)/Contents
DOCSET_RESOURCES=$(DOCSET_CONTENTS)/Resources
DOCSET_DOCUMENTS=$(DOCSET_RESOURCES)/Documents
DESTDIR=~/Library/Developer/Shared/Documentation/DocSets
XCODE_INSTALL=$(shell xcode-select -print-path)
all: docset
docset:
mkdir -p $(DOCSET_DOCUMENTS)
cp Nodes.xml $(DOCSET_RESOURCES)
cp Tokens.xml $(DOCSET_RESOURCES)
cp Info.plist $(DOCSET_CONTENTS)
tar --exclude $(DOCSET_NAME) \
--exclude Nodes.xml \
--exclude Tokens.xml \
--exclude Info.plist \
--exclude Makefile -c -f - . \
| (cd $(DOCSET_DOCUMENTS); tar xvf -)
$(XCODE_INSTALL)/usr/bin/docsetutil index $(DOCSET_NAME)
rm -f $(DOCSET_DOCUMENTS)/Nodes.xml
rm -f $(DOCSET_DOCUMENTS)/Info.plist
rm -f $(DOCSET_DOCUMENTS)/Makefile
rm -f $(DOCSET_RESOURCES)/Nodes.xml
rm -f $(DOCSET_RESOURCES)/Tokens.xml
install: docset
mkdir -p $(DESTDIR)
cp -R $(DOCSET_NAME) $(DESTDIR)
uninstall:
rm -rf $(DESTDIR)/$(DOCSET_NAME)
always:
If anyone has had a similer problem please let me know.
Cheers
Michael.
With Xcode 4, docsetutil is located under /Applications/Xcode.app/Contents/Developer/usr/bin/

problem compiling ffmpeg for iFrameExtractor

I'm trying to compile the ffmpeg by using the make and build files in iFrameExtractor example. firstly i tried to follow the readme file on the github, which only says to run the ./build_universal in ffmpeg folder. it did not work
i then tried to follow the info in INSTALL without success. i then tried doing the stuff in INSTALL followed by the ./build_universal which didn't work. All the *.a files that are imported to the project exists until the end of the build sequence. when the lipo commands in build_universal are run, which i guess concat the .a files for the different architectures(?). anyhow these leave the following errors:
lipo: specifed architecture type (armv6) for file (armv6/libavcodec.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
lipo: specifed architecture type (armv6) for file (armv6/libavdevice.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
lipo: specifed architecture type (armv6) for file (armv6/libavformat.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
lipo: specifed architecture type (armv6) for file (armv6/libavutil.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
lipo: specifed architecture type (armv6) for file (armv6/libswscale.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
i can get the project to compile for simulator if i only use ./build_armv7 but if i run the universal the .a files are removed in the end. and only using doesn't work to build for iphone 4 .
After a week of trial and error, I was finally able to create the ffmpeg universal libraries and successfully compile and run iFrameExtractor for the device as well as the simulator.
To compile and run the project on your iPhone device OR simulator:
1) open Terminal
2) clone the repository: git clone git://github.com/lajos/iFrameExtractor.git
3) go to the ffmpeg folder in the project: cd iFrameExtractor/ffmpeg
4) run: ./configure
5) Edit the build scripts (build_armv6, build_armv7, build_i386) as follows:
These scripts assume you are using iOS SDK 5.0 on Xcode 4.2.
build_armv6:
#!/bin/tcsh -f
if (! -d armv6) mkdir armv6
if (! -d lib) mkdir lib
rm armv6/*.a
make clean
./configure \
--disable-bzlib --disable-doc \
--disable-ffmpeg --disable-ffplay \
--disable-ffserver --disable-mmx \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--enable-cross-compile --target-os=darwin \
--arch=arm --cpu=arm1176jzf-s \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk \
--extra-ldflags="-arch armv6 -L//Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system" \
--extra-cflags="-arch armv6"
make
mv libavcodec/libavcodec.a armv6/
mv libavdevice/libavdevice.a armv6/
mv libavformat/libavformat.a armv6/
mv libavutil/libavutil.a armv6/
mv libswscale/libswscale.a armv6/
rm lib/*.a
cp armv6/*.a lib/
build_armv7:
#!/bin/tcsh -f
if (! -d armv7) mkdir armv7
if (! -d lib) mkdir lib
rm armv7/*.a
make clean
./configure \
--disable-bzlib --disable-doc \
--disable-ffmpeg --disable-ffplay \
--disable-ffserver --disable-mmx \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--enable-cross-compile --target-os=darwin \
--arch=arm --cpu=cortex-a8 --enable-pic \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk \
--extra-ldflags="-arch armv7 - L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system" \
--extra-cflags="-arch armv7"
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/
build_i386:
#!/bin/tcsh -f
if (! -d i386) mkdir i386
if (! -d lib) mkdir lib
rm i386/*.a
make clean
./configure \
--disable-bzlib --disable-doc \
--disable-ffmpeg --disable-ffplay \
--disable-ffserver --disable-mmx \
--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/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk \
--extra-ldflags="-arch i386 -L//Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/usr/lib/system" \
--extra-cflags="-arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -fasm-blocks -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=40000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2"
make
mv libavcodec/libavcodec.a i386/
mv libavdevice/libavdevice.a i386/
mv libavformat/libavformat.a i386/
mv libavutil/libavutil.a i386/
mv libswscale/libswscale.a i386/
rm lib/*.a
cp i386/*.a lib/
6) build the ffmpeg libraries: ./build_universal
7) open the xcode project and run it on your iPhone device or simulator
These steps work perfectly for me. I hope this will help others struggling to get the ffmpeg libraries working for iOS.
i downloaded the latest ffmpeg repository and used the following to compile only for armv6 and armv7. I couldn't get it working for i386, i receive errors that the cputype and subcputype are wrong. apparently the cputype is supposed to be x86 and subcputype should be intel.
anyhow i used the following build scripts to compile for the arm architectures:
build script:
#!/bin/sh
set -e
SCRIPT_DIR=$( (cd -P $(dirname $0) && pwd) )
DIST_DIR_BASE=${DIST_DIR_BASE:="$SCRIPT_DIR/dist"}
if [ -d ffmpeg ]
then
echo "Found ffmpeg source directory, no need to fetch from git..."
else
echo "Fetching ffmpeg from git://git.videolan.org/ffmpeg.git..."
git clone git://git.videolan.org/ffmpeg.git
fi
ARCHS=${ARCHS:-"armv6 armv7"}
for ARCH in $ARCHS
do
FFMPEG_DIR=ffmpeg-$ARCH
if [ -d $FFMPEG_DIR ]
then
echo "Removing old directory $FFMPEG_DIR"
rm -rf $FFMPEG_DIR
fi
echo "Copying source for $ARCH to directory $FFMPEG_DIR"
cp -a ffmpeg $FFMPEG_DIR
cd $FFMPEG_DIR
DIST_DIR=$DIST_DIR_BASE-$ARCH
mkdir -p $DIST_DIR
case $ARCH in
armv6)
EXTRA_FLAGS="--enable-cross-compile --target-os=darwin --arch=arm --cpu=arm1176jzf-s"
EXTRA_CFLAGS="-arch $ARCH"
EXTRA_LDFLAGS="-arch $ARCH"
;;
armv7)
EXTRA_FLAGS="--enable-cross-compile --target-os=darwin --arch=arm --cpu=cortex-a8 --enable-pic"
EXTRA_CFLAGS="-arch $ARCH"
EXTRA_LDFLAGS="-arch $ARCH"
;;
x86_64)
EXTRA_CC_FLAGS="-mdynamic-no-pic"
;;
esac
echo "Configuring ffmpeg for $ARCH..."
./configure \
--prefix=$DIST_DIR \
--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system \
--disable-bzlib \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk \
--extra-ldflags="$EXTRA_LDFLAGS" \
--extra-cflags="$EXTRA_CFLAGS" \
$EXTRA_FLAGS
echo "Installing ffmpeg for $ARCH..."
make && make install
cd $SCRIPT_DIR
if [ -d $DIST_DIR/bin ]
then
rm -rf $DIST_DIR/bin
fi
if [ -d $DIST_DIR/share ]
then
rm -rf $DIST_DIR/share
fi
done
and combine libs script:
#!/bin/bash
set -e
ARCHS="armv6 armv7"
for ARCH in $ARCHS
do
if [ -d dist-$ARCH ]
then
MAIN_ARCH=$ARCH
fi
done
if [ -z "$MAIN_ARCH" ]
then
echo "Please compile an architecture"
exit 1
fi
OUTPUT_DIR="dist-uarch"
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR/lib $OUTPUT_DIR/include
for LIB in dist-$MAIN_ARCH/lib/*.a
do
LIB=`basename $LIB`
LIPO_CREATE=""
for ARCH in $ARCHS
do
if [ -d dist-$ARCH ]
then
LIPO_CREATE="$LIPO_CREATE-arch $ARCH dist-$ARCH/lib/$LIB "
fi
done
OUTPUT="$OUTPUT_DIR/lib/$LIB"
echo "Creating: $OUTPUT"
lipo -create $LIPO_CREATE -output $OUTPUT
lipo -info $OUTPUT
done
echo "Copying headers from dist-$MAIN_ARCH..."
cp -R dist-$MAIN_ARCH/include/* $OUTPUT_DIR/include
then i import the .a files from BUILD-FOLDER/dist-uarch and it builds in xcode like a charm!
building FFMPEG for iOS 5.1
hope this will help you to build latest FFMPEG for iOS 5.1
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./build_universal
note: you have to create build_* scripts first, to do this see code below
script for ARMV7 - create file build_armv7
#!/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=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as='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/iPhoneOS5.1.sdk --cpu=cortex-a8 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk' --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/
script for ARMV6 - create file build_armv6
#!/bin/tcsh -f
if (! -d armv6) mkdir armv6
if (! -d lib) mkdir lib
rm armv6/*.a
make clean
./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.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk --cpu=arm1176jzf-s --extra-cflags='-arch armv6' --extra-ldflags='-arch armv6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk'
make
mv libavcodec/libavcodec.a armv6/
mv libavdevice/libavdevice.a armv6/
mv libavformat/libavformat.a armv6/
mv libavutil/libavutil.a armv6/
mv libswscale/libswscale.a armv6/
rm lib/*.a
cp armv6/*.a lib/
script for simulator - create file build_i386
#!/bin/tcsh -f
if (! -d i386) mkdir i386
if (! -d lib) mkdir lib
rm i386/*.a
make clean
./configure \
--disable-bzlib --disable-doc \
--disable-ffmpeg --disable-ffplay \
--disable-ffserver --disable-mmx \
--cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk \
--extra-ldflags="-arch i386 -L//Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/lib/system" \
--extra-cflags="-arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -fasm-blocks -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=40000 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2"
make
mv libavcodec/libavcodec.a i386/
mv libavdevice/libavdevice.a i386/
mv libavformat/libavformat.a i386/
mv libavutil/libavutil.a i386/
mv libswscale/libswscale.a i386/
rm lib/*.a
cp i386/*.a lib/
script for universal build (will merge libraries into one universal) - create file build_universal
#!/bin/tcsh -f
source ./build_armv6
source ./build_armv7
source ./build_i386
if (! -d universal) mkdir universal
if (! -d lib) mkdir lib
rm universal/*.a
lipo -create -arch armv6 armv6/libavcodec.a -arch armv7 armv7/libavcodec.a -arch i386 i386/libavcodec.a -output universal/libavcodec.a
lipo -create -arch armv6 armv6/libavdevice.a -arch armv7 armv7/libavdevice.a -arch i386 i386/libavdevice.a -output universal/libavdevice.a
lipo -create -arch armv6 armv6/libavformat.a -arch armv7 armv7/libavformat.a -arch i386 i386/libavformat.a -output universal/libavformat.a
lipo -create -arch armv6 armv6/libavutil.a -arch armv7 armv7/libavutil.a -arch i386 i386/libavutil.a -output universal/libavutil.a
lipo -create -arch armv6 armv6/libswscale.a -arch armv7 armv7/libswscale.a -arch i386 i386/libswscale.a -output universal/libswscale.a
rm lib/*.a
cp universal/*.a lib/