mac 下移植 x264 使用 neon加速
1.获取x264源码
git clone http://git.videolan.org/git/x264.git
2. 再x264上级目录创建build_x264.sh
sudo chmod 777 build_x264.sh
3.更改build_x264.sh的内容
#!/bin/sh
CONFIGURE_FLAGS="--enable-static --enable-pic --disable-cli"
ARCHS="arm64 x86_64 i386 armv7 armv7s"
# directories
SOURCE="x264"
FAT="x264-iOS"
SCRATCH="scratch-x264"
# must be an absolute path
THIN=/Users/chenglong/Documents/x264-ios-master/"thin-x264"
# the one included in x264 does not work; specify full path to working one
GAS_PREPROCESSOR=/usr/local/bin/gas-preprocessor.pl
COMPILE="y"
LIPO="y"
if [ "$*" ]
then
if [ "$*" = "lipo" ]
then
# skip compile
COMPILE=
else
ARCHS="$*"
if [ $# -eq 1 ]
then
# skip lipo
LIPO=
fi
fi
fi
if [ "$COMPILE" ]
then
CWD=/Users/chenglong/Documents/x264-ios-master
for ARCH in $ARCHS
do
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"
CFLAGS="-arch $ARCH"
ASFLAGS=
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CPU=
if [ "$ARCH" = "x86_64" ]
then
CFLAGS="$CFLAGS -mios-simulator-version-min=7.0"
HOST=
else
CFLAGS="$CFLAGS -mios-simulator-version-min=5.0"
HOST="--host=i386-apple-darwin"
fi
else
PLATFORM="iPhoneOS"
if [ $ARCH = "arm64" ]
then
HOST="--host=aarch64-apple-darwin"
XARCH="-arch aarch64"
else
HOST="--host=arm-apple-darwin"
XARCH="-arch arm"
fi
CFLAGS="$CFLAGS -fembed-bitcode -mios-version-min=7.0"
ASFLAGS="$CFLAGS"
fi
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
if [ $PLATFORM = "iPhoneOS" ]
then
export AS="gas-preprocessor.pl $XARCH -- $CC"
else
export -n AS
fi
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
CC=$CC $CWD/$SOURCE/configure \
$CONFIGURE_FLAGS \
$HOST \
--extra-cflags="$CFLAGS" \
--extra-asflags="$ASFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="$THIN/$ARCH" || exit 1
mkdir extras
ln -s $GAS_PREPROCESSOR extras
make -j3 install || exit 1
cd $CWD
done
fi
if [ "$LIPO" ]
then
echo "building fat binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB
done
cd $CWD
cp -rf $THIN/$1/include $FAT
fi
4. 下载
gas-preprocessor.pl
把gas-preprocessor.pl放到/usr/local/bin/ 目录下
cp gas-preprocessor.pl /usr/local/bin/
platform: AARCH64
byte order: little-endian
system: MACOSX
cli: no
libx264: internal
shared: no
static: yes
asm: yes
interlaced: yes
avs: no
lavf: no
ffms: no
mp4: no
gpl: yes
thread: posix
opencl: yes
filters: crop select_every
lto: no
debug: no
gprof: no
strip: no
PIC: yes
bit depth: 8
chroma format: all
从上边可以看出来开启asm加速,开启多线程加速
6. 最终会再x264-iOS 文件夹打包好的lib
7.放到工程里边输出信息
[libx264 @ 0x1408b9400] using cpu capabilities: ARMv8 NEON
[libx264 @ 0x1408b9400] profile High, level 3.0
说x264再ios能够正常的跑