├── .gitignore ├── README.md └── build-x264.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | .DS_store 32 | 33 | x264-snapshot-20140930-2245/ 34 | x264 35 | scratch-x264/ 36 | thin-x264/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # x264 iOS build script 2 | 3 | **My blog: [http://depthlove.github.io/](http://depthlove.github.io/)** 4 | 5 | This is a shell script to build x264 for iOS apps. 6 | 7 | Tested with: 8 | 9 | * x264-snapshot-20140914-2245 10 | * Xcode 6.4 11 | 12 | ## Requirements 13 | 14 | * https://github.com/libav/gas-preprocessor 15 | 16 | ## Usage 17 | 18 | * To build everything: 19 | 20 | ./build-x264.sh 21 | 22 | * To build for arm64: 23 | 24 | ./build-x264.sh arm64 25 | 26 | * To build fat library for armv7 and x86_64 (64-bit simulator): 27 | 28 | ./build-x264.sh armv7 x86_64 29 | 30 | * To build fat library from separately built thin libraries: 31 | 32 | ./build-x264.sh lipo 33 | 34 | #### About x264 encode video streaming to h264, you can watch my paper [http://depthlove.github.io/2015/09/17/use-x264-encode-iOS-camera-video-to-h264/](http://depthlove.github.io/2015/09/17/use-x264-encode-iOS-camera-video-to-h264/) 35 | 36 | ##### 关于x264编码视频流为h264的内容,可以参看我的文章:[http://depthlove.github.io/2015/09/17/use-x264-encode-iOS-camera-video-to-h264/](http://depthlove.github.io/2015/09/17/use-x264-encode-iOS-camera-video-to-h264/) 37 | 38 | --- 39 | 40 | ##### If you want to know more things, you can view my github blog: [http://depthlove.github.io/](http://depthlove.github.io/). 41 | 42 | ##### 更多内容可参看我的github博客:[http://depthlove.github.io/](http://depthlove.github.io/) 43 | -------------------------------------------------------------------------------- /build-x264.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CONFIGURE_FLAGS="--enable-static --enable-pic --disable-cli" 4 | 5 | # sunminmin blog: http://depthlove.github.io/ 6 | # modified by sunminmin, 2015/09/07 7 | ARCHS="arm64 armv7s armv7 x86_64 i386" 8 | 9 | 10 | # directories 11 | SOURCE="x264" 12 | FAT="x264-iOS" 13 | 14 | SCRATCH="scratch-x264" 15 | # must be an absolute path 16 | THIN=`pwd`/"thin-x264" 17 | 18 | # the one included in x264 does not work; specify full path to working one 19 | GAS_PREPROCESSOR=/usr/local/bin/gas-preprocessor.pl 20 | 21 | COMPILE="y" 22 | LIPO="y" 23 | 24 | if [ "$*" ] 25 | then 26 | if [ "$*" = "lipo" ] 27 | then 28 | # skip compile 29 | COMPILE= 30 | else 31 | ARCHS="$*" 32 | if [ $# -eq 1 ] 33 | then 34 | # skip lipo 35 | LIPO= 36 | fi 37 | fi 38 | fi 39 | 40 | if [ "$COMPILE" ] 41 | then 42 | 43 | # begin: added by sunminmin, 2015/09/07 44 | if [ ! -r $GAS_PREPROCESSOR ] 45 | then 46 | echo 'gas-preprocessor.pl not found. Trying to install...' 47 | (curl -L https://github.com/libav/gas-preprocessor/blob/master/gas-preprocessor.pl \ 48 | -o /usr/local/bin/gas-preprocessor.pl \ 49 | && chmod +x /usr/local/bin/gas-preprocessor.pl) \ 50 | || exit 1 51 | fi 52 | 53 | 54 | if [ ! -r $SOURCE ] 55 | then 56 | echo 'x264 source not found. Trying to download...' 57 | curl https://download.videolan.org/pub/x264/snapshots/x264-snapshot-20140930-2245.tar.bz2 | tar xj && ln -s x264-snapshot-20140930-2245 x264 || exit 1 58 | fi 59 | # end: added by sunminmin, 2015/09/07 60 | 61 | CWD=`pwd` 62 | for ARCH in $ARCHS 63 | do 64 | echo "building $ARCH..." 65 | mkdir -p "$SCRATCH/$ARCH" 66 | cd "$SCRATCH/$ARCH" 67 | 68 | CFLAGS="-arch $ARCH" 69 | ASFLAGS= 70 | 71 | if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ] 72 | then 73 | PLATFORM="iPhoneSimulator" 74 | CPU= 75 | if [ "$ARCH" = "x86_64" ] 76 | then 77 | CFLAGS="$CFLAGS -mios-simulator-version-min=7.0" 78 | HOST= 79 | else 80 | CFLAGS="$CFLAGS -mios-simulator-version-min=5.0" 81 | HOST="--host=i386-apple-darwin" 82 | fi 83 | else 84 | PLATFORM="iPhoneOS" 85 | if [ $ARCH = "arm64" ] 86 | then 87 | HOST="--host=aarch64-apple-darwin" 88 | XARCH="-arch aarch64" 89 | else 90 | HOST="--host=arm-apple-darwin" 91 | XARCH="-arch arm" 92 | fi 93 | 94 | CFLAGS="$CFLAGS -fembed-bitcode -mios-version-min=7.0" 95 | ASFLAGS="$CFLAGS" 96 | fi 97 | 98 | XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'` 99 | CC="xcrun -sdk $XCRUN_SDK clang" 100 | if [ $PLATFORM = "iPhoneOS" ] 101 | then 102 | export AS="$GAS_PREPROCESSOR $XARCH -- $CC" 103 | else 104 | export -n AS 105 | fi 106 | 107 | CXXFLAGS="$CFLAGS" 108 | LDFLAGS="$CFLAGS" 109 | 110 | CC=$CC $CWD/$SOURCE/configure \ 111 | $CONFIGURE_FLAGS \ 112 | $HOST \ 113 | --extra-cflags="$CFLAGS" \ 114 | --extra-asflags="$ASFLAGS" \ 115 | --extra-ldflags="$LDFLAGS" \ 116 | --prefix="$THIN/$ARCH" 117 | 118 | make -j3 install 119 | cd $CWD 120 | done 121 | fi 122 | 123 | if [ "$LIPO" ] 124 | then 125 | echo "building fat binaries..." 126 | mkdir -p $FAT/lib 127 | set - $ARCHS 128 | CWD=`pwd` 129 | cd $THIN/$1/lib 130 | for LIB in *.a 131 | do 132 | cd $CWD 133 | lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 134 | done 135 | 136 | cd $CWD 137 | cp -rf $THIN/$1/include $FAT 138 | fi 139 | 140 | # begin: added by sunminmin, 2015/09/07 141 | echo "copy config.h to ..." 142 | for ARCH in $ARCHS 143 | do 144 | cd $CWD 145 | echo "copy $SCRATCH/$ARCH/config.h to $THIN/$ARCH/$include" 146 | cp -rf $SCRATCH/$ARCH/config.h $THIN/$ARCH/$include || exit 1 147 | done 148 | 149 | echo "building success!" 150 | # end: added by sunminmin, 2015/09/07 151 | 152 | echo Done 153 | 154 | 155 | --------------------------------------------------------------------------------