之前都是看别人的,转载别人的,今天终于要自己亲自操刀啦。哎。
废话少说,入正题
我的环境:
xcode 6.1 sdk6.1
真机armv7 和 i386
X264 最新的
ffmpeg 1.2.1
一,x264库的编译
首先到http://www.videolan.org/developers/x264.html下载x264的库,然后解压。
我是在根目录下新建H264目录,解压后的代码放入H264目录。然后打开终端
cd H264 然后
i386 下命令
CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc ./configure --host=i386-apple-darwin --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk --extra-cflags='-arch i386' --extra-ldflags='-arch i386 -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/usr/lib/system -arch i386 ' --disable-asm --enable-shared --enable-static --disable-asm
armv7 下命令
CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc ./configure --host=arm-apple-darwin --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7 -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib/system' --enable-pic --enable-shared --enable-static --disable-asm
后回车,正常情况是如下:
fatal: Not a git repository (or any of the parent directories): .git
platform: ARM
system: MACOSX
cli: yes
libx264: internal
shared: yes
static: yes
asm: yes
interlaced: yes
avs: avxsynth
lavf: no
ffms: no
gpac: no
gpl: yes
thread: posix
opencl: yes
filters: crop select_every
debug: no
gprof: no
strip: no
PIC: yes
visualize: no
bit depth: 8
chroma format: all
You can run 'make' or 'make fprofiled' now.
然后就make 会执行一堆东西
然后就是make install 就会如下
install -d /usr/local/bin
install x264 /usr/local/bin
install -d /usr/local/include
install -d /usr/local/lib
install -d /usr/local/lib/pkgconfig
install -m 644 ./x264.h /usr/local/include
install -m 644 x264_config.h /usr/local/include
install -m 644 x264.pc /usr/local/lib/pkgconfig
ln -f -s libx264.135.dylib /usr/local/lib/libx264.dylib
install -m 755 libx264.135.dylib /usr/local/lib
install -m 644 libx264.a /usr/local/lib
ranlib /usr/local/lib/libx264.a
---恭喜你,单独编译好x264库了。
编译好之后,文件会生成在虚拟路径/usr/local下面
我遇到的几个错误:
1. No working C compiler found.
解决思路: 1.安装Xcode是否正确(一般都正确的)。2.独立安装command Line Tools(偏好设置-》下载-》command Line Tools 后面显示installed 状态)
3.这个是我犯的错误 命令行中少了L字符,我以为没有用,就省了,结果查了很久。 哎。 下次还是直接拷贝吧。拷贝绝对不会错。
4.终端的版本号也不要太低。我的是2.3(309)--在关于终端上查看。
2.Operation not permitted
如下:
install -d /usr/local/bin
install: chmod 755 /usr/local/bin: Operation not permitted
install x264 /usr/local/bin
install: /usr/local/bin/x264: Permission denied
make: *** [install-cli] Error 71
MACtekiiMac:H264 mac$ make install
install -d /usr/local/bin
install: chmod 755 /usr/local/bin: Operation not permitted
install x264 /usr/local/bin
install: /usr/local/bin/x264: Permission denied
make: *** [install-cli] Error 71
这些错误就是权限问题啦。
解决办法:在终端输入 sodu -s 回车 然后输入password,就可以。
3.如果是重复编译,不删除H264目录和/usr/local下的相关目录,会报错误。
解决办法:建议每次编译都要重新新建H264目录(就是放x264源码的目录)。
4.编译ffmpeg库,要先编译x264库,因为我这里的ffmpeg关联了x264库。不能先编译ffmpeg库,也不能编译好x264就删除/usr/local下x264生成的相关文件。
二,ffmpeg库的编译
1.https://github.com/yuvi/gas-preprocessor下载gas-preprocessor.pl文件并将其放置到/usr/sbin路径下
2.去官网下载http://ffmpeg.org/download.html下载所需要版本代码,我下载的是1.2.1(最新的),解压放在根目录下的ffmpeg1.2.1
3.进入终端,cd 到 ffmpeg1.2.1 目录,以下是编译参数
i386下命令
./configure \
--cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc' \
--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk\
--extra-ldflags=-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/usr/lib/system\
--target-os=darwin \
--arch=i386 \
--cpu=i386 \
--extra-cflags='-I/ffmpegs/ffmpeg-1.2.1/x264/build/i386/include -arch i386' \ // /ffmpegs/ffmpeg-1.2.1这个目录是我ffmpeg源码解压后的目录 。x264在ffmpeg-1.2.1目录下
--extra-ldflags='-L/ffmpegs/ffmpeg-1.2.1/x264/build/i386/lib -arch i386 ' \
--enable-pic \
--enable-cross-compile \
--enable-gpl \
--enable-libx264 \
--extra-cflags=-I$SRCDIR/ffmpeg-${VERSION}/x264/build/i386/include \
--extra-ldflags=-L$SRCDIR/ffmpeg-${VERSION}/x264/build/i386/lib \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--enable-decoder=h264 \
--enable-encoder=libx264 \
--disable-doc \
--disable-asm
armv7 下命令
./configure --enable-libx264 --enable-gpl --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --disable-doc --enable-ffmpeg --enable-ffplay --disable-ffserver --disable-avfilter --disable-debug --disable-decoders --enable-cross-compile --disable-encoders --disable-armv5te --enable-decoder=h264 --enable-encoder=libx264 --enable-pic --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' --extra-ldflags='-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk' --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk --target-os=darwin --arch=arm --cpu=cortex-a8 --extra-cflags='-arch armv7' --disable-asm
然后回车。
然后make
然后 make install。
如果顺利 如下:
bash-3.2# make install
INSTALL install-progs-yes
INSTALL ffprobe
INSTALL presets/libvpx-1080p.ffpreset
INSTALL presets/libvpx-1080p50_60.ffpreset
INSTALL presets/libvpx-360p.ffpreset
INSTALL presets/libvpx-720p.ffpreset
INSTALL presets/libvpx-720p50_60.ffpreset
INSTALL presets/libx264-ipod320.ffpreset
INSTALL presets/libx264-ipod640.ffpreset
INSTALL doc/ffprobe.xsd
INSTALL doc/examples/decoding_encoding.c
INSTALL doc/examples/demuxing.c
INSTALL doc/examples/filtering_audio.c
INSTALL doc/examples/filtering_video.c
INSTALL doc/examples/metadata.c
INSTALL doc/examples/muxing.c
INSTALL doc/examples/resampling_audio.c
INSTALL doc/examples/scaling_video.c
INSTALL doc/examples/Makefile
INSTALL doc/examples/README
INSTALL presets/libvpx-1080p.ffpreset
INSTALL presets/libvpx-1080p50_60.ffpreset
INSTALL presets/libvpx-360p.ffpreset
INSTALL presets/libvpx-720p.ffpreset
INSTALL presets/libvpx-720p50_60.ffpreset
INSTALL presets/libx264-ipod320.ffpreset
INSTALL presets/libx264-ipod640.ffpreset
INSTALL doc/ffprobe.xsd
INSTALL doc/examples/decoding_encoding.c
INSTALL doc/examples/demuxing.c
INSTALL doc/examples/filtering_audio.c
INSTALL doc/examples/filtering_video.c
INSTALL doc/examples/metadata.c
INSTALL doc/examples/muxing.c
INSTALL doc/examples/resampling_audio.c
INSTALL doc/examples/scaling_video.c
INSTALL doc/examples/Makefile
INSTALL doc/examples/README
INSTALL libavdevice/libavdevice.a
INSTALL libavformat/libavformat.a
INSTALL libavcodec/libavcodec.a
ranlib: file: /usr/local/lib/libavcodec.a(iff.o) has no symbols
INSTALL libpostproc/libpostproc.a
INSTALL libswresample/libswresample.a
INSTALL libswscale/libswscale.a
INSTALL libavutil/libavutil.a
INSTALL libavdevice/avdevice.h
INSTALL libavdevice/version.h
INSTALL libavdevice/libavdevice.pc
INSTALL libavformat/avformat.h
INSTALL libavformat/avio.h
INSTALL libavformat/version.h
INSTALL libavformat/libavformat.pc
INSTALL libavcodec/avcodec.h
INSTALL libavcodec/avfft.h
INSTALL libavcodec/dxva2.h
INSTALL libavcodec/old_codec_ids.h
INSTALL libavcodec/vaapi.h
INSTALL libavcodec/vda.h
INSTALL libavcodec/vdpau.h
INSTALL libavcodec/version.h
INSTALL libavcodec/xvmc.h
INSTALL libavcodec/libavcodec.pc
INSTALL libpostproc/postprocess.h
INSTALL libpostproc/version.h
INSTALL libpostproc/libpostproc.pc
INSTALL libswresample/swresample.h
INSTALL libswresample/version.h
INSTALL libswresample/libswresample.pc
INSTALL libswscale/swscale.h
INSTALL libswscale/version.h
INSTALL libswscale/libswscale.pc
INSTALL libavutil/adler32.h
INSTALL libavutil/aes.h
INSTALL libavutil/attributes.h
INSTALL libavutil/audio_fifo.h
INSTALL libavutil/audioconvert.h
INSTALL libavutil/avassert.h
INSTALL libavutil/avstring.h
INSTALL libavutil/avutil.h
INSTALL libavutil/base64.h
INSTALL libavutil/blowfish.h
INSTALL libavutil/bprint.h
INSTALL libavutil/bswap.h
INSTALL libavutil/channel_layout.h
INSTALL libavutil/common.h
INSTALL libavutil/cpu.h
INSTALL libavutil/crc.h
INSTALL libavutil/error.h
INSTALL libavutil/eval.h
INSTALL libavutil/fifo.h
INSTALL libavutil/file.h
INSTALL libavutil/hmac.h
INSTALL libavutil/imgutils.h
INSTALL libavutil/intfloat.h
INSTALL libavutil/intfloat_readwrite.h
INSTALL libavutil/intreadwrite.h
INSTALL libavutil/lfg.h
INSTALL libavutil/log.h
INSTALL libavutil/mathematics.h
INSTALL libavutil/md5.h
INSTALL libavutil/mem.h
INSTALL libavutil/dict.h
INSTALL libavutil/old_pix_fmts.h
INSTALL libavutil/opt.h
INSTALL libavutil/parseutils.h
INSTALL libavutil/pixdesc.h
INSTALL libavutil/pixfmt.h
INSTALL libavutil/random_seed.h
INSTALL libavutil/rational.h
INSTALL libavutil/samplefmt.h
INSTALL libavutil/sha.h
INSTALL libavutil/time.h
INSTALL libavutil/timecode.h
INSTALL libavutil/timestamp.h
INSTALL libavutil/version.h
INSTALL libavutil/xtea.h
INSTALL libavutil/lzo.h
INSTALL libavutil/avconfig.h
INSTALL libavutil/libavutil.pc
恭喜你,ffmpeg也编译好了。
--extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib就是你x264库的路径,用来寻找x264库的。用我之前编译的,默认就是/usr/local下面了;
--enable-libx264,--enable-encoder=libx264,这两句不要忘了,一个是连接x264,一个是打开x264的编码器,不写的话,因为我编译里面写了--disable-encoders ,程序里面会找不到x264的编码器的.
都编译好了以后,找到生成的几个库文件,将其添加到项目里面就可以使用了,当然别忘了头文件导入