您的位置:首页 > 移动开发 > IOS开发

mac系统编译 ffmpeg ios 静态库

2017-01-12 18:29 549 查看
1、源码下载

ffmpeg 源码:

https://ffmpeg.org/download.html#releases

gas-preprocessor 工具 (编译脚本会自己下载)

https://github.com/yuvi/gas-preprocessor

ffmpeg ios 编译脚本:

https://github.com/kewlbear/FFmpeg-iOS-build-script

2、编译

修改 编译脚本

如果系统里面缺工具,脚本会自动进行下载

#!/bin/sh

# directories
SOURCE="ffmpeg"
FAT="FFmpeg-iOS"

SCRATCH="scratch"
# must be an absolute path
THIN=`pwd`/"thin"

# absolute path to x264 library
#X264=`pwd`/fat-x264

#FDK_AAC=`pwd`/../fdk-aac-build-script-for-iOS/fdk-aac-ios #--disable-yasm

CONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs \
--disable-doc --enable-pic "

if [ "$X264" ]
then
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
fi

if [ "$FDK_AAC" ]
then
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-libfdk-aac"
fi

# avresample
#CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"

ARCHS="arm64 armv7 armv7s x86_64 i386"

COMPILE="y"
LIPO="y"

DEPLOYMENT_TARGET="6.0"

if [ "$*" ]
then
if [ "$*" = "lipo" ]
then
# skip compile
COMPILE=
else
ARCHS="$*"
if [ $# -eq 1 ]
then
# skip lipo
LIPO=
fi
fi
fi

if [ "$COMPILE" ]
then
if [ ! `which yasm` ]
then
echo 'Yasm not found'
if [ ! `which brew` ]
then
echo 'Homebrew not found. Trying to install...'
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \
|| exit 1
fi
echo 'Trying to install Yasm...'
brew install yasm || exit 1
fi
if [ ! `which gas-preprocessor.pl` ]
then
echo 'gas-preprocessor.pl not found. Trying to install...'
(curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
-o /usr/local/bin/gas-preprocessor.pl \
&& chmod +x /usr/local/bin/gas-preprocessor.pl) \
|| exit 1
fi

if [ ! -r $SOURCE ]
then
echo 'FFmpeg source not found. Trying to download...'
curl http://www.ffmpeg.org/releases/$SOURCE.tar.bz2 | tar xj \
|| exit 1
fi

CWD=`pwd`
for ARCH in $ARCHS
do
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"

CFLAGS="-arch $ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"
else
PLATFORM="iPhoneOS"
CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET -fembed-bitcode"
if [ "$ARCH" = "arm64" ]
4000
then
EXPORT="GASPP_FIX_XCODE5=1"
fi
fi

XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
if [ "$X264" ]
then
CFLAGS="$CFLAGS -I$X264/include"
LDFLAGS="$LDFLAGS -L$X264/lib"
fi
if [ "$FDK_AAC" ]
then
CFLAGS="$CFLAGS -I$FDK_AAC/include"
LDFLAGS="$LDFLAGS -L$FDK_AAC/lib"
fi

TMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \
--target-os=darwin \
--arch=$ARCH \
--cc="$CC" \
$CONFIGURE_FLAGS \
--extra-cflags="$CFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="$THIN/$ARCH" \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-iconv \
--disable-bzlib \
--enable-avresample \
--enable-avresample  \
--enable-pic	\
--disable-doc	\
--disable-decoders \
--enable-decoder=h264 \
--disable-encoders \
--disable-demuxers \
--enable-demuxer=avi \
--disable-muxers \
--enable-muxer=avi \
--disable-filters \
|| exit 1

make -j3 install $EXPORT || 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
echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
done

cd $CWD
cp -rf $THIN/$1/include $FAT
fi

echo Done


把ffmpeg源码解压到当前文件夹,文件夹名字修改为ffmpeg

编译程序:

./build-ffmpeg.sh

编译成功后,可以在FFmpeg-iOS目录下面看到 include lib 文件

ternencedeMac-mini:lib ternence$ lipo -info libavcodec.a

Architectures in the fat file: libavcodec.a are: armv7 armv7s i386 x86_64 arm64

我们这里编译 armv7 armv7s i386 x86_64 arm64 这几个平台的库出来了

大家可以根据需要自由的进行裁剪和修改

3、编译库文件

我编译了ffmpeg-2.0.2.tar.bz2 ffmpeg-3.2.2.tar.bz2

源码和编译后的库文件大家可以到下面的路径进行下载:

源码:链接:http://pan.baidu.com/s/1qYARLBu 密码:hsnc

编译出来的库文件:链接:http://pan.baidu.com/s/1sljf1b3 密码:drkm

修改后的编译脚本:链接:http://pan.baidu.com/s/1jHGn5A2 密码:ss71
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: