ffmpeg编译iOS静态库教程

来源:互联网 发布:彩超工作站软件 编辑:程序博客网 时间:2024/05/21 18:36

原文地址,直接进入正题了

本文大部分内容参考于此篇文章:How to Prepare Your Mac for iOS Development with FFmpeg Libraries , 然后针对最新情况做了一些修改。

1. 首先,准备编译环境

1. 安装Xcode和Command Line Tools2. 下载和安装 gas-preprocessor3. 安装 pkg-config

关于gas-preprocessor,安装方式是直接copy文件 gas-preprocessor.pl 到 /usr/bin ,记得修改权限可执行.

原文给出的下载地址是 gas-preprocessor , 不过这里的版本比较老 , 因为在编译ffmpeg的时候,gas-preprocessor版本必须和ffmpeg配合,所以如果你下载的ffmpeg源码是最新的,那么建议去 libav网站 下载最新的 gas-preprocessor.

如果之后在编译时候遇到类似这样的错误

unknown register alias 'TCOS_D0_HEAD'

那么可以尝试更换 gas-preprocessor版本来解决.

然后 pkg-config, 可以直接通过MacPorts来安装

sudo port install pkgconfig

2. 下载ffmpeg的源码

git clone git://source.ffmpeg.org/ffmpeg.git

3. 编译armv7的支持

configure参数如下

1
./configure --prefix=armv7 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --extra-cflags="-arch armv7 -mfpu=neon -miphoneos-version-min=5.1" --extra-ldflags="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=5.1" --arch=arm --cpu=cortex-a9 --enable-pic

编译和安装到armv7目录下

1
make clean && make && make install

4. 编译armv7s的支持

configure参数如下

1
./configure --prefix=armv7s --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --extra-cflags="-arch armv7s -mfpu=neon -miphoneos-version-min=5.1" --extra-ldflags="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=5.1" --arch=arm --cpu=cortex-a9 --enable-pic

编译和安装到armv7s目录下

1
make clean && make && make install

5. 编译i386的支持

configure参数如下

1
./configure --prefix=i386 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" --target-os=darwin --cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" --extra-cflags="-arch i386" --extra-ldflags="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" --arch=i386 --cpu=i386 --enable-pic --disable-asm

编译和安装到i386目录下

1
make clean && make && make install

如果一切顺利,那么ffmpeg目录下会分别生成 armv7、armv7s、i386几个目录,里面lib文件下就是我们需要的静态库了.

6. 最后,我们合并armv7、armv7s、i386库在一起.

1.建立universal/lib/目录.

2.新建bash脚本,内容如下:

123456789101112
#! /bin/shcd armv7/libfor file in *.adocd ../..xcrun -sdk iphoneos lipo -output universal/lib/$file  -create -arch armv7 armv7/lib/$file -arch armv7s armv7s/lib/$file -arch i386 i386/lib/$fileecho "Universal $file created."cd -donecd ../..

3.执行这个脚本,稍等完成后在universal/lib/下就是我们需要的静态库了。

以上这么简单的步骤就是编译ffmpeg为iOS静态库的方法,其他各种库编译方式也都大同小异.是不是很简单呢?

然后关于configure的参数,大家可以参考ffmepg官网解释

0 0
原创粉丝点击