實戰x264,ffmpeg庫編譯
之前都是看別人的,轉載別人的,今天終於要自己親自操刀啦。哎。
廢話少說,入正題
我的環境:
xcode 6.1 sdk6.1
真機armv7 和 i386
X264 最新的
ffmpeg 1.2.1
一,x264庫的編譯
我是在根目錄下新建H264目錄,解壓後的程式碼放入H264目錄。然後開啟終端
cd H264 然後
i386 下命令
CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc ./configure --host=i386
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
後回車,正常情況是如下:
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庫的編譯
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
INSTALLinstall-progs-yes
INSTALLffprobe
INSTALLpresets/libvpx-1080p.ffpreset
INSTALLpresets/libvpx-1080p50_60.ffpreset
INSTALLpresets/libvpx-360p.ffpreset
INSTALLpresets/libvpx-720p.ffpreset
INSTALLpresets/libvpx-720p50_60.ffpreset
INSTALLpresets/libx264-ipod320.ffpreset
INSTALLpresets/libx264-ipod640.ffpreset
INSTALLdoc/ffprobe.xsd
INSTALLdoc/examples/decoding_encoding.c
INSTALLdoc/examples/demuxing.c
INSTALLdoc/examples/filtering_audio.c
INSTALLdoc/examples/filtering_video.c
INSTALLdoc/examples/metadata.c
INSTALLdoc/examples/muxing.c
INSTALLdoc/examples/resampling_audio.c
INSTALLdoc/examples/scaling_video.c
INSTALLdoc/examples/Makefile
INSTALLdoc/examples/README
INSTALLpresets/libvpx-1080p.ffpreset
INSTALLpresets/libvpx-1080p50_60.ffpreset
INSTALLpresets/libvpx-360p.ffpreset
INSTALLpresets/libvpx-720p.ffpreset
INSTALLpresets/libvpx-720p50_60.ffpreset
INSTALLpresets/libx264-ipod320.ffpreset
INSTALLpresets/libx264-ipod640.ffpreset
INSTALLdoc/ffprobe.xsd
INSTALLdoc/examples/decoding_encoding.c
INSTALLdoc/examples/demuxing.c
INSTALLdoc/examples/filtering_audio.c
INSTALLdoc/examples/filtering_video.c
INSTALLdoc/examples/metadata.c
INSTALLdoc/examples/muxing.c
INSTALLdoc/examples/resampling_audio.c
INSTALLdoc/examples/scaling_video.c
INSTALLdoc/examples/Makefile
INSTALLdoc/examples/README
INSTALLlibavdevice/libavdevice.a
INSTALLlibavformat/libavformat.a
INSTALLlibavcodec/libavcodec.a
ranlib: file: /usr/local/lib/libavcodec.a(iff.o) has no symbols
INSTALLlibpostproc/libpostproc.a
INSTALLlibswresample/libswresample.a
INSTALLlibswscale/libswscale.a
INSTALLlibavutil/libavutil.a
INSTALLlibavdevice/avdevice.h
INSTALLlibavdevice/version.h
INSTALLlibavdevice/libavdevice.pc
INSTALLlibavformat/avformat.h
INSTALLlibavformat/avio.h
INSTALLlibavformat/version.h
INSTALLlibavformat/libavformat.pc
INSTALLlibavcodec/avcodec.h
INSTALLlibavcodec/avfft.h
INSTALLlibavcodec/dxva2.h
INSTALLlibavcodec/old_codec_ids.h
INSTALLlibavcodec/vaapi.h
INSTALLlibavcodec/vda.h
INSTALLlibavcodec/vdpau.h
INSTALLlibavcodec/version.h
INSTALLlibavcodec/xvmc.h
INSTALLlibavcodec/libavcodec.pc
INSTALLlibpostproc/postprocess.h
INSTALLlibpostproc/version.h
INSTALLlibpostproc/libpostproc.pc
INSTALLlibswresample/swresample.h
INSTALLlibswresample/version.h
INSTALLlibswresample/libswresample.pc
INSTALLlibswscale/swscale.h
INSTALLlibswscale/version.h
INSTALLlibswscale/libswscale.pc
INSTALLlibavutil/adler32.h
INSTALLlibavutil/aes.h
INSTALLlibavutil/attributes.h
INSTALLlibavutil/audio_fifo.h
INSTALLlibavutil/audioconvert.h
INSTALLlibavutil/avassert.h
INSTALLlibavutil/avstring.h
INSTALLlibavutil/avutil.h
INSTALLlibavutil/base64.h
INSTALLlibavutil/blowfish.h
INSTALLlibavutil/bprint.h
INSTALLlibavutil/bswap.h
INSTALLlibavutil/channel_layout.h
INSTALLlibavutil/common.h
INSTALLlibavutil/cpu.h
INSTALLlibavutil/crc.h
INSTALLlibavutil/error.h
INSTALLlibavutil/eval.h
INSTALLlibavutil/fifo.h
INSTALLlibavutil/file.h
INSTALLlibavutil/hmac.h
INSTALLlibavutil/imgutils.h
INSTALLlibavutil/intfloat.h
INSTALLlibavutil/intfloat_readwrite.h
INSTALLlibavutil/intreadwrite.h
INSTALLlibavutil/lfg.h
INSTALLlibavutil/log.h
INSTALLlibavutil/mathematics.h
INSTALLlibavutil/md5.h
INSTALLlibavutil/mem.h
INSTALLlibavutil/dict.h
INSTALLlibavutil/old_pix_fmts.h
INSTALLlibavutil/opt.h
INSTALLlibavutil/parseutils.h
INSTALLlibavutil/pixdesc.h
INSTALLlibavutil/pixfmt.h
INSTALLlibavutil/random_seed.h
INSTALLlibavutil/rational.h
INSTALLlibavutil/samplefmt.h
INSTALLlibavutil/sha.h
INSTALLlibavutil/time.h
INSTALLlibavutil/timecode.h
INSTALLlibavutil/timestamp.h
INSTALLlibavutil/version.h
INSTALLlibavutil/xtea.h
INSTALLlibavutil/lzo.h
INSTALLlibavutil/avconfig.h
INSTALLlibavutil/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的編碼器的.
都編譯好了以後,找到生成的幾個庫檔案,將其新增到專案裡面就可以使用了,當然別忘了標頭檔案匯入