编译iPhone下的FFmpeg

mkdir ./build

# configure for armv7 build
./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/iPhoneOS4.3.sdk \
--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system \
--target-os=darwin \
--arch=arm \
--cpu=cortex-a8 \
--extra-cflags='-arch armv7' \
--extra-ldflags='-arch armv7' \
--enable-pic \
--enable-cross-compile \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--disable-doc

# build for armv7
make clean
make

# copy out the armv7 libs
mkdir
./build/armv7
cp
-f ./libavcodec/libavcodec.a ./build/armv7/libavcodec.a
cp
-f ./libavdevice/libavdevice.a ./build/armv7/libavdevice.a
cp
-f ./libavfilter/libavfilter.a ./build/armv7/libavfilter.a
cp
-f ./libavformat/libavformat.a ./build/armv7/libavformat.a
cp
-f ./libavutil/libavutil.a ./build/armv7/libavutil.a
cp
-f ./libswscale/libswscale.a ./build/armv7/libswscale.a

# configure for armv6 build
./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/iPhoneOS4.3.sdk \
--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system \
--target-os=darwin \
--arch=arm \
--cpu=arm1176jzf-s \
--extra-cflags='-arch armv6' \
--extra-ldflags='-arch armv6' \
--enable-cross-compile \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--disable-doc

# build for armv6
make clean
make

# copy out the armv6 libs
mkdir
./build/armv6
cp
-f ./libavcodec/libavcodec.a ./build/armv6/libavcodec.a
cp
-f ./libavdevice/libavdevice.a ./build/armv6/libavdevice.a
cp
-f ./libavfilter/libavfilter.a ./build/armv6/libavfilter.a
cp
-f ./libavformat/libavformat.a ./build/armv6/libavformat.a
cp
-f ./libavutil/libavutil.a ./build/armv6/libavutil.a
cp
-f ./libswscale/libswscale.a ./build/armv6/libswscale.a

# configure for i386 build
./configure \
--cc=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor.pl /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc' \
--sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk \
--extra-ldflags=-L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/system \
--target-os=darwin \
--arch=i386 \
--cpu=i386 \
--extra-cflags='-arch i386' \
--extra-ldflags='-arch i386' \
--enable-cross-compile \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--disable-doc

# build for i386
make clean
make

# copy out the i386 libs
mkdir
./build/i386
cp
-f ./libavcodec/libavcodec.a ./build/i386/libavcodec.a
cp
-f ./libavdevice/libavdevice.a ./build/i386/libavdevice.a
cp
-f ./libavfilter/libavfilter.a ./build/i386/libavfilter.a
cp
-f ./libavformat/libavformat.a ./build/i386/libavformat.a
cp
-f ./libavutil/libavutil.a ./build/i386/libavutil.a
cp
-f ./libswscale/libswscale.a ./build/i386/libswscale.a

# make fat (universal) libs
lipo
-output ./build/libavcodec.a  -create \
-arch armv6 ./build/armv6/libavcodec.a \
-arch armv7 ./build/armv7/libavcodec.a \
-arch i386 ./build/i386/libavcodec.a

lipo
-output ./build/libavdevice.a  -create \
-arch armv6 ./build/armv6/libavdevice.a \
-arch armv7 ./build/armv7/libavdevice.a \
-arch i386 ./build/i386/libavdevice.a

lipo
-output ./build/libavfilter.a  -create \
-arch armv6 ./build/armv6/libavfilter.a \
-arch armv7 ./build/armv7/libavfilter.a \
-arch i386 ./build/i386/libavfilter.a

lipo
-output ./build/libavformat.a  -create \
-arch armv6 ./build/armv6/libavformat.a \
-arch armv7 ./build/armv7/libavformat.a \
-arch i386 ./build/i386/libavformat.a

lipo
-output ./build/libavutil.a  -create \
-arch armv6 ./build/armv6/libavutil.a \
-arch armv7 ./build/armv7/libavutil.a \
-arch i386 ./build/i386/libavutil.a

lipo
-output ./build/libswscale.a  -create \
-arch armv6 ./build/armv6/libswscale.a \
-arch armv7 ./build/armv7/libswscale.a \
-arch i386 ./build/i386/libswscale.a

上面针对i386,也就是模拟器的编译配置不一定,下面有另一种配置方式:
./configure \
--disable-bzlib \
--disable-mmx \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--cc=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1 \
--as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1' \
--sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk \
--extra-cflags='-fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -fasm-blocks -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=30000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2'


另外一篇文章

移值FFMPEG到iPhone或Mac OS/X

有关FFMPEG的详细说明可以参考网上相关文档;在这里我们只讲述FFMPEG移到iPhone或Mac OS/X的过程及相关注意事项。

FFMPEG功能相当强大,在完整的FFMPEG包中就包含了ffserver, ffplay, ffmpeg, avcodec, avdevice, avformat, avutil, swscale等;其中ffserver, ffplay, ffmpeg为应该程序,对与我们这些从事软件开发的人来说基本上没什么用;而avcodec为加解码库、avformat为格式库,avutil则为基础库(但平常我们很少用到), swscale则为图象处理库;所以我们所要的就是移值avcodec, avformat, avutil, swscale这四个库。

移值到Mac OS/X下过程:

一、   配置

./configure --prefix=/Developer/usr --cc=/Developer/usr/bin/gcc-4.0 --enable-gpl --enable-shared --disable-ipv6 --enable-swscale --enable-zlib --enable-bzlib --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-vhook

二、   编译

make

三、   安装

make install

说明:上面的/Developer/usr为目标目录,如果你的Xcode为默认安装,则这样安装后既可以在Xcode中编译及调式你的代码了;

移值到Mac OS/X下的模拟iPhone平台下过程:

一、   配置

./configure --prefix=/Developer/usr --disable-debug --cc=/Developer/usr/bin/i686-apple-darwin9-gcc-4.0.1 --enable-gpl --enable-static --disable-shared --disable-ipv6 --enable-swscale --enable-zlib --enable-bzlib --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-vhook --enable-pthreads

其中:也可以加入--enable-shared,这个选项是允许其编译产生动态库,在以后的编程中要用到这个几个动态库。--prefix设置的安装目录。如果在configure的时候不加上--enable-shared的,则采用静态链接的方式,不会生成那三个动态库。同时生成的ffplay、ffmpeg的执行文件也比较的大,因为他们不需要动态库的支持,就可以执行。但是不利于再次开发,所以我也可以考虑采用动态链接的方式。

二、   编译

make

三、   安装

make install

安装之后在/usr/local/ffmpeg会看到有三个目录
  lib 动态链接库位置
  include 编程要用到头文件
  bin 执行文件所在的目录

为了以后方便编程,我们把lib中的三个链接库libavcodec.so libavformat.so libavutil.so复制到/usr/lib下。把include目录下的ffmpeg目录复制到/usr/include下。 执行bin目录下的ffplay,可以去播放音频或者视频文件。例如播放1.mp3
  ./ffplay 1.mp3
  另外,bin目录下还有两个文件:ffmpeg和ffserver
  ffmpeg是一个很好的视频和音频的格式转化工具。网上有很多它的说明文档。如果不想生成ffserver,只要在./configure的时候加--disable-ffserver即可。

说明:上面的/Developer/usr为目标目录,如果你的Xcode为默认安装,则这样安装后既可以在Xcode中编译及在模拟器下调式你的代码了;

移值到iPhone平台下过程:

一、   配置

./configure --enable-cross-compile --cross-prefix=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1 --prefix=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr --extra-cflags="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" --extra-ldflags="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk -Wl,-syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" --arch=armv6 --enable-armv6 --enable-gpl --enable-shared --disable-ipv6 --enable-swscale --enable-zlib --enable-bzlib --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-vhook

二、   编译

make

三、   安装

make install

说明:上面的/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/为目标目录,如果你的Xcode为默认安装,则这样安装后既可以在Xcode中编译及在模拟器下调式你的代码了。

相关说明:

    在ffmpeg中如果使用静态库则会出现一些连接错;所以在安装ffmpeg库时请选中动态库。

OK,到现在我们就你已经知道了如何把ffmpeg移到到iPhone下并把ffmpeg库和Xcode结合起来了吧;当然如果你的Xcode工具非默认安装,请更上相关目录选项.

posted on 2011-08-09 10:01  wwwkhd  阅读(4755)  评论(0编辑  收藏  举报