iPhone ffmpeg+libx264编译
ffmpeg+libx264编译
编译环境:xcode4.2 ios5.0
编译版本:armv7 真机版本
一. X264编译
首先去下载X264源码http://www.videolan.org/developers/x264.html 打开终端, cd 到x264的目录,执行如下语句
CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc ./configure --host=arm-apple-darwin --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7 -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system' --enable-pic
make
不知道为什么sudo make install不能将.a和.h文件安装到/usr/local目录下.所以我选择手动拷贝.可以选择MAC 然后在 finder--->前往目录,输入/usr/local.如图
拷贝的时候可能需要你提供ROOT权限,提示让输入密码. 拷贝成功以后如图:
lib文件夹中有libx264.a, include 下面有x264.h, x264_config.h. 文件拷贝到这里的作用是方便FFMPEG编译时的引用.
二. FFMPEG编译
1.https://github.com/yuvi/gas-preprocessor下载gas-preprocessor.pl文件并将其放置到/usr/sbin路径下
2.下载FFMPEG http://ffmpeg.org/download.html
3.CD到目录, 执行以下的命令
./configure --disable-doc --enable-libx264 --enable-encoder=libx264 --enable-gpl --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='-I/usr/local/include-arch armv7' --extra-ldflags='-L/usr/local/lib -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk' --enable-pic
make
--extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib就是你x264库的路径,用来寻找x264库的。刚才已经拷贝到/usr/local下面了
--enable-libx264,--enable-encoder=libx264,一个是连接x264,一个是打开x264的编码器
生成的库文件拷贝到项目中 OK