美文网首页iOS学习
FFmpeg 一: 编译库脚本

FFmpeg 一: 编译库脚本

作者: 皮皮强 | 来源:发表于2017-11-21 10:59 被阅读10次

1. 首先去FFmpeg官网下载FFmpeg库: 当前我下载的版本是:ffmpeg-3.4

https://www.ffmpeg.org/

2. 下载后解压文件夹为: 解压后的文件夹如图: ffmpeg-3.4

2.1. 将 ffmpeg-3.4 文件夹放到某个文件夹里面: 例如我自己放在 clark-ffmpeg-iOS  文件夹下面:(文件夹名字不能有空格)

2.2. 将 gas-preprocessor.pl 文件也复制到 clark-ffmpeg-iOS  文件夹下面

2.3. 重点就是 ffmpeg-build.sh 编译ffmpeg 库的脚本了, 下面主要讲解这个文件内容

3. 打开 ffmpeg-build.sh 脚本文件如图:

4. 直接复制如下脚本用:

#!/bin/bash

source="ffmpeg-3.4"

cache="cache"

staticdir=`pwd`/"clark-ffmpeg-iOS"

configure_flags="--enable-cross-compile --disable-debug --disable-programs --disable-doc --enable-pic"

archs="arm64 armv7 x86_64 i386"

targetversion="7.0"

if [ "$*" ]

then

archs="$*"

fi

if [ ! `which yasm`  ]

then

if [ ! `which brew` ]

then

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" || exit 1

fi

brew install yasm || exit 1

fi

currentdir=`pwd`

for arch in $archs

do

mkdir -p "$cache/$arch"

cd "$cache/$arch"

archflags="-arch $arch"

if [ "$arch" = "i386" -o "$arch" = "x86_64" ]

then

platform="iPhoneSimulator"

archflags="$archflags -mios-simulator-version-min=$targetversion"

else

platform="iPhoneOS"

archflags="$archflags -mios-version-min=$targetversion -fembed-bitcode"

if [ "$arch" = "arm64" ]

then

EXPORT="GASPP_FIX_XCODE5=1"

fi

fi

XCRUN_SDK=`echo $platform | tr '[:upper:]' '[:lower:]'`

CC="xcrun -sdk $XCRUN_SDK clang"

if [ "$arch" = "arm64" ]

then

AS="gas-preprocessor.pl -arch aarch64 -- $CC"

else

AS="$CC"

fi

TMPDIR=${TMPDIR/%\/} $currentdir/$source/configure \

--target-os=darwin \

--arch=$arch \

--cc="$CC" \

--as="$AS" \

$configure_flags \

--extra-cflags="$archflags" \

--extra-ldflags="$archflags" \

--prefix="$staticdir/$arch" \

|| exit 1

make -j3 install $EXPORT || exit 1

cd $currentdir

done

5. 运行脚本,指定 arm64 架构,也可以生成其它的架构,用lipo 命令合并也可以:

6. 等一会....就开始编译库了, 生成完如图:

7. 搞定,拖include/lib 到工程中配置一下就可以使用了。

相关文章

网友评论

    本文标题:FFmpeg 一: 编译库脚本

    本文链接:https://www.haomeiwen.com/subject/wqpivxtx.html